You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shop-app/pages/account/address/create.vue

135 lines
3.2 KiB

3 years ago
<!--
* @Author: ch
* @Date: 2022-03-22 14:12:18
* @LastEditors: ch
3 years ago
* @LastEditTime: 2022-04-29 23:09:52
3 years ago
* @Description: file content
-->
<template>
3 years ago
<view class="container">
<view class="form">
<UiCell class="form--item" title="收货人" :rightIcon="false">
<template slot="value">
3 years ago
<input class="form--itemInput" v-model="address.name" :maxlength="10" placeholder="请输入收货人姓名"/>
3 years ago
</template>
</UiCell>
<UiCell class="form--item" title="手机号码" :rightIcon="false">
<template slot="value">
3 years ago
<input class="form--itemInput" v-model="address.phone" placeholder="请输入收货手机号码"/>
3 years ago
</template>
</UiCell>
3 years ago
<BsSelectCity class="form--item form--city" v-model="city"></BsSelectCity>
3 years ago
<UiCell class="form--item form--item__last" title="详细地址" :rightIcon="false">
<template slot="value">
3 years ago
<input class="form--itemInput" v-model="address.detailAddress" placeholder="请输入详细地址"/>
3 years ago
</template>
</UiCell>
</view>
<UiCell class="form--item form--item__last" title="设为默认地址" >
<template slot="right-icon">
<u-switch v-model="isDefault" activeColor="#FF875B" inactiveColor="#F3F3F3" />
3 years ago
</template>
</UiCell>
3 years ago
<UiButton class="saveBtn" type="solid" size="max" @click="save"></UiButton>
3 years ago
</view>
3 years ago
</template>
<script>
3 years ago
import BsSelectCity from '../../../components/BsSelectCity.vue';
import UiButton from '../../../components/UiButton.vue';
import UiCell from '../../../components/UiCell.vue';
3 years ago
import {IsPhone} from '@/common/utils';
import {ApiPostAddress} from '@/common/api/base';
3 years ago
3 years ago
export default {
3 years ago
components: { UiCell, UiButton, BsSelectCity },
data (){
return {
address : {},
isDefault : false,
3 years ago
city : []
}
},
onShow(){
if(this.$Route.query.first === 'true'){
this.isDefault = true;
}
3 years ago
},
methods: {
async save(){
const $toast = uni.$u.toast;
if(!this.address.name){
$toast('请填写收货人姓名');
return false;
}
if(!this.address.phone || !IsPhone(this.address.phone)){
$toast('请填写正确的手机号');
return false;
}
if(!this.city.length){
$toast('请选择地区');
return false;
}
if(!this.address.detailAddress){
$toast('请填写详细地址');
return false;
}
const areaCode = this.city[2].code;
const area = this.city[2].name;
const city = this.city[1].name;
const cityCode = this.city[1].code;
const provinceCode = this.city[0].code;
const province = this.city[0].name;
const {error} = await ApiPostAddress({
3 years ago
...this.address,
isDefault : this.isDefault,
3 years ago
province,provinceCode,areaCode,area,city,cityCode
});
if(error){
$toast(error.message);
return false;
}
$toast('保存成功');
this.$Router.back();
}
}
3 years ago
};
3 years ago
</script>
3 years ago
<style lang="scss">
3 years ago
page {
background: $color-grey1;
3 years ago
}
3 years ago
</style>
<style lang="scss" scoped>
3 years ago
.form{
background: $color-grey0;
3 years ago
margin: 20rpx 0;
3 years ago
&--item{
padding: 0 40rpx;
&__last{
border: 0;
}
}
&--city{
padding:0 ;
}
&--itemInput{
flex: 1;
font-size: $font-size-base;
3 years ago
padding-left: 40rpx;
}
}
.saveBtn{
position: fixed;
bottom: 89rpx;
left: 30rpx;
width: 670rpx;
3 years ago
}
/deep/ {
.form--city .ui-cell{
3 years ago
padding: 0 40rpx;
}
}
3 years ago
</style>