| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- <template>
- <uni-popup ref="popup" type="bottom">
- <view class="container">
- <form @submit="formSubmit" v-if="false">
- <view class='addAddress'>
- <view class="pad30">
- <view class='default acea-row row-middle borderRadius15'>
- <uni-easyinput type="textarea" v-model="addressValue" placeholder="粘贴地址信息,自动拆分姓名、电话和地址" @blur="identify()" />
- </view>
- </view>
- <view class="pad30 mt-22">
- <view class='list borderRadius15'>
- <view class='item acea-row row-between-wrapper'>
- <view class='name'>姓名</view>
- <input type='text' placeholder='请输入姓名' name='real_name' v-model="userAddress.real_name"
- placeholder-class='placeholder' />
- </view>
- <view class='item acea-row row-between-wrapper'>
- <view class='name'>联系电话</view>
- <input type='number' placeholder='请输入联系电话' name="phone" v-model='userAddress.phone'
- placeholder-class='placeholder' pattern="\d*" />
- </view>
- <view class='item acea-row row-between-wrapper'>
- <view class='name'>所在地区</view>
- <view class="address acea-row row-between">
- <input type='text' placeholder='请填写具体地址' name='region' placeholder-class='placeholder'
- v-model='userAddress.region' class="detail" />
- </view>
- </view>
- <view class='item acea-row row-between-wrapper'>
- <view class='name'>详细地址</view>
- <view class="address">
- <input type='text' placeholder='请填写具体地址' name='detail' placeholder-class='placeholder'
- v-model='userAddress.detail' class="detail" />
- </view>
- </view>
- <view class='item acea-row row-between-wrapper'>
- <view class='name'>详细地址</view>
- <view class="address">
- <uni-data-checkbox v-model="is_default" :localdata="range"></uni-data-checkbox>
- </view>
- </view>
- </view>
- </view>
- <button class='keepBnt bg-color' form-type="submit">立即保存</button>
- </view>
- </form>
- <view class="addbar">
- <text class="iconfont sp"></text>
- <text class="sp">添加地址</text>
- </view>
- <uni-swipe-action class="swipeAction">
- <uni-swipe-action-item class="swipeAction_item" v-for="(i,s) in addressList" :key="s">
- <view class="addressLi clearfix" @click="onSelect(i,s)">
- <view class="addressLi_l">
- <text v-if="i.status != 1" class="iconfont"></text>
- <text v-else class="iconfont pitchOn"></text>
- </view>
- <view class="addressLi_r">
- <view class="user">
- <text class="name">{{i.name}}</text>
- <text>{{i.mobile}}</text>
- </view>
- <view class="address">{{i.address}}</view>
- </view>
- </view>
- <template v-slot:right>
- <view class="btns clearfix">
- <view class="btn edit"><text class="iconfont"></text></view>
- <view class="btn del"><text class="iconfont"></text></view>
- </view>
- </template>
- </uni-swipe-action-item>
- </uni-swipe-action>
- </view>
- </uni-popup>
- </template>
- <script>
- import { get, post, u_post } from "@/request/api.js";
- import AddressParse from './zh-address-parse.min.js'
- let app = getApp();
- var appEv = app.$vm.$options;
- export default {
- data() {
- return {
- userAddress: {
- real_name:"",
- phone:"",
- region:"",
- detail:"",
- }, //地址详情
- addressValue:"",
- is_default: 0, //是否设为默认地址
- range: [{"value": 0,"text": "否" },{"value": 1,"text": "是"}],
- addressList: [],
- }
- },
- components:{},
- created () {
- this.loadAddress();
- },
- methods: {
- identify(){
- const options = {
- type: 0, // 哪种方式解析,0:正则,1:树查找
- textFilter: [], // 预清洗的字段
- nameMaxLength: 4, // 查找最大的中文名字长度
- }
- // type参数0表示使用正则解析,1表示采用树查找, textFilter地址预清洗过滤字段。
- if(!!this.addressValue){
- const parseResult = AddressParse(this.addressValue, options)
- // console.log(parseResult);
- this.userAddress.real_name = parseResult.name;
- this.userAddress.phone = parseResult.phone;
- this.userAddress.detail = parseResult.detail;
- this.userAddress.region = parseResult.province + '/' + parseResult.city + '/' + parseResult.area;
- }
- },
- formSubmit(){
- post("user/addAddress",{
- address: this.userAddress.region + this.userAddress.detail,
- mobile: this.userAddress.phone,
- name: this.userAddress.real_name,
- is_default: this.is_default
- }).then(res => {
- if (res.code === 0) {
- appEv.errTips(res.msg);
- setTimeout(() => {
- // uni.navigateBack();
- this.$emit('addressConfirm');
- this.close();
- }, 1500);
- }
- })
- },
- // 获取用户地址
- loadAddress(){
- post("user/addressList").then(res => {
- if(res.code === 0){
- this.addressList = res.data.data;
- }
- })
- },
- onSelect(i,s){
- this.addressList.forEach(e => {
- e.status = "0";
- });
- this.addressList[s].status = "1";
- this.editAddress();
- },
- editAddress(){
- this.addressList.forEach((e,s) => {
- post("user/editAddress",{
- ...e, is_default: e.status
- }).then(res=>{
- if(this.addressList.length == s+1){
- this.$emit('addressConfirm');
- this.close();
- }
- })
- });
- },
- open() {
- this.$refs.popup.open('top')
- },
- close() {
- this.$refs.popup.close()
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- .container{
- background-color: #f5f5f5;
- height: 100vh;
- padding:30rpx 0;
- }
-
- .pad30 {
- padding: 0 30rpx
- }
-
- .p_center {
- text-align: center;
- }
-
- .acea-row {
- display: flex;
- }
- .row-middle {
- align-items: center
- }
- .row-between-wrapper {
- align-items: center;
- justify-content: space-between
- }
- .borderRadius15 {
- border-radius: 15rpx !important;
- }
- .fontcolor{
- color: var(--view-theme);
- }
- .addAddress .list {
- background-color: #fff;
- }
-
- .addAddress .list .item {
- padding: 30rpx;
- border-top: 1rpx solid #eee;
- position: relative;
- }
-
- .addAddress .list .item .detail{
- width: 368rpx;
- }
-
- .addAddress .list .item .location{
- position: absolute;
- right: 46rpx;
- top: 50%;
- margin-top: -40rpx!important;
- font-size: 24rpx;
- text-align: center;
- }
-
- .addAddress .list .item .icon-dizhi{
- font-size: 36rpx!important;
- }
-
- .addAddress .list .item .name {
- width: 195rpx;
- font-size: 30rpx;
- color: #333;
- }
-
- .addAddress .list .item .address {
- flex: 1;
- }
-
- .addAddress .list .item .address .addressCon{
- width: 360rpx;
- }
-
- .addAddress .list .item .address .addressCon .tip{
- font-size: 21rpx;
- margin-top: 4rpx;
- }
-
- .addAddress .list .item input {
- /* // width: 475rpx; */
- flex: 1;
- font-size: 30rpx;
- }
-
- .placeholder {
- color: #ccc;
- }
-
- .addAddress .list .item .picker {
- width: 430rpx;
- font-size: 30rpx;
- }
-
- .addAddress .list .item .iconfont {
- font-size: 30rpx;
- margin-top: 4rpx;
- }
-
- .addAddress .default {
- padding: 30rpx;
- /* height: 90rpx; */
- background-color: #fff;
- }
-
- .addAddress .default checkbox {
- margin-right: 15rpx;
- }
-
- .addAddress .keepBnt {
- width: 690rpx;
- height: 86rpx;
- border-radius: 50rpx;
- text-align: center;
- line-height: 86rpx;
- margin: 50rpx auto;
- font-size: 32rpx;
- color: #fff;
- }
-
-
- .mt-22{
- margin-top: 22rpx;
- }
- .bg-color {
- background-color: #dd524d;
- }
- .addbar{
- background: #fff;
- text-align: center;
- margin-bottom: 50rpx;
- padding: 36rpx 0;
- .iconfont{
- font-size: 46rpx;
- margin-right: 20rpx;
- }
- .sp{
- vertical-align: middle;
- }
- }
- .swipeAction{
- // padding: 20rpx 30rpx;
- font-size: 28rpx;
- .addressLi{
- .addressLi_l{
- width: 80rpx;
- height: 80rpx;
- display: flex;
- // justify-content: center;
- align-items: center;
- .iconfont{
- color: #666;
- font-size: 38rpx;
- }
- .pitchOn{
- color: #1989fa;
- }
- }
- .addressLi_r{
- width: calc(100% - 80rpx);
- }
- .addressLi_l,.addressLi_r{
- float: left;
- }
- .user{
- margin-bottom: 10rpx;
- }
- .name{
- // font-weight: bold;
- font-size: 32rpx;
- margin-right: 10rpx;
- }
- .address{
- font-size: 24rpx;
- color: #999;
- }
- }
- .swipeAction_item{
- background: #fff;
- margin-bottom: 20rpx;
- }
- .btns{
- .btn{
- float: left;
- display:flex;
- justify-content : center;
- align-items : center;
- height: 100%;
- padding: 0 30rpx;
- color: #fff;
- font-size: 36rpx;
-
- }
- .edit{
- background: rgba(25,137,250,0.5);
- }
- .del{
- background: rgba(238,10,36,0.5);
- }
- }
- }
- ::v-deep .uni-swipe_box{
- padding: 20rpx 30rpx;
- }
- </style>
|