Endaddress.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view class="part1">
  5. <view class="name">
  6. <u-field v-model="name" placeholder="姓名" icon="account-fill" label-align="center">
  7. </u-field>
  8. </view>
  9. <view class="mobile">
  10. <u-field v-model="mobile" placeholder="联系电话" icon="phone-fill" type="number" label-align="center">
  11. </u-field>
  12. </view>
  13. <view class="address" @click="bindmap">
  14. <u-field v-model="cityaddress" placeholder="地址" :disabled="true" icon="map-fill" label-align="center">
  15. </u-field>
  16. </view>
  17. <view class="detailaddress">
  18. <u-field v-model="detailaddress" placeholder="详细地址" icon="map-fill" label-align="center">
  19. </u-field>
  20. </view>
  21. <view
  22. style="height: 100upx;background:#FFFFFF;display: flex;margin-top: 30upx;justify-content: space-between;padding: 0rpx 22rpx;">
  23. <view style="font-size: 30upx;color: #333333;text-align: left;padding: 30upx;width: 70%;">设为默认地址</view>
  24. <switch type="switch" :checked='isDefault === 1 ? true : false' @change="switch1Change"
  25. style="padding: 20upx;transform:scale(0.9)" color="#FF7F00" />
  26. </view>
  27. <view class="btn" @click="bindhelp">确定</view>
  28. </view>
  29. <!-- <view style="margin-top: 20upx;background-color: #FFFFFF;height: max-content;padding: 20upx 20upx 20upx 35upx;">
  30. <input type="text" placeholder="收货人" style="height: 80upx;color: #000000;font-size: 30upx;" v-model="consignee" />
  31. <input type="number" placeholder="手机号码" maxlength="11" style="height: 80upx;margin-top: 20upx;color: #000000;font-size: 30upx;"
  32. v-model="mobile" />
  33. <view style="height: 1upx;margin-top: 50upx;"></view>
  34. <pickerAddress style="padding-bottom: 20upx;color: #000000;font-size: 30upx;height: 30upx;" @change="change">{{provinces}}</pickerAddress>
  35. <input type="text" v-model="detail" placeholder="详情地址:如道路,门牌号,小区,楼栋号,单元室等" style="height: 80upx;margin-top: 30upx;color: #000000;font-size: 30upx;" />
  36. </view> -->
  37. <!-- #endif -->
  38. <!-- #ifndef MP-WEIXIN -->
  39. <view class="part1">
  40. <view class="mobile">
  41. <u-field v-model="mobile" placeholder="联系电话" icon="phone-fill" label-align="center">
  42. </u-field>
  43. </view>
  44. <view class="name">
  45. <u-field v-model="name" placeholder="姓名" icon="account-fill" label-align="center">
  46. </u-field>
  47. </view>
  48. <view class="address" @click="bindmap">
  49. <u-field v-model="cityaddress" placeholder="地址" :disabled="true" icon="map-fill" label-align="center">
  50. </u-field>
  51. </view>
  52. <view class="detailaddress">
  53. <u-field v-model="detailaddress" placeholder="详细地址" icon="map-fill" label-align="center">
  54. </u-field>
  55. </view>
  56. <view
  57. style="height: 100upx;background:#FFFFFF;display: flex;margin-top: 30upx;justify-content: space-between;padding: 0rpx 22rpx;">
  58. <view style="font-size: 34upx;color: #333333;text-align: left;padding: 30upx;width: 70%;">设为默认地址</view>
  59. <switch type="switch" :checked='isDefault === 1 ? true : false' @change="switch1Change"
  60. style="padding: 20upx;transform:scale(0.9)" color="#FF7F00" />
  61. </view>
  62. <view class="btn" @click="bindhelp">确定</view>
  63. </view>
  64. <!-- #endif -->
  65. <!-- <button
  66. style="width: 85%;height: 90upx;background: #FF332F;font-size: 32upx;color: #FFFFFF;margin-top: 40upx;border-radius: 50upx;line-height: 100upx;"
  67. @tap='setEditAddress'>保存</button> -->
  68. </view>
  69. </template>
  70. <script>
  71. // import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue'
  72. import pickerAddress from '@/pageA/components/wangding-pickerAddress/wangding-pickerAddress.vue'
  73. export default {
  74. components: {
  75. pickerAddress
  76. },
  77. data() {
  78. return {
  79. // provinces: '选择地址',
  80. // consignee: '',
  81. // mobile: '',
  82. // detail: '',
  83. // createAt: '',
  84. id: '',
  85. isDefault: 0,
  86. // id: 0,
  87. mobile: '',
  88. name: '',
  89. cityaddress: '',
  90. detailaddress: '',
  91. latitude: '',
  92. longitude: '',
  93. }
  94. },
  95. onLoad(d) {
  96. let id = d.id;
  97. if (id) {
  98. this.id = d.id;
  99. uni.setNavigationBarTitle({
  100. title: '编辑地址'
  101. });
  102. this.getAddressList(id);
  103. } else {
  104. uni.setNavigationBarTitle({
  105. title: '添加地址'
  106. });
  107. }
  108. },
  109. methods: {
  110. change(data) {
  111. this.provinces = data.data.join('')
  112. },
  113. bindmap() {
  114. var that = this
  115. // if (that.ciaddress == '') {
  116. uni.chooseLocation({
  117. success: function(res) {
  118. // console.log(res)
  119. console.log('位置名称:' + res.name);
  120. console.log('详细地址:' + res.address);
  121. console.log('纬度:' + res.latitude);
  122. console.log('经度:' + res.longitude);
  123. that.detailaddress = res.name
  124. that.latitude = res.latitude
  125. that.longitude = res.longitude
  126. that.shengcheng(res.longitude, res.latitude)
  127. }
  128. });
  129. // }
  130. },
  131. shengcheng(longitude, latitude) {
  132. this.$Request.getT('/app/Login/selectCity?lat=' + latitude + '&lng=' + longitude).then(res => {
  133. // console.log(res)
  134. if (res.code === 0) {
  135. this.cityaddress = res.data.province + res.data.city + res.data.district
  136. // console.log(this.address)
  137. }
  138. });
  139. },
  140. getAddressList(id) {
  141. uni.showLoading({
  142. title: '加载中...'
  143. });
  144. this.$Request.getT('/app/indent/findAddressById?addressId=' + id).then(res => {
  145. console.log(res)
  146. if (res.code == 0) {
  147. this.name = res.data.userName;
  148. this.mobile = res.data.userPhone;
  149. this.cityaddress = res.data.address;
  150. this.detailaddress = res.data.addressDetail;
  151. this.isDefault = res.data.addressDefault;
  152. this.userId = res.data.userId;
  153. this.latitude = res.data.latitude;
  154. this.longitude = res.data.longitude;
  155. }
  156. uni.hideLoading();
  157. });
  158. },
  159. bindhelp() {
  160. if (this.id) {
  161. this.$queue.showLoading('修改中...')
  162. } else {
  163. this.$queue.showLoading('添加中...')
  164. }
  165. let userId = this.$queue.getData('userId');
  166. let data = {
  167. userName: this.name,
  168. userPhone: this.mobile,
  169. address: this.cityaddress,
  170. addressDetail: this.detailaddress,
  171. addressLatitude: this.latitude,
  172. addressLongitude: this.longitude,
  173. userId: userId,
  174. addressId: this.id,
  175. addressDefault: this.isDefault
  176. }
  177. if (this.mobile.length < 11) {
  178. uni.showToast({
  179. icon: 'none',
  180. title: '请输入正确的电话信息'
  181. });
  182. return;
  183. }
  184. if (this.name != undefined && this.name != '') {} else {
  185. uni.showToast({
  186. icon: 'none',
  187. title: '收货人不能为空'
  188. });
  189. return;
  190. }
  191. if (this.cityaddress == '选择地址') {
  192. uni.showToast({
  193. icon: 'none',
  194. title: '请选择地址信息'
  195. });
  196. return;
  197. }
  198. if (this.detailaddress != undefined && this.detailaddress != '') {} else {
  199. uni.showToast({
  200. icon: 'none',
  201. title: '地址信息不能为空'
  202. });
  203. return;
  204. }
  205. if (this.id) {
  206. this.$Request.postJson('/app/indent/updateAddress', data).then(res => {
  207. if (res.code == 0) {
  208. uni.hideLoading()
  209. this.$queue.showToast("修改成功!");
  210. setTimeout(d => {
  211. uni.navigateBack();
  212. }, 1000)
  213. } else {
  214. uni.hideLoading()
  215. this.$queue.showToast(res.msg);
  216. }
  217. });
  218. } else {
  219. this.$Request.postJson('/app/indent/addUserAddress', data).then(res => {
  220. if (res.code == 0) {
  221. uni.hideLoading()
  222. this.$queue.showToast("添加成功!");
  223. setTimeout(d => {
  224. uni.navigateBack();
  225. }, 1000)
  226. } else {
  227. uni.hideLoading()
  228. this.$queue.showToast(res.msg);
  229. }
  230. });
  231. }
  232. },
  233. //校验手机格式
  234. checkMobile(mobile) {
  235. return RegExp(/^1[34578]\d{9}$/).test(mobile);
  236. },
  237. switch1Change(e) {
  238. this.isDefault = e.detail.value == true ? 1 : 0;
  239. }
  240. }
  241. }
  242. </script>
  243. <style>
  244. body {
  245. background: #FFFFFF;
  246. }
  247. .part1 {
  248. width: 100%;
  249. background: #ffffff;
  250. margin-top: 24rpx;
  251. padding-bottom: 40upx;
  252. }
  253. .btn {
  254. width: 90%;
  255. height: 80upx;
  256. background: #FF7F00;
  257. border-radius: 14upx;
  258. margin: 0 auto;
  259. color: white;
  260. text-align: center;
  261. line-height: 80upx;
  262. letter-spacing: 2upx;
  263. margin-top: 40upx;
  264. }
  265. .u-icon__icon {
  266. font-size: 45rpx !important;
  267. }
  268. .u-field {
  269. padding: 35rpx 28rpx !important;
  270. }
  271. .u-label {
  272. flex: 0 0 42px !important;
  273. }
  274. .u-field__input-wrap {
  275. font-size: 30rpx !important;
  276. }
  277. .u-textarea-class {
  278. font-size: 30rpx !important;
  279. }
  280. </style>