add.vue 11 KB

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