address.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="padding-lr padding-bottom-big margin-bottom ft-main bg-drak">
  3. <view class="bg-main padding-top padding-lr border-radius margin-top-sm" v-for="(item, index) in addressDatas"
  4. :key="index" @click="selectAddr(item)">
  5. <view class="w-full dflex-wrap-w border-line">
  6. <view class="fwb margin-bottom-xs desc">
  7. <text>{{item.province}}{{item.city}}{{item.county}}{{ item.address }}</text>
  8. </view>
  9. <view class="margin-bottom-sm">
  10. <text>{{ item.receiverName }}</text>
  11. <text class="margin-left">{{ item.phoneNum }}</text>
  12. </view>
  13. </view>
  14. <view class="dflex-b">
  15. <view v-if="item.defaultFlag == '1'" class="dflex active">
  16. <text class="iconfont iconxuanzhongzhuangtai padding-tb-sm padding-right-sm"></text>
  17. <text> 默认地址</text>
  18. </view>
  19. <view v-else class="dflex ft-dark" @tap.stop="setDefault(item)">
  20. <text class="iconfont iconweixuanzhongzhuangtai padding-tb-sm padding-right-sm"></text>
  21. <text> 设为默认</text>
  22. </view>
  23. <view v-if="source == 0 || source == 1" class="dflex">
  24. <view class="padding-tb-sm padding-right-sm" @tap.stop="addAddr('edit', item)"><text
  25. class="iconfont iconbianji-01 ft-dark"></text></view>
  26. <view class="padding-tb-sm padding-left-sm" @tap.stop="removeAddr(item)"><text
  27. class="iconfont iconlajitong-01 ft-dark"></text></view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="btn-container dflex-b pos-f border-radius-big">
  32. <view v-if="is_mp" class="tac padding-tb-sm flex1 bg-main" @click="importAddr">{{ platform_name }}导入</view>
  33. <view class="tac padding-tb-sm flex1 bg-base-address" @click="addAddr('add')">添加地址</view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. addresslist,
  40. addressadd,
  41. addressupdate,
  42. addressdelete
  43. } from '../../../utils/api_user.js'
  44. const __name = 'usemall-member-address';
  45. export default {
  46. data() {
  47. return {
  48. env: {},
  49. is_mp: false,
  50. platform: '',
  51. platform_name: '',
  52. platform_icon: '',
  53. source: 0,
  54. addressDatas: []
  55. };
  56. },
  57. onLoad(option) {
  58. this.$api.get_env((res) => {
  59. this.env = res;
  60. // console.log(this.env);
  61. this.is_mp = this.env.is_mp;
  62. this.platform = this.env.platform;
  63. this.platform_icon = this.env.platform_icon;
  64. this.platform_name = this.env.platform_name;
  65. });
  66. this.source = option.source || 0;
  67. },
  68. onShow() {
  69. this.loadData();
  70. },
  71. methods: {
  72. // 加载数据
  73. loadData() {
  74. let _self=this
  75. // 收货人列表
  76. addresslist().then((res) => {
  77. if(res.success){
  78. _self.addressDatas = res.data;
  79. return
  80. }
  81. _self.$api.msg(res.msg);
  82. })
  83. },
  84. // 导入地址
  85. importAddr() {
  86. let _this = this;
  87. uni.chooseAddress({
  88. success(res) {
  89. let addr = {};
  90. addr.defaultFlag = '0';
  91. addr.receiverName = res.userName;
  92. addr.phoneNum = res.telNumber;
  93. // addr.addr_detail = res.detailInfo;
  94. addr.province = res.provinceName;
  95. addr.city = res.cityName;
  96. addr.county = res.countyName || '';
  97. // #ifdef MP-ALIPAY
  98. addr.county = res.result.area;
  99. // #endif
  100. addr.address =address
  101. // addr.address = `${addr.province}-${addr.city}-${addr.county}`;
  102. // addr.addr_source = _this.$env.platform;
  103. if (!addr.phoneNum) {
  104. _this.$api.msg('收货人手机不存在')
  105. return;
  106. }
  107. //添加收货地址
  108. addressadd(addr).then((res) => {
  109. if(res.success){
  110. _this.$api.msg('导入成功');
  111. _this.loadData();
  112. return
  113. }
  114. _self.$api.msg(res.msg);
  115. })
  116. },
  117. fail(err) {
  118. if (err.errMsg.indexOf('cancel') !== -1) {
  119. _this.$api.msg('已取消')
  120. } else {
  121. uni.showModal({
  122. content: '打开授权',
  123. success: e => {
  124. if (e.confirm) {
  125. uni.openSetting({
  126. })
  127. }
  128. }
  129. });
  130. }
  131. }
  132. })
  133. },
  134. // 默认地址
  135. setDefault(options) {
  136. var _self=this
  137. uni.showModal({
  138. title: '提示',
  139. content: '设为默认',
  140. success: async (res) => {
  141. if (res.confirm) {
  142. if(options.defaultFlag=='0'){
  143. var defaultFlag='1'
  144. }else if(options.defaultFlag=='1'){
  145. var defaultFlag='0'
  146. }
  147. //修改收货地址
  148. var data={
  149. "id": options.id,
  150. "receiverName": options.receiverName,
  151. "phoneNum": options.phoneNum,
  152. "province": options.province,
  153. "city": options.city,
  154. "county": options.county,
  155. "address": options.address,
  156. "defaultFlag": defaultFlag,
  157. "createBy": options.createBy,
  158. "createTime": options.createTime,
  159. "updateTime": options.updateTime,
  160. "updateBy": options.updateBy
  161. }
  162. addressupdate(data).then((res) => {
  163. if(res.success){
  164. _self.loadData();
  165. return
  166. }
  167. _self.$api.msg(res.msg);
  168. })
  169. } else if (res.cancel) {
  170. console.log('用户点击取消');
  171. }
  172. }
  173. });
  174. },
  175. // 选择地址
  176. selectAddr(options) {
  177. if (this.source == 1) {
  178. uni.$emit('__event_choice_address', options);
  179. uni.navigateBack();
  180. }
  181. },
  182. // 添加|编辑 收货人
  183. addAddr(type, options) {
  184. options = options || {
  185. id: 0
  186. };
  187. uni.navigateTo({
  188. url: `/packageShang/pages/user/address/address-edit?type=${type}&id=${options.id}`
  189. });
  190. },
  191. // 删除收货人
  192. removeAddr(options) {
  193. var data=[options.id]
  194. let _this = this;
  195. uni.showModal({
  196. title: '提示',
  197. content: '删除收货人',
  198. success: function(res) {
  199. if (res.confirm) {
  200. //删除收货地址
  201. addressdelete(data).then((res) => {
  202. if(res.success){
  203. _this.loadData();
  204. return
  205. }
  206. _self.$api.msg(res.msg);
  207. })
  208. } else if (res.cancel) {
  209. console.log('用户点击取消');
  210. }
  211. }
  212. });
  213. }
  214. }
  215. };
  216. </script>
  217. <style lang="scss">
  218. @import url('/packageShang/components/iconfont/iconfont.css');
  219. @import url('/packageShang/common/common.scss');
  220. page {
  221. background: $page-color-base;
  222. }
  223. .desc {
  224. font-size: $font-lg;
  225. }
  226. .btn-container {
  227. left: 20rpx;
  228. right: 20rpx;
  229. bottom: 20rpx;
  230. }
  231. </style>