基本功能都已完成
This commit is contained in:
@@ -1,226 +1,213 @@
|
||||
<template>
|
||||
<view class="padding page">
|
||||
<view class="padding bg-white radius">
|
||||
<view class="flex justify-between">
|
||||
<view>
|
||||
<view class="text-bold text-black">{{ areaData.name || '区域名称' }}</view>
|
||||
<view class="margin-top flex align-center">
|
||||
<text>颜色:</text>
|
||||
<view class="color-dot" :style="{ backgroundColor: areaData.color }"></view>
|
||||
<text class="margin-left-xs">{{ areaData.color }}</text>
|
||||
<!-- 区域列表 -->
|
||||
<view class="area-list" v-if="areaList.length > 0">
|
||||
<view class="padding bg-white radius margin-bottom" v-for="item in areaList" :key="item.id">
|
||||
<view class="flex justify-between">
|
||||
<view>
|
||||
<view class="text-bold text-black">{{ item.name || '区域名称' }}</view>
|
||||
<view class="margin-top flex align-center">
|
||||
<text>颜色:</text>
|
||||
<view class="color-dot" :style="{ backgroundColor: item.color }"></view>
|
||||
<text class="margin-left-xs">{{ item.color }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<button class="bg-blue cu-btn" @click="openEditPopup(item)">编辑</button>
|
||||
<button class="bg-red cu-btn margin-left" @click="handleDelete(item)">删除</button>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<button class="bg-blue cu-btn" @click="openEditPopup" >编辑</button>
|
||||
<button class="bg-red cu-btn margin-left">删除</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<button class="cuIcon-add bg-blue round margin-top-xl">新增公司区域</button>
|
||||
|
||||
<!-- 编辑区域弹出框 -->
|
||||
<u-popup :show="showEditPopup" mode="center" round="20" @close="showEditPopup = false">
|
||||
<view class="popup-content">
|
||||
<view class="popup-header">
|
||||
<view class="popup-title text-bold">编辑区域</view>
|
||||
<view class="popup-close" @click="showEditPopup = false">×</view>
|
||||
</view>
|
||||
<view class="popup-body">
|
||||
<!-- 区域名称 -->
|
||||
<view class="flex margin-bottom-sm">
|
||||
<view>区域名称</view>
|
||||
<view class="text-red">*</view>
|
||||
</view>
|
||||
<up-input v-model="formData.name" placeholder="请输入区域名称"></up-input>
|
||||
|
||||
<!-- 区域颜色 -->
|
||||
<view class="flex margin-bottom-sm margin-top">
|
||||
<view>区域颜色</view>
|
||||
<view class="text-red">*</view>
|
||||
</view>
|
||||
<view class="flex align-center">
|
||||
<up-input v-model="formData.color" placeholder="#ef4444" class="flex-sub"></up-input>
|
||||
<view class="color-preview" :style="{ backgroundColor: formData.color }"></view>
|
||||
</view>
|
||||
|
||||
<!-- 预设颜色 -->
|
||||
<view class="margin-top margin-bottom-sm text-gray">预设颜色</view>
|
||||
<view class="color-grid">
|
||||
<view
|
||||
v-for="(color, index) in presetColors"
|
||||
:key="index"
|
||||
class="color-item"
|
||||
:style="{ backgroundColor: color }"
|
||||
@click="selectColor(color)"
|
||||
></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="popup-footer">
|
||||
<button class="btn-cancel" @click="showEditPopup = false">取消</button>
|
||||
<button class="btn-confirm bg-blue" @click="handleEdit">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
<!-- 空状态 -->
|
||||
<view class="empty-state" v-else>
|
||||
<text class="text-gray">暂无区域数据</text>
|
||||
</view>
|
||||
|
||||
<!-- 新增按钮 -->
|
||||
<button class="add-btn cuIcon-add bg-blue round" @click="openAddPopup">新增公司区域</button>
|
||||
|
||||
<!-- 新增/编辑弹窗组件 -->
|
||||
<AreaFormPopup
|
||||
v-model:visible="showPopup"
|
||||
:isEdit="isEdit"
|
||||
:editData="editData"
|
||||
:loading="submitting"
|
||||
@submit="handleSubmit"
|
||||
@close="handlePopupClose"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import AreaFormPopup from '@/components/AreaFormPopup.vue';
|
||||
import {
|
||||
getAreaList,
|
||||
getAreaDetail,
|
||||
addArea,
|
||||
updateArea,
|
||||
deleteArea
|
||||
} from '@/request/three_one_api/area.js';
|
||||
|
||||
// 弹出框显示状态
|
||||
const showEditPopup = ref(false);
|
||||
// 区域列表
|
||||
const areaList = ref([]);
|
||||
|
||||
// 当前区域数据(用于列表显示)
|
||||
const areaData = reactive({
|
||||
name: '区域名称',
|
||||
color: '#ef4444'
|
||||
// 弹窗控制
|
||||
const showPopup = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentEditId = ref(null);
|
||||
const submitting = ref(false);
|
||||
|
||||
// 编辑时的数据
|
||||
const editData = ref({});
|
||||
|
||||
// 页面加载
|
||||
onMounted(() => {
|
||||
loadAreaList();
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
name: '',
|
||||
color: '#ef4444'
|
||||
});
|
||||
|
||||
// 预设颜色
|
||||
const presetColors = [
|
||||
'#2563eb', '#ef4444', '#10b981', '#f59e0b', '#6366f1', '#ec4899', '#06b6d4',
|
||||
'#84cc16', '#f97316', '#4f46e5', '#dc2626', '#f59e0b', '#d97706', '#8b5cf6',
|
||||
'#db2777'
|
||||
];
|
||||
|
||||
// 打开编辑弹出框
|
||||
const openEditPopup = () => {
|
||||
// 初始化表单数据为当前区域数据
|
||||
formData.name = areaData.name;
|
||||
formData.color = areaData.color;
|
||||
showEditPopup.value = true;
|
||||
// 加载区域列表
|
||||
const loadAreaList = async () => {
|
||||
try {
|
||||
const res = await getAreaList();
|
||||
if (res.code === 0) {
|
||||
areaList.value = res.data.records || [];
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取区域列表失败:', err);
|
||||
}
|
||||
};
|
||||
|
||||
// 选择预设颜色
|
||||
const selectColor = (color) => {
|
||||
formData.color = color;
|
||||
// 打开新增弹窗
|
||||
const openAddPopup = () => {
|
||||
isEdit.value = false;
|
||||
currentEditId.value = null;
|
||||
editData.value = {};
|
||||
showPopup.value = true;
|
||||
};
|
||||
|
||||
// 确定编辑
|
||||
const handleEdit = () => {
|
||||
if (!formData.name) {
|
||||
uni.showToast({ title: '请输入区域名称', icon: 'none' });
|
||||
return;
|
||||
// 打开编辑弹窗
|
||||
const openEditPopup = async (item) => {
|
||||
try {
|
||||
const res = await getAreaDetail({ id: item.id });
|
||||
if (res.code === 0) {
|
||||
isEdit.value = true;
|
||||
currentEditId.value = item.id;
|
||||
editData.value = {
|
||||
name: res.data.name || '',
|
||||
color: res.data.color || '#FF5733'
|
||||
};
|
||||
showPopup.value = true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取区域详情失败:', err);
|
||||
uni.showToast({ title: '获取详情失败', icon: 'none' });
|
||||
}
|
||||
if (!formData.color) {
|
||||
uni.showToast({ title: '请选择区域颜色', icon: 'none' });
|
||||
return;
|
||||
};
|
||||
|
||||
// 弹窗关闭
|
||||
const handlePopupClose = () => {
|
||||
isEdit.value = false;
|
||||
currentEditId.value = null;
|
||||
editData.value = {};
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
const handleSubmit = async (formData) => {
|
||||
submitting.value = true;
|
||||
|
||||
try {
|
||||
const submitData = {
|
||||
name: formData.name,
|
||||
color: formData.color
|
||||
};
|
||||
|
||||
let res;
|
||||
if (isEdit.value) {
|
||||
submitData.id = currentEditId.value;
|
||||
res = await updateArea(submitData);
|
||||
} else {
|
||||
res = await addArea(submitData);
|
||||
}
|
||||
|
||||
if (res.code === 0) {
|
||||
showPopup.value = false;
|
||||
uni.showToast({
|
||||
title: isEdit.value ? '修改成功' : '新增成功',
|
||||
icon: 'success'
|
||||
});
|
||||
loadAreaList();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('提交失败:', err);
|
||||
uni.showToast({ title: '操作失败', icon: 'none' });
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
|
||||
// 更新区域数据
|
||||
areaData.name = formData.name;
|
||||
areaData.color = formData.color;
|
||||
|
||||
showEditPopup.value = false;
|
||||
uni.showToast({
|
||||
title: '编辑成功',
|
||||
icon: 'success'
|
||||
};
|
||||
|
||||
// 删除区域
|
||||
const handleDelete = (item) => {
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该区域吗?',
|
||||
confirmColor: '#e54d42',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
const result = await deleteArea({ id: item.id });
|
||||
if (result.code === 0) {
|
||||
uni.showToast({ title: '删除成功', icon: 'success' });
|
||||
loadAreaList();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('删除失败:', err);
|
||||
uni.showToast({ title: '删除失败', icon: 'none' });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #EBF2FC;
|
||||
}
|
||||
|
||||
.popup-content {
|
||||
width: 600rpx;
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #EBF2FC;
|
||||
padding-bottom: 120rpx;
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
}
|
||||
// 区域列表
|
||||
.area-list {
|
||||
padding-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
font-size: 32rpx;
|
||||
}
|
||||
// 空状态
|
||||
.empty-state {
|
||||
padding: 200rpx 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.popup-close {
|
||||
font-size: 40rpx;
|
||||
color: #999;
|
||||
cursor: pointer;
|
||||
}
|
||||
// 新增按钮
|
||||
.add-btn {
|
||||
position: fixed;
|
||||
bottom: 40rpx;
|
||||
left: 30rpx;
|
||||
right: 30rpx;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
border-radius: 44rpx;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.popup-body {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.popup-footer {
|
||||
display: flex;
|
||||
padding: 20rpx 30rpx 30rpx;
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
font-size: 30rpx;
|
||||
margin: 0 10rpx;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.btn-confirm {
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
// 颜色预览
|
||||
.color-preview {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 8rpx;
|
||||
margin-left: 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// 预设颜色网格
|
||||
.color-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.color-item {
|
||||
width: 70rpx;
|
||||
height: 70rpx;
|
||||
border-radius: 12rpx;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
}
|
||||
|
||||
// 颜色圆点
|
||||
.color-dot {
|
||||
width: 30rpx;
|
||||
height: 30rpx;
|
||||
border-radius: 6rpx;
|
||||
flex-shrink: 0;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
</style>
|
||||
// 颜色圆点
|
||||
.color-dot {
|
||||
width: 30rpx;
|
||||
height: 30rpx;
|
||||
border-radius: 6rpx;
|
||||
flex-shrink: 0;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user