Files
video_mini/pagesA/integral/newaddress.vue
T
2025-08-25 11:20:35 +08:00

253 lines
5.8 KiB
Vue

<template>
<view class="pagesContent">
<view class="message_select box ">
<view class="boxitem">
<view class="ft14 ftw5000 cl-333">收货人</view>
<input class="uni-input" style="width: 440rpx;" v-model="data.accept_name" placeholder="请输入收货人姓名" />
</view>
<view class="boxitem">
<view class="ft14 ftw5000 cl-333">手机号</view>
<input class="uni-input" style="width: 440rpx;" type="number" maxlength="11" v-model="data.accept_mobile" placeholder="请输入手机号码" />
</view>
<view class="boxitem">
<view class="ft14 ftw5000 cl-333">所在地区</view>
<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
<view class="flex alcenter" style="width: 440rpx; justify-content: space-between;color: grey;">
<text v-if="data.accept_province==''">请选择省、市、区</text>
<text v-else
style="color: #191919; line-height: 30rpx;">{{data.accept_province}},{{data.accept_city}},{{data.accept_exp_area}}</text>
<uni-icons class="backIcon" type="right" size="18" color="#333333"></uni-icons>
</view>
</pick-regions>
</view>
<view class="boxitem">
<view class="ft14 ftw5000 cl-333">详细地址</view>
<input class="uni-input" style="width: 440rpx;" v-model="data.accept_address" placeholder="请输入详细地址" />
</view>
<view class="boxitem">
<view class="ft14 ftw5000 cl-333">设置默认地址</view>
<switch :checked="checkeddata" @change="switch1Change" />
</view>
</view>
<view class="bottom_button " v-if="type == 1">
<view class="practices button" @click="baocun">保存</view>
</view>
<view class="bottom_button" v-else>
<view class="baocun1 button" @click="shanchu">删除</view>
<view class="baocun2 button" @click="xiugai">修改</view>
</view>
</view>
</template>
<script>
import pickRegions from '@/pagesA/components/pick-regions/pick-regions.vue'
export default {
components: {
pickRegions
},
data() {
return {
data: {
accept_name: "",
accept_mobile: "",
accept_province: "",
accept_city: "",
accept_exp_area: "",
accept_address: "",
is_default: 0,
},
defaultRegionCode: '100000',
type: 1,
ids: "",
checkeddata: true
}
},
onLoad(e) {
let data = JSON.parse(e.data)
if (data.is_default == 1) {
this.checkeddata = true
} else {
this.checkeddata = false
}
if (e.type == 1) {
this.type == 1
uni.setNavigationBarTitle({
title: "新增地址"
})
} else {
this.type = 2
uni.setNavigationBarTitle({
title: "修改地址"
})
this.ids = data.id
this.data.accept_name = data.accept_name
this.data.accept_mobile = data.accept_mobile
this.data.accept_province = data.accept_province
this.data.accept_city = data.accept_city
this.data.accept_exp_area = data.accept_exp_area
this.data.accept_address = data.accept_address
this.data.is_default = data.is_default
}
},
methods: {
switch1Change(e) {
if (e.detail.value) {
this.data.is_default = 1
this.checkeddata = e.detail.value
} else {
this.data.is_default = 0
this.checkeddata = e.detail.value
}
},
// 获取选择的地区
handleGetRegion(region) {
this.data.accept_province = region[0].name
this.data.accept_city = region[1].name
this.data.accept_exp_area = region[2].name
},
baocun() {
this.$httpRequest({
url: '/api/delivery/address/add',
data: this.data,
methods: "POST",
}).then(res => {
if (res.code == 1) {
uni.showToast({
title: "创建成功",
icon: 'none',
duration: 1500
})
uni.navigateBack(1);
}
}).catch(err => {
console.log('bind user err');
console.log(err);
})
},
shanchu() {
this.$httpRequest({
url: '/api/delivery/address/del',
data: {
id: this.ids
},
methods: "POST",
}).then(res => {
if (res.code == 1) {
uni.showToast({
title: "删除成功",
icon: 'none',
duration: 1500
})
uni.navigateBack(1)
}
}).catch(err => {
console.log('bind user err');
console.log(err);
})
},
xiugai() {
this.data.id = this.ids
this.$httpRequest({
url: '/api/delivery/address/edit',
data: this.data,
methods: "POST",
}).then(res => {
if (res.code == 1) {
uni.showToast({
title: "修改成功",
icon: 'none',
duration: 1500
})
}
}).catch(err => {
console.log('bind user err');
console.log(err);
})
}
}
}
</script>
<style scoped>
.pagesContent {}
.message_select {
margin: 25rpx;
width: 700rpx;
}
.boxitem {
display: flex;
height: 120rpx;
line-height: 120rpx;
justify-content: space-between;
align-items: center;
padding: 0 30rpx;
border-bottom: 2rpx solid #F7F8F9;
}
.bottom_button {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 160rpx;
z-index: 1;
background: #ffffff;
display: flex;
justify-content: space-between;
}
.practices {
height: 80rpx;
width: 100%;
border-radius: 40rpx;
background: linear-gradient(123deg, #00E075 0%, #09D89E 100%);
text-align: center;
line-height: 80rpx;
margin: 14rpx 80rpx 0 80rpx;
font-weight: 500;
font-size: 32rpx;
color: #FFFFFF;
}
.baocun1 {
height: 80rpx;
width: 45%;
border-radius: 40rpx;
border: 2rpx solid #D8D8D8;
text-align: center;
line-height: 80rpx;
margin: 14rpx 40rpx 0 40rpx;
font-weight: 500;
font-size: 32rpx;
color: #000000;
}
.baocun2 {
height: 80rpx;
width: 45%;
border-radius: 40rpx;
background: linear-gradient(123deg, #00E075 0%, #09D89E 100%);
text-align: center;
line-height: 80rpx;
margin: 14rpx 40rpx 0 40rpx;
font-weight: 500;
font-size: 32rpx;
color: #FFFFFF;
}
</style>