takeaddress.vue 9.3 KB

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