editAddress.vue 5.9 KB

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