Endaddress.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="Endaddress">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view class="part1">
  5. <view class="mobile">
  6. <u-field v-model="mobile" placeholder="联系电话" icon="phone-fill" maxlength="11" type="number" label-align="center">
  7. </u-field>
  8. </view>
  9. <view class="name">
  10. <u-field v-model="name" placeholder="姓名" icon="account-fill" 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="#2FB57A" />
  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="content">
  41. <view class="mobile">
  42. <u-field v-model="mobile" label="联系电话" placeholder="请填写联系电话" maxlength="11">
  43. </u-field>
  44. </view>
  45. <view class="name">
  46. <u-field v-model="name" label="姓名" placeholder="请填写姓名">
  47. </u-field>
  48. </view>
  49. <view class="address" @click="bindmap">
  50. <u-field v-model="cityaddress" label="地址" placeholder="请选择地址" >
  51. </u-field>
  52. </view>
  53. <view class="detailaddress">
  54. <u-field v-model="detailaddress" label="详细地址" placeholder="请填写详细地址">
  55. </u-field>
  56. </view>
  57. </view>
  58. <view
  59. style="height: 100upx;display: flex;margin-top: 20rpx;justify-content: space-between;">
  60. <view style="font-weight: bold;font-size: 28rpx;color: #222222;text-align: left;padding: 30upx;width: 70%;">设为默认地址</view>
  61. <switch type="switch" :checked='isDefault === 1 ? true : false' @change="switch1Change"
  62. style="padding: 20upx;transform:scale(0.9)" active-color="#557EFD" />
  63. </view>
  64. <view class="btn" @click="bindhelp">确定</view>
  65. </view>
  66. <!-- #endif -->
  67. </view>
  68. </template>
  69. <script>
  70. // import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue'
  71. import pickerAddress from '@/my/components/wangding-pickerAddress/wangding-pickerAddress.vue'
  72. export default {
  73. components: {
  74. pickerAddress
  75. },
  76. data() {
  77. return {
  78. // provinces: '选择地址',
  79. // consignee: '',
  80. // mobile: '',
  81. // detail: '',
  82. // createAt: '',
  83. id: '',
  84. isDefault: 0,
  85. // id: 0,
  86. mobile: '',
  87. name: '',
  88. cityaddress: '',
  89. detailaddress: '',
  90. latitude: '',
  91. longitude: '',
  92. province:'',
  93. city:'',
  94. district:''
  95. }
  96. },
  97. onLoad(d) {
  98. let id = d.id;
  99. if (id) {
  100. this.id = d.id;
  101. uni.setNavigationBarTitle({
  102. title: '编辑地址'
  103. });
  104. this.getAddressList(id);
  105. } else {
  106. uni.setNavigationBarTitle({
  107. title: '添加地址'
  108. });
  109. }
  110. },
  111. methods: {
  112. change(data) {
  113. this.provinces = data.data.join('')
  114. },
  115. bindmap() {
  116. var that = this
  117. // if (that.ciaddress == '') {
  118. uni.chooseLocation({
  119. latitude:uni.getStorageSync('latitude')||30.574174,
  120. longitude:uni.getStorageSync('longitude')||103.923765,
  121. success: function(res) {
  122. // console.log(res)
  123. console.log('位置名称:' + res.name);
  124. console.log('详细地址:' + res.address);
  125. console.log('纬度:' + res.latitude);
  126. console.log('经度:' + res.longitude);
  127. that.detailaddress = res.name
  128. that.latitude = res.latitude
  129. that.longitude = res.longitude
  130. that.shengcheng(res.longitude, res.latitude)
  131. }
  132. });
  133. // }
  134. },
  135. shengcheng(longitude, latitude) {
  136. this.$Request.getT('/app/Login/selectCity?lat=' + latitude + '&lng=' + longitude).then(res => {
  137. // console.log(res)
  138. if (res.code === 0) {
  139. this.cityaddress = res.data.province + res.data.city + res.data.district
  140. // console.log(this.address)
  141. this.province = res.data.province
  142. this.city = res.data.city
  143. this.district = res.data.district
  144. }
  145. });
  146. },
  147. getAddressList(id) {
  148. uni.showLoading({
  149. title: '加载中...'
  150. });
  151. this.$Request.getT('/app/address/selectAddressByAddressId?addressId=' + id).then(res => {
  152. console.log(res)
  153. if (res.code == 0) {
  154. this.name = res.data.name;
  155. this.mobile = res.data.phone;
  156. this.cityaddress =res.data.province+ res.data.city+res.data.district;
  157. this.detailaddress = res.data.detailsAddress;
  158. this.isDefault = res.data.isDefault;
  159. this.userId = res.data.userId;
  160. this.latitude = res.data.latitude;
  161. this.longitude = res.data.longitude;
  162. this.province = res.data.province
  163. this.city = res.data.city
  164. this.district = res.data.district
  165. }
  166. uni.hideLoading();
  167. });
  168. },
  169. bindhelp() {
  170. if (this.id) {
  171. this.$queue.showLoading('修改中...')
  172. } else {
  173. this.$queue.showLoading('添加中...')
  174. }
  175. let userId = this.$queue.getData('userId');
  176. let data = {
  177. name: this.name,
  178. phone: this.mobile,
  179. province:this.province,
  180. city:this.city,
  181. district:this.district,
  182. detailsAddress:this.detailaddress,
  183. isDefault:this.isDefault,
  184. addressId: this.id,
  185. // address: this.cityaddress,
  186. // addressDetail: this.detailaddress,
  187. latitude: this.latitude,
  188. longitude: this.longitude,
  189. // userId: userId,
  190. // addressDefault: this.isDefault
  191. }
  192. if (this.mobile.length < 11) {
  193. uni.showToast({
  194. icon: 'none',
  195. title: '请输入正确的电话信息'
  196. });
  197. return;
  198. }
  199. if (this.name != undefined && this.name != '') {} else {
  200. uni.showToast({
  201. icon: 'none',
  202. title: '姓名不能为空'
  203. });
  204. return;
  205. }
  206. if (this.cityaddress == '选择地址') {
  207. uni.showToast({
  208. icon: 'none',
  209. title: '请选择地址信息'
  210. });
  211. return;
  212. }
  213. if (this.detailaddress != undefined && this.detailaddress != '') {} else {
  214. uni.showToast({
  215. icon: 'none',
  216. title: '地址信息不能为空'
  217. });
  218. return;
  219. }
  220. if (this.id) {
  221. this.$Request.postJson('/app/address/updateAddress', data).then(res => {
  222. if (res.code == 0) {
  223. uni.hideLoading()
  224. this.$queue.showToast("修改成功!");
  225. setTimeout(d => {
  226. uni.navigateBack();
  227. }, 1000)
  228. } else {
  229. uni.hideLoading()
  230. this.$queue.showToast(res.msg);
  231. }
  232. });
  233. } else {
  234. this.$Request.postJson('/app/address/insertAddress', data).then(res => {
  235. if (res.code == 0) {
  236. uni.hideLoading()
  237. this.$queue.showToast("添加成功!");
  238. setTimeout(d => {
  239. uni.navigateBack();
  240. }, 1000)
  241. } else {
  242. uni.hideLoading()
  243. this.$queue.showToast(res.msg);
  244. }
  245. });
  246. }
  247. },
  248. //校验手机格式
  249. checkMobile(mobile) {
  250. return RegExp(/^1[34578]\d{9}$/).test(mobile);
  251. },
  252. switch1Change(e) {
  253. console.log(e);
  254. this.isDefault = e.detail.value == true ? 1 : 0;
  255. }
  256. }
  257. }
  258. </script>
  259. <style lang="scss" >
  260. .Endaddress ::v-deep uni-switch::before{
  261. display: none;
  262. }
  263. .Endaddress ::v-deep .uni-switch-input-checked{
  264. background:#07BF89!important;
  265. }
  266. .Endaddress ::v-deep .u-label-text{
  267. font-weight: bold;
  268. font-size: 28rpx;
  269. color: #222222;
  270. }
  271. .Endaddress {
  272. background: #F6F6F6;
  273. height: 100vh;
  274. padding-top: 20rpx;
  275. .part1 {
  276. width: 100%;
  277. margin-top: 24rpx;
  278. padding-bottom: 40upx;
  279. .content{
  280. background: #FFFFFF;
  281. border-radius: 32rpx 32rpx 32rpx 32rpx;
  282. margin-left: 32rpx;
  283. margin-right: 32rpx;
  284. }
  285. .btn {
  286. width: 686rpx;
  287. height: 100rpx;
  288. line-height: 100rpx;
  289. background: linear-gradient( 143deg, #FFE6EE 0%, #FF9AB2 100%);
  290. border-radius: 86rpx 86rpx 86rpx 86rpx;
  291. margin: 0 auto;
  292. font-weight: bold;
  293. font-size: 32rpx;
  294. color: #222222;
  295. text-align: center;
  296. margin-top: 20upx;
  297. }
  298. }
  299. }
  300. .u-icon__icon {
  301. font-size: 45rpx !important;
  302. }
  303. .u-field {
  304. padding: 35rpx 28rpx !important;
  305. }
  306. .u-label {
  307. flex: 0 0 42px !important;
  308. }
  309. .u-field__input-wrap {
  310. font-size: 30rpx !important;
  311. }
  312. .u-textarea-class {
  313. font-size: 30rpx !important;
  314. }
  315. </style>