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