add.vue 8.2 KB

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