selectCampus.vue 12 KB

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