selectAddress.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. for (var i = 0; i < this.dataList.length; i++) {
  142. if (this.dataList[i].defaultShipment == 1&&n=='默认装货') {
  143. this.dataList[i].radiovalue = ''
  144. }
  145. if (this.dataList[i].defaultReceipt == 1&&n=='默认卸货') {
  146. this.dataList[i].radiovalue = ''
  147. }
  148. }
  149. this.$set(val,'radioChange',n)
  150. let _flag;
  151. if (n == '默认卸货') {
  152. _flag = 2
  153. } else {
  154. _flag = 1
  155. }
  156. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  157. commonId: this.userInfo.id,
  158. id: val.id,
  159. defaultFlag: _flag
  160. }).then(res => {
  161. if (res.code == 200) {
  162. this.$refs.uToast.show({
  163. type: 'success',
  164. message: "设置成功",
  165. complete() {
  166. that.getList()
  167. }
  168. })
  169. }
  170. })
  171. .catch(res => {
  172. uni.showToast({
  173. title: res.message,
  174. icon: 'none',
  175. duration: 2000
  176. })
  177. });
  178. },
  179. toTop(val) {
  180. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  181. commonId: this.userInfo.id,
  182. id: val.id,
  183. }).then(res => {
  184. if (res.code == 200) {
  185. this.$refs.uToast.show({
  186. type: 'success',
  187. message: "置顶成功",
  188. complete() {
  189. that.getList()
  190. }
  191. })
  192. }
  193. })
  194. .catch(res => {
  195. uni.showToast({
  196. title: res.message,
  197. icon: 'none',
  198. duration: 2000
  199. })
  200. });
  201. },
  202. edit(val) {
  203. uni.$u.route('/pages/release/editAddress', val);
  204. },
  205. del(val) {
  206. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/deleteCargoOwnerAddress', {
  207. id: val.id,
  208. }).then(res => {
  209. if (res.code == 200) {
  210. this.$refs.uToast.show({
  211. type: 'success',
  212. message: "删除成功",
  213. complete() {
  214. that.getList()
  215. }
  216. })
  217. }
  218. })
  219. .catch(res => {
  220. uni.showToast({
  221. title: res.message,
  222. icon: 'none',
  223. duration: 2000
  224. })
  225. });
  226. },
  227. selectAddress(type) {
  228. // 0临时地址 1 新增地址
  229. if (type == 0) {
  230. let that = this
  231. uni.getLocation({
  232. type: 'wgs84',
  233. success: function(res) {
  234. console.log('当前位置的经度:' + res.longitude);
  235. console.log('当前位置的纬度:' + res.latitude);
  236. uni.chooseLocation({
  237. success: function(res) {
  238. console.log(res);
  239. console.log('位置名称:' + res.name);
  240. console.log('详细地址:' + res.address);
  241. console.log('纬度:' + res.latitude);
  242. console.log('经度:' + res.longitude);
  243. var locationObj = that.$helper.formatLocation(res);
  244. console.log(locationObj)
  245. that.temporaryAddress.latitude = res.latitude
  246. that.temporaryAddress.longitude = res.longitude
  247. that.temporaryAddress.detailedAddress = locationObj.ADDRESS
  248. that.temporaryAddress.province = locationObj.REGION_PROVINCE
  249. that.temporaryAddress.city = locationObj.REGION_CITY
  250. that.temporaryAddress.area = locationObj.REGION_COUNTRY
  251. that.temporaryAddress.commonId = that.userInfo.id
  252. that.configAddress(that.temporaryAddress)
  253. },
  254. fail: function() {
  255. // uni.getSetting({
  256. // success: function(res) {
  257. // var statu = res.authSetting;
  258. // if (!statu['scope.userLocation']) {
  259. // uni.showModal({
  260. // title: '是否授权当前位置',
  261. // content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
  262. // success: function(tip) {
  263. // if (tip.confirm) {
  264. // uni.openSetting({
  265. // success: function(
  266. // data
  267. // ) {
  268. // if (data
  269. // .authSetting[
  270. // "scope.userLocation"
  271. // ] ===
  272. // true
  273. // ) {
  274. // uni.showToast({
  275. // title: '授权成功',
  276. // icon: 'success',
  277. // duration: 1000
  278. // })
  279. // //授权成功之后,再调用chooseLocation选择地方
  280. // uni.chooseLocation({
  281. // success: function(
  282. // res
  283. // ) {
  284. // console
  285. // .log(
  286. // res
  287. // );
  288. // console
  289. // .log(
  290. // '位置名称:' +
  291. // res
  292. // .name
  293. // );
  294. // console
  295. // .log(
  296. // '详细地址:' +
  297. // res
  298. // .address
  299. // );
  300. // console
  301. // .log(
  302. // '纬度:' +
  303. // res
  304. // .latitude
  305. // );
  306. // console
  307. // .log(
  308. // '经度:' +
  309. // res
  310. // .longitude
  311. // );
  312. // var locationObj =
  313. // that
  314. // .$helper
  315. // .formatLocation(
  316. // res
  317. // );
  318. // console
  319. // .log(
  320. // locationObj
  321. // )
  322. // that.temporaryAddress
  323. // .latitude =
  324. // res
  325. // .latitude
  326. // that.temporaryAddress
  327. // .longitude =
  328. // res
  329. // .longitude
  330. // that.temporaryAddress
  331. // .detailedAddress =
  332. // locationObj
  333. // .ADDRESS
  334. // that.temporaryAddress
  335. // .province =
  336. // locationObj
  337. // .REGION_PROVINCE
  338. // that.temporaryAddress
  339. // .city =
  340. // locationObj
  341. // .REGION_CITY
  342. // that.temporaryAddress
  343. // .area =
  344. // locationObj
  345. // .REGION_COUNTRY
  346. // that.temporaryAddress
  347. // .commonId =
  348. // that
  349. // .userInfo
  350. // .id
  351. // that.configAddress(
  352. // that
  353. // .temporaryAddress
  354. // )
  355. // },
  356. // })
  357. // } else {
  358. // uni.showToast({
  359. // title: '授权失败',
  360. // icon: 'none',
  361. // duration: 1000
  362. // })
  363. // }
  364. // }
  365. // })
  366. // }
  367. // }
  368. // })
  369. // }
  370. // },
  371. // fail: function(res) {
  372. // uni.showToast({
  373. // title: '调用授权窗口失败',
  374. // icon: 'none',
  375. // duration: 1000
  376. // })
  377. // }
  378. // })
  379. }
  380. });
  381. }
  382. })
  383. } else {
  384. uni.$u.route('/pages/release/addAddress', {
  385. type: type,
  386. });
  387. }
  388. },
  389. }
  390. }
  391. </script>
  392. <style scoped lang="scss">
  393. .content1 {
  394. background: white;
  395. padding: 20rpx;
  396. }
  397. .content2 {
  398. border-radius: 20rpx;
  399. background: white;
  400. margin: 20rpx;
  401. padding: 20rpx;
  402. .row {
  403. margin-top: 20rpx;
  404. }
  405. .row1 {
  406. font-weight: 700;
  407. color: #333333;
  408. .name {
  409. margin-right: 20rpx;
  410. }
  411. }
  412. .row2 {
  413. color: #7D7D7D;
  414. }
  415. .row3 {
  416. font-size: 24rpx;
  417. }
  418. }
  419. .bottom-btn {
  420. position: fixed;
  421. bottom: 50rpx;
  422. width: 100%;
  423. display: flex;
  424. justify-content: space-around;
  425. .btn-left {
  426. text-align: center;
  427. width: 30%;
  428. font-size: 32rpx;
  429. font-weight: 500;
  430. color: #2772FB;
  431. background-color: #EEF4FF;
  432. padding: 20rpx 40rpx;
  433. border-radius: 40rpx;
  434. }
  435. .btn-right {
  436. text-align: center;
  437. width: 30%;
  438. font-size: 32rpx;
  439. font-weight: 500;
  440. color: white;
  441. background-color: #2772FB;
  442. padding: 20rpx 40rpx;
  443. border-radius: 50rpx;
  444. }
  445. }
  446. .icon-img {
  447. display: flex;
  448. align-items: center;
  449. color: #999999;
  450. }
  451. </style>