selectCity.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <view>
  3. <u-navbar :title="title" @leftClick='back' :placeholder='true'>
  4. </u-navbar>
  5. <view class="row1">
  6. <view class="start-place" :class="type==0?'active1':''" @click="changeCity(0)">选择发货地</view>
  7. <view class="end-place" :class="type==1?'active1':''" @click="changeCity(1)">选择收货地</view>
  8. </view>
  9. <view class="container">
  10. <view class="row2">
  11. <view class="content1" v-if="type==0">
  12. <view class="history-city-title">历史发货地</view>
  13. <view class="city-list">
  14. <view class="city" v-for="(item,index) in historyFcityList" :key='index'>
  15. {{item}}
  16. </view>
  17. </view>
  18. </view>
  19. <view class="content2" v-if="type==1">
  20. <view class="history-city-title">历史收货地</view>
  21. <view class="city-list">
  22. <view class="city" v-for="(item,index) in historyScityList" :key='index'>
  23. {{item}}
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="page">
  30. <view class="title flex flex-space-between">
  31. <view class="flex nav-bag-left">
  32. <view class="flex" :class="(type==0?fstatus:sstatus)==0?'select-active':''" @click="titleClick(0)">
  33. <view class="tt point">{{type==0?fchooseprovince:schooseprovince}}</view>
  34. <view v-if="type==0?fchooseprovince:schooseprovince" style="margin: 0 10rpx;">></view>
  35. </view>
  36. <view class="flex" v-if="(type==0?fchooseprovince:schooseprovince)!='选择'"
  37. :class="(type==0?fstatus:sstatus)==1?'select-active':''" @click="titleClick(1)">
  38. <view class="tt point nav-point">{{type==0?fchoosecity:schoosecity}}</view>
  39. <view v-if="type==0?fchoosecity:schoosecity" style="margin: 0 10rpx;">></view>
  40. </view>
  41. <view class="tt area"
  42. v-if="(type==0?fchooseprovince:schooseprovince)!='选择'&&(type==0?fchoosecity:schoosecity)!='请选择市'&&(type==0?fchoosecity:schoosecity)!='全部'"
  43. :class="(type==0?fstatus:sstatus)==2?'select-active':''" @click="titleClick(2)">
  44. {{type==0?fchoosearea:schoosearea}}
  45. </view>
  46. </view>
  47. <view class="back-level" v-if="(type==0?fstatus:sstatus)!=0" @click="backLevel">返回上一级</view>
  48. </view>
  49. <view class="link">
  50. <!-- 省 -->
  51. <view class="container" v-if="(type==0?fstatus:sstatus)==0">
  52. <view class="content-item" :class="index ==(type==0?isfprovince:issprovince) ?'active':''"
  53. @click="selectProvince(item, index,(type==0?fstatus:sstatus))"
  54. v-for="(item,index) in (type==0?fprovincelist:sprovincelist)" :key="index">
  55. {{item.label}}
  56. </view>
  57. </view>
  58. <!-- 市 -->
  59. <view class="container" v-if="(type==0?fstatus:sstatus)==1">
  60. <view class="content-item" :class="index == (type==0?isfcity:isscity)?'active':''"
  61. @click="selectCity(item, index,type==0?fstatus:sstatus)"
  62. v-for="(item,index) in (type==0?fcitylist:scitylist)" :key="index">
  63. {{item.label}}
  64. </view>
  65. </view>
  66. <!-- index ==(type==0?isfarea:issarea) -->
  67. <!-- 区 -->
  68. <view class="container" v-if="(type==0?fstatus:sstatus)==2">
  69. <view class="content-item" :class="item.checked?'active':''"
  70. @click="selectaArea(item, index,(type==0?fstatus:sstatus))"
  71. v-for="(item,index) in (type==0?farealist:sarealist)" :key="index">
  72. {{item.label}}
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <u-button class="btn" @click="confirmBtn">确定</u-button>
  78. <u-toast ref="uToast"></u-toast>
  79. </view>
  80. </template>
  81. <script>
  82. import {
  83. address
  84. } from '@/components/data/data.js'
  85. export default {
  86. data() {
  87. return {
  88. fstatus: 0,
  89. sstatus: 0,
  90. isfprovince: null,
  91. isfcity: null,
  92. isfarea: null,
  93. issprovince: null,
  94. isscity: null,
  95. issarea: null,
  96. fprovincelist: [],
  97. sprovincelist: [],
  98. fcitylist: [],
  99. scitylist: [],
  100. farealist: [],
  101. sarealist: [],
  102. fchooseprovince: '选择',
  103. fchoosecity: '请选择市',
  104. fchoosearea: '请选择区',
  105. schooseprovince: '选择',
  106. schoosecity: '请选择市',
  107. schoosearea: '请选择区',
  108. heightCot: 0,
  109. historyFcityList: [],
  110. historyScityList: [],
  111. title: '',
  112. type: 0,
  113. count: 0,
  114. ftitle: '',
  115. stitle: '',
  116. }
  117. },
  118. created() {
  119. this.fprovincelist = address
  120. this.sprovincelist = address
  121. console.log('---------------------------------')
  122. console.log(this.type)
  123. },
  124. onLoad(options) {
  125. console.log(options)
  126. this.type = options.type
  127. this.title = options.startPlace + '→' + options.endPlace
  128. },
  129. methods: {
  130. confirmBtn() {
  131. debugger
  132. //判断是否点击了选项
  133. if (this.fchooseprovince == '选择') {
  134. this.$refs.uToast.show({
  135. type: 'error',
  136. message: "请选择省或直辖市",
  137. })
  138. }
  139. //设置地区
  140. if (this.type == 0) {
  141. // this.fchooseprovince
  142. // this.fchoosecity
  143. // this.fchoosearea
  144. } else {
  145. // schooseprovince
  146. // schoosecity
  147. // schoosearea
  148. }
  149. },
  150. //返回上一级
  151. backLevel() {
  152. // this.count=0;
  153. if (this.type == 0) {
  154. this.fstatus--
  155. } else {
  156. this.sstatus--
  157. }
  158. if ((this.type == 0 ? this.fstatus : this.sstatus) == 1) {
  159. if (this.type == 0) {
  160. this.fchoosecity = '请选择市'
  161. this.fchoosearea = ''
  162. this.ftitle = ''
  163. this.isfcity = null
  164. } else {
  165. this.schoosecity = '请选择市'
  166. this.schoosearea = ''
  167. this.stitle = ''
  168. this.isscity = null
  169. }
  170. } else if ((this.type == 0 ? this.fstatus : this.sstatus) == 0) {
  171. if (this.type == 0) {
  172. this.fchooseprovince = '选择'
  173. this.isfprovince = null
  174. } else {
  175. this.schooseprovince = '选择'
  176. this.issprovince = null
  177. }
  178. }
  179. },
  180. // 点击面包屑导航
  181. titleClick(status) {
  182. debugger
  183. this.ftitle = ''
  184. this.stitle = ''
  185. this.count = 0
  186. if (this.type == 0) {
  187. this.fstatus = status
  188. this.isfprovince = null
  189. this.isfcity = null
  190. this.isfarea = null
  191. if (this.fchoosecity == '全部') return;
  192. } else {
  193. this.sstatus = status
  194. this.issprovince = null
  195. this.isscity = null
  196. this.issarea = null
  197. if (this.fchoosecity == '全部') return;
  198. }
  199. if (status == 0) {
  200. if (this.type == 0) {
  201. this.fchooseprovince = '选择'
  202. this.fchoosecity = '请选择市'
  203. this.fchoosearea = '请选择区'
  204. } else {
  205. this.schooseprovince = '选择'
  206. this.schoosecity = '请选择市'
  207. this.schoosearea = '请选择区'
  208. }
  209. } else if (status == 1) {
  210. if (this.type == 0) {
  211. this.fchoosecity = '请选择市'
  212. this.fchoosearea = '请选择区'
  213. } else {
  214. this.schoosecity = '请选择市'
  215. this.schoosearea = '请选择区'
  216. }
  217. }
  218. },
  219. // 选择省
  220. selectProvince(item, i, statusIndex) {
  221. debugger
  222. this.count = 0;
  223. if (this.type == 0) {
  224. if (i == 0) {
  225. this.$refs.uToast.show({
  226. type: 'error',
  227. message: "发货地不可选择全国!",
  228. })
  229. return
  230. }
  231. this.fchoosecity = '请选择市'
  232. this.fchoosearea = '请选择区'
  233. this.isfprovince = i
  234. } else {
  235. this.schoosecity = '请选择市'
  236. this.schoosearea = '请选择区'
  237. this.issprovince = i
  238. }
  239. if (item.child) {
  240. if (this.type == 0) {
  241. this.fcitylist = item.child
  242. } else {
  243. this.scitylist = item.child
  244. }
  245. }
  246. // this.setchose(1)
  247. if (this.type == 0) {
  248. this.fchooseprovince = item.label
  249. } else {
  250. this.schooseprovince = item.label
  251. }
  252. if ((this.type == 0 ? this.fchoosecity : this.schoosecity) != '全部') {
  253. if (this.type == 0) {
  254. this.fstatus = statusIndex + 1
  255. } else {
  256. this.sstatus = statusIndex + 1
  257. }
  258. }
  259. },
  260. // 选择市
  261. selectCity(item, i, statusIndex) {
  262. this.count = 0;
  263. if (this.type == 0) {
  264. this.isfcity = i
  265. } else {
  266. this.isscity = i
  267. }
  268. if (item.child) {
  269. for (let i = 0; i < item.child.length; i++) {
  270. item.child[i].checked = false
  271. }
  272. if (this.type == 0) {
  273. this.farealist = item.child
  274. } else {
  275. this.sarealist = item.child
  276. }
  277. }
  278. // this.setchose(2)
  279. // if (item.label != '市辖区' && item.label != '特别行政区') {
  280. if (this.type == 0) {
  281. this.fchoosecity = item.label
  282. } else {
  283. this.schoosecity = item.label
  284. }
  285. if ((this.type == 0 ? this.fchoosecity : this.schoosecity) != '全部') {
  286. if (this.type == 0) {
  287. this.fstatus = statusIndex + 1
  288. } else {
  289. this.sstatus = statusIndex + 1
  290. }
  291. }
  292. },
  293. //选择区
  294. selectaArea(item, i) {
  295. debugger
  296. if (item.label == '全部') {
  297. for (let i = 0; i < this.sarealist.length; i++) {
  298. if (i != 0) {
  299. this.sarealist[i].checked = false
  300. }
  301. }
  302. return
  303. }
  304. if (this.count < 3) {
  305. this.$u.toast(item.label)
  306. // if (item.checked) {
  307. // item.checked = !item.checked
  308. // return
  309. // }else{
  310. // // this.count--;
  311. // }
  312. item.checked = !item.checked
  313. if (item.checked && this.count < 3) {
  314. this.count++;
  315. } else if (!item.checked && this.count < 3) {
  316. this.count--;
  317. }
  318. } else {
  319. if (item.checked) {
  320. item.checked = !item.checked
  321. this.count--;
  322. } else {
  323. this.$refs.uToast.show({
  324. type: 'error',
  325. message: "最多选择3个地区",
  326. })
  327. }
  328. }
  329. this.$forceUpdate()
  330. if (this.type == 0) {
  331. if (item.checked && !this.fchoosearea.includes(item.label)) {
  332. if (this.ftitle) {
  333. this.ftitle += ',' + item.label
  334. } else {
  335. this.ftitle += item.label
  336. }
  337. this.fchoosearea = this.ftitle
  338. console.log(this.fchoosearea)
  339. } else {
  340. if (this.ftitle.includes(',' + item.label)) {
  341. this.ftitle = this.ftitle.replace(',' + item.label, '')
  342. this.fchoosearea = this.fchoosearea.replace(',' + item.label, '')
  343. } else {
  344. let _val = this.ftitle.split(',')
  345. let _len = _val.length;
  346. if (_len == 1) {
  347. this.ftitle = this.ftitle.replace(item.label, '')
  348. this.fchoosearea = '请选择区'
  349. } else if (_len > 1) {
  350. this.ftitle = this.ftitle.replace(item.label + ',', '')
  351. this.fchoosearea = this.fchoosearea.replace(item.label + ',', '')
  352. }
  353. }
  354. }
  355. } else {
  356. if (item.checked && !this.schoosearea.includes(item.label)) {
  357. if (this.stitle) {
  358. this.stitle += ',' + item.label
  359. } else {
  360. this.stitle += item.label
  361. }
  362. this.schoosearea = this.stitle
  363. } else {
  364. if (this.stitle.includes(',' + item.label)) {
  365. this.stitle = this.stitle.replace(',' + item.label, '')
  366. this.schoosearea = this.schoosearea.replace(',' + item.label, '')
  367. } else {
  368. let _val = this.stitle.split(',')
  369. let _len = _val.length;
  370. if (_len == 1) {
  371. this.stitle = this.stitle.replace(item.label, '')
  372. this.schoosearea = '请选择区'
  373. } else if (_len > 1) {
  374. this.stitle = this.stitle.replace(item.label + ',', '')
  375. this.schoosearea = this.schoosearea.replace(item.label + ',', '')
  376. }
  377. }
  378. }
  379. }
  380. // this.getchoose()
  381. },
  382. // getchoose() {
  383. // const {
  384. // chooseprovince,
  385. // choosecity,
  386. // choosearea
  387. // } = this
  388. // this.$emit('conceal', {
  389. // chooseprovince,
  390. // choosecity,
  391. // choosearea
  392. // })
  393. // },
  394. // setchose(id) {
  395. // if (id == 1) {
  396. // this.choosecity = ''
  397. // this.choosearea = ''
  398. // if (this.type == 0) {
  399. // this.isfcity = null
  400. // } else {
  401. // this.isscity = null
  402. // }
  403. // if (this.type == 0) {
  404. // this.isfarea = null
  405. // } else {
  406. // this.issarea = null
  407. // }
  408. // } else if (id == 2) {
  409. // this.choosearea = ''
  410. // if (this.type == 0) {
  411. // this.isfarea = null
  412. // } else {
  413. // this.issarea = null
  414. // }
  415. // }
  416. // },
  417. changeCity(type) {
  418. if (type == 0) {
  419. this.type = 0
  420. } else {
  421. this.type = 1
  422. }
  423. },
  424. // conceal1(param) {
  425. // const {
  426. // chooseprovince,
  427. // choosecity,
  428. // choosearea
  429. // } = param
  430. // // 获取到传过来的 省 市 区 县数据
  431. // this.title1 = chooseprovince + choosecity + choosearea
  432. // if (choosecity == '全部') {
  433. // this.succeed()
  434. // } else if (choosearea != '') {
  435. // this.succeed()
  436. // }
  437. // },
  438. //筛选框关闭
  439. // succeed() {
  440. // this.$refs.uDropdown.close();
  441. // },
  442. back() {
  443. uni.navigateBack({
  444. })
  445. },
  446. }
  447. }
  448. </script>
  449. <style lang="scss" scoped>
  450. .row1 {
  451. display: flex;
  452. justify-content: space-evenly;
  453. margin-top: 10rpx;
  454. border-bottom: 1px solid #E6E6E6;
  455. }
  456. .start-place,
  457. .end-place {
  458. font-size: 28rpx;
  459. color: #B1B5C0;
  460. padding-bottom: 20rpx;
  461. }
  462. .active1 {
  463. position: relative;
  464. color: black;
  465. font-size: 32rpx;
  466. font-weight: 700;
  467. display: flex;
  468. justify-content: center;
  469. }
  470. .active1:after {
  471. content: '';
  472. position: absolute;
  473. bottom: 0rpx;
  474. width: 50%;
  475. left: 25%;
  476. padding: 0 20rpx;
  477. box-sizing: border-box;
  478. height: 6rpx;
  479. background: #2772FB;
  480. border-radius: 3px;
  481. }
  482. .history-city-title {
  483. font-size: 28rpx;
  484. font-weight: 700;
  485. color: #363636;
  486. margin-bottom: 20rpx;
  487. }
  488. .container {
  489. padding: 0 20rpx;
  490. }
  491. .content1 {
  492. margin: 20rpx 0;
  493. }
  494. .city-list {
  495. // height: 118rpx;
  496. // overflow: hidden;
  497. }
  498. .city {
  499. display: inline-block;
  500. font-size: 26rpx;
  501. text-align: center;
  502. padding: 8rpx 16rpx;
  503. margin: 0 20rpx 20rpx 0;
  504. height: 33rpx;
  505. line-height: 33rpx;
  506. border-radius: 4rpx;
  507. background: #F7F8FA;
  508. }
  509. .content2 {
  510. margin: 20rpx 0;
  511. }
  512. .container {
  513. padding-left: 20rpx;
  514. }
  515. .select-active,
  516. .back-level {
  517. color: #2772FB;
  518. font-size: 28rpx;
  519. }
  520. .content-item {
  521. background: #F7F8FA;
  522. display: inline-block;
  523. width: calc(25% - 20rpx);
  524. margin: 10rpx 20rpx 10rpx 0;
  525. font-size: 26rpx;
  526. color: #333333;
  527. text-align: center;
  528. padding: 10rpx 0;
  529. border-radius: 10rx;
  530. overflow: hidden;
  531. text-overflow: ellipsis;
  532. white-space: nowrap;
  533. padding: 6rpx 8rpx;
  534. box-sizing: border-box;
  535. }
  536. .title {
  537. margin: 0 20rpx;
  538. }
  539. .active {
  540. background: #E5F0FE;
  541. border-radius: 10rpx;
  542. // border: 1px solid #2772FB;
  543. color: #2772FB;
  544. box-sizing: border-box;
  545. }
  546. .area {
  547. width: 55%;
  548. text-overflow: ellipsis;
  549. white-space: nowrap;
  550. overflow: hidden;
  551. }
  552. .nav-bag-left {
  553. width: 70%;
  554. font-size: 28rpx;
  555. }
  556. .btn {
  557. background: #2772FB;
  558. color: white;
  559. width: 80%;
  560. position: absolute;
  561. bottom: 30rpx;
  562. margin-left: 10%;
  563. border-radius: 50rpx;
  564. }
  565. </style>