first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1,312 @@
<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 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" />
</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="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: '',
xian_id: '',
is_id: '',
isedit: true,
themeColor: '#007AFF',
pickerValue: [0, 0, 1],
index: -1,
show_Aera: false,
form: {
address: '',
id: '',
consignee: '',
tel: '',
}
}
},
onLoad(option) {
},
mounted() {
},
methods: {
// 是否选择默认
switch2Change(e) {
this.is_checked = e.target.value
},
// 选择县、区
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)
}
})
},
//选择地区
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: '请选择所在地区'
});
} else {
this.area_id = this.qu_arr[this.qu_index].id
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)
}
}
})
},
// 提交
// 增加地址数据
async submit() {
if(this.form.tel=='' || this.form.consignee=='' || this.all_area=='' || this.form.address==''){
uni.showToast({
title: '请完善信息',
duration: 2000,
icon: 'none'
});
return
}
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.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()
}
this.handleError(res, res => {
uni.showToast({
title: res.message,
duration: 2000,
icon: 'none'
});
setTimeout(function() {
uni.redirectTo({
url: './user-path-list'
})
}, 500);
})
},
// defaultAddress
async is_defaultAddress() {
let res = await shippingAddress.defaultAddress(this.is_id)
this.handleError(res, res => {
})
}
}
}
</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;
}
}
.editBtn {
position: absolute;
bottom: 100upx;
left: 34upx;
}
.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;
}
}
}
}
}
}
</style>