address.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <view>
  3. <!-- <sjs src="../../../utils/formatFuc.sjs" module="utils" /> -->
  4. <view class="container">
  5. <view class="current-city">
  6. <image src="https://mall.zhaijieshi.cc/file/wx-dy/address-map.png" mode="asceptFit"></image>
  7. <text class="text">当前定位城市</text>
  8. <text>{{ city }}</text>
  9. </view>
  10. <view class="top-wrapper">
  11. <view class="dz">{{ addressName }}</view>
  12. <view class="sx" @tap="shaxin">
  13. <image src="https://mall.zhaijieshi.cc/file/wx-dy/address-refresh.png" mode="asceptFit"></image>
  14. <text>重新定位</text>
  15. </view>
  16. </view>
  17. <view class="address-title">
  18. <image src="https://mall.zhaijieshi.cc/file/wx-dy/address-list.png" mode="asceptFit"></image>
  19. <text v-if="!isShowServiceAddress">我的服务地址</text>
  20. <text v-if="isShowServiceAddress">请选择你的服务地址</text>
  21. </view>
  22. <!-- <view class="xzwz" wx:if="{{isShowServiceAddress}}">请选择你的服务地址</view> -->
  23. <view class="address-list" v-if="addressList.length > 0">
  24. <view class="item" v-for="(item, index) in addressList" :key="index">
  25. <!-- <view class="l">
  26. <image src="/static/images/address/dingwei.png"></image>
  27. </view> -->
  28. <view class="c" @tap="addressAddOrUpdate" :data-address-id="item.id" :data-address-detail="item.addressDetail">
  29. <view class="address">{{ item.province }} {{ item.city }} {{ item.county }} {{ item.addressDetail }}</view>
  30. <view class="mobile-wrapper">
  31. <!-- <view class="mobile">{{ item.name }} {{ utils.formatGender(item.gender) }} {{ item.tel }}</view> -->
  32. <view class="mobile">{{ item.name }} {{item.gender==1?'先生':'女士' }} {{ item.tel }}</view>
  33. <view class="default" v-if="item.isDefault">默认</view>
  34. </view>
  35. </view>
  36. <view class="r">
  37. <!-- <van-icon catchtap="deleteAddress" data-address-id="{{item.id}}" class="del" name="delete"/> -->
  38. <image src="https://mall.zhaijieshi.cc/file/wx-dy/address-edit.png" mode="asceptFit" :data-address-id="item.id" @tap="updateAddress" class="update" />
  39. </view>
  40. </view>
  41. </view>
  42. <view class="empty-view" v-if="addressList.length <= 0">
  43. <image src="https://mall.zhaijieshi.cc/file/wx-dy/address-null.png" mode="asceptFit"></image>
  44. <text class="text">空空如也呢~</text>
  45. </view>
  46. <view class="add-address" @tap="addressAddOrUpdate" data-address-id="0">添加服务地址</view>
  47. </view>
  48. </view>
  49. </template>
  50. <script module="utils" lang="wxs" src="@/utils/formatFuc.wxs"></script>
  51. <script>
  52. var util = require('../../../utils/util.js');
  53. var api = require('../../../config/api.js');
  54. var map = require('../../../utils/map.js');
  55. var app = getApp();
  56. export default {
  57. data() {
  58. return {
  59. addressList: [],
  60. total: 0,
  61. addressName: '位置获取中',
  62. city: '位置获取中',
  63. isShowServiceAddress: false
  64. };
  65. },
  66. onLoad: function (options) {
  67. // 页面初始化 options为页面跳转所带来的参数
  68. var pages = getCurrentPages();
  69. var prevPage = pages[pages.length - 2];
  70. if (prevPage.route == 'pages/index/index') {
  71. this.setData({
  72. isShowServiceAddress: true
  73. });
  74. }
  75. this.getUserLocation();
  76. },
  77. onReady: function () {
  78. // 页面渲染完成
  79. },
  80. onShow: function () {
  81. // 页面显示
  82. this.getAddressList();
  83. },
  84. onHide: function () {
  85. // 页面隐藏
  86. },
  87. onUnload: function () {
  88. // 页面关闭
  89. },
  90. methods: {
  91. shaxin() {
  92. this.getUserLocation();
  93. },
  94. getUserLocation: function () {
  95. map.getUserLocation();
  96. let that = this;
  97. setTimeout(function () {
  98. that.setData({
  99. addressName: app.globalData.currentLocationName,
  100. city: app.globalData.city
  101. });
  102. }, 2000);
  103. },
  104. getAddressList() {
  105. let that = this;
  106. util.request(api.AddressList).then(function (res) {
  107. if (res.errno === 0) {
  108. that.setData({
  109. addressList: res.data.list,
  110. total: res.data.total
  111. });
  112. }
  113. });
  114. },
  115. updateAddress(event) {
  116. let addressId = event.currentTarget.dataset.addressId;
  117. uni.navigateTo({
  118. url: '/pages/ucenter/addressAdd/addressAdd?id=' + addressId
  119. });
  120. },
  121. async updateAddressData(address) {
  122. await util.request(api.AddressSave, address, 'POST').then(function (res) {
  123. if (res.errno === 0) {
  124. var city = res.data.city.indexOf('市辖') != -1 ? res.data.province : res.data.city;
  125. var addresInfo = {
  126. city: city,
  127. lng: res.data.lng,
  128. lat: res.data.lat,
  129. shopId: res.data.shopId,
  130. address: res.data.addressDetail
  131. };
  132. uni.setStorageSync('addressInfo', addresInfo);
  133. }
  134. });
  135. },
  136. addressAddOrUpdate(event) {
  137. // console.log(event)
  138. let addressId = event.currentTarget.dataset.addressId;
  139. let addressDetail = event.currentTarget.dataset.addressDetail;
  140. let address = null;
  141. this.addressList.forEach((item) => {
  142. if (addressId == item.id) {
  143. address = item;
  144. }
  145. });
  146. console.info(address);
  147. //返回之前,先取出上一页对象,并设置addressId
  148. var pages = getCurrentPages();
  149. var prevPage = pages[pages.length - 2];
  150. if (null != address && prevPage.route == 'pages/index/index') {
  151. // console.log("市辖区".indexOf("市"));
  152. var city = address.city.indexOf('市辖') != -1 ? address.province : address.city;
  153. //通过jz_shop的shop_no关联服务力分配的门店id,拿实际的jz_shop的门店id
  154. //这个是拿的服务力分配的门店,如果不转要改后台查询商品,要用shopNo,这里的shopId是shopNo
  155. // let distribution_unit=address.shopId;
  156. if (address.shopId == null) {
  157. this.updateAddressData(address);
  158. } else {
  159. var addresInfo = {
  160. city: city,
  161. lng: address.lng,
  162. lat: address.lat,
  163. shopId: address.shopId,
  164. address: address.addressDetail,
  165. shopName: address.shopName
  166. };
  167. uni.setStorageSync('addressInfo', addresInfo);
  168. }
  169. uni.navigateBack();
  170. } else if (prevPage.route == 'pages/checkout/checkout' || prevPage.route == 'pages/ucenter/appointOrder/appointOrder') {
  171. try {
  172. uni.setStorageSync('addressId', event.currentTarget.dataset.addressId);
  173. uni.setStorageSync('addressName', event.currentTarget.dataset.addressDetail);
  174. } catch (e) {
  175. console.log('CatchClause', e);
  176. console.log('CatchClause', e);
  177. }
  178. if (addressId && addressId != 0) {
  179. uni.navigateBack();
  180. } else {
  181. uni.navigateTo({
  182. url: '/pages/ucenter/addressAdd/addressAdd?id=' + addressId
  183. });
  184. }
  185. } else if (prevPage.route == 'pages/goods/infoCollect/infoCollect') {
  186. if (addressId && addressId != 0) {
  187. app.globalData.infoAddress = {
  188. addressId: addressId,
  189. addressDetail: addressDetail
  190. };
  191. uni.navigateBack();
  192. } else {
  193. uni.navigateTo({
  194. url: '/pages/ucenter/addressAdd/addressAdd?id=' + addressId
  195. });
  196. }
  197. } else {
  198. uni.navigateTo({
  199. url: '/pages/ucenter/addressAdd/addressAdd?id=' + event.currentTarget.dataset.addressId
  200. });
  201. }
  202. },
  203. deleteAddress(event) {
  204. console.log(event.target);
  205. let that = this;
  206. uni.showModal({
  207. title: '',
  208. content: '确定要删除地址?',
  209. success: function (res) {
  210. if (res.confirm) {
  211. let addressId = event.target.dataset.addressId;
  212. util.request(
  213. api.AddressDelete,
  214. {
  215. id: addressId
  216. },
  217. 'POST'
  218. ).then(function (res) {
  219. if (res.errno === 0) {
  220. that.getAddressList();
  221. uni.removeStorage({
  222. key: 'addressId',
  223. success: function (res) {}
  224. });
  225. }
  226. });
  227. console.log('用户点击确定');
  228. }
  229. }
  230. });
  231. return false;
  232. }
  233. }
  234. };
  235. </script>
  236. <style>
  237. page {
  238. height: 100%;
  239. width: 100%;
  240. background: #fff;
  241. }
  242. .container {
  243. padding: 0 30rpx;
  244. background: #fff;
  245. }
  246. .current-city {
  247. height: 90rpx;
  248. display: flex;
  249. align-items: center;
  250. }
  251. .current-city image {
  252. width: 30rpx;
  253. height: 30rpx;
  254. margin-top: 4rpx;
  255. }
  256. .current-city text {
  257. font-size: 28rpx;
  258. color: #333;
  259. }
  260. .current-city .text {
  261. margin: 0 20rpx 0 12rpx;
  262. }
  263. .dz {
  264. width: 570rpx;
  265. /* border: 1px solid red; */
  266. color: #333;
  267. /* background: #B8E3F9;
  268. text-indent: 20rpx; */
  269. white-space: nowrap;
  270. overflow: hidden;
  271. text-overflow: ellipsis;
  272. width: 466rpx;
  273. font-size: 30rpx;
  274. }
  275. .sx {
  276. display: flex;
  277. align-items: center;
  278. height: 90rpx;
  279. /* border: 1px solid red; */
  280. }
  281. .sx image {
  282. width: 30rpx;
  283. height: 30rpx;
  284. margin-right: 12rpx;
  285. }
  286. .sx text {
  287. color: #00c0ff;
  288. font-size: 26rpx;
  289. }
  290. .xzwz {
  291. text-indent: 20rpx;
  292. color: #90a4ae;
  293. }
  294. .update {
  295. width: 44rpx;
  296. height: 44rpx;
  297. }
  298. .address-title {
  299. height: 28rpx;
  300. margin: 30rpx 0 10rpx;
  301. display: flex;
  302. align-items: center;
  303. }
  304. .address-title image {
  305. width: 28rpx;
  306. height: 28rpx;
  307. margin-right: 10rpx;
  308. }
  309. .address-title text {
  310. font-size: 26rpx;
  311. color: #666;
  312. }
  313. .address-list {
  314. padding: 0 28rpx 0 30rpx;
  315. background: #fff;
  316. padding-bottom: 200rpx;
  317. }
  318. .address-list .item {
  319. /* height: 156.55rpx; */
  320. padding: 30rpx 0;
  321. align-items: center;
  322. display: flex;
  323. border-bottom: 2rpx solid #f2f2f2;
  324. }
  325. .address-list .l {
  326. width: 50rpx;
  327. height: 80rpx;
  328. overflow: hidden;
  329. }
  330. .address-list .l image {
  331. width: 40rpx;
  332. height: 50rpx;
  333. }
  334. .address-list .name {
  335. width: 125rpx;
  336. height: 43rpx;
  337. font-size: 29rpx;
  338. color: #333;
  339. margin-bottom: 5.2rpx;
  340. text-overflow: ellipsis;
  341. white-space: nowrap;
  342. overflow: hidden;
  343. }
  344. .address-list .default {
  345. float: right;
  346. /* margin-right: 40rpx; */
  347. border: 1px solid #00c0ff;
  348. color: #00c0ff;
  349. border-radius: 6rpx;
  350. line-height: 20px;
  351. width: 80rpx;
  352. height: 36rpx;
  353. line-height: 34rpx;
  354. text-align: center;
  355. font-size: 24rpx;
  356. visibility: visible;
  357. }
  358. .address-list .c {
  359. flex: 1;
  360. height: auto;
  361. overflow: hidden;
  362. }
  363. .mobile-wrapper {
  364. height: 36rpx;
  365. display: flex;
  366. align-items: center;
  367. justify-content: space-between;
  368. margin-top: 12rpx;
  369. }
  370. .address-list .mobile {
  371. /* height: 29rpx; */
  372. font-size: 26rpx;
  373. line-height: 2rrpx;
  374. color: #999;
  375. flex: 1;
  376. margin-right: 20rpx;
  377. }
  378. .address-list .address {
  379. /* height: 37rpx; */
  380. font-size: 30rpx;
  381. line-height: 38rpx;
  382. /* overflow: hidden; */
  383. color: #333;
  384. }
  385. .address-list .r {
  386. margin-left: 28rpx;
  387. /* width: 52rpx;
  388. height: auto;
  389. overflow: hidden;
  390. margin-right: 16.5rpx; */
  391. }
  392. .address-list .del {
  393. display: block;
  394. width: 52rpx;
  395. height: 52rpx;
  396. }
  397. .add-address {
  398. border: none;
  399. right: 0;
  400. display: flex;
  401. justify-content: center;
  402. align-items: center;
  403. width: 90%;
  404. height: 90rpx;
  405. line-height: 98rpx;
  406. position: fixed;
  407. bottom: 40rpx;
  408. left: 0;
  409. border-radius: 0;
  410. padding: 0;
  411. margin: 0;
  412. margin-left: 5%;
  413. text-align: center;
  414. /* padding-left: -5rpx; */
  415. font-size: 30rpx;
  416. color: #f4f4f4;
  417. border-top-left-radius: 50rpx;
  418. border-bottom-left-radius: 50rpx;
  419. border-top-right-radius: 50rpx;
  420. border-bottom-right-radius: 50rpx;
  421. letter-spacing: 3rpx;
  422. background-image: linear-gradient(to right, #09afff 0%, #09afff 100%);
  423. }
  424. .empty-view {
  425. /* height: 100%; */
  426. width: 100%;
  427. display: flex;
  428. flex-direction: column;
  429. align-items: center;
  430. /* justify-content: center; */
  431. }
  432. .empty-view image {
  433. width: 254rpx;
  434. height: 224rpx;
  435. margin: 256rpx 0 34rpx;
  436. }
  437. .empty-view .text {
  438. font-size: 22rpx;
  439. line-height: 24rpx;
  440. color: #666;
  441. }
  442. .top-wrapper {
  443. height: 90rpx;
  444. border-bottom: 2rpx solid #f2f2f2;
  445. display: flex;
  446. align-items: center;
  447. justify-content: space-between;
  448. }
  449. </style>