closeaddress.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <view>
  3. <u-navbar :is-back="true">
  4. <!-- #ifndef MP-WEIXIN -->
  5. <view style="width: 100%;text-align: center;letter-spacing: 2rpx;font-weight: bold;font-size: 30rpx;">
  6. <view v-if="indentType == 1||indentType == 2||indentType == 3">填写收货地址</view>
  7. <view v-if="indentType == 4">填写服务地址</view>
  8. </view>
  9. <!-- #endif -->
  10. <!-- #ifdef MP-WEIXIN -->
  11. <view class="slot-wrap">
  12. <view v-if="indentType == 1||indentType == 2||indentType == 3">填写收货地址</view>
  13. <view v-if="indentType == 4">填写服务地址</view>
  14. </view>
  15. <!-- #endif -->
  16. </u-navbar>
  17. <view class="content">
  18. <!-- 正文内容 -->
  19. <view class="takeaddress">
  20. <view class="part1">
  21. <view class="name">
  22. <u-field v-model="name" placeholder="联系人姓名" type="text" icon="account-fill"
  23. label-align="center">
  24. </u-field>
  25. </view>
  26. <view class="mobile">
  27. <u-field :maxlength="11" v-model="mobile" type="number" placeholder="联系电话" icon="phone-fill"
  28. label-align="center">
  29. </u-field>
  30. </view>
  31. <view class="address" @click="bindmap">
  32. <u-field v-model="cityaddress" placeholder="选择地址" :disabled="true" icon="map-fill"
  33. label-align="center">
  34. </u-field>
  35. </view>
  36. <view class="detailaddress">
  37. <u-field v-model="detailaddress" placeholder="详细地址" icon="map-fill" label-align="center">
  38. </u-field>
  39. </view>
  40. <view class="btn" @click="bindhelp">确定</view>
  41. </view>
  42. <view class="part2">
  43. <view v-if="oldlist.length>0">
  44. <view class="address1">常用地址</view>
  45. <view class="address_box" v-for="(item,index) in oldlist" :key="index" @click="goBack(item.addressId)">
  46. <view class="address_left">
  47. <u-icon name="map-fill"></u-icon>
  48. </view>
  49. <view class="address_right">
  50. <view class="add">
  51. {{item.address}}{{item.addressDetail}}
  52. </view>
  53. <view class="num">
  54. <view class="name">{{item.userName}}</view>
  55. <view class="number">{{item.userPhone}}</view>
  56. </view>
  57. </view>
  58. <view @tap.stop='deleteAddressList(item)' class="dete">删除</view>
  59. </view>
  60. </view>
  61. <!-- <view v-else>
  62. <view style="width: 50%;margin: 0 auto;">
  63. <image src="../../static/image/emety.png" style="width: 100%;height: 390rpx;"></image>
  64. </view>
  65. </view> -->
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. export default {
  73. data() {
  74. return {
  75. mobile: '',
  76. name: '',
  77. cityaddress: '',
  78. detailaddress: '',
  79. latitude: '',
  80. longitude: '',
  81. oldlist: [],
  82. indentType: 1,
  83. current: 0,
  84. addressType: ''
  85. }
  86. },
  87. onLoad(e) {
  88. console.log(e)
  89. if (e.addressType) {
  90. this.addressType = e.addressType
  91. }
  92. this.indentType = e.index
  93. this.current = e.current
  94. this.oldAddress()
  95. },
  96. onShow() {
  97. },
  98. methods: {
  99. bindhelp() {
  100. let that = this
  101. let token = that.$queue.getData("token")
  102. if (!token) {
  103. uni.showToast({
  104. title: '请先登录',
  105. icon: 'none',
  106. duration: 2000
  107. });
  108. return;
  109. }
  110. if (that.mobile.length != 11) {
  111. uni.showToast({
  112. title: '请正确输入联系电话',
  113. icon: 'none',
  114. duration: 2000
  115. });
  116. return;
  117. }
  118. if (!/^1[3456789]\d{9}$/.test(that.mobile)) {
  119. uni.showToast({
  120. title: '请正确输入联系电话',
  121. icon: 'none',
  122. duration: 2000
  123. });
  124. return;
  125. }
  126. if (that.name == '') {
  127. uni.showToast({
  128. title: '请输入联系人姓名',
  129. icon: 'none',
  130. duration: 2000
  131. });
  132. return;
  133. }
  134. if (that.cityaddress == '') {
  135. uni.showToast({
  136. title: '请输入收货地址',
  137. icon: 'none',
  138. duration: 2000
  139. });
  140. return;
  141. }
  142. if (that.detailaddress == '') {
  143. uni.showToast({
  144. title: '请输入详细地址',
  145. icon: 'none',
  146. duration: 2000
  147. });
  148. return;
  149. }
  150. let userId = that.$queue.getData('userId');
  151. let data = {
  152. type: that.type,
  153. userPhone: that.mobile,
  154. userName: that.name,
  155. address: that.cityaddress, ///注释
  156. addressDetail: that.detailaddress,
  157. addressLatitude: that.latitude,
  158. addressLongitude: that.longitude,
  159. userId: userId
  160. }
  161. that.$Request.postJson('/app/indent/addUserAddress', data).then(res => {
  162. if (res.code == 0) {
  163. that.$queue.showToast("地址保存成功!");
  164. // uni.navigateBack();
  165. setTimeout(function(){
  166. that.goBack(res.data)
  167. },500)
  168. } else {
  169. that.$queue.showToast(res.msg);
  170. }
  171. });
  172. },
  173. // 点击地址返回上一页
  174. goBack(e) {
  175. console.log(e)
  176. uni.setStorageSync('addressId',e)
  177. uni.setStorageSync('addressType',this.addressType)
  178. setTimeout(function(){
  179. uni.navigateBack()
  180. },10)
  181. },
  182. bindback(e) {
  183. let address = uni.getStorageSync('closeAddress')
  184. console.log(e)
  185. let add = {
  186. addressId: e.addressId,
  187. deliveryUserPhone: e.userPhone,
  188. deliveryUserName: e.userName,
  189. deliveryAddress: e.address, ///注释
  190. deilveryAddressDetail: e.addressDetail,
  191. userId: e.userId,
  192. deliveryAddressLatitude: e.addressLatitude,
  193. deliveryAddressLongitude: e.addressLongitude
  194. }
  195. if (this.indentType == 1) {
  196. address.data2 = add
  197. uni.navigateTo({
  198. url: '/pages/Helpsend/Helpsend?index=' + this.indentType
  199. })
  200. } else if (this.indentType == 2) {
  201. address.data2 = add
  202. uni.navigateTo({
  203. url: '/pages/Helpsend/Helpsend?index=' + this.indentType
  204. })
  205. } else if (this.indentType == 3 && this.current == 0) {
  206. address.data3 = add
  207. uni.navigateTo({
  208. url: '/pages/Helppay/Helppay?index=' + this.indentType + '&current=' + this.current
  209. })
  210. } else if (this.indentType == 3 && this.current == 1) {
  211. address.data4 = add
  212. uni.navigateTo({
  213. url: '/pages/Helppay/Helppay?index=' + this.indentType + '&current=' + this.current
  214. })
  215. } else if (this.indentType == 4) {
  216. address.citydata = add
  217. uni.navigateTo({
  218. url: '/pages/Cityservice/Cityservice?index=' + this.indentType
  219. })
  220. }
  221. uni.setStorageSync("closeAddress", address)
  222. // uni.navigateBack()
  223. // uni.navigateBack()
  224. // if (this.indentType == 1) {
  225. // uni.navigateTo({
  226. // url: '/pages/Helpsend/Helpsend?index=' + this.indentType
  227. // })
  228. // }
  229. },
  230. bindmap() {
  231. var that = this
  232. // if (that.ciaddress == '') {
  233. uni.chooseLocation({
  234. success: function(res) {
  235. // console.log('位置名称:' + res.name);
  236. // console.log('详细地址:' + res.address);
  237. // console.log('纬度:' + res.latitude);
  238. // console.log('经度:' + res.longitude);
  239. that.detailaddress = res.name
  240. that.latitude = res.latitude
  241. that.longitude = res.longitude
  242. that.shengcheng(res.longitude, res.latitude)
  243. }
  244. });
  245. // }
  246. },
  247. shengcheng(longitude, latitude) {
  248. this.$Request.getT('/app/Login/selectCity?lat=' + latitude + '&lng=' + longitude).then(res => {
  249. // console.log(res)
  250. if (res.code === 0) {
  251. this.cityaddress = res.data.province + res.data.city + res.data.district
  252. // console.log(this.address)
  253. }
  254. });
  255. },
  256. oldAddress() {
  257. this.$Request.getT('/app/indent/findUserAddress').then(res => {
  258. // console.log(res)
  259. if (res.code === 0) {
  260. this.oldlist = res.data
  261. console.log(this.oldlist)
  262. }
  263. });
  264. },
  265. deleteAddressList(e) {
  266. console.log(e)
  267. let data = {
  268. userName: e.userName,
  269. userPhone: e.userPhone,
  270. address: e.address,
  271. addressDetail: e.addressDetail,
  272. addressLatitude: e.addressLatitude,
  273. addressLongitude: e.addressLongitude,
  274. userId: e.userId,
  275. addressId: e.addressId,
  276. addressDefault: e.addressDefault
  277. }
  278. uni.showModal({
  279. title: '温馨提示',
  280. content: '您确定要删除此地址信息吗?',
  281. showCancel: true,
  282. cancelText: '取消',
  283. confirmText: '确认',
  284. success: res => {
  285. if (res.confirm) {
  286. this.$Request.getT('/app/indent/delUserAddress', data).then(res => {
  287. console.log(res)
  288. if (res.code == 0) {
  289. this.$queue.showToast("删除成功!");
  290. this.oldAddress();
  291. } else {
  292. this.$queue.showToast(res.msg);
  293. }
  294. });
  295. }
  296. }
  297. });
  298. },
  299. }
  300. }
  301. </script>
  302. <style>
  303. body {
  304. background: #F5F5F5;
  305. }
  306. .dete {
  307. /* flex: 2; */
  308. width: 15%;
  309. text-align: center;
  310. background: #FF7F00;
  311. height: 60rpx;
  312. line-height: 60rpx;
  313. color: #ffffff;
  314. letter-spacing: 1rpx;
  315. border-radius: 15rpx;
  316. margin-right: 20rpx;
  317. }
  318. .slot-wrap {
  319. /* display: flex; */
  320. /* align-items: center; */
  321. /* 如果您想让slot内容占满整个导航栏的宽度 */
  322. /* flex: 1; */
  323. /* 如果您想让slot内容与导航栏左右有空隙 */
  324. /* padding: 0 30rpx; */
  325. width: 100%;
  326. text-align: center;
  327. margin-left: 100rpx;
  328. letter-spacing: 2rpx;
  329. font-weight: bold;
  330. font-size: 30rpx;
  331. }
  332. .takeaddress {
  333. width: 100%;
  334. }
  335. .part1 {
  336. width: 100%;
  337. background: #ffffff;
  338. margin-top: 24rpx;
  339. padding-bottom: 40upx;
  340. }
  341. .btn {
  342. width: 90%;
  343. height: 80upx;
  344. background: #FF7F00;
  345. border-radius: 14upx;
  346. margin: 0 auto;
  347. color: white;
  348. text-align: center;
  349. line-height: 80upx;
  350. letter-spacing: 2upx;
  351. margin-top: 40upx;
  352. }
  353. .part2 {
  354. width: 100%;
  355. background: #ffffff;
  356. margin-top: 10upx;
  357. }
  358. .address1 {
  359. width: 90%;
  360. margin: 0 auto;
  361. font-size: 37rpx;
  362. font-weight: bold;
  363. padding-top: 30upx;
  364. }
  365. .address_box {
  366. display: flex;
  367. padding-bottom: 30upx;
  368. padding-top: 30upx;
  369. width: 100%;
  370. }
  371. .address_left {
  372. /* flex: 2; */
  373. width: 15%;
  374. display: flex;
  375. justify-content: center;
  376. align-items: center;
  377. }
  378. .address_right {
  379. /* flex: 10; */
  380. width: 80%;
  381. font-size: 31rpx;
  382. overflow: hidden;
  383. }
  384. .add {
  385. /* color: #333333; */
  386. /* font-size: 31rpx; */
  387. /* letter-spacing: 1upx; */
  388. }
  389. .name {
  390. display: inline;
  391. font-size: 34rpx;
  392. color: #999999;
  393. }
  394. .number {
  395. display: initial;
  396. color: #999999;
  397. font-size: 34rpx;
  398. margin-left: 30upx;
  399. }
  400. .u-icon__icon {
  401. font-size: 45rpx !important;
  402. }
  403. .u-field {
  404. padding: 35rpx 28rpx !important;
  405. }
  406. .u-label {
  407. flex: 0 0 42px !important;
  408. }
  409. .u-field__input-wrap {
  410. font-size: 30rpx !important;
  411. }
  412. .u-textarea-class {
  413. font-size: 30rpx !important;
  414. }
  415. </style>