takeaddress.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. let data = {
  212. lng: longitude,
  213. lat:latitude
  214. };
  215. this.$Request.getT('/app/Login/selectCity',data ).then(res => {
  216. // console.log(res)
  217. if (res.code === 0) {
  218. this.cityaddress = res.data.province + res.data.city + res.data.district
  219. console.log(this.cityaddress)
  220. }
  221. });
  222. },
  223. // 获取常用地址列表
  224. oldAddress() {
  225. this.$Request.getT('/app/tbindent/findUserAddress').then(res => {
  226. console.log(res)
  227. if (res.code == 0) {
  228. this.oldlist = res.data
  229. }
  230. });
  231. },
  232. // 删除常用地址
  233. deleteAddressList(e) {
  234. console.log(e)
  235. let data = {
  236. userName: e.userName,
  237. userPhone: e.userPhone,
  238. address: e.address,
  239. addressDetail: e.addressDetail,
  240. addressLatitude: e.addressLatitude,
  241. addressLongitude: e.addressLongitude,
  242. userId: e.userId,
  243. addressId: e.addressId,
  244. addressDefault: e.addressDefault
  245. }
  246. uni.showModal({
  247. title: '温馨提示',
  248. content: '您确定要删除此地址信息吗?',
  249. showCancel: true,
  250. cancelText: '取消',
  251. confirmText: '确认',
  252. success: res => {
  253. if (res.confirm) {
  254. this.$Request.getT('/app/indent/delUserAddress', data).then(res => {
  255. console.log(res)
  256. if (res.code == 0) {
  257. this.$queue.showToast("删除成功!");
  258. this.oldAddress();
  259. } else {
  260. this.$queue.showToast(res.msg);
  261. }
  262. });
  263. }
  264. }
  265. });
  266. },
  267. }
  268. }
  269. </script>
  270. <style>
  271. body {
  272. background: #F5F5F5;
  273. }
  274. .dete {
  275. /* flex: 2; */
  276. width: 15%;
  277. text-align: center;
  278. background: #FF7F00;
  279. height: 60rpx;
  280. line-height: 60rpx;
  281. color: #ffffff;
  282. letter-spacing: 1rpx;
  283. border-radius: 15rpx;
  284. margin-right: 20rpx;
  285. }
  286. .slot-wrap {
  287. /* display: flex; */
  288. /* align-items: center; */
  289. /* 如果您想让slot内容占满整个导航栏的宽度 */
  290. /* flex: 1; */
  291. /* 如果您想让slot内容与导航栏左右有空隙 */
  292. /* padding: 0 30rpx; */
  293. width: 100%;
  294. text-align: center;
  295. margin-left: 100rpx;
  296. letter-spacing: 2rpx;
  297. font-weight: bold;
  298. font-size: 30rpx;
  299. }
  300. .takeaddress {
  301. width: 100%;
  302. }
  303. .part1 {
  304. width: 100%;
  305. background: #ffffff;
  306. margin-top: 24rpx;
  307. padding-bottom: 40upx;
  308. }
  309. .btn {
  310. width: 90%;
  311. height: 80upx;
  312. background: #FF7F00;
  313. border-radius: 14upx;
  314. margin: 0 auto;
  315. color: white;
  316. text-align: center;
  317. line-height: 80upx;
  318. letter-spacing: 2upx;
  319. margin-top: 40upx;
  320. }
  321. .part2 {
  322. width: 100%;
  323. background: #ffffff;
  324. margin-top: 10upx;
  325. }
  326. .address1 {
  327. width: 90%;
  328. margin: 0 auto;
  329. font-size: 37rpx;
  330. font-weight: bold;
  331. padding-top: 30upx;
  332. }
  333. .address_box {
  334. display: flex;
  335. padding-bottom: 30upx;
  336. padding-top: 30upx;
  337. width: 100%;
  338. }
  339. .address_left {
  340. /* flex: 2; */
  341. width: 15%;
  342. display: flex;
  343. justify-content: center;
  344. align-items: center;
  345. }
  346. .address_right {
  347. /* flex: 10; */
  348. width: 80%;
  349. font-size: 31rpx;
  350. overflow: hidden;
  351. }
  352. .add {
  353. /* color: #333333; */
  354. /* font-size: 31rpx; */
  355. /* letter-spacing: 1upx; */
  356. }
  357. .name {
  358. display: inline;
  359. font-size: 34rpx;
  360. color: #999999;
  361. }
  362. .number {
  363. display: initial;
  364. color: #999999;
  365. font-size: 34rpx;
  366. margin-left: 30upx;
  367. }
  368. .u-icon__icon {
  369. font-size: 45rpx !important;
  370. }
  371. .u-field {
  372. padding: 35rpx 28rpx !important;
  373. }
  374. .u-label {
  375. flex: 0 0 42px !important;
  376. }
  377. .u-field__input-wrap {
  378. font-size: 30rpx !important;
  379. }
  380. .u-textarea-class {
  381. font-size: 30rpx !important;
  382. }
  383. </style>