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