selectAddress.vue 9.8 KB

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