address_list.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <view class="dt-page">
  3. <view class="container">
  4. <view class="no-data-wrap" v-if="dataList.length <= 0">
  5. <image class="addr-nodata-img" src="http://139.9.103.171:1888/img/image/noData.png"></image>
  6. <view class="addr-nodata-tip">暂无可用地址哦</view>
  7. </view>
  8. <view v-for="(item, idx) in dataList" :key="idx" class="item-list" @tap="addressItemClick(item)">
  9. <view style="display: flex;align-items: center;">
  10. <view class="addr-name-phone">{{ item.consignee }} {{ item.phone }}</view>
  11. <view v-if="item.isAgent" style="
  12. margin-top: 33upx;
  13. font-size: 18upx;
  14. margin-left: 10upx;
  15. border-radius: 10upx;
  16. padding: 10upx;
  17. height: 18upx;
  18. line-height: 18upx;
  19. background-color: red;
  20. color: white;">代理</view>
  21. </view>
  22. <view class="addr-des">{{ item.areaName }}{{ item.address }}</view>
  23. <view class="item-bottom">
  24. <view @tap.native.stop="setDefaultAddress(item, idx)" class="bottom-left">
  25. <image v-if="item.isDefault" class="addr-def-icon" src="/static/mail/select.png" mode="widthFix"></image>
  26. <image v-else class="addr-def-icon" src="http://139.9.103.171:1888/img/image/no_selected_icon.png" mode="widthFix"></image>
  27. <text class="addr-def-text">默认地址</text>
  28. </view>
  29. <view class="bottom-right">
  30. <image @tap.native.stop="editAdd(item)" src="http://139.9.103.171:1888/img/image/addr_edit.png" class="addr-edit-img"></image>
  31. <image @tap.native.stop="deleteAdd(item, idx)" src="http://139.9.103.171:1888/img/image/delete.png" class="addr-del-img"></image>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="addr-list-fix" :style="footSafe"></view>
  36. </view>
  37. <view>
  38. <view class="addr-add-wrap" :style="footSafe">
  39. <view class="btnLayout" @tap="getNewAdd">
  40. <text class="addr-add-tip">获取微信收货地址</text>
  41. </view>
  42. <view class="btnLayout" @tap="addNewAdd">
  43. <!-- <image class="addr-add-icon" src="http://139.9.103.171:1888/img/image/addr_add.png" mode="widthFix"></image> -->
  44. <text class="addr-add-tip">新增收货地址</text>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. export default {
  52. data() {
  53. return {
  54. flag:false,
  55. dataList: [],
  56. isFromOrder: null,
  57. memberId: 0
  58. };
  59. },
  60. computed: {
  61. footSafe() {
  62. return `padding-bottom:${this.safeAreaBottom}px`;
  63. }
  64. },
  65. methods: {
  66. editAdd(item) {
  67. var objStr = JSON.stringify(item);
  68. uni.navigateTo({
  69. url: '/pagesM/pages/address_edit?addNew=0' + '&item=' + objStr
  70. });
  71. },
  72. addNewAdd() {
  73. uni.navigateTo({
  74. url: '/pagesM/pages/address_edit?addNew=1'
  75. });
  76. },
  77. getNewAdd(){
  78. let _this = this;
  79. wx.chooseAddress({
  80. success(res) {
  81. if (res.errMsg == 'chooseAddress:ok') {
  82. _this.getAreaList(res);
  83. }
  84. }
  85. });
  86. },
  87. async setDefaultAddress(item, idx) {
  88. if (item.isDefault) return;
  89. let areaId = item.areaIds[item.areaIds.length - 1];
  90. let res = await this.$api.addAddress({
  91. id: item.id,
  92. consignee: item.consignee,
  93. phone: item.phone,
  94. address: item.address,
  95. isDefault: true,
  96. areaId: areaId
  97. });
  98. this.$dialog.success('修改成功');
  99. this.isNoMore = false;
  100. this.pageIndex = 0;
  101. this.dataList.length = 0;
  102. this.getAddressList();
  103. },
  104. addressItemClick(item) {
  105. if (this.loadOptions.isFromOrder === '1') {
  106. console.log(86, 'select');
  107. let lastPage = this.$util.getPageCtx(1).$vm;
  108. lastPage.isCalculate = true;
  109. lastPage.receiverAddress = item;
  110. uni.navigateBack({ delta: 1 });
  111. }else if (this.loadOptions.isFromOrder === '2') {
  112. console.log(86, 'select');
  113. if(item.isAgent){
  114. let lastPage = this.$util.getPageCtx(1).$vm;
  115. lastPage.isCalculate = true;
  116. lastPage.receiverAddress = item;
  117. uni.navigateBack({ delta: 1 });
  118. }else{
  119. this.$dialog.toast('该地址不是代理收货地址,请先新增代理收货地址');
  120. }
  121. }
  122. },
  123. // 获取地址列表
  124. async getAddressList() {
  125. if (this.isPull) {
  126. this.isNoMore = false;
  127. this.pageIndex = 0;
  128. this.dataList.length = 0;
  129. }
  130. // let resp = await this.$api.queryAddrList({
  131. // pageNo: this.pageIndex,
  132. // pageSize: this.pageSize
  133. // });
  134. let resp = await this.$api.queryAddrList({
  135. pageNo: 0,
  136. pageSize: 1000
  137. });
  138. this.dataList = this.getDataList(resp);
  139. // this.dataList = this.dataList.concat(list);
  140. },
  141. deleteAdd(item, index) {
  142. this.$dialog.confirm({
  143. titie: '温馨提示',
  144. content: '是否要删除?',
  145. success: res => {
  146. if (res.confirm) {
  147. this.deleteAddAction(item, index);
  148. }
  149. }
  150. });
  151. },
  152. async deleteAddAction(item, index) {
  153. let resp = await this.$api.deleteAddress({
  154. id: item.id
  155. });
  156. this.dataList.splice(index, 1);
  157. this.$dialog.success('删除成功');
  158. },
  159. onLoadPage(options) {
  160. this.flag=true
  161. wx.hideShareMenu();
  162. if (this.isLoad) {
  163. this.memberId = this.$auth.getMemberId();
  164. }
  165. this.getAddressList();
  166. },
  167. async getAreaList(res){
  168. let addressList = await this.$api.areaList();
  169. if(addressList != null && addressList.length > 0){
  170. let areaId = 0;
  171. let address = res.detailInfo;
  172. let isOk1 = false, isOk2 = false, isOk3 = false;
  173. for (let item of addressList) {
  174. if(item.name == res.provinceName){
  175. areaId = item.id;
  176. isOk1 = true;
  177. if(item.addresses != null && item.addresses.length > 0){
  178. for (let item2 of item.addresses) {
  179. if(item2.name == res.cityName){
  180. areaId = item2.id;
  181. isOk2 = true;
  182. if(item2.addresses != null && item2.addresses.length > 0){
  183. for (let item3 of item2.addresses) {
  184. if(item3.name == res.countyName){
  185. areaId = item3.id;
  186. isOk3 = true;
  187. break;
  188. }
  189. }
  190. if(!isOk3) address = res.countyName + address;
  191. }
  192. break;
  193. }
  194. }
  195. if(!isOk2) address = res.cityName + res.countyName + address;
  196. }
  197. break;
  198. }
  199. }
  200. if(!isOk1) address = res.provinceName + res.cityName + res.countyName + address;
  201. let params = {
  202. _isShowLoading:true,
  203. _loadingText:'添加中...',
  204. consignee: res.userName,
  205. phone: res.telNumber,
  206. address: address,
  207. isDefault: false,
  208. areaId: areaId
  209. }
  210. let isExit = false;
  211. if(this.dataList != null && this.dataList.length > 0){
  212. for (let item of this.dataList) {
  213. if(item.address == params.address && item.consignee == params.consignee && item.phone == params.phone){
  214. if(item.areaIds != null && item.areaIds.length > 0){
  215. for (let areaId of item.areaIds) {
  216. if(areaId == params.areaId){
  217. isExit = true;
  218. break;
  219. }
  220. }
  221. }
  222. break;
  223. }
  224. }
  225. }
  226. if(!isExit){
  227. let resp = await this.$api.addAddress(params);
  228. this.dataList = [];
  229. this.getAddressList();
  230. }
  231. }
  232. }
  233. },
  234. onShow() {
  235. //第一次进入页面不通过onshow方法获取地址列表
  236. if (this.flag) {
  237. this.flag=false
  238. }else{
  239. this.getAddressList()
  240. }
  241. this.onShowPage();
  242. },
  243. onReachBottom() {
  244. this.onReachBottomPage();
  245. }
  246. };
  247. </script>
  248. <style lang="scss" scoped>
  249. .dt-page {
  250. min-height: 100vh;
  251. background-color: #f2f2f2;
  252. .container {
  253. font-size: 28upx;
  254. color: rgb(51, 51, 51);
  255. .item-list {
  256. display: flex;
  257. flex-direction: column;
  258. margin-top: 20upx;
  259. background: white;
  260. .addr-name-phone {
  261. margin-top: 33upx;
  262. margin-left: 30upx;
  263. }
  264. .addr-des {
  265. margin-top: 30upx;
  266. margin-left: 30upx;
  267. color: #666;
  268. }
  269. .item-bottom {
  270. display: flex;
  271. flex-direction: row;
  272. justify-content: space-between;
  273. margin-top: 28upx;
  274. border: 2upx solid rgb(238, 238, 238);
  275. .bottom-left {
  276. display: flex;
  277. flex-direction: row;
  278. align-items: center;
  279. .addr-def-icon {
  280. margin: 0 14upx 0 30upx;
  281. width: 34upx;
  282. height: 34upx;
  283. }
  284. .addr-def-text {
  285. color: #666666;
  286. padding-left: 20upx;
  287. padding-top: 24upx;
  288. padding-bottom: 23upx;
  289. font-size: 24upx;
  290. }
  291. }
  292. .bottom-right {
  293. display: flex;
  294. flex-direction: row;
  295. align-items: center;
  296. .addr-edit-img {
  297. width: 33upx;
  298. height: 32upx;
  299. padding: 20upx 25upx;
  300. // padding-right: 50upx;
  301. }
  302. .addr-del-img {
  303. width: 33upx;
  304. height: 32upx;
  305. padding: 20upx 25upx;
  306. padding-right: 40upx;
  307. }
  308. }
  309. }
  310. }
  311. .addr-list-fix {
  312. width: 100%;
  313. height: 98upx;
  314. }
  315. }
  316. .addr-add-wrap {
  317. height: 120upx;
  318. position: fixed;
  319. bottom: 0;
  320. left: 0;
  321. width: 100%;
  322. display: flex;
  323. flex-direction: row;
  324. justify-content: center;
  325. align-items: center;
  326. background-color: #fff;
  327. border-top: 2upx solid rgb(238, 238, 238);
  328. .btnLayout{
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. margin: 10upx 10upx;
  333. border: 1px solid $base;
  334. border-radius: 10upx;
  335. flex: 1;
  336. height: 70%;
  337. .addr-add-tip {
  338. color: $base;
  339. font-size: 30upx;
  340. padding-left: 10upx;
  341. }
  342. .addr-add-icon {
  343. width: 40upx;
  344. height: 40upx;
  345. }
  346. }
  347. }
  348. .no-data-wrap {
  349. width: 100%;
  350. padding-top: 302upx;
  351. display: flex;
  352. flex-direction: column;
  353. justify-content: center;
  354. align-items: center;
  355. .addr-nodata-img {
  356. width: 215upx;
  357. height: 159upx;
  358. }
  359. .addr-nodata-tip {
  360. color: #999;
  361. font-size: 30upx;
  362. padding-top: 22upx;
  363. }
  364. }
  365. }
  366. </style>