address.vue 12 KB

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