selectAddress.vue 9.6 KB

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