功能完善

This commit is contained in:
2024-04-13 00:57:24 +08:00
parent 93e9c5227b
commit be328f9243
14 changed files with 244 additions and 107 deletions

View File

@@ -1,33 +1,34 @@
<template>
<view class='card-view'>
<view class='card-view' @click.stop='emits("onChecked",item)'>
<view class='c-flex-row'>
<text>默认</text>
<text class='status' v-if='item?.defaultstatus==1'>默认</text>
<text>
黄先生
<!-- {{ item.name }}-->
{{ item?.name }}
</text>
<text>
13xxxxxx8900
<!-- {{ item.mobile }}-->
{{ item?.mobile }}
</text>
</view>
<text class='address'>
湖南省 长沙市 雨花区 地址地址地址
{{ item.address }}
{{ item?.addr }}
</text>
<view class='btn-view c-flex-row'>
<text>编辑</text>
<text>删除</text>
<text @click.stop='emits("onEdit",item)'>编辑</text>
<text @click.stop='emits("onDelete",item)'>删除</text>
</view>
</view>
</template>
<script lang='ts' setup>
import { PropType } from 'vue';
defineProps({
item: <any>[]
item: Object as PropType<{ name: string, mobile: string, addr: string, defaultstatus: number }>
});
const emits = defineEmits(['onEdit', 'onDelete', 'onChecked']);
</script>
<style lang='scss' scoped>
@@ -36,7 +37,7 @@ defineProps({
padding: 38rpx 30rpx 30rpx 34rpx;
view:nth-of-type(1) {
text:nth-of-type(1) {
.status {
border-radius: 5rpx;
border: 1rpx solid #F32B2B;
color: #F32B2B;

View File

@@ -2,13 +2,13 @@
<view class='content'>
<view class='c-flex-row'>
<text>收货人</text>
<input placeholder='请输入收货人姓名' @input='bindConsignee' />
<input placeholder='请输入收货人姓名' v-model='params.name' @input='bindConsignee' />
</view>
<view class='divider' />
<view class='c-flex-row'>
<text>手机号</text>
<input placeholder='请输入收货人手机号' @input='bindMobile' :maxlength='11' />
<input placeholder='请输入收货人手机号' v-model='params.mobile' @input='bindMobile' :maxlength='11' />
</view>
<view class='divider' />
@@ -16,6 +16,7 @@
<text>详细地址</text>
<view class='c-flex-column'>
<textarea placeholder='详细地址:如街道、门牌\n号、楼栋号、单元室等'
v-model='params.addr'
@input='bindAddress' />
<view class='tips-view c-flex-row'>
<image :src='assetsUrl("ic_tips.png")' />
@@ -29,7 +30,7 @@
<text style='width: auto'>设为默认地址</text>
<text style='width: auto'>提醒每次下单会默认推荐使用该地址</text>
<!-- @change='ev=>{params.defaultstatus = ev.detail.value}'-->
<switch color='#F32B2B' @change='bindStatus' />
<switch color='#F32B2B' @change='bindStatus' :checked='params.defaultstatus == 1' />
</view>
<view class='bottom-button-view'>
@@ -41,15 +42,17 @@
<script lang='ts' setup>
import { assetsUrl } from '@/utils/assets';
import { addressCreate } from '@/api/user';
import { addressCreate, addressUpdate } from '@/api/user';
const params = ref<{
addrid: string,
name: string,
mobile: string,
zonecode: string,
addr: string,
defaultstatus: number
}>({
addrid: '',
name: '',
mobile: '',
zonecode: '',
@@ -57,6 +60,12 @@ const params = ref<{
defaultstatus: 0
});
onLoad(async (e: any) => {
// const result = await getAddressDetail(e.addrid);
params.value = JSON.parse(decodeURIComponent(e.bean));
console.log('----------->>>', params.value);
});
const bindConsignee = (e: any) => {
params.value.name = e.detail.value;
};
@@ -73,17 +82,25 @@ const bindStatus = (e: any) => {
params.value.defaultstatus = e.detail.value == true ? 1 : 0;
};
const save = () => {
addressCreate(
{
bean: params.value
}
).then(() => {
const save = async () => {
let result = false;
if(params.value.addrid) {
result = await addressUpdate(params.value);
} else {
result = await addressCreate(
params.value
);
}
if(result === true) {
uni.showToast({
title: '保存成功',
icon: 'none'
icon: 'none',
success(result) {
uni.navigateBack();
}
});
});
}
};
</script>

View File

@@ -1,7 +1,10 @@
<template>
<view class='content'>
<scroll-view :scroll-y='true'>
<item v-for='(item,index) in addressList' :key='index' :item='item' />
<item v-for='(item,index) in addressList' :key='index' :item='item'
@on-checked='onChecked(item)'
@on-edit='args => goPath(`create?bean=${encodeURIComponent(JSON.stringify(args))}`)'
@on-delete='args => {addressDelete(args?.addrid);fetchAddressList}' />
</scroll-view>
<view class='bottom-button-view'>
@@ -14,13 +17,17 @@
import Item from './components/item.vue';
import { goPath } from '@/utils';
import { getAddressList } from '@/api/user';
import { addressDelete, getAddressList } from '@/api/user';
import { useUserStore } from '@/store';
const userStore = useUserStore();
const addressList = ref<{
name: string,
mobile: string,
address: string,
status: number
addr: string,
status: number,
defaultstatus: number,
}[]>([]);
onLoad((e) => {
@@ -32,8 +39,12 @@ onShow(() => {
});
const fetchAddressList = async () => {
const { data } = await getAddressList();
addressList.value = data;
addressList.value = await getAddressList();
};
const onChecked = (e: any) => {
uni.navigateBack();
userStore.setDeliveryAddress(e);
};
</script>