editAddress.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view>
  3. <view>
  4. <u-navbar :back-text="i18n('Back')" :back-text-style="backStyle" back-icon-color="#fff" title-color="#fff"
  5. :background="background" title-width="300" :title="i18n('editConsignee')"></u-navbar>
  6. </view>
  7. <view style="background: #fff;box-sizing:border-box;padding: 20rpx;">
  8. <u-form :model="form" ref="uForm">
  9. <u-form-item label-width="140rpx" :label="$i18n.locale == 'zh' ? '姓名:' : 'Name:'">
  10. <u-input :placeholder="$i18n.locale == 'zh'? '请输入姓名': 'Please enter your name'" type="text"
  11. :border="border" v-model="form.name" />
  12. </u-form-item>
  13. <u-form-item label-width="140rpx" :label="$i18n.locale == 'zh' ? '手机号码:' : 'Phone:'">
  14. <u-input :placeholder="$i18n.locale == 'zh'? '请输入手机号码': 'Please enter your phone'" type="text"
  15. :border="border" v-model="form.phone" />
  16. </u-form-item>
  17. <u-form-item label-width="140rpx" :label="$i18n.locale == 'zh' ? '邮政编码:' : 'Code:'">
  18. <u-input :placeholder="$i18n.locale == 'zh'? '请输入邮政编码': 'Please enter your post code'" type="text"
  19. :border="border" v-model="form.postCode" />
  20. </u-form-item>
  21. <u-form-item v-if="$i18n.locale == 'zh'" label-width="140rpx"
  22. :label="$i18n.locale == 'zh' ? '所在区域:' : 'Area:'">
  23. <u-input :disabled='info' :placeholder="$i18n.locale == 'zh'? '请选择地区': 'Please select a region'"
  24. @tap='cancelInfo' :border="border" v-model="this.form.division"></u-input>
  25. <u-select v-model="show" mode="muitl-column-auto" child-name="child" value-name="id"
  26. label-name="name" :list="sysAreaList" @confirm="confirm">
  27. </u-select>
  28. <u-picker mode="region" v-model="show" :area-code='["11", "1101", "110101"]' @confirm="confirm">
  29. </u-picker>
  30. </u-form-item>
  31. <u-form-item label-width="140rpx" :label="$i18n.locale == 'zh' ? '详细地址:' : 'Detail:'">
  32. <u-input :placeholder="$i18n.locale == 'zh'? '请输入详细地址': 'Please enter detail address'" type="text"
  33. :border="border" v-model="form.address" />
  34. </u-form-item>
  35. <u-form-item>
  36. <u-checkbox-group>
  37. <u-checkbox v-model="form.status" shape="circle">
  38. {{$i18n.locale=='zh'?'设为默认地址':'Set as default address'}}
  39. </u-checkbox>
  40. </u-checkbox-group>
  41. </u-form-item>
  42. </u-form>
  43. <view>
  44. <u-button @click="save" shape="circle" type="primary">
  45. <text style="margin-left:20rpx">{{$i18n.locale=='zh'?'保存':'Save'}}</text>
  46. </u-button>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. addUmsUserCommodityAddresss,
  54. getUmsUserCommodityAddresss
  55. } from "@/api/address"
  56. export default {
  57. data() {
  58. return {
  59. info: true,
  60. background: {
  61. backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
  62. },
  63. backStyle: {
  64. color: '#FFFFFF',
  65. },
  66. name: "name",
  67. id: "id",
  68. child: "child",
  69. test: [],
  70. form: {
  71. name: '',
  72. phone: '',
  73. postCode: '',
  74. division: "",
  75. address: "",
  76. status: false,
  77. },
  78. border: true,
  79. show: false,
  80. userId: null,
  81. addressId: null,
  82. addressDetail: {},
  83. sysAreaList: [],
  84. }
  85. },
  86. onShow() {
  87. this.getAddressDetail()
  88. },
  89. onLoad() {
  90. let option = uni.getStorageSync("addressId");
  91. this.addressId = option
  92. },
  93. methods: {
  94. cancelInfo() {
  95. uni.hideKeyboard()
  96. this.show = true
  97. },
  98. navTo(route) {
  99. this.$mRouter.push({
  100. route
  101. });
  102. },
  103. i18n(data) {
  104. return this.$t('common.' + data);
  105. },
  106. getAddressDetail() {
  107. console.log(this.addressId, '111')
  108. getUmsUserCommodityAddresss(this.addressId).then(res => {
  109. console.log(res, '2222');
  110. this.addressDetail = res.data.umsUserCommodityAddresss[0]
  111. this.form.name = this.addressDetail.consignee;
  112. this.form.phone = this.addressDetail.mobile;
  113. this.form.postCode = this.addressDetail.postalCode;
  114. this.form.address = this.addressDetail.address;
  115. this.form.division = this.addressDetail.province + '/' + this.addressDetail.city + '/' + this
  116. .addressDetail.area;
  117. this.form.status = this.addressDetail.status == '1' ? true : false
  118. }).catch(e => {
  119. console.log("======>>>>", e);
  120. })
  121. },
  122. async save() {
  123. this.userId = JSON.parse(uni.getStorageSync("user"))
  124. let params = {
  125. id: this.addressId,
  126. // userId: this.userId.id,
  127. consignee: this.form.name,
  128. mobile: this.form.phone,
  129. province: this.test[0] ? this.test[0] : this.addressDetail.province,
  130. city: this.test[1] ? this.test[1] : this.addressDetail.city,
  131. area: this.test[2] ? this.test[2] : this.addressDetail.area,
  132. address: this.form.address,
  133. postalCode: this.form.postCode,
  134. status: this.form.status ? '1' : '0',
  135. };
  136. console.log(params)
  137. const tokendata = await this.$myRequest({
  138. url: '/sys/token',
  139. method: 'get'
  140. });
  141. addUmsUserCommodityAddresss(params, tokendata.data).then((res) => {
  142. if (res.status == '200') {
  143. this.navTo('/pages/profile/personIntegrate/userAddress')
  144. }
  145. });
  146. },
  147. confirm(e) {
  148. console.log(e)
  149. this.form.division = e.province.label + '/' + e.city.label + '/' + e.area.label;
  150. let str = e.province.label + '/' + e.city.label + '/' + e.area.label;
  151. this.test = str.split('/')
  152. }
  153. }
  154. }
  155. </script>
  156. <style>
  157. </style>