add.vue 9.9 KB

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