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