|
|
@@ -1,9 +1,9 @@
|
|
|
<template>
|
|
|
<div class="quota-apply-container">
|
|
|
<div class="page-header">
|
|
|
- <el-button type="primary" link @click="handleBack"
|
|
|
- ><el-icon><ArrowLeft /></el-icon>返回</el-button
|
|
|
- >
|
|
|
+ <el-button type="primary" link @click="handleBack">
|
|
|
+ <el-icon><ArrowLeft /></el-icon>返回
|
|
|
+ </el-button>
|
|
|
<span class="page-title">额度申请</span>
|
|
|
</div>
|
|
|
|
|
|
@@ -36,15 +36,11 @@
|
|
|
</el-form-item>
|
|
|
</div>
|
|
|
|
|
|
- <el-form-item label="主要办公采购类目" prop="mainPurchase">
|
|
|
+ <!-- 核心修改区域:绑定逻辑保持不变 -->
|
|
|
+ <el-form-item label="主要办公采购类目" prop="mainPurchaseArr">
|
|
|
<div class="mainPurchase-tags">
|
|
|
- <div
|
|
|
- v-for="item in categoryList"
|
|
|
- :key="item.value"
|
|
|
- :class="['tag-item', { active: formData.mainPurchase === item.value }]"
|
|
|
- @click="formData.mainPurchase = item.value"
|
|
|
- >
|
|
|
- {{ item.label }}
|
|
|
+ <div v-for="item in categoryList" :key="item.id" :class="['tag-item', { active: isSelected(item.id) }]" @click="toggleSelect(item.id)">
|
|
|
+ {{ item.categoryName }}
|
|
|
</div>
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
@@ -71,27 +67,39 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive } from 'vue';
|
|
|
+import { ref, reactive, onMounted, getCurrentInstance } from 'vue';
|
|
|
import { useRouter } from 'vue-router';
|
|
|
import { ArrowLeft, Plus } from '@element-plus/icons-vue';
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
import { addCreditApply } from '@/api/pc/cost/creditApply';
|
|
|
+import { getProductCategoryList } from '@/api/home/index';
|
|
|
+import type { ComponentInternalInstance } from 'vue';
|
|
|
+
|
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
-const { purchase_item } = toRefs<any>(proxy?.useDict('purchase_item'));
|
|
|
const router = useRouter();
|
|
|
const formRef = ref();
|
|
|
|
|
|
+// 表单数据
|
|
|
const formData = reactive({
|
|
|
monthPurchase: '',
|
|
|
yearPurchase: '',
|
|
|
applyAmount: '',
|
|
|
amountPeriod: '',
|
|
|
- mainPurchase: '0',
|
|
|
+ mainPurchaseArr: [] as (string | number)[], // 明确类型
|
|
|
+ mainPurchase: '', // 最终提交的字符串
|
|
|
otherPurchase: '',
|
|
|
cooperationImage: ''
|
|
|
});
|
|
|
|
|
|
-const categoryList = computed(() => purchase_item.value || []);
|
|
|
+// 商品类别列表
|
|
|
+interface CategoryItem {
|
|
|
+ id?: number | string;
|
|
|
+ categoryName?: string;
|
|
|
+ [key: string]: any;
|
|
|
+}
|
|
|
+
|
|
|
+const categoryList = ref<CategoryItem[]>([]);
|
|
|
+
|
|
|
const rules = {
|
|
|
monthPurchase: [{ required: true, message: '请输入月度采购金额', trigger: 'blur' }],
|
|
|
applyAmount: [{ required: true, message: '请输入申请信用金额', trigger: 'blur' }]
|
|
|
@@ -101,9 +109,35 @@ const handleBack = () => {
|
|
|
router.back();
|
|
|
};
|
|
|
|
|
|
+// --- 核心逻辑:多选切换 ---
|
|
|
+const toggleSelect = (id: string | number) => {
|
|
|
+ // 统一转换为字符串进行比较,防止数字1和字符串"1"不匹配
|
|
|
+ const currentId = String(id);
|
|
|
+ const index = formData.mainPurchaseArr.findIndex((item) => String(item) === currentId);
|
|
|
+
|
|
|
+ if (index > -1) {
|
|
|
+ formData.mainPurchaseArr.splice(index, 1); // 取消选中
|
|
|
+ } else {
|
|
|
+ formData.mainPurchaseArr.push(currentId); // 选中
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const isSelected = (id: string | number) => {
|
|
|
+ return formData.mainPurchaseArr.includes(String(id));
|
|
|
+};
|
|
|
+// -------------------------
|
|
|
+
|
|
|
const handleSave = async () => {
|
|
|
const valid = await formRef.value?.validate();
|
|
|
if (!valid) return;
|
|
|
+ if (formData.mainPurchaseArr.length === 0) {
|
|
|
+ ElMessage.error('请选择主要办公采购类目');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将数组转换为逗号分隔的字符串
|
|
|
+ formData.mainPurchase = formData.mainPurchaseArr.join(',');
|
|
|
+
|
|
|
try {
|
|
|
await addCreditApply(formData);
|
|
|
ElMessage.success('保存成功');
|
|
|
@@ -112,6 +146,21 @@ const handleSave = async () => {
|
|
|
ElMessage.error('保存失败');
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+const loadCategoryList = async () => {
|
|
|
+ try {
|
|
|
+ const res = await getProductCategoryList({ datasource: 'A10', classLevel: 1 });
|
|
|
+ if (res.data) {
|
|
|
+ categoryList.value = res.data;
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取商品类别失败:', error);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ loadCategoryList();
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
@@ -157,27 +206,34 @@ const handleSave = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/* 标签选择器样式 - 核心修改 */
|
|
|
.mainPurchase-tags {
|
|
|
display: flex;
|
|
|
flex-wrap: wrap;
|
|
|
- gap: 10px;
|
|
|
+ gap: 12px; // 标签间距
|
|
|
+}
|
|
|
|
|
|
- .tag-item {
|
|
|
- padding: 6px 16px;
|
|
|
- border-radius: 4px;
|
|
|
- cursor: pointer;
|
|
|
- font-size: 13px;
|
|
|
- color: #666;
|
|
|
- background: #f5f5f5;
|
|
|
- transition: all 0.2s;
|
|
|
+.tag-item {
|
|
|
+ padding: 8px 20px;
|
|
|
+ border: 1px solid #dcdfe6;
|
|
|
+ border-radius: 4px;
|
|
|
+ cursor: pointer;
|
|
|
+ font-size: 14px;
|
|
|
+ color: #606266;
|
|
|
+ background-color: #f5f7fa;
|
|
|
+ transition: all 0.2s ease;
|
|
|
+ user-select: none; // 防止快速点击时文字被选中
|
|
|
|
|
|
- &:hover {
|
|
|
- color: #e60012;
|
|
|
- }
|
|
|
- &.active {
|
|
|
- background: #e60012;
|
|
|
- color: #fff;
|
|
|
- }
|
|
|
+ &:hover {
|
|
|
+ color: #e60012; // 鼠标悬停变绿
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 选中状态下的高亮样式 - 红色主题 */
|
|
|
+ &.active {
|
|
|
+ background-color: #e60012;
|
|
|
+ color: #ffffff;
|
|
|
+ border-color: #e60012;
|
|
|
+ box-shadow: 0 2px 0 rgba(230, 0, 18, 0.2);
|
|
|
}
|
|
|
}
|
|
|
|