| | |
| | | } |
| | | }, |
| | | /** |
| | | * 按产品类型自动设置生产车间(单选/多选均由类型决定,用户不可改) |
| | | * 按产品类型自动设置生产车间(固定传值,用户不可改) |
| | | */ |
| | | syncWorkshopFromProductType() { |
| | | const pt = this.form.productType; |
| | | const list = this.workshopList; |
| | | if (!pt) { |
| | | this.form.workshop = ""; |
| | | return; |
| | | } |
| | | if (!list.length) { |
| | | this.form.workshop = ""; |
| | | return; |
| | | } |
| | | if (pt === "TG01") { |
| | | const w = |
| | | list.find((x) => x.label === "铜杆") || |
| | | list.find((x) => x.label.includes("铜杆")); |
| | | if (w) { |
| | | this.form.workshop = w.value; |
| | | } else { |
| | | this.form.workshop = ""; |
| | | uni.showToast({ title: "字典中未找到铜杆车间", icon: "none" }); |
| | | } |
| | | this.setWorkshopByValues(["CT01", "ZF01"]); |
| | | return; |
| | | } |
| | | if (pt === "DT01") { |
| | | this.setWorkshopByLabels(["导体车间", "导体车间2"]); |
| | | this.setWorkshopByValues(["CD01", "CY01", "ZF01"]); |
| | | return; |
| | | } |
| | | if (pt === "DT02") { |
| | | this.setWorkshopByLabels(["导体车间", "导体车间2", "直发"]); |
| | | this.setWorkshopByValues(["CD01", "CY01", "ZF01"]); |
| | | } |
| | | }, |
| | | setWorkshopByLabels(requiredLabels) { |
| | | const list = this.workshopList; |
| | | const picked = []; |
| | | const missing = []; |
| | | requiredLabels.forEach((lbl) => { |
| | | let w = list.find((x) => x.label === lbl); |
| | | if (!w && lbl === "直发") { |
| | | w = list.find((x) => x.label.includes("直发")); |
| | | } |
| | | if (w) picked.push(w); |
| | | else missing.push(lbl); |
| | | }); |
| | | if (missing.length) { |
| | | this.form.workshop = ""; |
| | | uni.showToast({ |
| | | title: `车间字典缺少:${missing.join("、")}`, |
| | | icon: "none", |
| | | }); |
| | | return; |
| | | } |
| | | setWorkshopByValues(requiredValues) { |
| | | const uniq = []; |
| | | const seen = new Set(); |
| | | picked.forEach((w) => { |
| | | if (!seen.has(w.value)) { |
| | | seen.add(w.value); |
| | | uniq.push(w); |
| | | requiredValues.forEach((value) => { |
| | | if (!seen.has(value)) { |
| | | seen.add(value); |
| | | uniq.push(value); |
| | | } |
| | | }); |
| | | this.form.workshop = uniq.map((x) => x.value).join(","); |
| | | this.form.workshop = uniq.join(","); |
| | | |
| | | // 若字典已加载则做一次存在性提示,避免配置不一致时无感知 |
| | | if (this.workshopList.length) { |
| | | const dictValues = new Set(this.workshopList.map((x) => String(x.value))); |
| | | const missing = uniq.filter((v) => !dictValues.has(String(v))); |
| | | if (missing.length) { |
| | | uni.showToast({ |
| | | title: `车间字典缺少编码:${missing.join("、")}`, |
| | | icon: "none", |
| | | }); |
| | | } |
| | | } |
| | | }, |
| | | // 司磅员 |
| | | weighmanChange(e, storage) { |