selectAddress.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. 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.getLocation({
  268. type: 'gcj02',
  269. geocode:true,
  270. altitude:true,
  271. isHighAccuracy:true,
  272. success: function(res) {
  273. console.log('当前位置的经度:' + res.longitude);
  274. console.log('当前位置的纬度:' + res.latitude);
  275. uni.chooseLocation({
  276. success: function(res) {
  277. // var locationObj = that.$helper.formatLocation(res);
  278. // console.log(locationObj)
  279. console.log(res);
  280. console.log('位置名称:' + res.name);
  281. console.log('详细地址:' + res.address);
  282. console.log('纬度:' + res.latitude);
  283. console.log('经度:' + res.longitude);
  284. let _address = that.$helper.formatLocation(res.address)
  285. console.log('----------------------------')
  286. console.log(_address, that.type)
  287. var data = {}
  288. data.latitude = res.latitude
  289. data.longitude = res.longitude
  290. data.detailedAddress = _address.Village
  291. data.province = _address.Province
  292. data.city = _address.City
  293. data.area = _address.Country
  294. data.commonId = that.userInfo.id
  295. if (that.type == 0) {
  296. uni.setStorageSync('storage_faddress', data)
  297. } else {
  298. uni.setStorageSync('storage_saddress', data)
  299. }
  300. uni.navigateBack({
  301. delta: 1
  302. })
  303. // uni.$u.route('/pages/release/release');
  304. // that.temporaryAddress.latitude = res.latitude
  305. // that.temporaryAddress.longitude = res.longitude
  306. // that.temporaryAddress.detailedAddress = locationObj.ADDRESS
  307. // that.temporaryAddress.province = locationObj.REGION_PROVINCE
  308. // that.temporaryAddress.city = locationObj.REGION_CITY
  309. // that.temporaryAddress.area = locationObj.REGION_COUNTRY
  310. // that.temporaryAddress.commonId = that.userInfo.id
  311. // that.configAddress(that.temporaryAddress)
  312. // that.$forceUpdate()
  313. },
  314. fail(err) {
  315. console.log(err)
  316. },
  317. complete(res1) {
  318. console.log(res1)
  319. }
  320. });
  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. }
  340. .content2-wrap {
  341. margin-bottom: 200rpx;
  342. }
  343. .jt-icon {
  344. position: relative;
  345. top: 4rpx;
  346. width: 24rpx;
  347. margin: 0 10rpx;
  348. }
  349. .content2 {
  350. border-radius: 20rpx;
  351. background: white;
  352. margin: 20rpx;
  353. padding: 20rpx;
  354. .row {
  355. margin-top: 20rpx;
  356. }
  357. .row1 {
  358. font-weight: 700;
  359. color: #333333;
  360. .name {
  361. margin-right: 20rpx;
  362. }
  363. }
  364. .row2 {
  365. color: #7D7D7D;
  366. }
  367. .row3 {
  368. font-size: 24rpx;
  369. }
  370. }
  371. .bottom-btn {
  372. position: fixed;
  373. bottom: 0rpx;
  374. padding: 50rpx 0;
  375. width: 100%;
  376. background-color: #fff;
  377. display: flex;
  378. justify-content: space-around;
  379. .btn-left {
  380. text-align: center;
  381. width: 30%;
  382. font-size: 32rpx;
  383. font-weight: 500;
  384. color: #2772FB;
  385. background-color: #EEF4FF;
  386. padding: 20rpx 40rpx;
  387. border-radius: 40rpx;
  388. }
  389. .btn-right {
  390. text-align: center;
  391. width: 30%;
  392. font-size: 32rpx;
  393. font-weight: 500;
  394. color: white;
  395. background-color: #2772FB;
  396. padding: 20rpx 40rpx;
  397. border-radius: 50rpx;
  398. }
  399. }
  400. .icon-img {
  401. display: flex;
  402. align-items: center;
  403. color: #999999;
  404. }
  405. </style>