add.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <view class="" v-if="XCXIsSelect=='是'">
  3. <form>
  4. <view class="cu-form-group">
  5. <view class="title">联系人</view>
  6. <input placeholder="请输入联系人" name="input" v-model="form.userName"></input>
  7. </view>
  8. <view class="cu-form-group">
  9. <view class="title">联系电话</view>
  10. <input placeholder="请输入联系电话" name="input" v-model="form.userPhone" maxlength="11"></input>
  11. </view>
  12. <view v-if="form.isInner">
  13. <view class="cu-form-group">
  14. <view class="title">选择校区</view>
  15. <view style="width: 50vw;text-align: end;">
  16. <picker style="padding-right: 0;" @change="bindPickerChange_station" :value="stationIndex" range-key="stationName" :range="stationList">
  17. <view :style="stationIndex==null?'color:#aaa':''">
  18. {{stationIndex==null?"请选择校区":stationList[stationIndex].stationName}}
  19. </view>
  20. </picker>
  21. </view>
  22. </view>
  23. <view class="cu-form-group">
  24. <view class="title">选择地址</view>
  25. <view style="width: 50vw;text-align: end;">
  26. <picker style="padding-right: 0;" @change="bindPickerChange" :value="addressIndex" range-key="addressDetail" :range="addressList">
  27. <view :style="addressIndex==null?'color:#aaa':''">
  28. {{addressIndex==null?"请选择地址":addressList[addressIndex].addressDetail}}
  29. </view>
  30. </picker>
  31. </view>
  32. </view>
  33. <view class="cu-form-group" v-if="form.insideDeliveryFee">
  34. <view class="title">当前特殊地址跑腿费:</view>
  35. <view style="color: #5E9289;">
  36. ¥{{form.insideDeliveryFee}}
  37. </view>
  38. </view>
  39. <view class="cu-form-group">
  40. <view class="title">备注信息</view>
  41. <view style="width: 60vw;height: 200rpx;border-radius: 12rpx;background-color: #F5F5F5;">
  42. <textarea v-model="form.remark" style="margin: 0; padding: 12rpx;height: 200rpx;"/>
  43. </view>
  44. </view>
  45. </view>
  46. <view v-else>
  47. <view class="cu-form-group" @click="pickerShow">
  48. <view class="title">所在地区</view>
  49. <input placeholder="请选择地区" name="input" disabled v-model="form.address"></input>
  50. <text class='cuIcon-locationfill text-orange'></text>
  51. </view>
  52. <view class="cu-form-group">
  53. <view class="title">详细地址</view>
  54. <input placeholder="请输入详细地址" name="input" v-model="form.addressDetail"></input>
  55. </view>
  56. </view>
  57. <view class="cu-form-group">
  58. <view class="title">设为默认</view>
  59. <switch @change="SwitchA" :class="form.addressDefault?'checked':''"
  60. :checked="form.addressDefault?true:false"></switch>
  61. </view>
  62. </form>
  63. <view class="btn" v-if="!id">
  64. <view class="address_push" @click="submit">保存</view>
  65. </view>
  66. <view class="btn" v-if="id">
  67. <view class="address_push" @click="updata">修改</view>
  68. </view>
  69. </view>
  70. <view v-else>
  71. <view style="font-size: 28upx;" v-html="content"></view>
  72. </view>
  73. </template>
  74. <script>
  75. import {
  76. requestAndroidPermission,
  77. gotoAppPermissionSetting
  78. } from '@/components/permission.js'
  79. export default {
  80. data() {
  81. return {
  82. form: {
  83. addressId: '',
  84. userName: '',
  85. userPhone: '',
  86. address: '',
  87. addressDetail: '',
  88. addressDefault: 0, //默认地址 0不默认 1默认
  89. lng: '',
  90. lat: '',
  91. isInner:false,
  92. insideAddressId:'',
  93. insideDeliveryFee:0,
  94. remark:""
  95. },
  96. region: '',
  97. id: '',
  98. latitude: '',
  99. longitude: '',
  100. XCXIsSelect: '是',
  101. content: '',
  102. addressList: [],
  103. addressIndex: null,
  104. stationList: [],
  105. stationIndex: null,
  106. stationId:'',
  107. deliveryFee:0
  108. }
  109. },
  110. onLoad(option) {
  111. this.XCXIsSelect = this.$queue.getData('XCXIsSelect') ? this.$queue.getData('XCXIsSelect') : '是';
  112. if (this.XCXIsSelect == '否') {
  113. this.getGuize()
  114. uni.setNavigationBarTitle({
  115. title: '隐私政策'
  116. });
  117. } else {
  118. uni.setNavigationBarTitle({
  119. title: '添加地址'
  120. });
  121. }
  122. this.getSetData()
  123. this.getStationData()
  124. this.id = option.id
  125. if (option.id) {
  126. this.getAddressDet(option.id)
  127. uni.setNavigationBarTitle({
  128. title: "修改地址"
  129. })
  130. }
  131. },
  132. methods: {
  133. getSetData(){
  134. this.$Request.get("/app/common/type/442").then(res => {
  135. if(res.code == 0){
  136. if(res.data.value == '1'){
  137. this.form.isInner = true
  138. }else{
  139. this.form.isInner = false
  140. }
  141. }
  142. });
  143. },
  144. getStationData(){
  145. this.$Request.get("/app/riderStation/stationList").then(res => {
  146. // console.log(res);
  147. if(res.code == 0){
  148. this.stationList = res.data
  149. }
  150. });
  151. },
  152. bindPickerChange_station(e){
  153. this.stationIndex = e.detail.value
  154. this.stationId = this.stationList[this.stationIndex].id
  155. this.form.address =this.stationList[this.stationIndex].stationName
  156. this.getAddress(this.stationId ,false)
  157. },
  158. getAddress(stationId ,type){
  159. this.$Request.get(`/app/inside-address/list/${stationId}`).then(res => {
  160. // console.log(res);
  161. if(res.code == 0){
  162. this.addressList = res.data
  163. if(type){
  164. this.addressIndex = this.addressList.findIndex((ele)=>ele.id == this.form.insideAddressId)
  165. }
  166. }
  167. });
  168. },
  169. bindPickerChange(e){
  170. this.addressIndex = e.detail.value
  171. this.form.lng = this.addressList[this.addressIndex].lng
  172. this.form.lat = this.addressList[this.addressIndex].lat
  173. this.form.province = this.addressList[this.addressIndex].province
  174. this.form.city = this.addressList[this.addressIndex].city
  175. this.form.district = this.addressList[this.addressIndex].district
  176. this.form.addressDetail = this.form.province + this.form.city + this.form.district + this.addressList[this.addressIndex].addressDetail
  177. this.form.insideAddressId = this.addressList[this.addressIndex].id
  178. this.form.insideDeliveryFee = this.addressList[this.addressIndex].deliveryFee
  179. },
  180. getGuize() {
  181. this.$Request.getT('/app/common/type/237').then(res => {
  182. if (res.code == 0) {
  183. this.content = res.data.value;
  184. // this.tit = res.data.min
  185. }
  186. });
  187. },
  188. pickerShow() {
  189. let that = this
  190. // An highlighted block
  191. uni.chooseLocation({
  192. success: function(res) {
  193. console.log(res)
  194. console.log('位置名称:' + res.name);
  195. console.log('详细地址:' + res.address);
  196. console.log('纬度:' + res.latitude);
  197. console.log('经度:' + res.longitude);
  198. let latitude = res.latitude; //纬度
  199. let longitude = res.longitude; //经度
  200. that.form.lng = longitude
  201. that.form.lat = latitude
  202. that.form.addressDetail = res.name
  203. let data = {
  204. lat: latitude,
  205. lng: longitude
  206. }
  207. that.$Request.get("/app/address/selectCity", data).then(res => {
  208. if (res.code == 0) {
  209. that.form.province = res.data.province
  210. that.form.city = res.data.city
  211. that.form.district = res.data.district
  212. that.form.address = res.data.province + res.data.city + res.data.district
  213. }
  214. });
  215. },fail(e) {
  216. console.log(e)
  217. uni.showModal({
  218. title: '温馨提示',
  219. content: '您的定位权限未开启,请开启后再来刷新操作吧!',
  220. showCancel: true,
  221. cancelText: '取消',
  222. confirmText: '确认',
  223. success: res => {
  224. if(res.confirm){
  225. // #ifdef MP-WEIXIN
  226. uni.openSetting({ // 打开设置页
  227. success(rea) {
  228. console.log(rea.authSetting)
  229. }
  230. });
  231. // #endif
  232. // #ifdef APP-PLUS
  233. gotoAppPermissionSetting()
  234. // #endif
  235. }
  236. }
  237. });
  238. }
  239. });
  240. },
  241. SwitchA(e) {
  242. // console.log(e.detail.value)
  243. this.form.addressDefault = e.detail.value
  244. },
  245. // 选择地区回调
  246. regionConfirm(e) {
  247. console.log(e)
  248. this.form.province = e.province.label
  249. this.form.city = e.city.label
  250. this.form.area = e.area.label
  251. this.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
  252. console.log(this.region)
  253. },
  254. // 提交
  255. submit() {
  256. if (!this.form.userName) {
  257. uni.showToast({
  258. title: '请输入姓名',
  259. icon: 'none'
  260. })
  261. return
  262. }
  263. if (!this.form.userPhone) {
  264. uni.showToast({
  265. title: '请输入联系电话',
  266. icon: 'none'
  267. })
  268. return
  269. }
  270. let phonereg = /^1[3-9]\d{9}$/
  271. if (!phonereg.test(this.form.userPhone)) {
  272. uni.showToast({
  273. title: '请输入正确联系电话',
  274. icon: 'none'
  275. })
  276. return
  277. }
  278. if(this.form.isInner){
  279. if (!this.form.address) {
  280. uni.showToast({
  281. title: '请选择骑手站点',
  282. icon: 'none'
  283. })
  284. return
  285. }
  286. if (!this.form.addressDetail) {
  287. uni.showToast({
  288. title: '请选择详细地址',
  289. icon: 'none'
  290. })
  291. return
  292. }
  293. }else{
  294. if (!this.form.address) {
  295. uni.showToast({
  296. title: '请选择所在地区',
  297. icon: 'none'
  298. })
  299. return
  300. }
  301. if (!this.form.addressDetail) {
  302. uni.showToast({
  303. title: '请输入详细地址',
  304. icon: 'none'
  305. })
  306. return
  307. }
  308. }
  309. this.form.addressDefault = this.form.addressDefault ? 1 : 0
  310. console.log(this.form);
  311. this.$Request.postJson("/app/address/insertAddress", this.form).then(res => {
  312. console.log(res,'地址')
  313. if (res.code == 0) {
  314. uni.showToast({
  315. title: '保存成功',
  316. icon: 'none'
  317. })
  318. setTimeout(function() {
  319. uni.navigateBack()
  320. }, 1000)
  321. }
  322. });
  323. },
  324. // 修改
  325. updata() {
  326. if (!this.form.userName) {
  327. uni.showToast({
  328. title: '请输入姓名',
  329. icon: 'none'
  330. })
  331. return
  332. }
  333. if (!this.form.userPhone) {
  334. uni.showToast({
  335. title: '请输入联系电话',
  336. icon: 'none'
  337. })
  338. return
  339. }
  340. if (!this.form.address) {
  341. uni.showToast({
  342. title: '请选择所在地区',
  343. icon: 'none'
  344. })
  345. return
  346. }
  347. if (!this.form.addressDetail) {
  348. uni.showToast({
  349. title: '请输入详细地址',
  350. icon: 'none'
  351. })
  352. return
  353. }
  354. let data = {
  355. addressId: this.form.addressId,
  356. userName: this.form.userName,
  357. userPhone: this.form.userPhone,
  358. province: this.form.province,
  359. city: this.form.city,
  360. district: this.form.district,
  361. address: this.form.address,
  362. addressDetail: this.form.addressDetail,
  363. addressDefault: this.form.addressDefault ? 1 : 0,
  364. lng: this.form.lng,
  365. lat: this.form.lat,
  366. insideAddressId:this.form.insideAddressId
  367. }
  368. console.log(data);
  369. this.$Request.postJson("/app/address/updateAddress", data).then(res => {
  370. console.log(res);
  371. if (res.code == 0) {
  372. uni.showToast({
  373. title: '修改成功',
  374. icon: 'none'
  375. })
  376. setTimeout(function() {
  377. uni.navigateBack()
  378. }, 1500)
  379. }
  380. });
  381. },
  382. // 根据id获取地址详情
  383. getAddressDet(e) {
  384. let data = {
  385. addressId: e,
  386. }
  387. this.$Request.get("/app/address/selectAddressById",data).then(res => {
  388. console.log(res);
  389. if (res.code == 0) {
  390. this.form.addressId = res.data.addressId
  391. this.form.userName = res.data.userName
  392. this.form.userPhone = res.data.userPhone
  393. this.form.address = res.data.province + res.data.city + res.data.district
  394. this.form.addressDetail = res.data.addressDetail
  395. this.form.lng = res.data.lng
  396. this.form.lat = res.data.lat
  397. this.form.addressDefault = res.data.addressDefault
  398. this.form.province = res.data.province
  399. this.form.city = res.data.city
  400. this.form.district = res.data.district
  401. this.form.insideAddressId = res.data.insideAddressId
  402. this.form.insideDeliveryFee = res.data.insideDeliveryFee
  403. this.form.remark = res.data.remark
  404. this.stationIndex = this.stationList.findIndex((ele)=>ele.id == res.data.stationId)
  405. if(this.stationIndex){
  406. this.getAddress(res.data.stationId ,true)
  407. }
  408. }
  409. });
  410. }
  411. }
  412. }
  413. </script>
  414. <style>
  415. page {
  416. background-color: #fff !important;
  417. }
  418. /* 添加收货地址 */
  419. .btn {
  420. position: fixed;
  421. bottom: 100rpx;
  422. width: 100%;
  423. height: 100rpx;
  424. line-height: 100rpx;
  425. background-color: white;
  426. margin-top: 30rpx;
  427. }
  428. .address_push {
  429. width: 90%;
  430. height: 80rpx;
  431. margin: 0 auto;
  432. border-radius: 100rpx;
  433. color: white;
  434. text-align: center;
  435. line-height: 80rpx;
  436. font-size: 35rpx;
  437. background: linear-gradient(90deg, #5D9188 0%, #71A296 100%);
  438. }
  439. </style>