userAddress.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <uni-popup ref="popup" type="bottom">
  3. <view class="container">
  4. <form @submit="formSubmit" v-if="false">
  5. <view class='addAddress'>
  6. <view class="pad30">
  7. <view class='default acea-row row-middle borderRadius15'>
  8. <uni-easyinput type="textarea" v-model="addressValue" placeholder="粘贴地址信息,自动拆分姓名、电话和地址" @blur="identify()" />
  9. </view>
  10. </view>
  11. <view class="pad30 mt-22">
  12. <view class='list borderRadius15'>
  13. <view class='item acea-row row-between-wrapper'>
  14. <view class='name'>姓名</view>
  15. <input type='text' placeholder='请输入姓名' name='real_name' v-model="userAddress.real_name"
  16. placeholder-class='placeholder' />
  17. </view>
  18. <view class='item acea-row row-between-wrapper'>
  19. <view class='name'>联系电话</view>
  20. <input type='number' placeholder='请输入联系电话' name="phone" v-model='userAddress.phone'
  21. placeholder-class='placeholder' pattern="\d*" />
  22. </view>
  23. <view class='item acea-row row-between-wrapper'>
  24. <view class='name'>所在地区</view>
  25. <view class="address acea-row row-between">
  26. <input type='text' placeholder='请填写具体地址' name='region' placeholder-class='placeholder'
  27. v-model='userAddress.region' class="detail" />
  28. </view>
  29. </view>
  30. <view class='item acea-row row-between-wrapper'>
  31. <view class='name'>详细地址</view>
  32. <view class="address">
  33. <input type='text' placeholder='请填写具体地址' name='detail' placeholder-class='placeholder'
  34. v-model='userAddress.detail' class="detail" />
  35. </view>
  36. </view>
  37. <view class='item acea-row row-between-wrapper'>
  38. <view class='name'>详细地址</view>
  39. <view class="address">
  40. <uni-data-checkbox v-model="is_default" :localdata="range"></uni-data-checkbox>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <button class='keepBnt bg-color' form-type="submit">立即保存</button>
  46. </view>
  47. </form>
  48. <view class="addbar">
  49. <text class="iconfont sp">&#xe760;</text>
  50. <text class="sp">添加地址</text>
  51. </view>
  52. <uni-swipe-action class="swipeAction">
  53. <uni-swipe-action-item class="swipeAction_item" v-for="(i,s) in addressList" :key="s">
  54. <view class="addressLi clearfix" @click="onSelect(i,s)">
  55. <view class="addressLi_l">
  56. <text v-if="i.status != 1" class="iconfont">&#xe623;</text>
  57. <text v-else class="iconfont pitchOn">&#xe624;</text>
  58. </view>
  59. <view class="addressLi_r">
  60. <view class="user">
  61. <text class="name">{{i.name}}</text>
  62. <text>{{i.mobile}}</text>
  63. </view>
  64. <view class="address">{{i.address}}</view>
  65. </view>
  66. </view>
  67. <template v-slot:right>
  68. <view class="btns clearfix">
  69. <view class="btn edit"><text class="iconfont">&#xe600;</text></view>
  70. <view class="btn del"><text class="iconfont">&#xe601;</text></view>
  71. </view>
  72. </template>
  73. </uni-swipe-action-item>
  74. </uni-swipe-action>
  75. </view>
  76. </uni-popup>
  77. </template>
  78. <script>
  79. import { get, post, u_post } from "@/request/api.js";
  80. import AddressParse from './zh-address-parse.min.js'
  81. let app = getApp();
  82. var appEv = app.$vm.$options;
  83. export default {
  84. data() {
  85. return {
  86. userAddress: {
  87. real_name:"",
  88. phone:"",
  89. region:"",
  90. detail:"",
  91. }, //地址详情
  92. addressValue:"",
  93. is_default: 0, //是否设为默认地址
  94. range: [{"value": 0,"text": "否" },{"value": 1,"text": "是"}],
  95. addressList: [],
  96. }
  97. },
  98. components:{},
  99. created () {
  100. this.loadAddress();
  101. },
  102. methods: {
  103. identify(){
  104. const options = {
  105. type: 0, // 哪种方式解析,0:正则,1:树查找
  106. textFilter: [], // 预清洗的字段
  107. nameMaxLength: 4, // 查找最大的中文名字长度
  108. }
  109. // type参数0表示使用正则解析,1表示采用树查找, textFilter地址预清洗过滤字段。
  110. if(!!this.addressValue){
  111. const parseResult = AddressParse(this.addressValue, options)
  112. // console.log(parseResult);
  113. this.userAddress.real_name = parseResult.name;
  114. this.userAddress.phone = parseResult.phone;
  115. this.userAddress.detail = parseResult.detail;
  116. this.userAddress.region = parseResult.province + '/' + parseResult.city + '/' + parseResult.area;
  117. }
  118. },
  119. formSubmit(){
  120. post("user/addAddress",{
  121. address: this.userAddress.region + this.userAddress.detail,
  122. mobile: this.userAddress.phone,
  123. name: this.userAddress.real_name,
  124. is_default: this.is_default
  125. }).then(res => {
  126. if (res.code === 0) {
  127. appEv.errTips(res.msg);
  128. setTimeout(() => {
  129. // uni.navigateBack();
  130. this.$emit('addressConfirm');
  131. this.close();
  132. }, 1500);
  133. }
  134. })
  135. },
  136. // 获取用户地址
  137. loadAddress(){
  138. post("user/addressList").then(res => {
  139. if(res.code === 0){
  140. this.addressList = res.data.data;
  141. }
  142. })
  143. },
  144. onSelect(i,s){
  145. this.addressList.forEach(e => {
  146. e.status = "0";
  147. });
  148. this.addressList[s].status = "1";
  149. this.editAddress();
  150. },
  151. editAddress(){
  152. this.addressList.forEach((e,s) => {
  153. post("user/editAddress",{
  154. ...e, is_default: e.status
  155. }).then(res=>{
  156. if(this.addressList.length == s+1){
  157. this.$emit('addressConfirm');
  158. this.close();
  159. }
  160. })
  161. });
  162. },
  163. open() {
  164. this.$refs.popup.open('top')
  165. },
  166. close() {
  167. this.$refs.popup.close()
  168. }
  169. },
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .container{
  174. background-color: #f5f5f5;
  175. height: 100vh;
  176. padding:30rpx 0;
  177. }
  178. .pad30 {
  179. padding: 0 30rpx
  180. }
  181. .p_center {
  182. text-align: center;
  183. }
  184. .acea-row {
  185. display: flex;
  186. }
  187. .row-middle {
  188. align-items: center
  189. }
  190. .row-between-wrapper {
  191. align-items: center;
  192. justify-content: space-between
  193. }
  194. .borderRadius15 {
  195. border-radius: 15rpx !important;
  196. }
  197. .fontcolor{
  198. color: var(--view-theme);
  199. }
  200. .addAddress .list {
  201. background-color: #fff;
  202. }
  203. .addAddress .list .item {
  204. padding: 30rpx;
  205. border-top: 1rpx solid #eee;
  206. position: relative;
  207. }
  208. .addAddress .list .item .detail{
  209. width: 368rpx;
  210. }
  211. .addAddress .list .item .location{
  212. position: absolute;
  213. right: 46rpx;
  214. top: 50%;
  215. margin-top: -40rpx!important;
  216. font-size: 24rpx;
  217. text-align: center;
  218. }
  219. .addAddress .list .item .icon-dizhi{
  220. font-size: 36rpx!important;
  221. }
  222. .addAddress .list .item .name {
  223. width: 195rpx;
  224. font-size: 30rpx;
  225. color: #333;
  226. }
  227. .addAddress .list .item .address {
  228. flex: 1;
  229. }
  230. .addAddress .list .item .address .addressCon{
  231. width: 360rpx;
  232. }
  233. .addAddress .list .item .address .addressCon .tip{
  234. font-size: 21rpx;
  235. margin-top: 4rpx;
  236. }
  237. .addAddress .list .item input {
  238. /* // width: 475rpx; */
  239. flex: 1;
  240. font-size: 30rpx;
  241. }
  242. .placeholder {
  243. color: #ccc;
  244. }
  245. .addAddress .list .item .picker {
  246. width: 430rpx;
  247. font-size: 30rpx;
  248. }
  249. .addAddress .list .item .iconfont {
  250. font-size: 30rpx;
  251. margin-top: 4rpx;
  252. }
  253. .addAddress .default {
  254. padding: 30rpx;
  255. /* height: 90rpx; */
  256. background-color: #fff;
  257. }
  258. .addAddress .default checkbox {
  259. margin-right: 15rpx;
  260. }
  261. .addAddress .keepBnt {
  262. width: 690rpx;
  263. height: 86rpx;
  264. border-radius: 50rpx;
  265. text-align: center;
  266. line-height: 86rpx;
  267. margin: 50rpx auto;
  268. font-size: 32rpx;
  269. color: #fff;
  270. }
  271. .mt-22{
  272. margin-top: 22rpx;
  273. }
  274. .bg-color {
  275. background-color: #dd524d;
  276. }
  277. .addbar{
  278. background: #fff;
  279. text-align: center;
  280. margin-bottom: 50rpx;
  281. padding: 36rpx 0;
  282. .iconfont{
  283. font-size: 46rpx;
  284. margin-right: 20rpx;
  285. }
  286. .sp{
  287. vertical-align: middle;
  288. }
  289. }
  290. .swipeAction{
  291. // padding: 20rpx 30rpx;
  292. font-size: 28rpx;
  293. .addressLi{
  294. .addressLi_l{
  295. width: 80rpx;
  296. height: 80rpx;
  297. display: flex;
  298. // justify-content: center;
  299. align-items: center;
  300. .iconfont{
  301. color: #666;
  302. font-size: 38rpx;
  303. }
  304. .pitchOn{
  305. color: #1989fa;
  306. }
  307. }
  308. .addressLi_r{
  309. width: calc(100% - 80rpx);
  310. }
  311. .addressLi_l,.addressLi_r{
  312. float: left;
  313. }
  314. .user{
  315. margin-bottom: 10rpx;
  316. }
  317. .name{
  318. // font-weight: bold;
  319. font-size: 32rpx;
  320. margin-right: 10rpx;
  321. }
  322. .address{
  323. font-size: 24rpx;
  324. color: #999;
  325. }
  326. }
  327. .swipeAction_item{
  328. background: #fff;
  329. margin-bottom: 20rpx;
  330. }
  331. .btns{
  332. .btn{
  333. float: left;
  334. display:flex;
  335. justify-content : center;
  336. align-items : center;
  337. height: 100%;
  338. padding: 0 30rpx;
  339. color: #fff;
  340. font-size: 36rpx;
  341. }
  342. .edit{
  343. background: rgba(25,137,250,0.5);
  344. }
  345. .del{
  346. background: rgba(238,10,36,0.5);
  347. }
  348. }
  349. }
  350. ::v-deep .uni-swipe_box{
  351. padding: 20rpx 30rpx;
  352. }
  353. </style>