123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- <template>
- <view class="content">
- <view class="inner">
- <view class="form-box">
- <view class="form-item">
- <text class="label">收货人</text>
- <input type="text" v-model="form.realName" maxlength="10" placeholder="请输入姓名" class="form-input" />
- </view>
- <view class="form-item">
- <text class="label">手机号</text>
- <input type="number" v-model="form.phone" maxlength="11" placeholder="请输入手机号" class="form-input" />
- </view>
- <view class="form-item">
- <text class="label">所在地区</text>
- <picker :value="multiIndex" class="birth-picker" mode="multiSelector" range-key="n" :range="addressList" @change="pickerChange" @columnchange="pickerColumnchange">
- <view class="right-box">
- <view class="input-box">
- <input type="text" v-model="form.address" placeholder="请选择省市区" class="form-input" disabled="disabled" />
- </view>
- <image class="arrow" src="../../static/images/arrow_gray.png" mode=""></image>
- </view>
- </picker>
- </view>
- <view class="form-item">
- <text class="label">详细地址</text>
- <input type="text" v-model="form.detail" placeholder="请输入详细地址" class="form-input" />
- </view>
- </view>
- <view class="address-box">
- <textarea class="textarea" v-model="content" placeholder="请粘贴或输入文本,点击'识别'自动识别姓名、电话、地址,格式:深圳市龙岗区坂田街道长坑路西2巷2号202 黄大大 18888888888" />
- <view class="btns" >
- <view class="btn parse" @click="parseAddress()">识别</view>
- </view>
- </view>
- <!-- 设为默认地址 -->
- <view class="setting-box">
- <text class="label">设为默认地址</text>
- <u-switch v-model="isDefault" activeColor="#C39A58" ></u-switch>
- </view>
- </view>
- <view class="btn-box">
- <view class="sub-btn" @click="submit()">保存地址</view>
- </view>
- </view>
- </template>
- <script>
- import {getCitys} from '@/api/common.js'
- import {parseAddress,getAddressById,addAddress,editAddress} from '@/api/userAddress.js'
- export default {
- components: {
- },
- data() {
- return {
- content:null,
- type:null,
- addressId:null,
- isDefault: false,
- addressList:[[],[],[]],
- multiIndex:[0,0,0],
- address:[],
- form: {
- realName:null,
- phone:null,
- detail:null,
- address: null,
- isDefault: 0,
- }
- }
- },
- onLoad(option) {
- this.type=option.type;
- if(this.type=='edit'){
- uni.setNavigationBarTitle({
- title:"修改收货地址"
- })
- this.addressId=option.addressId;
- this.getAddressById();
- }
- else{
- uni.setNavigationBarTitle({
- title:"新增收货地址"
- })
- }
- this.getCitys()
- },
- methods: {
- parseAddress(){
- if(this.content==null||this.content==""){
- uni.showToast({
- icon:'none',
- title: '请输入地址信息',
- });
- return;
- }
- var data={content:this.content};
- parseAddress(data).then(
- res => {
- if(res.code==200){
- this.form.realName=res.data.name
- this.form.phone=res.data.mobile
- this.form.address=res.data.provinceName+res.data.cityName+res.data.expAreaName
- this.form.province=res.data.provinceName
- this.form.city=res.data.cityName
- this.form.district=res.data.expAreaName
- this.form.detail=res.data.streetName+res.data.address
- this.form.detail=this.form.detail.replace(/\s+/g,"");
- }else{
- uni.showToast({
- icon:'none',
- title: res.msg,
- });
- }
- },
- rej => {}
- );
- },
- getAddressById(){
- var data={addressId:this.addressId};
- getAddressById(data).then(
- res => {
- if(res.code==200){
- this.form=res.data;
- this.isDefault=this.form.isDefault==1?true:false;
- this.form.address=this.form.province+this.form.city+this.form.district
- }else{
- uni.showToast({
- icon:'none',
- title: res.msg,
- });
- }
- },
- rej => {}
- );
- },
- submit(){
- if(this.type=="add"){
- this.addAddress()
- }
- else if(this.type=="edit"){
- this.editAddress()
- }
-
- },
- editAddress(){
- this.form.isDefault=this.isDefault?1:0
- editAddress(this.form).then(
- res => {
- if(res.code==200){
- uni.showToast({
- icon:'success',
- title: "操作成功",
- });
- setTimeout(function() {
- uni.$emit('refreshAddress');
- uni.navigateBack({
- delta: 1
- })
- }, 500);
- }else{
- uni.showToast({
- icon:'none',
- title: res.msg,
- });
- }
- },
- rej => {}
- );
- },
- addAddress(){
- this.form.isDefault=this.isDefault?1:0
- addAddress(this.form).then(
- res => {
- if(res.code==200){
- uni.showToast({
- icon:'success',
- title: "操作成功",
- });
- setTimeout(function() {
- uni.$emit('refreshAddress');
- uni.navigateBack({
- delta: 1
- })
- }, 500);
- }else{
- uni.showToast({
- icon:'none',
- title: res.msg,
- });
- }
- },
- rej => {}
- );
- },
- // 地区选择
- pickerChange(e) {
- this.multiIndex = e.detail.value;
- // 数组内的下标
- // 获取一级类目
- // 获取二级类目
- // 获取三级类目
- this.form.address=this.addressList[0][this.multiIndex[0]].n+this.addressList[1][this.multiIndex[1]].n+this.addressList[2][this.multiIndex[2]].n
- this.form.province=this.addressList[0][this.multiIndex[0]].n
- this.form.city=this.addressList[1][this.multiIndex[1]].n
- this.form.district=this.addressList[2][this.multiIndex[2]].n
- this.form.cityId=this.addressList[1][this.multiIndex[1]].v;
- },
- pickerColumnchange(e){
- // 第一列滑动
- if(e.detail.column === 0){
- this.multiIndex[0] = e.detail.value
- // console.log('第一列滑动');
- this.addressList[1] = this.address[this.multiIndex[0]].c;
- this.addressList[2] = this.address[this.multiIndex[0]].c[0].c
- // 第一列滑动 第二列 和第三列 都变为第一个
- this.multiIndex.splice(1, 1, 0)
- this.multiIndex.splice(2, 1, 0)
- }
- // 第二列滑动
- if(e.detail.column === 1){
- this.multiIndex[1] = e.detail.value
- // console.log('第二列滑动');
- // console.log(this.multiIndex)
- this.addressList[2] = this.address[this.multiIndex[0]].c[this.multiIndex[1]].c
- // 第二列 滑动 第三列 变成第一个
- this.multiIndex.splice(2, 1, 0)
- }
- // 第三列滑动
- if(e.detail.column === 2){
- this.multiIndex[2] = e.detail.value
- }
- },
- getCitys(){
- getCitys().then(
- res => {
- if(res.code==200){
- this.address=res.data
- for(var i=0; i<this.address.length; i++){
- this.addressList[0].push(this.address[i])
- }
- for(var i=0; i<this.address[0].c.length; i++){
- this.addressList[1].push(this.address[0].c[i])
- }
- for(var i=0; i<this.address[0].c[0].c.length; i++){
- this.addressList[2].push(this.address[0].c[0].c[i])
- }
- }else{
- uni.showToast({
- icon:'none',
- title: "请求失败",
- });
- }
- },
- rej => {}
- );
- }
- }
- }
- </script>
- <style lang="scss">
- page{
- height: 100%;
- }
- .content{
- height: 100%;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
-
- .inner{
- height: calc(100% - 120upx);
- padding: 20upx;
- .address-box{
- margin-top: 20rpx;
- padding: 30upx;
- background: #FFFFFF;
- border-radius: 16upx;
- margin-bottom: 20upx;
- position: relative;
- .textarea{
- width: 100%;
- height: 200upx;
- font-size: 30upx;
- color: #999999;
- padding-bottom:100rpx;
- }
- .btns{
- right:10rpx;
- bottom:10rpx;
- position: absolute;
- .btn{
- width: 155upx;
- height: 64upx;
- line-height: 64upx;
- font-size: 26upx;
- font-family: PingFang SC;
- font-weight: 500;
- text-align: center;
- border-radius: 32upx;
- &.parse{
- background: #C39A58;
- color: #FFFFFF;
- }
- }
- }
- }
- .form-box{
- padding: 0 30upx;
- background: #FFFFFF;
- border-radius: 16upx;
- .form-item{
- height: 103upx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- border-bottom: 1px solid #F1F1F1;
- &:last-child{
- border-bottom: none;
- }
- .label{
- min-width: 200upx;
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #222222;
- }
- .input-width{
- width: calc(100% - 200upx);
- text-align: right;
- }
- .form-input{
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #999999;
- text-align: right;
- }
- .birth-picker {
- display: flex;
- align-items: center;
- .right-box{
- width: 100%;
- display: flex;
- align-items: center;
- .arrow{
- width: 13upx;
- height: 23upx;
- margin-left: 15upx;
- }
- }
- }
- }
- }
- .setting-box{
- height: 88upx;
- background: #FFFFFF;
- border-radius: 16upx;
- margin-top: 20upx;
- padding: 0 30upx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .label{
- font-size: 28upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #111111;
- }
- }
- }
- .btn-box{
- height: 120upx;
- padding: 0 30upx;
- display: flex;
- align-items: center;
- justify-content: center;
- background: #FFFFFF;
- .sub-btn{
- width: 100%;
- height: 88upx;
- line-height: 88upx;
- text-align: center;
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #FFFFFF;
- background: #C39A58;
- border-radius: 44upx;
- }
- }
- }
- </style>
|