city.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="container">
  3. <TopBar id="topbar"></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.name}}</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. }
  65. this.computedScollviewHeight();
  66. this.getHotCitys()
  67. },
  68. methods:{
  69. computedScollviewHeight(){
  70. let query = uni.createSelectorQuery();
  71. let heightLeaf=0;
  72. let str=this.type==='add'?'#topbar,#linebar,#title,#tip,#chooselist':'#topbar,#title,#tip,#chooselist'
  73. query.selectAll(str).boundingClientRect(data => {
  74. data.forEach(item=>{
  75. heightLeaf+=item.height;
  76. })
  77. }).exec(()=>{
  78. let sysInfo=uni.getSystemInfoSync();
  79. this.scollHeight=sysInfo.windowHeight-heightLeaf-(this.type==='add'?160:145);
  80. console.log(this.scollHeight)
  81. });
  82. },
  83. sure(){
  84. if(this.type==='add'){
  85. if(this.chooseCitys.length===0){
  86. uni.showToast({
  87. title:'请选择常驻城市',
  88. icon:'none'
  89. })
  90. return;
  91. }
  92. for(let i=0;i<this.chooseCitys.length;i++){
  93. this.saveOption.cities.push(`${this.chooseCitys[i].name}`);
  94. }
  95. this.saveOption.completeUser=JSON.parse(uni.getStorageSync('user'));
  96. uni.showLoading({
  97. title:'保存中',
  98. mask:true
  99. })
  100. this.$api.login.saveCity(this.saveOption).then(res=>{
  101. if(res.data.succ){
  102. uni.setStorageSync('regStep','WxInfo');
  103. uni.hideLoading();
  104. uni.reLaunch({
  105. url:`/pages/info/wechat`
  106. })
  107. }
  108. })
  109. }else{
  110. let pages = getCurrentPages();
  111. let prevPage = pages[pages.length - 2];
  112. let arr=[];
  113. for(let i=0;i<this.chooseCitys.length;i++){
  114. arr.push(`${this.chooseCitys[i].name}`);
  115. }
  116. console.log(arr)
  117. prevPage.$vm.myCitys=arr;
  118. uni.navigateBack({
  119. delta:1
  120. })
  121. }
  122. },
  123. deleteTag(index){
  124. this.chooseCitys.splice(index,1);
  125. setTimeout(()=>{
  126. this.computedScollviewHeight();
  127. },10)
  128. },
  129. chooseTag(index,sindex){
  130. if(this.chooseCitys.length>5){return;}
  131. this.cityList[index].data[sindex].choose=!this.cityList[index].data[sindex].choose;
  132. if(this.cityList[index].data[sindex].choose&&!this.chooseCitys.includes({name:this.cityList[index].data[sindex].name,code:this.cityList[index].data[sindex].code})){
  133. this.chooseCitys.push({name:this.cityList[index].data[sindex].name,code:this.cityList[index].data[sindex].code})
  134. }
  135. setTimeout(()=>{
  136. this.computedScollviewHeight();
  137. },10)
  138. setTimeout(()=>{
  139. this.cityList[index].data[sindex].choose=false;
  140. },500)
  141. },
  142. getHotCitys(){
  143. let arr=[],obj={name:'',code:'',data:[]},obj1={name:'',code:'',choose:false}
  144. this.$api.login.popularCities({}).then(res=>{
  145. for(let i=0;i<res.data.cities.length;i++){
  146. obj={name:'',code:'',data:[]};
  147. obj.name=res.data.cities[i].n;
  148. obj.code=res.data.cities[i].c;
  149. for(let j=0;j<res.data.cities[i].cities.length;j++){
  150. obj1={name:'',code:'',choose:false}
  151. obj1.name=res.data.cities[i].cities[j].split('#')[1];
  152. obj1.code=res.data.cities[i].cities[j].split('#')[0];
  153. obj.data.push(obj1);
  154. }
  155. arr.push(obj)
  156. }
  157. this.cityList=arr;
  158. })
  159. },
  160. bindClick(e){
  161. console.log(e)
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .container{
  168. width: 100vw;
  169. min-height: 100vh;
  170. background-color: $bgcolor1;
  171. .line-bar{
  172. margin: 0 60rpx;
  173. margin-top: 30rpx;
  174. .span{
  175. width: 120rpx;
  176. height: 8rpx;
  177. border-radius: 4rpx 0rpx 0rpx 4rpx;
  178. background-color: $bgcolor4;
  179. }
  180. .active{
  181. background-color: $primary;
  182. }
  183. }
  184. .title{
  185. color: $fontcolor5;
  186. padding-left: 60rpx;
  187. margin-top: 108rpx;
  188. }
  189. .tip{
  190. color: $fontcolor3;
  191. padding-left: 60rpx;
  192. margin-top: 8rpx;
  193. }
  194. .choose-list{
  195. padding: 72rpx 60rpx 8rpx 60rpx;
  196. flex-wrap: wrap;
  197. .choose-tag{
  198. background-color: $bgcolor4;
  199. border-radius: 38rpx;
  200. padding: 0 20rpx;
  201. height: 72rpx;
  202. margin-right: 32rpx;
  203. margin-bottom: 32rpx;
  204. .tag-text{
  205. color: $fontcolor4;
  206. text-align: center;
  207. line-height: 72rpx;
  208. }
  209. .tag-img{
  210. width: 24rpx;
  211. height: 24rpx;
  212. padding-left: 16rpx;
  213. }
  214. }
  215. }
  216. .citys{
  217. height: 700rpx;
  218. padding: 0 60rpx;
  219. box-sizing: border-box;
  220. .city-tags{
  221. .c-label{
  222. color: $fontcolor3;
  223. margin-bottom: 24rpx;
  224. margin-top: 16rpx;
  225. }
  226. .c-tags{
  227. flex-wrap: wrap;
  228. .c-tag{
  229. background-color: $bgcolor3;
  230. color: $fontcolor3;
  231. padding: 0 20rpx;
  232. height: 72rpx;
  233. line-height: 72rpx;
  234. text-align: center;
  235. border-radius: 38rpx;
  236. margin-right: 24rpx;
  237. margin-bottom: 24rpx;
  238. transition: all .3s;
  239. }
  240. }
  241. .tag-choose{
  242. background: $primary !important;
  243. color: $fontcolor5 !important;
  244. }
  245. }
  246. }
  247. .btn{
  248. position: fixed;
  249. z-index: 999;
  250. left: 0;
  251. right: 0;
  252. bottom: 44rpx;
  253. margin: auto;
  254. width: 630rpx;
  255. height: 104rpx;
  256. border-radius: 52rpx;
  257. background-color: $primary;
  258. color: $fontcolor5;
  259. text-align: center;
  260. line-height: 104rpx;
  261. }
  262. }
  263. </style>