city.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="container">
  3. <TopBar id="topbar" :icon="type==='edit'?'back':''"></TopBar>
  4. <view class="line-bar flex-between" id="linebar" v-if="type==='add'">
  5. <view class="span active"></view>
  6. <view class="span active"></view>
  7. <view class="span active"></view>
  8. <view class="span active"></view>
  9. <view class="span"></view>
  10. </view>
  11. <view class="title font44 fw600" id='title'>
  12. 选择你常驻的城市
  13. </view>
  14. <view class="tip font28 fw400" id="tip">
  15. 选择你居住的、经常去的城市,以便推荐异性朋友
  16. </view>
  17. <view class="choose-list flex-start" id="chooselist">
  18. <view class="choose-tag flex-center" v-for="(item,index) in chooseCitys" :key="index">
  19. <text class="tag-text font28 fw600">{{item}}</text>
  20. <image :src="`${assetsUrl}info-figure-close.png`" mode="aspectFill" class="tag-img" @click="deleteTag(index)"></image>
  21. </view>
  22. </view>
  23. <scroll-view scroll-y="true" class="citys" :style="{'height':`${scollHeight}px`}">
  24. <view class="city-tags" v-for="(item,index) in cityList" :key="index">
  25. <view class="c-label font28 fw700">
  26. {{item.name}}
  27. </view>
  28. <view class="c-tags flex-start">
  29. <view class="c-tag font28 fw400" :class="sitem.choose?'tag-choose':''" v-for="(sitem,sindex) in item.data" :key="sindex" @click="chooseTag(index,sindex)">
  30. {{sitem.name}}
  31. </view>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. <cover-view class="btn font32 fw600" @click="sure">
  36. {{type==='add'?'下一步':'完成'}}
  37. </cover-view>
  38. </view>
  39. </template>
  40. <script>
  41. import TopBar from '@/components/TopBar/TopBar.vue';
  42. export default {
  43. components:{TopBar},
  44. data() {
  45. return {
  46. type:'add',
  47. assetsUrl:this.$util.assetsUrl,
  48. chooseCitys:[],
  49. cityList:[],
  50. scollHeight:0,
  51. saveOption:{
  52. cities:[],
  53. completeUser:null,
  54. }
  55. };
  56. },
  57. onLoad(option) {
  58. console.log(option)
  59. if(option.type==='edit'){
  60. this.type="edit";
  61. let pages = getCurrentPages();
  62. let prevPage = pages[pages.length - 2];
  63. this.chooseCitys=prevPage.$vm.myCitys;
  64. console.log(this.chooseCitys)
  65. }
  66. this.computedScollviewHeight();
  67. this.getHotCitys()
  68. },
  69. methods:{
  70. computedScollviewHeight(){
  71. let query = uni.createSelectorQuery();
  72. let heightLeaf=0;
  73. let str=this.type==='add'?'#topbar,#linebar,#title,#tip,#chooselist':'#topbar,#title,#tip,#chooselist'
  74. query.selectAll(str).boundingClientRect(data => {
  75. data.forEach(item=>{
  76. heightLeaf+=item.height;
  77. })
  78. }).exec(()=>{
  79. let sysInfo=uni.getSystemInfoSync();
  80. this.scollHeight=sysInfo.windowHeight-heightLeaf-(this.type==='add'?160:145);
  81. console.log(this.scollHeight)
  82. });
  83. },
  84. sure(){
  85. if(this.type==='add'){
  86. if(this.chooseCitys.length===0){
  87. uni.showToast({
  88. title:'请选择常驻城市',
  89. icon:'none'
  90. })
  91. return;
  92. }
  93. for(let i=0;i<this.chooseCitys.length;i++){
  94. this.saveOption.cities.push(`${this.chooseCitys[i]}`);
  95. }
  96. this.saveOption.completeUser=JSON.parse(uni.getStorageSync('user'));
  97. uni.showLoading({
  98. title:'保存中',
  99. mask:true
  100. })
  101. this.$api.login.saveCity(this.saveOption).then(res=>{
  102. if(res.data.succ){
  103. uni.setStorageSync('regStep','WxInfo');
  104. uni.hideLoading();
  105. uni.reLaunch({
  106. url:`/pages/info/wechat`
  107. })
  108. }
  109. })
  110. }else{
  111. let pages = getCurrentPages();
  112. let prevPage = pages[pages.length - 2];
  113. let arr=[];
  114. for(let i=0;i<this.chooseCitys.length;i++){
  115. arr.push(`${this.chooseCitys[i]}`);
  116. }
  117. console.log(arr)
  118. prevPage.$vm.myCitys=arr;
  119. uni.navigateBack({
  120. delta:1
  121. })
  122. }
  123. },
  124. deleteTag(index){
  125. this.chooseCitys.splice(index,1);
  126. setTimeout(()=>{
  127. this.computedScollviewHeight();
  128. },10)
  129. },
  130. chooseTag(index,sindex){
  131. if(this.chooseCitys.length>5){return;}
  132. this.cityList[index].data[sindex].choose=!this.cityList[index].data[sindex].choose;
  133. if(this.cityList[index].data[sindex].choose&&!this.chooseCitys.includes(this.cityList[index].data[sindex].name)){
  134. this.chooseCitys.push(this.cityList[index].data[sindex].name)
  135. }
  136. setTimeout(()=>{
  137. this.computedScollviewHeight();
  138. },10)
  139. setTimeout(()=>{
  140. this.cityList[index].data[sindex].choose=false;
  141. },500)
  142. },
  143. getHotCitys(){
  144. let arr=[],obj={name:'',code:'',data:[]},obj1={name:'',code:'',choose:false}
  145. this.$api.login.popularCities({}).then(res=>{
  146. for(let i=0;i<res.data.cities.length;i++){
  147. obj={name:'',code:'',data:[]};
  148. obj.name=res.data.cities[i].n;
  149. obj.code=res.data.cities[i].c;
  150. for(let j=0;j<res.data.cities[i].cities.length;j++){
  151. obj1={name:'',code:'',choose:false}
  152. obj1.name=res.data.cities[i].cities[j].split('#')[1];
  153. obj1.code=res.data.cities[i].cities[j].split('#')[0];
  154. obj.data.push(obj1);
  155. }
  156. arr.push(obj)
  157. }
  158. this.cityList=arr;
  159. })
  160. },
  161. bindClick(e){
  162. console.log(e)
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .container{
  169. width: 100vw;
  170. min-height: 100vh;
  171. background-color: $bgcolor1;
  172. .line-bar{
  173. margin: 0 60rpx;
  174. margin-top: 30rpx;
  175. .span{
  176. width: 120rpx;
  177. height: 8rpx;
  178. border-radius: 4rpx 0rpx 0rpx 4rpx;
  179. background-color: $bgcolor4;
  180. }
  181. .active{
  182. background-color: $primary;
  183. }
  184. }
  185. .title{
  186. color: $fontcolor5;
  187. padding-left: 60rpx;
  188. margin-top: 108rpx;
  189. }
  190. .tip{
  191. color: $fontcolor3;
  192. padding-left: 60rpx;
  193. margin-top: 8rpx;
  194. }
  195. .choose-list{
  196. padding: 72rpx 60rpx 8rpx 60rpx;
  197. flex-wrap: wrap;
  198. .choose-tag{
  199. background-color: $bgcolor4;
  200. border-radius: 38rpx;
  201. padding: 0 20rpx;
  202. height: 72rpx;
  203. margin-right: 32rpx;
  204. margin-bottom: 32rpx;
  205. .tag-text{
  206. color: $fontcolor4;
  207. text-align: center;
  208. line-height: 72rpx;
  209. }
  210. .tag-img{
  211. width: 24rpx;
  212. height: 24rpx;
  213. padding-left: 16rpx;
  214. }
  215. }
  216. }
  217. .citys{
  218. height: 700rpx;
  219. padding: 0 60rpx;
  220. box-sizing: border-box;
  221. .city-tags{
  222. .c-label{
  223. color: $fontcolor3;
  224. margin-bottom: 24rpx;
  225. margin-top: 16rpx;
  226. }
  227. .c-tags{
  228. flex-wrap: wrap;
  229. .c-tag{
  230. background-color: $bgcolor3;
  231. color: $fontcolor3;
  232. padding: 0 20rpx;
  233. height: 72rpx;
  234. line-height: 72rpx;
  235. text-align: center;
  236. border-radius: 38rpx;
  237. margin-right: 24rpx;
  238. margin-bottom: 24rpx;
  239. transition: all .3s;
  240. }
  241. }
  242. .tag-choose{
  243. background: $primary !important;
  244. color: $fontcolor5 !important;
  245. }
  246. }
  247. }
  248. .btn{
  249. position: fixed;
  250. z-index: 999;
  251. left: 0;
  252. right: 0;
  253. bottom: 44rpx;
  254. margin: auto;
  255. width: 630rpx;
  256. height: 104rpx;
  257. border-radius: 52rpx;
  258. background-color: $primary;
  259. color: $fontcolor5;
  260. text-align: center;
  261. line-height: 104rpx;
  262. }
  263. }
  264. </style>