address.vue 14 KB

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