selectAddress.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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.chooseLocation({
  223. success: function(res) {
  224. console.log(res);
  225. console.log('位置名称:' + res.name);
  226. console.log('详细地址:' + res.address);
  227. console.log('纬度:' + res.latitude);
  228. console.log('经度:' + res.longitude);
  229. var locationObj = that.$helper.formatLocation(res);
  230. console.log(locationObj)
  231. that.temporaryAddress.latitude = res.latitude
  232. that.temporaryAddress.longitude = res.longitude
  233. that.temporaryAddress.detailedAddress = locationObj.ADDRESS
  234. that.temporaryAddress.province = locationObj.REGION_PROVINCE
  235. that.temporaryAddress.city = locationObj.REGION_CITY
  236. that.temporaryAddress.area = locationObj.REGION_COUNTRY
  237. that.temporaryAddress.commonId = that.userInfo.id
  238. that.configAddress(that.temporaryAddress)
  239. },
  240. fail: function() {
  241. uni.getSetting({
  242. success: function(res) {
  243. var statu = res.authSetting;
  244. if (!statu['scope.userLocation']) {
  245. uni.showModal({
  246. title: '是否授权当前位置',
  247. content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
  248. success: function(tip) {
  249. if (tip.confirm) {
  250. uni.openSetting({
  251. success: function(
  252. data) {
  253. if (data
  254. .authSetting[
  255. "scope.userLocation"
  256. ] === true
  257. ) {
  258. uni.showToast({
  259. title: '授权成功',
  260. icon: 'success',
  261. duration: 1000
  262. })
  263. //授权成功之后,再调用chooseLocation选择地方
  264. uni.chooseLocation({
  265. success: function(
  266. res
  267. ) {
  268. console
  269. .log(
  270. res
  271. );
  272. console
  273. .log(
  274. '位置名称:' +
  275. res
  276. .name
  277. );
  278. console
  279. .log(
  280. '详细地址:' +
  281. res
  282. .address
  283. );
  284. console
  285. .log(
  286. '纬度:' +
  287. res
  288. .latitude
  289. );
  290. console
  291. .log(
  292. '经度:' +
  293. res
  294. .longitude
  295. );
  296. var locationObj =
  297. that
  298. .$helper
  299. .formatLocation(
  300. res
  301. );
  302. console
  303. .log(
  304. locationObj
  305. )
  306. that.temporaryAddress
  307. .latitude =
  308. res
  309. .latitude
  310. that.temporaryAddress
  311. .longitude =
  312. res
  313. .longitude
  314. that.temporaryAddress
  315. .detailedAddress =
  316. locationObj
  317. .ADDRESS
  318. that.temporaryAddress
  319. .province =
  320. locationObj
  321. .REGION_PROVINCE
  322. that.temporaryAddress
  323. .city =
  324. locationObj
  325. .REGION_CITY
  326. that.temporaryAddress
  327. .area =
  328. locationObj
  329. .REGION_COUNTRY
  330. that.temporaryAddress
  331. .commonId =
  332. that
  333. .userInfo
  334. .id
  335. that.configAddress(
  336. that
  337. .temporaryAddress
  338. )
  339. },
  340. })
  341. } else {
  342. uni.showToast({
  343. title: '授权失败',
  344. icon: 'none',
  345. duration: 1000
  346. })
  347. }
  348. }
  349. })
  350. }
  351. }
  352. })
  353. }
  354. },
  355. fail: function(res) {
  356. uni.showToast({
  357. title: '调用授权窗口失败',
  358. icon: 'none',
  359. duration: 1000
  360. })
  361. }
  362. })
  363. }
  364. })
  365. // that.$helper.getLocation(that.temporaryAddress)
  366. // console.log('1111111111111111111111111111111111')
  367. // console.log(that.temporaryAddress)
  368. // let that = this
  369. // // this.isShowMap = true
  370. // uni.chooseLocation({
  371. // success: function(res) {
  372. // console.log(res);
  373. // console.log('位置名称:' + res.name);
  374. // console.log('详细地址:' + res.address);
  375. // console.log('纬度:' + res.latitude);
  376. // console.log('经度:' + res.longitude);
  377. // // let _address = that.$helper.getAddress(res.address)
  378. // let _address = that.$helper.getLocation(res.address)
  379. // console.log(_address)
  380. // // that.temporaryAddress.latitude = res.latitude
  381. // // that.temporaryAddress.longitude = res.longitude
  382. // // that.temporaryAddress.detailedAddress = _address.village
  383. // // that.temporaryAddress.province = _address.province
  384. // // that.temporaryAddress.city = _address.city
  385. // // that.temporaryAddress.area = _address.county
  386. // // that.temporaryAddress.commonId = that.userInfo.id
  387. // // that.configAddress(that.temporaryAddress)
  388. // }
  389. // });
  390. // // console.log(123)
  391. // // uni.$u.route('/pages/release/map', {
  392. // // id: 1,
  393. // // });
  394. } else {
  395. uni.$u.route('/pages/release/addAddress', {
  396. type: type,
  397. });
  398. }
  399. },
  400. }
  401. }
  402. </script>
  403. <style scoped lang="scss">
  404. .content1 {
  405. background: white;
  406. padding: 20rpx;
  407. }
  408. .content2 {
  409. border-radius: 20rpx;
  410. background: white;
  411. margin: 20rpx;
  412. padding: 20rpx;
  413. .row {
  414. margin-top: 20rpx;
  415. }
  416. .row1 {
  417. font-weight: 700;
  418. color: #333333;
  419. .name {
  420. margin-right: 20rpx;
  421. }
  422. }
  423. .row2 {
  424. color: #7D7D7D;
  425. }
  426. .row3 {
  427. font-size: 24rpx;
  428. }
  429. }
  430. .bottom-btn {
  431. position: fixed;
  432. bottom: 50rpx;
  433. width: 100%;
  434. display: flex;
  435. justify-content: space-around;
  436. .btn-left {
  437. text-align: center;
  438. width: 30%;
  439. font-size: 32rpx;
  440. font-weight: 500;
  441. color: #2772FB;
  442. background-color: #EEF4FF;
  443. padding: 20rpx 40rpx;
  444. border-radius: 40rpx;
  445. }
  446. .btn-right {
  447. text-align: center;
  448. width: 30%;
  449. font-size: 32rpx;
  450. font-weight: 500;
  451. color: white;
  452. background-color: #2772FB;
  453. padding: 20rpx 40rpx;
  454. border-radius: 50rpx;
  455. }
  456. }
  457. .icon-img {
  458. display: flex;
  459. align-items: center;
  460. color: #999999;
  461. }
  462. </style>