selectAddress.vue 12 KB

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