Files
CompanyProject/金壶/appV1/pages/my/user-path-edit.vue
2024-09-27 01:32:49 +08:00

357 lines
9.0 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<!-- 修改地址 -->
<view class="content w-100 h-100">
<HeaderTop page_title='修改地址'></HeaderTop>
<view class="p-2 border-bottom d-flex a-center bg-white">
<view class="font-md text-secondary mr-1 flex-shrink text-dark">
收货人</view>
<input class="px-1 font-md flex-1" type="text" v-model="form.consignee" />
</view>
<view class="p-2 d-flex a-center bg-white border-bottom">
<view class="font-md text-secondary mr-1 flex-shrink text-dark ">
手机号码</view>
<input class="px-1 font-md flex-1" type="number" v-model="form.tel" />
</view>
<view class="p-2 d-flex a-center bg-white border-bottom" @click="chooseAera()">
<view class="font-md text-secondary mr-1 flex-shrink text-dark">
请选择{{all_area}}</view>
</view>
<!-- <view class="p-2 border-bottom d-flex a-center bg-white">
<view class="font-md text-secondary mr-1 flex-shrink text-dark">
所在地区</view>
<input class="px-1 font-md flex-1" type="text" disabled
@click="showMulLinkageThreePicker" placeholder="请选择所在地区"
:value="form.path"/>
<mpvue-city-picker :themeColor="themeColor" ref="mpvueCityPicker" :pickerValueDefault="pickerValue" @onConfirm="onConfirm"></mpvue-city-picker>
</view> -->
<view class="p-2 d-flex a-center bg-white border-bottom">
<view class="font-md text-secondary mr-1 flex-shrink text-dark">
详细地址</view>
<input class="px-1 font-md flex-1" type="text" v-model="form.address" />
</view>
<view class="p-2 d-flex a-center bg-white">
<view class="font-md text-secondary mr-1 flex-shrink text-dark">
设为默认地址</view>
<switch class="ml-auto" @change="switch2Change" :checked="is_checked" />
</view>
<text class="pt-0 p-2 d-flex a-center bg-white text-danger">
每次下单默认推荐使用该地址</text>
<view class="x_public_box x-text-white x-bg-159 margin-shu20 editBtn w-90" style="line-height: 80upx;" @click="submit()">确认</view>
<!-- <view class="x_public_box x-text-white x-bg-159 margin-shu20" style="line-height: 80upx;" @click="del_address()">删除地址</view> -->
<!-- <view class="p-3">
<view class="text-center w-100 bg-danger text-white font-md rounded py-2" hover-class="main-bg-hover-color" @click="submit">
确认
</view>
<view class="text-center w-100 bg-danger text-white font-md rounded py-2 margin-shu20" hover-class="main-bg-hover-color" @click="del_address()">
删除地址
</view>
</view> -->
<!-- 选择地区遮挡层 -->
<view class="region w-100 h-100 " v-if='show_Aera==true'>
<view class="region_box w-100 padding-30">
<view class="d-flex j-sb region_top">
<view @click="cancel()">取消</view>
<view @click="sure()">确定</view>
</view>
<view class="region_list d-flex j-sb">
<view class="region_item">
<view v-for='(item,index) of sheng' :key='index' @click="choose_sheng(index)" :class="{active:sheng_index==index}">{{item.area_name}}</view>
</view>
<view class="region_item">
<view v-for='(item,index) of shi_arr' :key='index' @click="choose_shi(index)" :class="{active:shi_index==index}">{{item.area_name}}</view>
</view>
<view class="region_item">
<view v-for='(item,index) of qu_arr' :key='index' @click="choose_qu(index)" :class="{active:qu_index==index}">{{item.area_name}}</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import {
mapActions
} from "vuex"
import verification from '../../common/verification.js' //正则验证
import shippingAddress from '../../utils/models/shop.js'
export default {
data() {
return {
all_area:'',
sheng: [],
shi: [],
shi_arr:[],
qu: [],
qu_arr:[],
sheng_index :0,
shi_index:0,
qu_index:0,
is_show:false,
is_checked:false,
// 测试修改id,区县id
addAddress_id: '', //新增时传入默认地址
address_item: '', // 传参地址对象
area_id: 2,
xian_id:'',
isedit: true,
themeColor: '#007AFF',
pickerValue: [0, 0, 1],
index: -1,
show_Aera: false,
form: ''
}
},
onLoad(option) {
this.form = option.address_item
if(JSON.parse(option.address_item).is_default!=0){
this.is_checked = true
}else{
this.is_checked = false
}
if(this.form==''){
}else{
this.form = JSON.parse(this.form)
this.all_area = this.form.area_name
this.id = this.form.id
}
},
// 监听返回
onBackPress() {
},
mounted() {
},
methods: {
...mapActions(['updatePathAction', 'createPathAction']),
// 是否选择默认
switch2Change(e){
this.is_checked = e.target.value
},
// 删除地址
async del_address(){
let res = await shippingAddress.deleteAddress(this.form.id);
this.handleError(res, res => {
})
uni.showToast({
title: res.message,
duration: 2000,
icon: 'none'
});
setTimeout(function() {
uni.redirectTo({
url:'./user-path-list'
})
}, 1000);
},
// id_moren
id_moren(){
this.is_show = !this.is_show
},
// 选择县、区
choose_qu(index){
this.qu_index = index
this.xian_id = this.qu_arr[index].id
},
// 选择市
choose_shi(index){
this.shi_index = index
this.qu_arr = [];
this.qu.forEach(item=>{
if(this.shi_arr[this.shi_index].id == item.parent_area_id){
this.qu_arr.push(item)
}
})
},
// 选择省
choose_sheng(index){
this.sheng_index = index
this.shi_arr = [];
this.shi.forEach(item=>{
if(item.parent_area_id == this.sheng[index].id){
this.shi_arr.push(item)
// console.log(this.shi_arr,'shi')
}
})
},
//选择地区
chooseAera() {
this.show_Aera = !this.show_Aera
this.chooseAeraList()
},
sure(){
this.show_Aera = false
if(this.sheng[this.sheng_index].area_name=='' || this.shi_arr[this.shi_index].area_name=='' || this.qu_arr[this.qu_index].area_name==''){
uni.showToast({
title: '请选择所在地区',
duration: 2000,
icon: 'none'
});
}else{
this.all_area = this.sheng[this.sheng_index].area_name + '-' +this.shi_arr[this.shi_index].area_name + '-' + this.qu_arr[this.qu_index].area_name
}
},
// 取消
cancel(){
this.show_Aera = false
},
//地区列表
async chooseAeraList() {
let res = await shippingAddress.shippingAddress();
this.handleError(res, res => {
for (let i in res.data) {
var item = res.data[i]
if (item.id && !item.parent_area_id && !item.grand_pa_id) {
this.sheng.push(item)
}
if (item.id && item.parent_area_id && !item.grand_pa_id) {
this.shi.push(item)
}
if (item.id && item.parent_area_id && item.grand_pa_id) {
this.qu.push(item)
}
}
})
},
// defaultAddress 是否设置成默认地址
async is_defaultAddress(){
let res = await shippingAddress.defaultAddress(this.is_id)
this.handleError(res, res => {
})
},
// 增加地址数据
async submit() {
verification.isPhone(this.form.tel); // 手机号格式验证
if (verification.isPhone.prototype.the_isPhone !== true) {
uni.showToast({
title: '请输入正确的手机号',
duration: 2000,
icon: 'none'
});
return
}
let res = await shippingAddress.makeChangeAddress(
this.form.area_id, //区县id
this.form.address,
this.form.id, //id地址id
this.form.consignee,
this.form.tel
);
this.is_id = res.data.data.id
if(this.is_checked==true){
this.is_defaultAddress()
}
setTimeout(function() {
uni.redirectTo({
url:'./user-path-list'
})
// uni.navigateTo({
// url:'./user-path-list'
// })
}, 500);
this.handleError(res, res => {
this.addAddress_id = res.data.data.id
})
},
// 三级联动确定
onConfirm(e) {
this.form.path = e.label
this.pickerValue = e.value
},
// 显示三级联动选择
showMulLinkageThreePicker() {
this.$refs.mpvueCityPicker.show()
},
}
}
</script>
<style lang="scss">
page {
background: #F7F7F7;
}
.content {
.header {
height: 148upx;
font-size: 32upx;
position: relative;
line-height: 194upx;
.edit_shoppingCar {
position: absolute;
bottom: -48upx;
right: 31upx;
}
}
.region {
overflow: hidden;
position: absolute;
left: 0%;
top: 0%;
background-color: rgba(0, 0, 0, 0.2);
.region_box {
position: fixed;
bottom: 0;
left: 0;
background-color: #FFFFFF;
height: 600upx;
.region_top {
line-height: 70upx;
height: 70upx;
}
.region_list {
line-height: 90upx;
height: calc(100% - 70upx);
overflow-y: auto;
.region_item {
height: 100%;
overflow-y: auto;
color: #b2b2b2;
width: 33.3%;
text-align: center;
.active{
color:#6E67FF;
font-weight: bold;
}
}
}
}
}
.editBtn{
position: absolute;
bottom:100upx;
left: 34upx;
}
}
</style>