-
-
+
+
-
@@ -565,7 +563,7 @@ export default {
editFieldLabel: "",
editRow: null,
activeTab: "base",
- skuType: "single",
+ skuType: 1,
skuList: [{ name: "", value: "" }],
specList: [{ name: "", values: [""] }],
skuTable: [],
@@ -605,12 +603,16 @@ export default {
status: null,
tags: null,
cateId: null,
- skuType: null,
- sku: null,
+ skuType: 1,
+ sku: "{}",
+ skuName: null,
+ skuValue: null,
contetnt: null,
createdAt: null,
updatedAt: null,
};
+ // 重置skuType为默认值
+ this.skuType = 1;
this.resetForm("form");
},
/** 搜索按钮操作 */
@@ -682,24 +684,60 @@ export default {
const id = row.id || this.ids;
getIntegralProduct(id).then((response) => {
this.form = response.data;
+ // 设置skuType,如果没有则默认为1
+ this.skuType = this.form.skuType || 1;
+ // 如果是单规格且sku有数据,尝试解析
+ if (this.skuType === 1 && this.form.sku && this.form.sku !== '{}') {
+ try {
+ const skuData = JSON.parse(this.form.sku);
+ if (skuData.name && skuData.value) {
+ this.form.skuName = skuData.name;
+ this.form.skuValue = skuData.value;
+ }
+ } catch (e) {
+ console.warn('解析单规格数据失败:', e);
+ }
+ }
this.open = true;
this.title = "修改积分商品";
});
},
/** 提交按钮 */
submitForm() {
-
-
- if(this.$refs.skuRef){
-
- if(this.$refs.skuRef.submit()){
- this.form.sku=this.$refs.skuRef.submit();
- }else{
- return
+ // 设置规格类型
+ this.form.skuType = this.skuType;
+
+ // 处理规格信息
+ if (this.skuType === 2) {
+ // 多规格模式
+ if (this.$refs.skuRef && this.$refs.skuRef.submit) {
+ const skuData = this.$refs.skuRef.submit();
+ if (!skuData) {
+ this.$modal.msgError("请完善规格信息");
+ return;
+ }
+ this.form.sku = typeof skuData === 'string' ? skuData : JSON.stringify(skuData);
+ } else {
+ this.$modal.msgError("规格信息不能为空");
+ return;
}
+ } else {
+ // 单规格模式
+ if (!this.form.skuName || !this.form.skuValue) {
+ this.$modal.msgError("请完善单规格信息");
+ return;
+ }
+ const singleSku = {
+ name: this.form.skuName,
+ value: this.form.skuValue
+ };
+ this.form.sku = JSON.stringify(singleSku);
+ }
- }else{
- this.form.sku='{}';
+ // 验证sku不能为空
+ if (!this.form.sku || this.form.sku === '{}') {
+ this.$modal.msgError("规格信息不能为空");
+ return;
}
this.$refs["form"].validate((valid) => {
diff --git a/ruoyi-ui/src/views/system/ServiceGoods/index.vue b/ruoyi-ui/src/views/system/ServiceGoods/index.vue
index 919bbd9..b28f995 100644
--- a/ruoyi-ui/src/views/system/ServiceGoods/index.vue
+++ b/ruoyi-ui/src/views/system/ServiceGoods/index.vue
@@ -134,8 +134,8 @@
-
{{ scope.row.stock }}
-
+
{{ scope.row.stock }}
+
@@ -156,6 +156,12 @@
+
+
+ {{ formatBasicNames(scope.row.basic) }}
+
+
+
-
-
+
+
+ 暂无技能数据,请检查接口是否正常
+
+
+
+ 已选择 {{ form.skillIdsArray.length }} 项技能:{{ getSelectedSkillNames() }}
+
-
+
+
+
+ {{ item }}
+
+
+
+
+
+ 添加
+
+
+
+
@@ -387,7 +437,9 @@ export default {
serviceCateList: [],
siteSkillList : [],
-
+
+ // 基检现象选项
+ basicOptions: [],
total: 0,
// 服务内容表格数据
@@ -422,11 +474,18 @@ export default {
{ required: true, message: "副标题不能为空", trigger: "blur" }
],
price: [
- { required: true, message: "价格不能为空", trigger: "blur" }
+ { required: true, message: "价格不能为空", trigger: "blur" },
+ { pattern: /^(0|[1-9]\d*)(\.\d{1,2})?$/, message: "请输入正确的价格格式", trigger: "blur" }
],
sales: [
{ required: true, message: "销量不能为空", trigger: "blur" }
],
+ sort: [
+ { required: true, message: "排序不能为空", trigger: "blur" }
+ ],
+ cateId: [
+ { required: true, message: "请选择分类", trigger: "change" }
+ ],
status: [
{ required: true, message: "状态不能为空", trigger: "change" }
],
@@ -444,6 +503,10 @@ export default {
skuList: [ { name: '', value: '' } ],
specList: [ { name: '', values: [''] } ],
skuTable: [],
+
+ // 基检现象标签相关
+ showBasicInput: false,
+ newBasicTag: '',
}
},
created() {
@@ -451,6 +514,34 @@ export default {
this.getserviceCateList();
this.getSiteSkillList();
this.testSkillList();
+ this.testJsonConversion(); // 测试JSON转换功能
+ },
+ watch: {
+ // 监听技能数组变化,确保UI同步
+ 'form.skillIdsArray': {
+ handler(newVal, oldVal) {
+ console.log('技能数组变化监听:', '旧值:', oldVal, '新值:', newVal);
+ // 确保是数组格式
+ if (newVal && !Array.isArray(newVal)) {
+ console.warn('技能数组不是数组格式,自动修正:', newVal);
+ this.$set(this.form, 'skillIdsArray', []);
+ }
+ },
+ deep: true,
+ immediate: true
+ },
+
+ // 监听技能列表加载状态
+ 'siteSkillList': {
+ handler(newVal) {
+ console.log('技能列表变化:', newVal.length, '项技能');
+ if (newVal.length > 0) {
+ console.log('技能列表详情:', newVal.map(skill => ({ id: skill.id, title: skill.title })));
+ }
+ },
+ deep: true,
+ immediate: true
+ }
},
methods: {
/** 查询服务内容列表 */
@@ -488,13 +579,14 @@ export default {
skuValue: '',
latitude: null,
longitude: null,
- type: null,
+ type: 1, // 默认为服务类型
cateId: null,
project: null,
- sort: 0,
+ sort: 50, // 默认排序值
material: null,
postage: null,
basic: null,
+ basicArray: [], // 基检现象数组
margin: null,
skillIds: null,
skillIdsArray: [], // 重置技能数组
@@ -502,10 +594,18 @@ export default {
updatedAt: null,
deletedAt: null
}
- // 使用Vue.set确保响应式
- this.$set(this.form, 'skillIdsArray', []);
- this.skuType = 1
- this.resetForm("form")
+ // 使用Vue.set确保响应式
+ this.$set(this.form, 'skillIdsArray', []);
+ this.$set(this.form, 'basicArray', []);
+ // 重置基检现象标签输入状态
+ this.showBasicInput = false;
+ this.newBasicTag = '';
+ // 重置时清空基检现象选项列表
+ this.basicOptions = [];
+ this.skuType = 1;
+ // 重置活动标签页
+ this.activeTab = 'base';
+ this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
@@ -535,37 +635,74 @@ export default {
this.multiple = !selection.length
},
- // 任务状态修改
+ // 状态修改
handlefenleiStatusChange(row) {
- let text = row.status === "0" ? "启用" : "停用"
- this.$modal.confirm('确认要"' + text + '""' + row.title + '"状态吗?').then(function() {
- return changefenleiStatus(row.id, row.status)
+ const text = row.status === "0" ? "启用" : "停用";
+ this.$modal.confirm('确认要"' + text + '""' + row.title + '"吗?').then(function() {
+ return changefenleiStatus(row.id, row.status);
}).then(() => {
- this.$modal.msgSuccess(text + "成功")
+ this.$modal.msgSuccess(text + "成功");
}).catch(function() {
- row.status = row.status === "0" ? "1" : "0"
- })
+ // 操作失败时恢复原状态
+ row.status = row.status === "0" ? "1" : "0";
+ });
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
- // 确保技能数组被正确初始化
+ // 确保技能数组和基检现象数组被正确初始化
this.$set(this.form, 'skillIdsArray', []);
+ this.$set(this.form, 'basicArray', []);
+ // 新增时清空基检现象选项列表
+ this.basicOptions = [];
+ // 重置基检现象标签输入状态
+ this.showBasicInput = false;
+ this.newBasicTag = '';
console.log('新增时初始化form:', this.form);
+
+ // 验证技能列表是否已加载
+ if (this.siteSkillList.length === 0) {
+ console.warn('技能列表未加载,重新获取...');
+ this.getSiteSkillList();
+ }
+
this.open = true
this.title = "添加服务内容"
},
getSiteSkillList(){
- getSiteSkillList().then(response => {
+ console.log('开始获取技能列表...');
+ return getSiteSkillList().then(response => {
+ console.log('技能列表响应:', response);
console.log('技能列表数据:', response.data);
- this.$set(this, 'siteSkillList', response.data || []);
- // 强制更新
- this.$forceUpdate();
+
+ // 确保数据是数组格式,并且每个技能都有id和title
+ let skillData = [];
+ if (Array.isArray(response.data)) {
+ skillData = response.data.filter(skill => skill && skill.id !== undefined && skill.title);
+ // 确保id是数字类型
+ skillData = skillData.map(skill => ({
+ ...skill,
+ id: parseInt(skill.id)
+ }));
+ }
+
+ this.$set(this, 'siteSkillList', skillData);
+ console.log('技能列表设置完成,数量:', skillData.length);
+ console.log('技能列表详情:', skillData);
+
+ // 如果没有技能数据,给出友好提示
+ if (skillData.length === 0) {
+ console.warn('技能列表为空,请检查后端数据');
+ this.$message.warning('暂无技能数据,请联系管理员添加技能信息');
+ }
+
+ return skillData;
}).catch(error => {
console.error('获取技能列表失败:', error);
this.$set(this, 'siteSkillList', []);
- this.$message.error('获取技能列表失败');
+ this.$message.error('获取技能列表失败,请检查网络连接或联系管理员');
+ return [];
})
},
@@ -574,14 +711,54 @@ export default {
handleUpdate(row) {
this.reset()
const id = row.id || this.ids
- getServiceGoods(id).then(response => {
- this.form = response.data
+
+ // 确保技能列表已加载
+ const skillPromise = this.siteSkillList.length > 0 ?
+ Promise.resolve(this.siteSkillList) :
+ this.getSiteSkillList();
+
+ Promise.all([
+ getServiceGoods(id),
+ skillPromise
+ ]).then(([serviceResponse, skillData]) => {
+ this.form = serviceResponse.data
console.log('编辑数据:', this.form);
- // 处理技能ID转换:将字符串转为数组
+ console.log('技能列表数据:', skillData);
+ console.log('原始基检现象数据:', this.form.basic);
+ // 处理技能ID转换:将JSON字符串或数组转为数组
if (this.form.skillIds) {
try {
- // 如果skillIds是逗号分隔的字符串,转为数组
- const skillArray = this.form.skillIds.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id))
+ let skillArray = [];
+ console.log('原始技能数据:', this.form.skillIds, '类型:', typeof this.form.skillIds);
+
+ if (typeof this.form.skillIds === 'string') {
+ // 尝试解析JSON格式 ["30", "32", "45"]
+ try {
+ const parsedSkills = JSON.parse(this.form.skillIds);
+ if (Array.isArray(parsedSkills)) {
+ skillArray = parsedSkills.map(id => parseInt(id)).filter(id => !isNaN(id));
+ } else {
+ // 如果不是JSON数组,尝试逗号分隔的字符串
+ skillArray = this.form.skillIds.split(',').map(id => {
+ const numId = parseInt(id.trim());
+ return isNaN(numId) ? null : numId;
+ }).filter(id => id !== null);
+ }
+ } catch (jsonError) {
+ // JSON解析失败,尝试逗号分隔的字符串
+ skillArray = this.form.skillIds.split(',').map(id => {
+ const numId = parseInt(id.trim());
+ return isNaN(numId) ? null : numId;
+ }).filter(id => id !== null);
+ }
+ } else if (Array.isArray(this.form.skillIds)) {
+ // 如果已经是数组,直接使用
+ skillArray = this.form.skillIds.map(id => parseInt(id)).filter(id => !isNaN(id));
+ } else if (typeof this.form.skillIds === 'number') {
+ // 如果是单个数字
+ skillArray = [this.form.skillIds];
+ }
+
this.$set(this.form, 'skillIdsArray', skillArray);
console.log('转换后的技能数组:', this.form.skillIdsArray);
} catch (e) {
@@ -592,6 +769,52 @@ export default {
this.$set(this.form, 'skillIdsArray', []);
}
+ // 处理基检现象转换:将JSON字符串转为数组
+ if (this.form.basic) {
+ try {
+ let basicArray = [];
+ console.log('原始基检现象数据:', this.form.basic, '类型:', typeof this.form.basic);
+
+ if (typeof this.form.basic === 'string') {
+ // 尝试解析JSON格式 ["冷气输出不足", "无冷空气", "空调异味"]
+ try {
+ const parsedBasic = JSON.parse(this.form.basic);
+ if (Array.isArray(parsedBasic)) {
+ basicArray = parsedBasic.filter(item => item && item.trim());
+ } else {
+ // 如果不是JSON数组,尝试逗号分隔的字符串(兼容旧格式)
+ basicArray = this.form.basic.split(',').map(item => item.trim()).filter(item => item);
+ }
+ } catch (jsonError) {
+ // JSON解析失败,尝试逗号分隔的字符串
+ basicArray = this.form.basic.split(',').map(item => item.trim()).filter(item => item);
+ }
+ } else if (Array.isArray(this.form.basic)) {
+ // 如果已经是数组,直接使用
+ basicArray = this.form.basic.filter(item => item && item.trim());
+ }
+
+ this.$set(this.form, 'basicArray', basicArray);
+ console.log('转换后的基检现象数组:', this.form.basicArray);
+
+ // 编辑时需要将已保存的标签添加到选项列表中以便显示和维护
+ basicArray.forEach(item => {
+ if (!this.basicOptions.includes(item)) {
+ this.basicOptions.push(item);
+ }
+ });
+ } catch (e) {
+ console.error('基检现象转换错误:', e);
+ this.$set(this.form, 'basicArray', []);
+ }
+ } else {
+ this.$set(this.form, 'basicArray', []);
+ }
+
+ // 重置基检现象标签输入状态
+ this.showBasicInput = false;
+ this.newBasicTag = '';
+
// 处理规格类型
if (this.form.skuType) {
this.skuType = parseInt(this.form.skuType);
@@ -599,92 +822,175 @@ export default {
this.skuType = 1; // 默认单规格
}
- // 处理 sku 字段:将字符串转换为对象
- // if (this.form.sku && typeof this.form.sku === 'string') {
- // try {
- // this.form.sku = JSON.parse(this.form.sku);
- // console.log('转换后的sku对象:', this.form.sku);
- // } catch (e) {
- // console.log('sku字符串解析失败,设置为空对象:', e);
- // this.$set(this.form, 'sku', {});
- // }
- // } else if (!this.form.sku) {
- // this.$set(this.form, 'sku', {});
- // }
+ // 处理 sku 字段:确保格式正确
+ if (this.form.sku && typeof this.form.sku === 'string') {
+ try {
+ // 验证是否为有效JSON
+ JSON.parse(this.form.sku);
+ // 如果是有效JSON,保持原样
+ } catch (e) {
+ console.log('sku字符串解析失败,设置为空对象:', e);
+ this.form.sku = '{}';
+ }
+ } else if (!this.form.sku) {
+ this.form.sku = '{}';
+ }
+
+ // 确保数字字段的正确类型
+ if (this.form.price) {
+ this.form.price = parseFloat(this.form.price);
+ }
+ if (this.form.margin) {
+ this.form.margin = parseFloat(this.form.margin);
+ }
+ if (this.form.sales) {
+ this.form.sales = parseInt(this.form.sales);
+ }
+ if (this.form.stock) {
+ this.form.stock = parseInt(this.form.stock);
+ }
+ if (this.form.sort) {
+ this.form.sort = parseInt(this.form.sort);
+ }
console.log('编辑时的规格类型:', this.skuType);
console.log('编辑时的规格数据:', this.form.sku);
+ // 调试:等待Vue更新周期完成后测试技能初始化
+ this.$nextTick(() => {
+ console.log('=== 编辑数据初始化完成后的状态 ===');
+ console.log('技能数组:', this.form.skillIdsArray);
+ console.log('技能字符串:', this.form.skillIds);
+ console.log('技能列表长度:', this.siteSkillList.length);
+ console.log('技能列表:', this.siteSkillList.map(s => ({id: s.id, title: s.title})));
+ console.log('已选择技能名称:', this.getSelectedSkillNames());
+
+ // 测试格式化功能
+ if (this.form.skillIds) {
+ console.log('表格显示格式化结果:', this.formatSkillNames(this.form.skillIds));
+ }
+ });
+
this.open = true
this.title = "修改服务内容"
+ }).catch(error => {
+ console.error('编辑数据加载失败:', error);
+ this.$message.error('编辑数据加载失败,请重试');
})
},
/** 提交按钮 */
submitForm() {
- // 设置规格类型
- this.form.skuType = this.skuType;
-
- // 处理规格数据
- if (this.skuType === 2) {
- // 多规格模式 - 验证规格数据
- if (!this.$refs.skuRef) {
- this.$modal.msgError("多规格组件未初始化");
- return;
- }
-
- const skuData = this.$refs.skuRef.submit();
- if (!skuData) {
- this.$modal.msgError("请完整配置多规格信息");
- return;
- }
-
-
- this.form.sku = skuData;
- console.log('多规格数据:', skuData);
- } else {
- // 单规格模式 - 直接设置为空对象
- this.form.sku = '{}';
- console.log('单规格数据:', this.form.sku);
- }
-
-
- // 处理技能ID转换:将数组转为字符串
- console.log('提交前的技能数组:', this.form.skillIdsArray);
- if (this.form.skillIdsArray && this.form.skillIdsArray.length > 0) {
- this.form.skillIds = this.form.skillIdsArray.join(',')
- } else {
- this.form.skillIds = null
- }
- console.log('提交的技能字符串:', this.form.skillIds);
-
this.$refs["form"].validate(valid => {
if (valid) {
+ // 设置规格类型
+ this.form.skuType = this.skuType;
+
+ // 处理规格数据
+ if (this.skuType === 2) {
+ // 多规格模式 - 验证规格数据
+ if (!this.$refs.skuRef) {
+ this.$modal.msgError("多规格组件未初始化");
+ return;
+ }
+
+ const skuData = this.$refs.skuRef.submit();
+ if (!skuData) {
+ this.$modal.msgError("请完整配置多规格信息");
+ return;
+ }
+
+ this.form.sku = typeof skuData === 'object' ? JSON.stringify(skuData) : skuData;
+ console.log('多规格数据:', this.form.sku);
+ } else {
+ // 单规格模式 - 直接设置为空对象字符串
+ this.form.sku = '{}';
+ console.log('单规格数据:', this.form.sku);
+ }
+
+ // 处理技能ID转换:将数组转为JSON字符串
+ console.log('提交前的技能数组:', this.form.skillIdsArray);
+ if (this.form.skillIdsArray && Array.isArray(this.form.skillIdsArray) && this.form.skillIdsArray.length > 0) {
+ // 确保所有ID都是有效的数字,并转换为字符串格式
+ const validSkillIds = this.form.skillIdsArray
+ .filter(id => id !== null && id !== undefined && !isNaN(id))
+ .map(id => id.toString()); // 转换为字符串,匹配数据库格式 ["30", "32", "45"]
+
+ this.form.skillIds = validSkillIds.length > 0 ? JSON.stringify(validSkillIds) : null;
+ } else {
+ this.form.skillIds = null;
+ }
+ console.log('提交的技能JSON字符串:', this.form.skillIds);
+
+ // 处理基检现象转换:将数组转为JSON字符串
+ console.log('提交前的基检现象数组:', this.form.basicArray);
+ if (this.form.basicArray && Array.isArray(this.form.basicArray) && this.form.basicArray.length > 0) {
+ // 过滤掉空字符串和无效值
+ const validBasicItems = this.form.basicArray.filter(item => item && item.trim());
+ this.form.basic = validBasicItems.length > 0 ? JSON.stringify(validBasicItems) : null;
+ } else {
+ this.form.basic = null;
+ }
+ console.log('提交的基检现象JSON字符串:', this.form.basic);
+
+ // 确保数字字段的正确格式
+ if (this.form.price) {
+ this.form.price = parseFloat(this.form.price);
+ }
+ if (this.form.margin) {
+ this.form.margin = parseFloat(this.form.margin);
+ }
+ if (this.form.sales) {
+ this.form.sales = parseInt(this.form.sales);
+ }
+ if (this.form.stock) {
+ this.form.stock = parseInt(this.form.stock);
+ }
+ if (this.form.sort) {
+ this.form.sort = parseInt(this.form.sort);
+ }
+
console.log('最终提交的表单数据:', this.form);
+
+ // 提交表单
if (this.form.id != null) {
updateServiceGoods(this.form).then(response => {
- this.$modal.msgSuccess("修改成功")
- this.open = false
- this.getList()
- })
+ this.$modal.msgSuccess("修改成功");
+ // 不自动关闭弹窗,让用户手动关闭
+ this.getList(); // 刷新列表数据
+ }).catch(error => {
+ console.error('修改失败:', error);
+ this.$modal.msgError("修改失败,请检查输入数据");
+ });
} else {
addServiceGoods(this.form).then(response => {
- this.$modal.msgSuccess("新增成功")
- this.open = false
- this.getList()
- })
+ this.$modal.msgSuccess("新增成功");
+ // 不自动关闭弹窗,让用户手动关闭
+ this.getList(); // 刷新列表数据
+ }).catch(error => {
+ console.error('新增失败:', error);
+ this.$modal.msgError("新增失败,请检查输入数据");
+ });
}
+ } else {
+ console.log('表单验证失败');
+ this.$message.error('请完善必填信息');
}
- })
+ });
},
/** 删除按钮操作 */
handleDelete(row) {
- const ids = row.id || this.ids
- this.$modal.confirm('是否确认删除服务内容编号为"' + ids + '"的数据项?').then(function() {
- return delServiceGoods(ids)
+ const ids = row.id || this.ids;
+ const names = row.title || this.ServiceGoodsList.filter(item => this.ids.includes(item.id)).map(item => item.title).join('、');
+
+ this.$modal.confirm('是否确认删除服务内容"' + names + '"?').then(function() {
+ return delServiceGoods(ids);
}).then(() => {
- this.getList()
- this.$modal.msgSuccess("删除成功")
- }).catch(() => {})
+ this.getList();
+ this.$modal.msgSuccess("删除成功");
+ }).catch((error) => {
+ console.error('删除失败:', error);
+ this.$modal.msgError("删除失败,请稍后重试");
+ });
},
getserviceCateList(){
selectServiceCateList().then(response => {
@@ -710,20 +1016,43 @@ export default {
},
async saveEditField() {
if (!this.editRow) return;
- const value = ['price', 'sales', 'stock', 'sort'].includes(this.editField)
- ? Number(this.editFieldValue)
- : this.editFieldValue;
+
+ // 验证输入值
+ let value = this.editFieldValue;
+ if (['price', 'margin'].includes(this.editField)) {
+ // 价格字段验证
+ const numValue = parseFloat(value);
+ if (isNaN(numValue) || numValue < 0) {
+ this.$message.error('请输入有效的价格');
+ return;
+ }
+ value = numValue;
+ } else if (['sales', 'stock', 'sort'].includes(this.editField)) {
+ // 整数字段验证
+ const numValue = parseInt(value);
+ if (isNaN(numValue) || numValue < 0) {
+ this.$message.error('请输入有效的数字');
+ return;
+ }
+ value = numValue;
+ }
+
const payload = {
id: this.editRow.id,
[this.editField]: value
};
+
try {
await updateServiceGoods(payload);
this.$message.success('修改成功');
- this.editDialogVisible = false;
+ // 更新本地数据
+ this.editRow[this.editField] = value;
this.getList();
- } catch (e) {
- this.$message.error('修改失败');
+ // 快捷编辑成功后自动关闭对话框
+ this.editDialogVisible = false;
+ } catch (error) {
+ console.error('快捷编辑失败:', error);
+ this.$message.error('修改失败,请稍后重试');
}
},
addSpec() {
@@ -775,6 +1104,31 @@ export default {
console.log('技能列表长度:', this.siteSkillList.length);
}, 5000);
},
+
+ // 测试JSON格式转换
+ testJsonConversion() {
+ console.log('=== 测试JSON格式转换 ===');
+
+ // 模拟数据库返回的JSON字符串格式
+ const testSkillIds = '["30", "32", "45"]';
+ console.log('测试数据:', testSkillIds);
+
+ try {
+ const parsed = JSON.parse(testSkillIds);
+ console.log('解析结果:', parsed);
+ console.log('是否为数组:', Array.isArray(parsed));
+
+ const converted = parsed.map(id => parseInt(id)).filter(id => !isNaN(id));
+ console.log('转换后的数组:', converted);
+
+ // 测试反向转换
+ const backToJson = JSON.stringify(converted.map(id => id.toString()));
+ console.log('转换回JSON:', backToJson);
+
+ } catch (e) {
+ console.error('转换测试失败:', e);
+ }
+ },
// 规格类型变化处理
handleSkuTypeChange(value) {
console.log('规格类型变化:', value);
@@ -795,24 +1149,178 @@ export default {
// 技能选择变化处理
handleSkillChange(value) {
console.log('技能选择变化:', value);
- this.form.skillIdsArray = value;
+ // 确保value是数组格式
+ const skillArray = Array.isArray(value) ? value : [];
+ this.$set(this.form, 'skillIdsArray', skillArray);
+ console.log('设置后的技能数组:', this.form.skillIdsArray);
},
+
+ // 获取已选择的技能名称
+ getSelectedSkillNames() {
+ if (!this.form.skillIdsArray || !this.form.skillIdsArray.length || !this.siteSkillList.length) {
+ return '无';
+ }
+ const selectedSkills = this.form.skillIdsArray.map(id => {
+ const skill = this.siteSkillList.find(s => s.id === parseInt(id));
+ return skill ? skill.title : `ID:${id}`;
+ }).filter(name => name);
+ return selectedSkills.join(', ');
+ },
+
+ // 切换基检现象标签选中状态
+ toggleBasicTag(tag) {
+ // 确保basicArray已初始化
+ if (!this.form.basicArray) {
+ this.$set(this.form, 'basicArray', []);
+ }
+
+ const index = this.form.basicArray.indexOf(tag);
+ if (index > -1) {
+ // 如果已选中,则取消选中
+ this.form.basicArray.splice(index, 1);
+ } else {
+ // 如果未选中,则添加选中
+ this.form.basicArray.push(tag);
+ }
+ console.log('基检现象选择变化:', this.form.basicArray);
+ },
+
+ // 删除基检现象标签
+ removeBasicTag(tag) {
+ // 确保basicArray已初始化
+ if (!this.form.basicArray) {
+ this.$set(this.form, 'basicArray', []);
+ return;
+ }
+
+ const index = this.form.basicArray.indexOf(tag);
+ if (index > -1) {
+ this.form.basicArray.splice(index, 1);
+ console.log('删除基检现象标签:', tag, '剩余:', this.form.basicArray);
+ }
+ },
+
+ // 显示新增基检现象输入框
+ showBasicInputBox() {
+ this.showBasicInput = true;
+ this.newBasicTag = '';
+ this.$nextTick(() => {
+ if (this.$refs.basicInput) {
+ this.$refs.basicInput.focus();
+ }
+ });
+ },
+
+ // 确认新增基检现象标签
+ handleBasicInputConfirm() {
+ const tag = this.newBasicTag.trim();
+ if (tag) {
+ // 确保basicArray已初始化
+ if (!this.form.basicArray) {
+ this.$set(this.form, 'basicArray', []);
+ }
+ // 添加到选项列表以便显示
+ if (!this.basicOptions.includes(tag)) {
+ this.basicOptions.push(tag);
+ }
+ // 添加到已选择的标签中
+ if (!this.form.basicArray.includes(tag)) {
+ this.form.basicArray.push(tag);
+ }
+ }
+ this.showBasicInput = false;
+ this.newBasicTag = '';
+ },
+
// 格式化技能名称显示
formatSkillNames(skillIds) {
if (!skillIds || !this.siteSkillList.length) {
return '-'
}
try {
- const skillIdArray = skillIds.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id))
+ let skillIdArray = [];
+
+ // 尝试解析JSON格式 ["30", "32", "45"]
+ if (typeof skillIds === 'string') {
+ try {
+ const parsedSkills = JSON.parse(skillIds);
+ if (Array.isArray(parsedSkills)) {
+ skillIdArray = parsedSkills.map(id => parseInt(id)).filter(id => !isNaN(id));
+ } else {
+ // 如果不是JSON数组,尝试逗号分隔的字符串(兼容旧格式)
+ skillIdArray = skillIds.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id));
+ }
+ } catch (jsonError) {
+ // JSON解析失败,尝试逗号分隔的字符串
+ skillIdArray = skillIds.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id));
+ }
+ } else if (Array.isArray(skillIds)) {
+ skillIdArray = skillIds.map(id => parseInt(id)).filter(id => !isNaN(id));
+ }
+
const skillNames = skillIdArray.map(id => {
const skill = this.siteSkillList.find(s => s.id === id)
- return skill ? skill.title : id
+ return skill ? skill.title : `ID:${id}`
}).filter(name => name)
+
return skillNames.length > 0 ? skillNames.join(', ') : '-'
} catch (e) {
+ console.warn('格式化技能名称失败:', e, skillIds);
+ return '-'
+ }
+ },
+
+ // 格式化基检现象名称显示
+ formatBasicNames(basic) {
+ if (!basic || typeof basic !== 'string') {
+ return '-'
+ }
+ try {
+ let basicArray = [];
+
+ // 尝试解析JSON格式 ["冷气输出不足", "无冷空气", "空调异味"]
+ try {
+ const parsedBasic = JSON.parse(basic);
+ if (Array.isArray(parsedBasic)) {
+ basicArray = parsedBasic.filter(item => item && item.trim());
+ } else {
+ // 如果不是JSON数组,尝试逗号分隔的字符串(兼容旧格式)
+ basicArray = basic.split(',').map(item => item.trim()).filter(item => item);
+ }
+ } catch (jsonError) {
+ // JSON解析失败,尝试逗号分隔的字符串
+ basicArray = basic.split(',').map(item => item.trim()).filter(item => item);
+ }
+
+ return basicArray.length > 0 ? basicArray.join(', ') : '-'
+ } catch (e) {
+ console.warn('格式化基检现象失败:', e)
return '-'
}
},
}
}
+
+