editAddress.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <!--pages/editAddress/editAddress.wxml-->
  3. <form @submit="formSubmit">
  4. <view class="list">
  5. <view class="li">
  6. <text>收货人</text>
  7. <view class="item">
  8. <input name="name" :value="form.userName" placeholder="请填写收货人姓名"></input>
  9. </view>
  10. </view>
  11. <view class="li">
  12. <text>手机号</text>
  13. <view class="item">
  14. <input name="phone" :value="form.telNumber" placeholder="请填写手机号"></input>
  15. </view>
  16. </view>
  17. <view class="li">
  18. <text>所在地区</text>
  19. <picker class="item" mode="region" @change="bindRegionChange" :value="region" :custom-item="customItem">
  20. <view class="picker">
  21. {{region.length > 0 ? region[0]+region[1]+region[2] : '请选择所在地区'}}
  22. </view>
  23. </picker>
  24. <!-- <image src="/static/pages/images/more.png" class="rico"></image> -->
  25. <image src="../static/mine/images/fbico2.png" class="loca" @click="chooseLocation()"></image>
  26. </view>
  27. <view class="li">
  28. <text>详细信息</text>
  29. <view class="item">
  30. <input name="house" :value="form.detailInfo" placeholder="如街道、门牌号"></input>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="list moren">
  35. <view class="li">
  36. <text>设为默认</text>
  37. <view class="item she">
  38. <image :src="isDefault ? '/static/pages/images/gou_h.png' : '/static/pages/images/gou.png'" class="check" @tap="setDefault"></image>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="btn dflex">
  43. <view class="del" @tap="deleteAddress">删除</view>
  44. <button class="submit" form-type="submit">确定</button>
  45. </view>
  46. </form>
  47. </template>
  48. <script>
  49. const req = require("../../utils/request.js"); // 引入SDK核心类
  50. // 引入SDK核心类
  51. var QQMapWX = require("../../utils/qqmap.js");
  52. export default {
  53. data() {
  54. return {
  55. region: [],
  56. isDefault: false,
  57. isChoose: false,
  58. form: {},
  59. once: false,
  60. address: ""
  61. };
  62. },
  63. components: {},
  64. props: {},
  65. onLoad: function (options) {
  66. this.id = options.id;
  67. this.addressId = options.addressId;
  68. this.chooseAddress(); // 实例化API核心类
  69. QQMapWX.initMap('3OJBZ-EQEKO-PFNWC-SHHEK-CGWAJ-KRBF7');
  70. },
  71. methods: {
  72. chooseLocation() {
  73. var tha = this;
  74. uni.chooseLocation({
  75. success: function(res) {
  76. if (res.name) {
  77. tha.form.detailInfo = res.name;
  78. tha.reverseGeocoder(res);
  79. console.log('地址数据》》》:', res);
  80. }
  81. }
  82. });
  83. },
  84. reverseGeocoder(location) {
  85. QQMapWX.initMap();
  86. QQMapWX.reverseGeocoder(location, data => {
  87. this.region = [data.ad_info.province, data.ad_info.city, data.ad_info.district]
  88. console.log('解析后的地址地址数据:', data);
  89. });
  90. },
  91. bindRegionChange(event) {
  92. this.setData({
  93. region: event.detail.value
  94. });
  95. },
  96. setDefault() {
  97. this.setData({
  98. isDefault: !this.isDefault
  99. });
  100. },
  101. chooseAddress() {
  102. let _ts = this;
  103. req.getRequest('/api/address/get', {
  104. id: this.id
  105. }, res => {
  106. // console.log(res);
  107. const form = {
  108. id: res.id,
  109. userName: res.name,
  110. telNumber: res.phone,
  111. detailInfo: res.house
  112. };
  113. _ts.setData({
  114. form: form,
  115. isDefault: res.isDefault,
  116. region: res.region.split(',')
  117. });
  118. });
  119. },
  120. formSubmit(event) {
  121. let data = event.detail.value;
  122. if (!data.name) return req.msg('请填写收货人姓名');
  123. data.name = req.excludeSpecial(data.name);
  124. if (!data.phone) return req.msg('请填写手机号');
  125. if (this.region.length == 0) return req.msg('请选择收货人地区');
  126. data.address = this.region.join('');
  127. data.region = this.region.join(',');
  128. if (!data.house) return req.msg('请输入详细地址');
  129. data.isDefault = this.isDefault ? 1 : 0;
  130. let that = this; //进行地址解析
  131. data.id = this.form.id;
  132. QQMapWX.geocoder(data.address + data.house, res => {
  133. data.lat = res.location.lat;
  134. data.lng = res.location.lng;
  135. // if (res.deviation < 0 || res.reliability < 7) return req.msg('请输入详细的街道及门牌号');
  136. let isShowLoading = false;
  137. if (this.once) return false;
  138. this.setData({
  139. once: true
  140. });
  141. if (!isShowLoading) {
  142. req.loadIng('保存中');
  143. isShowLoading = true;
  144. }
  145. req.postRequest('/api/address/save', data, dto => {
  146. // 如果选择的地址和修改的地址一致就修改提交订单页面的地址
  147. if (this.addressId == this.id) {
  148. let pages = getCurrentPages();
  149. var prevPage = pages[pages.length - 3];
  150. prevPage.$vm.setData({
  151. address: data
  152. });
  153. }
  154. if (isShowLoading) {
  155. uni.hideLoading();
  156. uni.navigateBack();
  157. isShowLoading = false;
  158. }
  159. });
  160. });
  161. },
  162. deleteAddress() {
  163. let that = this;
  164. req.msgConfirm('确定删除该地址', () => {
  165. req.postRequest('/api/address/delete', {
  166. id: that.form.id
  167. }, () => {
  168. uni.navigateBack();
  169. });
  170. });
  171. }
  172. }
  173. };
  174. </script>
  175. <style>
  176. @import "./editAddress.css";
  177. </style>