selectCampus.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <template>
  2. <view class="container">
  3. <view class="flex align-center" style="background: #fff">
  4. <view class="content padding-left bg-white" style="color: #333; font-size: 28upx; font-weight: bold" v-if="city">
  5. <text @click="goCity()">
  6. {{ city }}
  7. <text class="cuIcon-right"></text>
  8. </text>
  9. </view>
  10. <view class="padding-tb-sm padding-lr-xs margin-right-xs flex-sub">
  11. <view class="search-bar-form">
  12. <view class="search-bar-box">
  13. <icon class="icon-search-in-box" type="search" size="16"></icon>
  14. <input
  15. confirm-type="search"
  16. class="search-bar-input"
  17. placeholder="输入地址查询"
  18. placeholder-class="phcolor"
  19. :value="inputVal"
  20. :focus="inputShowed"
  21. @input="inputTyping"
  22. />
  23. <view class="icon-clear" v-if="inputVal" @tap="clearInput">
  24. <!-- #ifdef APP-PLUS || MP -->
  25. <icon type="clear" :size="15"></icon>
  26. <!-- #endif -->
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="tui-list search-result" v-if="inputShowed">
  33. <view class="padding margin-lr radius flex justify-between align-center" v-for="(item, index) in searchResult" :key="index" @click="update(item)">
  34. <view>
  35. <view class="text-lg text-bold text-black">{{ item.addressDetail }}</view>
  36. <view class="text-df text-gray margin-top-xs">{{ item.province }}{{ item.city }}{{ item.district }}</view>
  37. </view>
  38. </view>
  39. </view>
  40. <view v-else>
  41. <view class="tui-list city-list" v-if="list && list.length > 0">
  42. <view class="flex justify-between">
  43. <view class="title text-lg text-bold padding-sm padding-top-sm">我的地址</view>
  44. <view style="display: flex; align-items: center; font-size: 26rpx" class="padding-sm padding-top-sm" @tap="goAddressList">
  45. <view>地址管理</view>
  46. <image src="../../static/images/index/right2.png" style="width: 12rpx; height: 20rpx; margin-left: 6rpx"></image>
  47. </view>
  48. </view>
  49. <view
  50. class="padding margin-lr radius flex justify-between align-center"
  51. v-for="(item, index) in list"
  52. :key="index"
  53. v-if="index == 0"
  54. @click="update(item)"
  55. style="border: 2rpx solid #fcd202"
  56. >
  57. <view>
  58. <view class="text-lg text-bold text-black">{{ item.addressDetail }}</view>
  59. <view class="text-df text-gray margin-top-xs">{{ item.province }}{{ item.city }}{{ item.district }}</view>
  60. </view>
  61. <u-icon name="checkbox-mark" color="#FCD202" size="42"></u-icon>
  62. </view>
  63. <view class="padding margin-lr radius flex justify-between align-center" v-for="(item, index) in list" :key="index" v-if="index > 0" @click="update(item)">
  64. <view>
  65. <view class="text-lg text-bold text-black">{{ item.addressDetail }}</view>
  66. <view class="text-df text-gray margin-top-xs">{{ item.province }}{{ item.city }}{{ item.district }}</view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 添加收货地址 -->
  72. <view class="btn">
  73. <view class="address_push" @click="addAddress">添加收货地址</view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. export default {
  79. data() {
  80. return {
  81. region: [],
  82. inputVal: '', // 搜索框输入的内容
  83. inputShowed: false, // 输入框是否显示
  84. list: [],
  85. searchResult: [], // 搜索城市的结果
  86. localCampus: '',
  87. campusDetails: '',
  88. txt: '选择城市',
  89. province: '', //省
  90. city: '', //市
  91. district: '', //区
  92. page: 1,
  93. limit: 10,
  94. totalCount: 0,
  95. longitude: '',
  96. latitude: ''
  97. }
  98. },
  99. onLoad: function (options) {
  100. console.log(options)
  101. if (uni.getStorageSync('city')) {
  102. this.city = uni.getStorageSync('city')
  103. this.longitude = uni.getStorageSync('lng')
  104. this.latitude = uni.getStorageSync('lat')
  105. } else {
  106. this.getlocation()
  107. }
  108. },
  109. onShow() {
  110. if (uni.getStorageSync('userId')) {
  111. this.initCampusList()
  112. }
  113. },
  114. methods: {
  115. goAddressList() {
  116. uni.navigateTo({
  117. url: '/my/address/index'
  118. })
  119. },
  120. update(e) {
  121. // console.log(e)
  122. let data = {
  123. addressId: e.addressId,
  124. addressDefault: 1,
  125. userName: e.userName,
  126. userPhone: e.userPhone,
  127. insideAddressId: e.insideAddressId,
  128. province: e.province,
  129. city: e.city,
  130. district: e.district,
  131. addressDetail: e.addressDetail,
  132. lng: e.lng,
  133. lat: e.lat
  134. }
  135. // console.log(data)
  136. this.$Request.postJson('/app/address/updateAddress', data).then((res) => {
  137. // console.log(res)
  138. if (res.code == 0) {
  139. uni.removeStorageSync('city')
  140. uni.removeStorageSync('lng')
  141. uni.removeStorageSync('lat')
  142. setTimeout(function () {
  143. uni.navigateBack()
  144. }, 10)
  145. }
  146. })
  147. },
  148. goCity() {
  149. let that = this
  150. uni.chooseLocation({
  151. success: function (res) {
  152. console.log(res, '选择')
  153. that.longitude = res.longitude
  154. that.latitude = res.latitude
  155. that.city = res.name
  156. uni.setStorageSync('lng', that.longitude)
  157. uni.setStorageSync('lat', that.latitude)
  158. uni.setStorageSync('city', res.name)
  159. setTimeout(function () {
  160. uni.navigateBack()
  161. }, 10)
  162. }
  163. })
  164. },
  165. getlocation() {
  166. let that = this
  167. // that.list=[]
  168. uni.getLocation({
  169. type: 'gcj02',
  170. success: function (res) {
  171. console.log('当前位置的经度:' + res.longitude)
  172. console.log('当前位置的纬度:' + res.latitude)
  173. that.longitude = res.longitude
  174. that.latitude = res.latitude
  175. let data = {
  176. lat: res.latitude,
  177. lng: res.longitude
  178. }
  179. that.$Request.get('/app/address/selectCity', data).then((res) => {
  180. if (res.code == 0) {
  181. that.city = res.data.city
  182. }
  183. })
  184. // that.initCampusList();
  185. }
  186. })
  187. },
  188. //获取社区列表
  189. initCampusList() {
  190. let that = this
  191. let data = {
  192. page: that.page,
  193. limit: that.limit
  194. }
  195. that.$Request.getT('/app/address/selectAddressList', data).then((res) => {
  196. console.log(res)
  197. if (res.code === 0) {
  198. if (that.page == 1) {
  199. that.list = res.data.list
  200. } else {
  201. that.list = [...that.list, ...res.data.list]
  202. }
  203. }
  204. })
  205. },
  206. showInput() {
  207. this.inputShowed = true
  208. },
  209. clearInput() {
  210. this.inputVal = ''
  211. this.inputShowed = false
  212. this.searchResult = []
  213. uni.hideKeyboard() //强行隐藏键盘
  214. },
  215. inputTyping(e) {
  216. this.inputVal = e.detail.value
  217. if (e.detail.value.length === 0) {
  218. this.searchResult = []
  219. this.inputShowed = false
  220. } else {
  221. this.inputShowed = true
  222. }
  223. this.searchCity()
  224. },
  225. // 搜索城市
  226. searchCity() {
  227. let data = {
  228. impotr: this.inputVal,
  229. page: 1,
  230. limit: 1000
  231. }
  232. this.$Request.get('/app/address/searchAddress', data).then((res) => {
  233. if (res.code == 0) {
  234. this.searchResult = res.data.list
  235. }
  236. })
  237. },
  238. // 添加地址
  239. addAddress() {
  240. let userId = this.$queue.getData('userId')
  241. if (!userId) {
  242. uni.navigateTo({
  243. url: '/pages/public/login'
  244. })
  245. return
  246. }
  247. uni.navigateTo({
  248. url: '/my/address/add?page=2'
  249. })
  250. }
  251. },
  252. onReachBottom: function () {
  253. this.page = this.page + 1
  254. this.initCampusList()
  255. },
  256. onPullDownRefresh: function () {
  257. this.page = 1
  258. this.initCampusList()
  259. }
  260. }
  261. </script>
  262. <style lang="scss">
  263. page {
  264. height: 100%;
  265. background: #ffffff;
  266. }
  267. .page {
  268. height: 100%;
  269. overflow: hidden;
  270. }
  271. .search-bar {
  272. display: flex;
  273. align-items: center;
  274. position: relative;
  275. padding: 27rpx 30rpx 35rpx;
  276. background-color: #fff;
  277. }
  278. .search-bar-form {
  279. flex: 1;
  280. position: relative;
  281. border-radius: 32rpx;
  282. background: #f2f5f7;
  283. }
  284. .search-bar-box {
  285. display: flex;
  286. align-items: center;
  287. position: relative;
  288. padding-left: 20rpx;
  289. padding-right: 20rpx;
  290. height: 64rpx;
  291. z-index: 1;
  292. }
  293. .search-bar-input {
  294. line-height: normal;
  295. width: 100%;
  296. padding-left: 20rpx;
  297. font-size: 30rpx;
  298. color: #333;
  299. }
  300. .phcolor {
  301. font-size: 30rpx;
  302. }
  303. .icon-clear {
  304. height: 38rpx;
  305. }
  306. .icon-clear .tui-icon-class {
  307. display: block;
  308. }
  309. .search-bar-label {
  310. height: 64rpx;
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. position: absolute;
  315. top: 0;
  316. right: 0;
  317. bottom: 0;
  318. left: 0;
  319. z-index: 2;
  320. border-radius: 32rpx;
  321. color: #ccc;
  322. background: #f2f5f7;
  323. }
  324. .icon-search {
  325. position: relative;
  326. height: 26rpx;
  327. margin-right: 20rpx;
  328. font-size: inherit;
  329. }
  330. .search-bar-text {
  331. font-size: 30rpx;
  332. line-height: 32rpx;
  333. }
  334. .cancel-btn {
  335. padding-left: 30rpx;
  336. }
  337. .search-result::before {
  338. display: none;
  339. }
  340. .search-result::after {
  341. display: none;
  342. }
  343. .tui-list-cell {
  344. // padding: 30upx;
  345. // display: flex;
  346. // flex-direction: row;
  347. // justify-content: space-between;
  348. // align-items: center;
  349. // width: 100%;
  350. }
  351. .tui-list-cell-hover {
  352. // background-color: #eee !important;
  353. }
  354. .tui-list-cell-navigate {
  355. // width: 100%;
  356. // position: relative;
  357. // padding: 30rpx 0 30rpx 30rpx;
  358. font-size: 30rpx;
  359. color: #333;
  360. font-weight: 800;
  361. }
  362. .tui-list-cell-navigate::after {
  363. content: '';
  364. position: absolute;
  365. border-bottom: 1rpx solid #eaeef1;
  366. -webkit-transform: scaleY(0.5);
  367. transform: scaleY(0.5);
  368. bottom: 0;
  369. right: 0;
  370. left: 30rpx;
  371. }
  372. .current-city {
  373. padding: 0 30rpx 30rpx;
  374. background: #fff;
  375. }
  376. .tui-icon-class {
  377. margin-right: 10rpx;
  378. }
  379. .current-city .title {
  380. font-size: 28rpx;
  381. line-height: 24rpx;
  382. color: #333333;
  383. }
  384. .box {
  385. background: #f5f5f5;
  386. border-radius: 10upx;
  387. width: 686upx;
  388. // height: 134upx;
  389. }
  390. .city-name {
  391. display: flex;
  392. align-items: center;
  393. // margin-top: 17rpx;
  394. font-size: 30rpx;
  395. font-weight: bold;
  396. line-height: 30rpx;
  397. color: #333;
  398. }
  399. .hot-city .title {
  400. height: 48rpx !important;
  401. padding-left: 30rpx;
  402. font-size: 24rpx !important;
  403. line-height: 48rpx !important;
  404. color: #999;
  405. background: #f2f5f7 !important;
  406. }
  407. .city-names {
  408. display: flex;
  409. flex-wrap: wrap;
  410. justify-content: space-between;
  411. align-content: space-between;
  412. padding: 12rpx 90rpx 26rpx 30rpx;
  413. background: #fff;
  414. }
  415. .city-name-item {
  416. display: flex;
  417. justify-content: center;
  418. align-items: center;
  419. width: 140rpx;
  420. height: 56rpx;
  421. margin-top: 16rpx;
  422. /* border: solid 1rpx #ccc; */
  423. border-radius: 28rpx;
  424. font-size: 28rpx;
  425. color: #333;
  426. position: relative;
  427. }
  428. .city-name-item::before {
  429. content: '';
  430. position: absolute;
  431. width: 200%;
  432. height: 200%;
  433. -webkit-transform-origin: 0 0;
  434. transform-origin: 0 0;
  435. -webkit-transform: scale(0.5, 0.5);
  436. transform: scale(0.5, 0.5);
  437. -webkit-box-sizing: border-box;
  438. box-sizing: border-box;
  439. left: 0;
  440. top: 0;
  441. border-radius: 56rpx;
  442. border: 1px solid #ccc;
  443. }
  444. .tap-city {
  445. color: #fff;
  446. background: #5677fc;
  447. /* border: solid 1rpx #5677fc; */
  448. }
  449. .tui-list {
  450. background-color: #fff;
  451. position: relative;
  452. width: 100%;
  453. display: flex;
  454. flex-direction: column;
  455. padding-bottom: env(safe-area-inset-bottom);
  456. }
  457. .tui-list-cell-divider {
  458. height: 48rpx;
  459. padding-left: 30rpx;
  460. font-size: 24rpx;
  461. color: #999;
  462. background: #f2f5f7;
  463. padding: 0 30rpx;
  464. display: flex;
  465. align-items: center;
  466. }
  467. .tui-indexed-list-bar {
  468. display: flex;
  469. flex-direction: column;
  470. align-items: center;
  471. justify-content: flex-start;
  472. z-index: 9999;
  473. position: absolute;
  474. top: 132rpx;
  475. right: 0;
  476. padding-right: 10rpx;
  477. width: 44rpx;
  478. }
  479. .tui-indexed-list-text {
  480. font-size: 22rpx;
  481. white-space: nowrap;
  482. }
  483. .tui-indexed-list-bar.active {
  484. background-color: rgb(200, 200, 200);
  485. }
  486. .tui-indexed-list-alert {
  487. position: absolute;
  488. z-index: 20;
  489. width: 160rpx;
  490. height: 160rpx;
  491. left: 50%;
  492. top: 50%;
  493. margin-left: -80rpx;
  494. margin-top: -80rpx;
  495. border-radius: 80rpx;
  496. text-align: center;
  497. line-height: 160rpx;
  498. font-size: 70rpx;
  499. color: #fff;
  500. background-color: rgba(0, 0, 0, 0.5);
  501. }
  502. /* 添加收货地址 */
  503. .btn {
  504. position: fixed;
  505. bottom: 0rpx;
  506. width: 100%;
  507. height: 100rpx;
  508. line-height: 100rpx;
  509. background-color: white;
  510. padding-top: 10rpx;
  511. }
  512. .address_push {
  513. width: 90%;
  514. height: 80rpx;
  515. margin: 0 auto;
  516. background: #fcd202;
  517. border-radius: 20rpx;
  518. color: white;
  519. text-align: center;
  520. line-height: 80rpx;
  521. font-size: 35rpx;
  522. }
  523. </style>