selectAddress.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <view class="content">
  3. <view class="content1">
  4. <u-search placeholder="可按地址、联系人和电话查找" v-model="searchKeyWord" :showAction='false' @search="getList()">
  5. </u-search>
  6. </view>
  7. <view class="content2-wrap">
  8. <view class="content2" v-for="(item,index) in dataList" :key='index' @click="configAddress(item)">
  9. <view class="row flex row1">
  10. <view class="name">
  11. {{item.contacts}}
  12. </view>
  13. <view class="phone">
  14. {{item.contactPhone1}}
  15. </view>
  16. </view>
  17. <view class="row flex row2">
  18. {{item.province}}{{item.city}}{{item.area}}{{item.detailedAddress}}
  19. </view>
  20. <view class="row flex row3">
  21. <u-radio-group placement="row" class="select-type" v-model="item.radiovalue">
  22. <u-radio :customStyle="radioCustomStyle" v-for="(item1, index) in radiolist1" :key="index"
  23. :label="item1.name" :name="item1.name" @change="radioChange($event,item)" labelSize='12px'
  24. :iconSize='10'>
  25. </u-radio>
  26. </u-radio-group>
  27. <view class="flex">
  28. <view class="mr20 icon-img" @click.stop="toTop(item)">
  29. <!-- <u-icon name="arrow-upward" color="#999999" size="18"></u-icon> -->
  30. <image class="jt-icon" src="@/static/images/release/zhiding.png" mode='widthFix'>
  31. </image>
  32. 置顶
  33. </view>
  34. <view class="mr20 icon-img" @click.stop="edit(item)">
  35. <!-- <u-icon name="edit-pen-fill" color="#999999" size="18"></u-icon> -->
  36. <image class="jt-icon" src="@/static/images/release/bianji.png" mode='widthFix'>
  37. </image>
  38. 编辑
  39. </view>
  40. <view class="mr20 icon-img" @click.stop="del(item)">
  41. <!-- <u-icon name="trash-fill" color="#999999" size="18"></u-icon> -->
  42. <image class="jt-icon" src="@/static/images/release/shanchu.png" mode='widthFix'>
  43. </image>
  44. 删除
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="bottom-btn">
  51. <view class="btn-left" @click="selectAddress(0)">选择临时地址</view>
  52. <view class="btn-right" @click="selectAddress(1)">新增地址</view>
  53. </view>
  54. <u-toast ref="uToast"></u-toast>
  55. </view>
  56. </template>
  57. <script>
  58. let that;
  59. import {
  60. mapState
  61. } from 'vuex';
  62. export default {
  63. data() {
  64. return {
  65. temporaryAddress: {
  66. latitude: '',
  67. longitude: '',
  68. detailedAddress: '',
  69. province: '',
  70. city: '',
  71. area: '',
  72. commonId: '',
  73. },
  74. radioCustomStyle: {
  75. margin: '0 20rpx 0 0',
  76. },
  77. type: '',
  78. radiovalue: '',
  79. dataList: [],
  80. searchKeyWord: '',
  81. radiolist1: [
  82. {
  83. name: '默认装货',
  84. disabled: false
  85. },
  86. {
  87. name: '默认卸货',
  88. disabled: false
  89. },
  90. ],
  91. }
  92. },
  93. computed: {
  94. ...mapState(['hasLogin', 'userInfo'])
  95. },
  96. onLoad(options) {
  97. console.log(options)
  98. this.type = options.type
  99. that = this
  100. },
  101. onShow() {
  102. this.getList()
  103. },
  104. methods: {
  105. configAddress(val) {
  106. if (this.type == 0) {
  107. uni.setStorageSync('storage_faddress', val);
  108. } else {
  109. uni.setStorageSync('storage_saddress', val);
  110. }
  111. // uni.$u.route('/pages/release/release');
  112. uni.navigateBack({
  113. delta: 1
  114. })
  115. },
  116. getList() {
  117. uni.showLoading({
  118. mask: true,
  119. title: '加载中...'
  120. })
  121. this.$request.baseRequest('get', '/cargoOwnerAddressInfo/selectCargoOwnerAddress', {
  122. commonId: this.userInfo.id,
  123. searchKeyWord: this.searchKeyWord,
  124. pageSize: 100,
  125. currentPage: 1
  126. }).then(res => {
  127. if (res.code == 200) {
  128. if(res.data.records.length){
  129. for (var i = 0; i < res.data.records.length; i++) {
  130. res.data.records[i].contactPhone1=res.data.records[i].contactPhone.replace(/(\d{3})(\d{4})(\d{4})/, "$1****$3")
  131. }
  132. }
  133. console.log(res.data.records)
  134. this.dataList = res.data.records
  135. this.$forceUpdate()
  136. for (let i = 0; i < this.dataList.length; i++) {
  137. if (this.dataList[i].defaultShipment == 1) {
  138. this.dataList[i].radiovalue = '默认装货'
  139. }
  140. if (this.dataList[i].defaultReceipt == 1) {
  141. this.dataList[i].radiovalue = '默认卸货'
  142. }
  143. }
  144. uni.hideLoading()
  145. }
  146. })
  147. .catch(res => {
  148. uni.showToast({
  149. title: res.message,
  150. icon: 'none',
  151. duration: 2000
  152. })
  153. });
  154. },
  155. radioChange(n, val) {
  156. console.log('radioChange', n);
  157. console.log('radioChange', val);
  158. for (var i = 0; i < this.dataList.length; i++) {
  159. if (this.dataList[i].defaultShipment == 1&&n=='默认装货') {
  160. this.dataList[i].radiovalue = ''
  161. }
  162. if (this.dataList[i].defaultReceipt == 1&&n=='默认卸货') {
  163. this.dataList[i].radiovalue = ''
  164. }
  165. }
  166. this.$set(val,'radioChange',n)
  167. let _flag;
  168. if (n == '默认卸货') {
  169. _flag = 2
  170. } else {
  171. _flag = 1
  172. }
  173. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  174. commonId: this.userInfo.id,
  175. id: val.id,
  176. defaultFlag: _flag
  177. }).then(res => {
  178. if (res.code == 200) {
  179. this.$refs.uToast.show({
  180. type: 'success',
  181. message: "设置成功",
  182. complete() {
  183. that.getList()
  184. }
  185. })
  186. }
  187. })
  188. .catch(res => {
  189. uni.showToast({
  190. title: res.message,
  191. icon: 'none',
  192. duration: 2000
  193. })
  194. });
  195. },
  196. toTop(val) {
  197. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  198. commonId: this.userInfo.id,
  199. id: val.id,
  200. }).then(res => {
  201. if (res.code == 200) {
  202. this.$refs.uToast.show({
  203. type: 'success',
  204. message: "置顶成功",
  205. complete() {
  206. that.getList()
  207. }
  208. })
  209. }
  210. })
  211. .catch(res => {
  212. uni.showToast({
  213. title: res.message,
  214. icon: 'none',
  215. duration: 2000
  216. })
  217. });
  218. },
  219. edit(val) {
  220. uni.$u.route('/pages/release/editAddress', val);
  221. },
  222. del(val) {
  223. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/deleteCargoOwnerAddress', {
  224. id: val.id,
  225. }).then(res => {
  226. if (res.code == 200) {
  227. this.$refs.uToast.show({
  228. type: 'success',
  229. message: "删除成功",
  230. complete() {
  231. that.getList()
  232. }
  233. })
  234. }
  235. })
  236. .catch(res => {
  237. uni.showToast({
  238. title: res.message,
  239. icon: 'none',
  240. duration: 2000
  241. })
  242. });
  243. },
  244. selectAddress(type) {
  245. // 0临时地址 1 新增地址
  246. if (type == 0) {
  247. console.log(111111111)
  248. let that = this
  249. uni.getLocation({
  250. type: 'wgs84',
  251. success: function(res) {
  252. console.log('当前位置的经度:' + res.longitude);
  253. console.log('当前位置的纬度:' + res.latitude);
  254. uni.chooseLocation({
  255. success: function(res) {
  256. console.log(res);
  257. console.log('位置名称:' + res.name);
  258. console.log('详细地址:' + res.address);
  259. console.log('纬度:' + res.latitude);
  260. console.log('经度:' + res.longitude);
  261. var locationObj = that.$helper.formatLocation(res);
  262. console.log(locationObj)
  263. that.temporaryAddress.latitude = res.latitude
  264. that.temporaryAddress.longitude = res.longitude
  265. that.temporaryAddress.detailedAddress = locationObj.ADDRESS
  266. that.temporaryAddress.province = locationObj.REGION_PROVINCE
  267. that.temporaryAddress.city = locationObj.REGION_CITY
  268. that.temporaryAddress.area = locationObj.REGION_COUNTRY
  269. that.temporaryAddress.commonId = that.userInfo.id
  270. that.configAddress(that.temporaryAddress)
  271. },
  272. fail: function() {
  273. console.log(2222222)
  274. // uni.getSetting({
  275. // success: function(res) {
  276. // var statu = res.authSetting;
  277. // if (!statu['scope.userLocation']) {
  278. // uni.showModal({
  279. // title: '是否授权当前位置',
  280. // content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
  281. // success: function(tip) {
  282. // if (tip.confirm) {
  283. // uni.openSetting({
  284. // success: function(
  285. // data
  286. // ) {
  287. // if (data
  288. // .authSetting[
  289. // "scope.userLocation"
  290. // ] ===
  291. // true
  292. // ) {
  293. // uni.showToast({
  294. // title: '授权成功',
  295. // icon: 'success',
  296. // duration: 1000
  297. // })
  298. // //授权成功之后,再调用chooseLocation选择地方
  299. // uni.chooseLocation({
  300. // success: function(
  301. // res
  302. // ) {
  303. // console
  304. // .log(
  305. // res
  306. // );
  307. // console
  308. // .log(
  309. // '位置名称:' +
  310. // res
  311. // .name
  312. // );
  313. // console
  314. // .log(
  315. // '详细地址:' +
  316. // res
  317. // .address
  318. // );
  319. // console
  320. // .log(
  321. // '纬度:' +
  322. // res
  323. // .latitude
  324. // );
  325. // console
  326. // .log(
  327. // '经度:' +
  328. // res
  329. // .longitude
  330. // );
  331. // var locationObj =
  332. // that
  333. // .$helper
  334. // .formatLocation(
  335. // res
  336. // );
  337. // console
  338. // .log(
  339. // locationObj
  340. // )
  341. // that.temporaryAddress
  342. // .latitude =
  343. // res
  344. // .latitude
  345. // that.temporaryAddress
  346. // .longitude =
  347. // res
  348. // .longitude
  349. // that.temporaryAddress
  350. // .detailedAddress =
  351. // locationObj
  352. // .ADDRESS
  353. // that.temporaryAddress
  354. // .province =
  355. // locationObj
  356. // .REGION_PROVINCE
  357. // that.temporaryAddress
  358. // .city =
  359. // locationObj
  360. // .REGION_CITY
  361. // that.temporaryAddress
  362. // .area =
  363. // locationObj
  364. // .REGION_COUNTRY
  365. // that.temporaryAddress
  366. // .commonId =
  367. // that
  368. // .userInfo
  369. // .id
  370. // that.configAddress(
  371. // that
  372. // .temporaryAddress
  373. // )
  374. // },
  375. // })
  376. // } else {
  377. // uni.showToast({
  378. // title: '授权失败',
  379. // icon: 'none',
  380. // duration: 1000
  381. // })
  382. // }
  383. // }
  384. // })
  385. // }
  386. // }
  387. // })
  388. // }
  389. // },
  390. // fail: function(res) {
  391. // uni.showToast({
  392. // title: '调用授权窗口失败',
  393. // icon: 'none',
  394. // duration: 1000
  395. // })
  396. // }
  397. // })
  398. }
  399. });
  400. }
  401. })
  402. } else {
  403. uni.$u.route('/pages/release/addAddress', {
  404. type: type,
  405. });
  406. }
  407. },
  408. }
  409. }
  410. </script>
  411. <style scoped lang="scss">
  412. .content1 {
  413. background: white;
  414. padding: 20rpx;
  415. }
  416. .content2-wrap{
  417. margin-bottom:200rpx;
  418. }
  419. .jt-icon {
  420. position: relative;
  421. top: 4rpx;
  422. width: 24rpx;
  423. margin: 0 10rpx;
  424. }
  425. .content2 {
  426. border-radius: 20rpx;
  427. background: white;
  428. margin: 20rpx ;
  429. padding: 20rpx;
  430. .row {
  431. margin-top: 20rpx;
  432. }
  433. .row1 {
  434. font-weight: 700;
  435. color: #333333;
  436. .name {
  437. margin-right: 20rpx;
  438. }
  439. }
  440. .row2 {
  441. color: #7D7D7D;
  442. }
  443. .row3 {
  444. font-size: 24rpx;
  445. }
  446. }
  447. .bottom-btn {
  448. position: fixed;
  449. bottom: 0rpx;
  450. padding:50rpx 0;
  451. width: 100%;
  452. background-color: #fff;
  453. display: flex;
  454. justify-content: space-around;
  455. .btn-left {
  456. text-align: center;
  457. width: 30%;
  458. font-size: 32rpx;
  459. font-weight: 500;
  460. color: #2772FB;
  461. background-color: #EEF4FF;
  462. padding: 20rpx 40rpx;
  463. border-radius: 40rpx;
  464. }
  465. .btn-right {
  466. text-align: center;
  467. width: 30%;
  468. font-size: 32rpx;
  469. font-weight: 500;
  470. color: white;
  471. background-color: #2772FB;
  472. padding: 20rpx 40rpx;
  473. border-radius: 50rpx;
  474. }
  475. }
  476. .icon-img {
  477. display: flex;
  478. align-items: center;
  479. color: #999999;
  480. }
  481. </style>