selectAddress.vue 12 KB

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