userAddress.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <uni-popup ref="popup" type="bottom">
  3. <view class="Address_container">
  4. <div class="tit flex_r flex_jb">
  5. <text class="cancel" v-if="isadd" @click="isadd = false">取消</text>
  6. <text v-else></text>
  7. <text class="close" @click="close">关闭</text>
  8. </div>
  9. <div class="s_con">
  10. <form @submit="formSubmit" v-if="isadd">
  11. <view class='addAddress'>
  12. <!-- <view class="pad30">
  13. <view class='default acea-row borderRadius15'>
  14. <textarea v-model="addressValue" placeholder="粘贴地址信息,自动拆分姓名、电话和地址" @blur="identify()" class="inputa-text" />
  15. </view>
  16. </view> -->
  17. <view class="pad30 mt-22">
  18. <view class='list borderRadius15'>
  19. <view class='item acea-row row-between-wrapper'>
  20. <view class='name'>姓名</view>
  21. <input type='text' placeholder='请输入姓名' v-model="userAddress.name" class="inputa" />
  22. </view>
  23. <view class='item acea-row row-between-wrapper'>
  24. <view class='name'>联系电话</view>
  25. <input type='number' placeholder='请输入联系电话' v-model='userAddress.mobile' class="inputa" />
  26. </view>
  27. <view class='item acea-row row-between-wrapper'>
  28. <view class='name'>所在地区</view>
  29. <input type='text' placeholder='请填写具体地址' v-model='userAddress.region' @click="btnClick" disabled class="inputa" />
  30. </view>
  31. <view class='item acea-row row-between-wrapper'>
  32. <view class='name'>详细地址</view>
  33. <input type='text' placeholder='请填写具体地址' v-model='userAddress.address' class="inputa" />
  34. </view>
  35. <view class='item acea-row'>
  36. <view class='name'>默认地址</view>
  37. <uni-data-checkbox v-model="is_default" :localdata="range"></uni-data-checkbox>
  38. </view>
  39. </view>
  40. </view>
  41. <button class='keepBnt bg-color' form-type="submit">立即保存</button>
  42. </view>
  43. </form>
  44. <div class="editaddress" v-else>
  45. <view class="addbar" @click="onadd">
  46. <text class="iconfont sp">&#xe760;</text>
  47. <text class="sp">添加地址</text>
  48. </view>
  49. <uni-swipe-action class="swipeAction">
  50. <uni-swipe-action-item class="swipeAction_item" v-for="(i,s) in addressList" :key="s">
  51. <view class="addressLi clearfix" @click="onSelect(i,s)">
  52. <view class="addressLi_l">
  53. <text v-if="i.id != presentId" class="iconfont">&#xe623;</text>
  54. <text v-else class="iconfont pitchOn">&#xe624;</text>
  55. </view>
  56. <view class="addressLi_r">
  57. <view class="user">
  58. <text class="name">{{i.name}}</text>
  59. <text>{{i.mobile}}</text>
  60. <text v-if="i.status == 1" class="defaultAddress">默认</text>
  61. </view>
  62. <view class="address">{{i.province + ' ' + i.city + ' ' + i.area + ' ' + i.street + ' ' + i.address}}</view>
  63. </view>
  64. </view>
  65. <template v-slot:right>
  66. <view class="btns clearfix">
  67. <view class="btn edit" @click="onedit(i)"><text class="iconfont">&#xe600;</text></view>
  68. <view class="btn del" @click="delAddress(i.id)"><text class="iconfont">&#xe601;</text></view>
  69. </view>
  70. </template>
  71. </uni-swipe-action-item>
  72. </uni-swipe-action>
  73. </div>
  74. </div>
  75. </view>
  76. <select-address :address.sync="address" ref='selectAddress' @change="changeAddress"/>
  77. </uni-popup>
  78. </template>
  79. <script>
  80. import { post } from "@/request/api.js";
  81. import selectAddress from "@/components/lcw-select-address/lcw-select-address.vue"
  82. export default {
  83. components: {
  84. selectAddress
  85. },
  86. data() {
  87. return {
  88. userAddress: {}, //地址详情
  89. // addressValue: "",
  90. is_default: 0, //是否设为默认地址
  91. range: [{ "value": 0, "text": "否" }, { "value": 1, "text": "是" }],
  92. isadd: false,
  93. addressList: [],
  94. presentId: "", //当前选择地址的id
  95. address: {
  96. province: '',
  97. city: '',
  98. area: '',
  99. street: ''
  100. }
  101. }
  102. },
  103. created() {
  104. this.loadAddress();
  105. },
  106. methods: {
  107. btnClick() {
  108. this.$refs.selectAddress.open()
  109. },
  110. changeAddress(address){ //选择成功回调
  111. this.address = address;
  112. this.userAddress.region = ""
  113. for (const i in address) {
  114. if(i != "regional_code") this.userAddress.region += address[i] + " "
  115. }
  116. },
  117. // identify() {
  118. // if (this.addressValue) {
  119. // const da = smart(this.addressValue)
  120. // let {province,city,county,street} = da
  121. // street = street || ''
  122. // let obj = {
  123. // name: da.name,
  124. // mobile: da.phone,
  125. // address: da.address,
  126. // region: province + ' ' + city + ' ' + county + ' ' + street
  127. // }
  128. // this.address = { province,city,area: county,street }
  129. // this.$set(this,"userAddress",obj)
  130. // }
  131. // },
  132. formSubmit() {
  133. let url;
  134. let { address, mobile, name } = this.userAddress
  135. let data = {
  136. ...this.address,
  137. address, mobile, name,
  138. is_default: this.is_default
  139. }
  140. if (this.userAddress.id) {
  141. url = "v1/user/editAddress";
  142. data.id = this.userAddress.id
  143. } else url = "v1/user/addAddress";
  144. post(url, data).then(res => {
  145. if (res.code === 0) {
  146. this.$toast(res.msg);
  147. this.loadAddress();
  148. this.isadd = false;
  149. }
  150. })
  151. },
  152. // 获取用户地址
  153. loadAddress() {
  154. post("v1/user/addressList").then(res => {
  155. if (res.code === 0) {
  156. this.addressList = res.data.data;
  157. }
  158. })
  159. },
  160. onSelect(i, s) {
  161. this.presentId = i.id;
  162. this.$emit('addressConfirm', i);
  163. this.close();
  164. },
  165. onadd() {
  166. this.isadd = true;
  167. this.userAddress = {};
  168. },
  169. onedit(da) {
  170. let {id,name,mobile,address,province,city,area,street,status, regional_code} = da
  171. this.userAddress = { id,name,mobile,address };
  172. this.address = { province,city,area,street, regional_code };
  173. this.userAddress.region = province + ' ' + city + ' ' + area + ' ' + street;
  174. this.is_default = status
  175. this.isadd = true
  176. },
  177. delAddress(id) {
  178. post("v1/user/delAddress", { id }).then(res => {
  179. if (res.code === 0) {
  180. this.$toast(res.msg);
  181. this.loadAddress();
  182. }
  183. })
  184. },
  185. open(da) {
  186. this.$refs.popup.open('bottom')
  187. if (da == "add") this.isadd = true
  188. else {
  189. this.isadd = false;
  190. this.presentId = da;
  191. }
  192. },
  193. close() {
  194. this.$refs.popup.close()
  195. }
  196. },
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .inputa-text{
  201. width: 100%;
  202. height: 160rpx;
  203. border: 1px solid #c0b5b5;
  204. border-radius: 16rpx;
  205. padding: 12rpx;
  206. }
  207. .Address_container {
  208. // height: 70vh;
  209. min-height: 70vh;
  210. background-color: #f5f5f5;
  211. border-radius: 30rpx 30rpx 0 0;
  212. overflow: hidden;
  213. }
  214. .tit {
  215. height: 100rpx;
  216. line-height: 100rpx;
  217. background: #fff;
  218. border-radius: 30rpx 30rpx 0 0;
  219. color: #333;
  220. .cancel {
  221. padding: 0 30rpx;
  222. }
  223. .close {
  224. // float: right;
  225. padding: 0 30rpx;
  226. }
  227. }
  228. .s_con {
  229. height: calc(100% - 100rpx);
  230. // overflow-y: auto;
  231. padding-top: 20rpx;
  232. .pad30 {
  233. padding: 0 30rpx
  234. }
  235. .p_center {
  236. text-align: center;
  237. }
  238. .acea-row {
  239. display: flex;
  240. }
  241. .row-middle {
  242. align-items: center
  243. }
  244. .row-between-wrapper {
  245. align-items: center;
  246. justify-content: space-between
  247. }
  248. .borderRadius15 {
  249. border-radius: 15rpx !important;
  250. }
  251. }
  252. .addAddress {
  253. width: 100%;
  254. .list {
  255. background-color: #fff;
  256. .item {
  257. padding: 30rpx;
  258. border-top: 1rpx solid #eee;
  259. // position: relative;
  260. .icon-dizhi {
  261. font-size: 36rpx !important;
  262. }
  263. .name {
  264. width: 180rpx;
  265. font-size: 30rpx;
  266. color: #333;
  267. }
  268. .address {
  269. flex: 1;
  270. }
  271. input {
  272. flex: 1;
  273. font-size: 0 30rpx;
  274. }
  275. }
  276. }
  277. .default {
  278. padding: 30rpx;
  279. background-color: #fff;
  280. }
  281. .keepBnt {
  282. width: 690rpx;
  283. height: 86rpx;
  284. border-radius: 50rpx;
  285. text-align: center;
  286. line-height: 86rpx;
  287. margin: 50rpx auto;
  288. font-size: 32rpx;
  289. color: #fff;
  290. }
  291. }
  292. .placeholder {
  293. color: #ccc;
  294. }
  295. .mt-22 {
  296. margin-top: 22rpx;
  297. }
  298. .bg-color {
  299. background-color: #2DB389;
  300. }
  301. .addbar {
  302. background: #fff;
  303. text-align: center;
  304. margin-bottom: 20rpx;
  305. padding: 36rpx 0;
  306. .iconfont {
  307. font-size: 46rpx;
  308. margin-right: 20rpx;
  309. }
  310. .sp {
  311. vertical-align: middle;
  312. }
  313. }
  314. .swipeAction {
  315. font-size: 28rpx;
  316. .addressLi {
  317. .addressLi_l {
  318. width: 80rpx;
  319. height: 80rpx;
  320. display: flex;
  321. align-items: center;
  322. .iconfont {
  323. color: #666;
  324. font-size: 38rpx;
  325. }
  326. .pitchOn {
  327. color: #1989fa;
  328. }
  329. }
  330. .addressLi_r {
  331. width: calc(100% - 80rpx);
  332. }
  333. .addressLi_l,
  334. .addressLi_r {
  335. float: left;
  336. }
  337. .user {
  338. margin-bottom: 10rpx;
  339. }
  340. .name {
  341. font-size: 32rpx;
  342. margin-right: 10rpx;
  343. }
  344. .address {
  345. font-size: 24rpx;
  346. color: #999;
  347. padding: 0;
  348. }
  349. }
  350. // .swipeAction_item {
  351. // background: #fff;
  352. // margin-bottom: 20rpx;
  353. // }
  354. .btns {
  355. .btn {
  356. float: left;
  357. display: flex;
  358. justify-content: center;
  359. align-items: center;
  360. height: 100%;
  361. padding: 0 30rpx;
  362. color: #fff;
  363. font-size: 36rpx;
  364. }
  365. .edit {
  366. background: rgba(25, 137, 250, 0.5);
  367. }
  368. .del {
  369. background: rgba(238, 10, 36, 0.5);
  370. }
  371. .iconfont {
  372. color: #fff;
  373. }
  374. }
  375. }
  376. ::v-deep .uni-swipe_box {
  377. padding: 20rpx 30rpx;
  378. background: #fff;
  379. margin-bottom: 20rpx;
  380. }
  381. .defaultAddress {
  382. border: 1rpx solid #2DB389;
  383. color: #2DB389;
  384. border-radius: 6rpx;
  385. font-size: 18rpx;
  386. padding: 0 6rpx;
  387. margin-left: 20rpx;
  388. }
  389. </style>