add.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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.getSetData()
  112. this.getStationData(option.page)
  113. this.XCXIsSelect = this.$queue.getData('XCXIsSelect') ? this.$queue.getData('XCXIsSelect') : '是';
  114. if (this.XCXIsSelect == '否') {
  115. this.getGuize()
  116. uni.setNavigationBarTitle({
  117. title: '隐私政策'
  118. });
  119. } else {
  120. uni.setNavigationBarTitle({
  121. title: '添加地址'
  122. });
  123. }
  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(page){
  145. this.$Request.get("/app/riderStation/stationList").then(res => {
  146. console.log(res);
  147. if(res.code == 0){
  148. this.stationList = res.data
  149. if(page){
  150. this.stationList.forEach((ele,index)=>{
  151. if(ele.stationName =='墨轩湖校区'){
  152. this.stationIndex = index
  153. this.stationId = this.stationList[this.stationIndex].id
  154. this.form.address =this.stationList[this.stationIndex].stationName
  155. this.getAddress(this.stationId ,false)
  156. }
  157. })
  158. }
  159. }
  160. });
  161. },
  162. bindPickerChange_station(e){
  163. this.stationIndex = e.detail.value
  164. this.stationId = this.stationList[this.stationIndex].id
  165. this.form.address =this.stationList[this.stationIndex].stationName
  166. this.getAddress(this.stationId ,false)
  167. },
  168. getAddress(stationId ,type){
  169. this.$Request.get(`/app/inside-address/list/${stationId}`).then(res => {
  170. console.log(res,96325);
  171. if(res.code == 0){
  172. this.addressList = res.data
  173. if(type){
  174. this.addressIndex = this.addressList.findIndex((ele)=>ele.id == this.form.insideAddressId)
  175. }
  176. }
  177. });
  178. },
  179. bindPickerChange(e){
  180. this.addressIndex = e.detail.value
  181. this.form.lng = this.addressList[this.addressIndex].lng
  182. this.form.lat = this.addressList[this.addressIndex].lat
  183. this.form.province = this.addressList[this.addressIndex].province
  184. this.form.city = this.addressList[this.addressIndex].city
  185. this.form.district = this.addressList[this.addressIndex].district
  186. this.form.addressDetail = this.form.province + this.form.city + this.form.district + this.addressList[this.addressIndex].addressDetail
  187. this.form.insideAddressId = this.addressList[this.addressIndex].id
  188. this.form.insideDeliveryFee = this.addressList[this.addressIndex].deliveryFee
  189. },
  190. getGuize() {
  191. this.$Request.getT('/app/common/type/237').then(res => {
  192. if (res.code == 0) {
  193. this.content = res.data.value;
  194. // this.tit = res.data.min
  195. }
  196. });
  197. },
  198. pickerShow() {
  199. let that = this
  200. // An highlighted block
  201. uni.chooseLocation({
  202. success: function(res) {
  203. console.log(res)
  204. console.log('位置名称:' + res.name);
  205. console.log('详细地址:' + res.address);
  206. console.log('纬度:' + res.latitude);
  207. console.log('经度:' + res.longitude);
  208. let latitude = res.latitude; //纬度
  209. let longitude = res.longitude; //经度
  210. that.form.lng = longitude
  211. that.form.lat = latitude
  212. that.form.addressDetail = res.name
  213. let data = {
  214. lat: latitude,
  215. lng: longitude
  216. }
  217. that.$Request.get("/app/address/selectCity", data).then(res => {
  218. if (res.code == 0) {
  219. that.form.province = res.data.province
  220. that.form.city = res.data.city
  221. that.form.district = res.data.district
  222. that.form.address = res.data.province + res.data.city + res.data.district
  223. }
  224. });
  225. },fail(e) {
  226. console.log(e)
  227. uni.showModal({
  228. title: '温馨提示',
  229. content: '您的定位权限未开启,请开启后再来刷新操作吧!',
  230. showCancel: true,
  231. cancelText: '取消',
  232. confirmText: '确认',
  233. success: res => {
  234. if(res.confirm){
  235. // #ifdef MP-WEIXIN
  236. uni.openSetting({ // 打开设置页
  237. success(rea) {
  238. console.log(rea.authSetting)
  239. }
  240. });
  241. // #endif
  242. // #ifdef APP-PLUS
  243. gotoAppPermissionSetting()
  244. // #endif
  245. }
  246. }
  247. });
  248. }
  249. });
  250. },
  251. SwitchA(e) {
  252. // console.log(e.detail.value)
  253. this.form.addressDefault = e.detail.value
  254. },
  255. // 选择地区回调
  256. regionConfirm(e) {
  257. console.log(e)
  258. this.form.province = e.province.label
  259. this.form.city = e.city.label
  260. this.form.area = e.area.label
  261. this.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
  262. console.log(this.region)
  263. },
  264. // 提交
  265. submit() {
  266. if (!this.form.userName) {
  267. uni.showToast({
  268. title: '请输入姓名',
  269. icon: 'none'
  270. })
  271. return
  272. }
  273. if (!this.form.userPhone) {
  274. uni.showToast({
  275. title: '请输入联系电话',
  276. icon: 'none'
  277. })
  278. return
  279. }
  280. let phonereg = /^1[3-9]\d{9}$/
  281. if (!phonereg.test(this.form.userPhone)) {
  282. uni.showToast({
  283. title: '请输入正确联系电话',
  284. icon: 'none'
  285. })
  286. return
  287. }
  288. if(this.form.isInner){
  289. if (!this.form.address) {
  290. uni.showToast({
  291. title: '请选择校区',
  292. icon: 'none'
  293. })
  294. return
  295. }
  296. if (!this.form.addressDetail) {
  297. uni.showToast({
  298. title: '请选择详细地址',
  299. icon: 'none'
  300. })
  301. return
  302. }
  303. }else{
  304. if (!this.form.address) {
  305. uni.showToast({
  306. title: '请选择所在地区',
  307. icon: 'none'
  308. })
  309. return
  310. }
  311. if (!this.form.addressDetail) {
  312. uni.showToast({
  313. title: '请输入详细地址',
  314. icon: 'none'
  315. })
  316. return
  317. }
  318. }
  319. this.form.addressDefault = this.form.addressDefault ? 1 : 0
  320. console.log(this.form);
  321. this.$Request.postJson("/app/address/insertAddress", this.form).then(res => {
  322. console.log(res,'地址')
  323. if (res.code == 0) {
  324. uni.showToast({
  325. title: '保存成功',
  326. icon: 'none'
  327. })
  328. setTimeout(function() {
  329. uni.navigateBack()
  330. }, 1000)
  331. }
  332. });
  333. },
  334. // 修改
  335. updata() {
  336. if (!this.form.userName) {
  337. uni.showToast({
  338. title: '请输入姓名',
  339. icon: 'none'
  340. })
  341. return
  342. }
  343. if (!this.form.userPhone) {
  344. uni.showToast({
  345. title: '请输入联系电话',
  346. icon: 'none'
  347. })
  348. return
  349. }
  350. let phonereg = /^1[3-9]\d{9}$/
  351. if (!phonereg.test(this.form.userPhone)) {
  352. uni.showToast({
  353. title: '请输入正确联系电话',
  354. icon: 'none'
  355. })
  356. return
  357. }
  358. if(this.form.isInner){
  359. if (!this.form.address) {
  360. uni.showToast({
  361. title: '请选择校区',
  362. icon: 'none'
  363. })
  364. return
  365. }
  366. if (!this.form.addressDetail) {
  367. uni.showToast({
  368. title: '请选择详细地址',
  369. icon: 'none'
  370. })
  371. return
  372. }
  373. }else{
  374. if (!this.form.address) {
  375. uni.showToast({
  376. title: '请选择所在地区',
  377. icon: 'none'
  378. })
  379. return
  380. }
  381. if (!this.form.addressDetail) {
  382. uni.showToast({
  383. title: '请输入详细地址',
  384. icon: 'none'
  385. })
  386. return
  387. }
  388. }
  389. let data = {
  390. addressId: this.form.addressId,
  391. userName: this.form.userName,
  392. userPhone: this.form.userPhone,
  393. province: this.form.province,
  394. city: this.form.city,
  395. district: this.form.district,
  396. address: this.form.address,
  397. addressDetail: this.form.addressDetail,
  398. addressDefault: this.form.addressDefault ? 1 : 0,
  399. lng: this.form.lng,
  400. lat: this.form.lat,
  401. insideAddressId:this.form.insideAddressId
  402. }
  403. console.log(data);
  404. this.$Request.postJson("/app/address/updateAddress", data).then(res => {
  405. console.log(res);
  406. if (res.code == 0) {
  407. uni.showToast({
  408. title: '修改成功',
  409. icon: 'none'
  410. })
  411. setTimeout(function() {
  412. uni.navigateBack()
  413. }, 1500)
  414. }
  415. });
  416. },
  417. // 根据id获取地址详情
  418. getAddressDet(e) {
  419. let data = {
  420. addressId: e,
  421. }
  422. this.$Request.get("/app/address/selectAddressById",data).then(res => {
  423. console.log(res);
  424. if (res.code == 0) {
  425. this.form.addressId = res.data.addressId
  426. this.form.userName = res.data.userName
  427. this.form.userPhone = res.data.userPhone
  428. this.form.address = res.data.province + res.data.city + res.data.district
  429. this.form.addressDetail = res.data.addressDetail
  430. this.form.lng = res.data.lng
  431. this.form.lat = res.data.lat
  432. this.form.addressDefault = res.data.addressDefault
  433. this.form.province = res.data.province
  434. this.form.city = res.data.city
  435. this.form.district = res.data.district
  436. this.form.insideAddressId = res.data.insideAddressId
  437. this.form.insideDeliveryFee = res.data.insideDeliveryFee
  438. this.form.remark = res.data.remark
  439. this.stationIndex = this.stationList.findIndex((ele)=>ele.id == res.data.stationId)
  440. if(this.stationIndex){
  441. this.getAddress(res.data.stationId ,true)
  442. }
  443. }
  444. });
  445. }
  446. }
  447. }
  448. </script>
  449. <style>
  450. page {
  451. background-color: #fff !important;
  452. }
  453. .btn {
  454. position: fixed;
  455. bottom: 100rpx;
  456. width: 100%;
  457. height: 100rpx;
  458. line-height: 100rpx;
  459. background-color: white;
  460. margin-top: 30rpx;
  461. }
  462. .address_push {
  463. width: 90%;
  464. height: 80rpx;
  465. margin: 0 auto;
  466. border-radius: 100rpx;
  467. color: white;
  468. text-align: center;
  469. line-height: 80rpx;
  470. font-size: 35rpx;
  471. background: linear-gradient(90deg, #5D9188 0%, #71A296 100%);
  472. }
  473. </style>