selectAddress.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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, 5000)" @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. }
  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. if (res.code == 200) {
  161. if (res.data.records.length) {
  162. for (var i = 0; i < res.data.records.length; i++) {
  163. res.data.records[i].contactPhone1 = res.data.records[i].contactPhone.replace(
  164. /(\d{3})(\d{4})(\d{4})/, "$1****$3")
  165. }
  166. }
  167. console.log(res.data.records)
  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. uni.hideLoading()
  179. }
  180. })
  181. .catch(res => {
  182. uni.showToast({
  183. title: res.message,
  184. icon: 'none',
  185. duration: 2000
  186. })
  187. });
  188. },
  189. radioChange(n, val) {
  190. console.log('radioChange', n);
  191. console.log('radioChange', val);
  192. for (var i = 0; i < this.dataList.length; i++) {
  193. if (this.dataList[i].defaultShipment == 1 && n == '默认装货') {
  194. this.dataList[i].radiovalue = ''
  195. }
  196. if (this.dataList[i].defaultReceipt == 1 && n == '默认卸货') {
  197. this.dataList[i].radiovalue = ''
  198. }
  199. }
  200. this.$set(val, 'radioChange', n)
  201. let _flag;
  202. if (n == '默认卸货') {
  203. _flag = 2
  204. } else {
  205. _flag = 1
  206. }
  207. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  208. commonId: this.userInfo.id,
  209. id: val.id,
  210. defaultFlag: _flag
  211. }).then(res => {
  212. if (res.code == 200) {
  213. this.$refs.uToast.show({
  214. type: 'success',
  215. message: "设置成功",
  216. complete() {
  217. that.getList()
  218. }
  219. })
  220. }
  221. })
  222. .catch(res => {
  223. uni.showToast({
  224. title: res.message,
  225. icon: 'none',
  226. duration: 2000
  227. })
  228. });
  229. },
  230. toTop(val) {
  231. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/setDefault', {
  232. commonId: this.userInfo.id,
  233. id: val.id,
  234. }).then(res => {
  235. if (res.code == 200) {
  236. this.$refs.uToast.show({
  237. type: 'success',
  238. message: "置顶成功",
  239. complete() {
  240. that.getList()
  241. }
  242. })
  243. }
  244. })
  245. .catch(res => {
  246. uni.showToast({
  247. title: res.message,
  248. icon: 'none',
  249. duration: 2000
  250. })
  251. });
  252. },
  253. edit(val) {
  254. uni.$u.route('/pages/release/editAddress', val);
  255. },
  256. del(val) {
  257. this.delId = val.id
  258. this.isShowAlert = true
  259. this.alertTitle = "确定将要删除该常用地址?"
  260. },
  261. selectAddress(type) {
  262. // 0临时地址 1 新增地址
  263. if (type == 0) {
  264. console.log(111111111)
  265. let that = this
  266. uni.getLocation({
  267. type: 'gcj02',
  268. geocode:true,
  269. altitude:true,
  270. isHighAccuracy:true,
  271. success: function(res) {
  272. console.log('当前位置的经度:' + res.longitude);
  273. console.log('当前位置的纬度:' + res.latitude);
  274. uni.chooseLocation({
  275. success: function(res) {
  276. // var locationObj = that.$helper.formatLocation(res);
  277. // console.log(locationObj)
  278. console.log(res);
  279. console.log('位置名称:' + res.name);
  280. console.log('详细地址:' + res.address);
  281. console.log('纬度:' + res.latitude);
  282. console.log('经度:' + res.longitude);
  283. let _address = that.$helper.formatLocation(res.address)
  284. console.log('----------------------------')
  285. console.log(_address, that.type)
  286. var data = {}
  287. data.latitude = res.latitude
  288. data.longitude = res.longitude
  289. data.detailedAddress = _address.Village
  290. data.province = _address.Province
  291. data.city = _address.City
  292. data.area = _address.Country
  293. data.commonId = that.userInfo.id
  294. if (that.type == 0) {
  295. uni.setStorageSync('storage_faddress', data)
  296. } else {
  297. uni.setStorageSync('storage_saddress', data)
  298. }
  299. uni.navigateBack({
  300. delta: 1
  301. })
  302. // uni.$u.route('/pages/release/release');
  303. // that.temporaryAddress.latitude = res.latitude
  304. // that.temporaryAddress.longitude = res.longitude
  305. // that.temporaryAddress.detailedAddress = locationObj.ADDRESS
  306. // that.temporaryAddress.province = locationObj.REGION_PROVINCE
  307. // that.temporaryAddress.city = locationObj.REGION_CITY
  308. // that.temporaryAddress.area = locationObj.REGION_COUNTRY
  309. // that.temporaryAddress.commonId = that.userInfo.id
  310. // that.configAddress(that.temporaryAddress)
  311. // that.$forceUpdate()
  312. },
  313. fail(err) {
  314. console.log(err)
  315. },
  316. complete(res1) {
  317. console.log(res1)
  318. }
  319. });
  320. }
  321. })
  322. } else {
  323. uni.$u.route('/pages/release/addAddress', {
  324. type: type,
  325. });
  326. }
  327. },
  328. }
  329. }
  330. </script>
  331. <style scoped lang="scss">
  332. .content1 {
  333. background: white;
  334. padding: 20rpx;
  335. }
  336. .content {
  337. height: 100vh;
  338. }
  339. .content2-wrap {
  340. margin-bottom: 200rpx;
  341. }
  342. .jt-icon {
  343. position: relative;
  344. top: 4rpx;
  345. width: 24rpx;
  346. margin: 0 10rpx;
  347. }
  348. .content2 {
  349. border-radius: 20rpx;
  350. background: white;
  351. margin: 20rpx;
  352. padding: 20rpx;
  353. .row {
  354. margin-top: 20rpx;
  355. }
  356. .row1 {
  357. font-weight: 700;
  358. color: #333333;
  359. .name {
  360. margin-right: 20rpx;
  361. }
  362. }
  363. .row2 {
  364. color: #7D7D7D;
  365. }
  366. .row3 {
  367. font-size: 24rpx;
  368. }
  369. }
  370. .bottom-btn {
  371. position: fixed;
  372. bottom: 0rpx;
  373. padding: 50rpx 0;
  374. width: 100%;
  375. background-color: #fff;
  376. display: flex;
  377. justify-content: space-around;
  378. .btn-left {
  379. text-align: center;
  380. width: 30%;
  381. font-size: 32rpx;
  382. font-weight: 500;
  383. color: #2772FB;
  384. background-color: #EEF4FF;
  385. padding: 20rpx 40rpx;
  386. border-radius: 40rpx;
  387. }
  388. .btn-right {
  389. text-align: center;
  390. width: 30%;
  391. font-size: 32rpx;
  392. font-weight: 500;
  393. color: white;
  394. background-color: #2772FB;
  395. padding: 20rpx 40rpx;
  396. border-radius: 50rpx;
  397. }
  398. }
  399. .icon-img {
  400. display: flex;
  401. align-items: center;
  402. color: #999999;
  403. }
  404. </style>