selectAddress.vue 12 KB

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