selectAddress.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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-wrap">
  8. <view class="content2" v-for="(item,index) in dataList" @click="configAddress(item)">
  9. <view class="row flex row1">
  10. <view class="name">
  11. {{item.contacts}}
  12. </view>
  13. <view class="phone">
  14. {{item.contactPhone1}}
  15. </view>
  16. </view>
  17. <view class="row flex row2">
  18. {{item.province}}{{item.city}}{{item.area}}{{item.detailedAddress}}
  19. </view>
  20. <view class="row flex row3">
  21. <u-radio-group placement="row" class="select-type" v-model="item.radiovalue">
  22. <u-radio :customStyle="radioCustomStyle" v-for="item1 in radiolist1"
  23. :label="item1.name" :name="item1.name" @change="radioChange($event,item)" labelSize='12px'
  24. :iconSize='10'>
  25. </u-radio>
  26. </u-radio-group>
  27. <view class="flex">
  28. <view class="mr20 icon-img" @click.stop="toTop(item)">
  29. <!-- <u-icon name="arrow-upward" color="#999999" size="18"></u-icon> -->
  30. <image class="jt-icon" src="@/static/images/release/zhiding.png" mode='widthFix'>
  31. </image>
  32. 置顶
  33. </view>
  34. <view class="mr20 icon-img" @click.stop="edit(item)">
  35. <!-- <u-icon name="edit-pen-fill" color="#999999" size="18"></u-icon> -->
  36. <image class="jt-icon" src="@/static/images/release/bianji.png" mode='widthFix'>
  37. </image>
  38. 编辑
  39. </view>
  40. <view class="mr20 icon-img" @click.stop="del(item)">
  41. <!-- <u-icon name="trash-fill" color="#999999" size="18"></u-icon> -->
  42. <image class="jt-icon" src="@/static/images/release/shanchu.png" mode='widthFix'>
  43. </image>
  44. 删除
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="bottom-btn">
  51. <view class="btn-left" @click="selectAddress(0)">选择临时地址</view>
  52. <view class="btn-right" @click="selectAddress(1)">新增常用地址</view>
  53. </view>
  54. <u-modal :show="isShowAlert" :title="alertTitle" :content='alertContent' :closeOnClickOverlay='true'
  55. :showCancelButton='showCancelButton' confirmColor='#2772FB' @confirm="$u.throttle(confirmClick, 1000)" @close="cancelClick"
  56. @cancel="cancelClick"></u-modal>
  57. <u-toast ref="uToast"></u-toast>
  58. </view>
  59. </template>
  60. <script>
  61. let that;
  62. import {
  63. mapState
  64. } from 'vuex';
  65. export default {
  66. data() {
  67. return {
  68. temporaryAddress: {
  69. latitude: '',
  70. longitude: '',
  71. detailedAddress: '',
  72. province: '',
  73. city: '',
  74. area: '',
  75. commonId: '',
  76. },
  77. radioCustomStyle: {
  78. margin: '0 20rpx 0 0',
  79. },
  80. type: '',
  81. radiovalue: '',
  82. dataList: [],
  83. searchKeyWord: '',
  84. radiolist1: [
  85. {
  86. name: '默认装货',
  87. disabled: false
  88. },
  89. {
  90. name: '默认卸货',
  91. disabled: false
  92. },
  93. ],
  94. delId: "",
  95. isShowAlert: false,
  96. alertTitle: "",
  97. alertContent: "",
  98. showCancelButton:false
  99. }
  100. },
  101. computed: {
  102. ...mapState(['hasLogin', 'userInfo'])
  103. },
  104. onLoad(options) {
  105. console.log(options)
  106. this.type = options.type
  107. that = this
  108. },
  109. onShow() {
  110. this.getList()
  111. },
  112. methods: {
  113. confirmClick() {
  114. this.isShowAlert = false
  115. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/deleteCargoOwnerAddress', {
  116. id: this.delId,
  117. }).then(res => {
  118. if (res.code == 200) {
  119. this.$refs.uToast.show({
  120. type: 'success',
  121. message: "删除成功",
  122. complete() {
  123. that.getList()
  124. }
  125. })
  126. }
  127. })
  128. .catch(res => {
  129. uni.showToast({
  130. title: res.message,
  131. icon: 'none',
  132. duration: 2000
  133. })
  134. });
  135. },
  136. cancelClick() {
  137. this.isShowAlert = false
  138. },
  139. configAddress(val) {
  140. if (this.type == 0) {
  141. uni.setStorageSync('storage_faddress', val);
  142. } else {
  143. uni.setStorageSync('storage_saddress', val);
  144. }
  145. // uni.$u.route('/pages/release/release');
  146. uni.navigateBack({
  147. delta: 1
  148. })
  149. },
  150. getList() {
  151. uni.showLoading({
  152. mask: true,
  153. title: '加载中...'
  154. })
  155. this.$request.baseRequest('get', '/cargoOwnerAddressInfo/selectCargoOwnerAddress', {
  156. commonId: this.userInfo.id,
  157. searchKeyWord: this.searchKeyWord,
  158. pageSize: 100,
  159. currentPage: 1
  160. }).then(res => {
  161. uni.hideLoading()
  162. if (res.code == 200) {
  163. if (res.data.records.length) {
  164. for (var i = 0; i < res.data.records.length; i++) {
  165. res.data.records[i].contactPhone1 = res.data.records[i].contactPhone.replace(
  166. /(\d{3})(\d{4})(\d{4})/, "$1****$3")
  167. }
  168. }
  169. console.log(res.data.records)
  170. this.dataList = res.data.records
  171. this.$forceUpdate()
  172. for (let i = 0; i < this.dataList.length; i++) {
  173. if (this.dataList[i].defaultShipment == 1) {
  174. this.dataList[i].radiovalue = '默认装货'
  175. }
  176. if (this.dataList[i].defaultReceipt == 1) {
  177. this.dataList[i].radiovalue = '默认卸货'
  178. }
  179. }
  180. }
  181. })
  182. .catch(res => {
  183. uni.hideLoading()
  184. uni.showToast({
  185. title: res.message,
  186. icon: 'none',
  187. duration: 2000
  188. })
  189. });
  190. },
  191. radioChange(n, val) {
  192. console.log('radioChange', n);
  193. console.log('radioChange', val);
  194. for (var i = 0; i < this.dataList.length; i++) {
  195. if (this.dataList[i].defaultShipment == 1 && n == '默认装货') {
  196. this.dataList[i].radiovalue = ''
  197. }
  198. if (this.dataList[i].defaultReceipt == 1 && n == '默认卸货') {
  199. this.dataList[i].radiovalue = ''
  200. }
  201. }
  202. this.$set(val, 'radioChange', n)
  203. let _flag;
  204. if (n == '默认卸货') {
  205. _flag = 2
  206. } else {
  207. _flag = 1
  208. }
  209. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  210. commonId: this.userInfo.id,
  211. id: val.id,
  212. defaultFlag: _flag
  213. }).then(res => {
  214. if (res.code == 200) {
  215. this.$refs.uToast.show({
  216. type: 'success',
  217. message: "设置成功",
  218. complete() {
  219. that.getList()
  220. }
  221. })
  222. }
  223. })
  224. .catch(res => {
  225. uni.showToast({
  226. title: res.message,
  227. icon: 'none',
  228. duration: 2000
  229. })
  230. });
  231. },
  232. toTop(val) {
  233. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  234. commonId: this.userInfo.id,
  235. id: val.id,
  236. }).then(res => {
  237. if (res.code == 200) {
  238. this.$refs.uToast.show({
  239. type: 'success',
  240. message: "置顶成功",
  241. complete() {
  242. that.getList()
  243. }
  244. })
  245. }
  246. })
  247. .catch(res => {
  248. uni.showToast({
  249. title: res.message,
  250. icon: 'none',
  251. duration: 2000
  252. })
  253. });
  254. },
  255. edit(val) {
  256. uni.$u.route('/pages/release/editAddress', val);
  257. },
  258. del(val) {
  259. this.delId = val.id
  260. this.isShowAlert = true
  261. this.alertTitle = "确定将要删除该常用地址?"
  262. },
  263. selectAddress(type) {
  264. // 0临时地址 1 新增地址
  265. if (type == 0) {
  266. console.log(111111111)
  267. let that = this
  268. uni.getLocation({
  269. type: 'gcj02',
  270. geocode:true,
  271. altitude:true,
  272. isHighAccuracy:true,
  273. success: function(res) {
  274. console.log('当前位置的经度:' + res.longitude);
  275. console.log('当前位置的纬度:' + res.latitude);
  276. uni.chooseLocation({
  277. success: function(res) {
  278. // var locationObj = that.$helper.formatLocation(res);
  279. // console.log(locationObj)
  280. console.log(res);
  281. console.log('位置名称:' + res.name);
  282. console.log('详细地址:' + res.address);
  283. console.log('纬度:' + res.latitude);
  284. console.log('经度:' + res.longitude);
  285. let _address = that.$helper.formatLocation(res.address)
  286. console.log('----------------------------')
  287. console.log(_address, that.type)
  288. var data = {}
  289. data.latitude = res.latitude
  290. data.longitude = res.longitude
  291. data.detailedAddress = _address.Village
  292. data.province = _address.Province
  293. data.city = _address.City
  294. data.area = _address.Country
  295. data.commonId = that.userInfo.id
  296. if (that.type == 0) {
  297. uni.setStorageSync('storage_faddress', data)
  298. } else {
  299. uni.setStorageSync('storage_saddress', data)
  300. }
  301. uni.navigateBack({
  302. delta: 1
  303. })
  304. // uni.$u.route('/pages/release/release');
  305. // that.temporaryAddress.latitude = res.latitude
  306. // that.temporaryAddress.longitude = res.longitude
  307. // that.temporaryAddress.detailedAddress = locationObj.ADDRESS
  308. // that.temporaryAddress.province = locationObj.REGION_PROVINCE
  309. // that.temporaryAddress.city = locationObj.REGION_CITY
  310. // that.temporaryAddress.area = locationObj.REGION_COUNTRY
  311. // that.temporaryAddress.commonId = that.userInfo.id
  312. // that.configAddress(that.temporaryAddress)
  313. // that.$forceUpdate()
  314. },
  315. fail(err) {
  316. console.log(err)
  317. },
  318. complete(res1) {
  319. console.log(res1)
  320. }
  321. });
  322. }
  323. })
  324. } else {
  325. uni.$u.route('/pages/release/addAddress', {
  326. type: type,
  327. });
  328. }
  329. },
  330. }
  331. }
  332. </script>
  333. <style scoped lang="scss">
  334. .content1 {
  335. background: white;
  336. padding: 20rpx;
  337. }
  338. .content {
  339. height: 100vh;
  340. overflow:scroll;
  341. }
  342. .content2-wrap {
  343. margin-bottom: 200rpx;
  344. }
  345. .jt-icon {
  346. position: relative;
  347. top: 4rpx;
  348. width: 24rpx;
  349. margin: 0 10rpx;
  350. }
  351. .content2 {
  352. border-radius: 20rpx;
  353. background: white;
  354. margin: 20rpx;
  355. padding: 20rpx;
  356. .row {
  357. margin-top: 20rpx;
  358. }
  359. .row1 {
  360. font-weight: 700;
  361. color: #333333;
  362. .name {
  363. margin-right: 20rpx;
  364. }
  365. }
  366. .row2 {
  367. color: #7D7D7D;
  368. }
  369. .row3 {
  370. font-size: 24rpx;
  371. }
  372. }
  373. .bottom-btn {
  374. position: fixed;
  375. bottom: 0rpx;
  376. padding: 50rpx 0;
  377. width: 100%;
  378. background-color: #fff;
  379. display: flex;
  380. justify-content: space-around;
  381. .btn-left {
  382. text-align: center;
  383. width: 30%;
  384. font-size: 32rpx;
  385. font-weight: 500;
  386. color: #2772FB;
  387. background-color: #EEF4FF;
  388. padding: 20rpx 40rpx;
  389. border-radius: 40rpx;
  390. }
  391. .btn-right {
  392. text-align: center;
  393. width: 30%;
  394. font-size: 32rpx;
  395. font-weight: 500;
  396. color: white;
  397. background-color: #2772FB;
  398. padding: 20rpx 40rpx;
  399. border-radius: 50rpx;
  400. }
  401. }
  402. .icon-img {
  403. display: flex;
  404. align-items: center;
  405. color: #999999;
  406. }
  407. </style>