|
@@ -0,0 +1,298 @@
|
|
|
+<template>
|
|
|
+ <div class="form">
|
|
|
+ <van-nav-bar :title="'公司产品库'" :left-text="$t('common.back')" left-arrow @click-left="onClickLeft">
|
|
|
+ </van-nav-bar>
|
|
|
+
|
|
|
+ <testForm v-model="formData.data" :formOption="formOption" :formConfig="formConfig" :rules="rules" @onSubmit="onSubmit" ref="formDom"></testForm>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { ref, getCurrentInstance, onMounted, reactive } from "vue";
|
|
|
+import { showSuccessToast, showToast } from "vant";
|
|
|
+import { useRoute } from "vue-router";
|
|
|
+import { getUserInfo } from "@/utils/auth";
|
|
|
+import testForm from "@/components/testForm/index.vue";
|
|
|
+const proxy = getCurrentInstance().proxy;
|
|
|
+const route = useRoute();
|
|
|
+const show = ref(false);
|
|
|
+const typeModal = ref(false);
|
|
|
+const unitModal = ref(false);
|
|
|
+const classification = ref([]);
|
|
|
+const formData = reactive({
|
|
|
+ data: {},
|
|
|
+});
|
|
|
+const formDom = ref(null);
|
|
|
+const formOption = reactive({
|
|
|
+ readonly: false, //用于控制整个表单是否只读
|
|
|
+ disabled: false,
|
|
|
+ labelAlign: "top",
|
|
|
+ scroll: true,
|
|
|
+ labelWidth: "62pk",
|
|
|
+ hiddenSubmitBtn: false,
|
|
|
+});
|
|
|
+const formConfig = reactive([
|
|
|
+ {
|
|
|
+ type: "cascader",
|
|
|
+ label: proxy.t("productLibrary.productClassification"),
|
|
|
+ prop: "productClassifyId",
|
|
|
+ itemType: "common",
|
|
|
+ showPicker: false,
|
|
|
+ // data: classification.value,
|
|
|
+ data: [],
|
|
|
+ fieldNames: {
|
|
|
+ text: "label",
|
|
|
+ value: "id",
|
|
|
+ children: "children",
|
|
|
+ },
|
|
|
+ // onChangeFn: (option) => {
|
|
|
+ // // console.log("aa");
|
|
|
+ // },
|
|
|
+ // finishFn: (current, option) => {
|
|
|
+ // current.showPicker = false;
|
|
|
+ // },
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "text",
|
|
|
+ label: proxy.t("productLibrary.productName"),
|
|
|
+ prop: "name",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "text",
|
|
|
+ label: "英文名",
|
|
|
+ prop: "nameEnglish",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "text",
|
|
|
+ label: proxy.t("productLibrary.specificationModel"),
|
|
|
+ prop: "spec",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "number",
|
|
|
+ label: "销售指导价",
|
|
|
+ prop: "price",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "number",
|
|
|
+ label: "成本价",
|
|
|
+ prop: "costPrice",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "number",
|
|
|
+ label: "长(cm)",
|
|
|
+ prop: "productLong",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "number",
|
|
|
+ label: "宽(cm)",
|
|
|
+ prop: "productWide",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "number",
|
|
|
+ label: "高(cm)",
|
|
|
+ prop: "productHigh",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "number",
|
|
|
+ label: "净重(kg)",
|
|
|
+ prop: "netWeight",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "text",
|
|
|
+ label: "内包装方式",
|
|
|
+ prop: "innerPackMethod",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "text",
|
|
|
+ label: "外包装方式",
|
|
|
+ prop: "outerPackMethod",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "number",
|
|
|
+ label: "海关编码",
|
|
|
+ prop: "hsCode",
|
|
|
+ clearable: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "input",
|
|
|
+ itemType: "textarea",
|
|
|
+ label: proxy.t("productLibrary.remarks"),
|
|
|
+ prop: "remark",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "upload",
|
|
|
+ label: proxy.t("productLibrary.fileUpload"),
|
|
|
+ prop: "fileList",
|
|
|
+ },
|
|
|
+]);
|
|
|
+const rules = {
|
|
|
+ productClassifyId: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: proxy.t("productLibrary.productClassificationCanNotBeEmpty"),
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ type: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: proxy.t("productLibrary.productTypeCanNotBeEmpty"),
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ name: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: proxy.t("productLibrary.productNameCanNotBeEmpty"),
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ spec: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: proxy.t("productLibrary.specificationModelCanNotBeEmpty"),
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ unit: [
|
|
|
+ { required: true, message: proxy.t("productLibrary.unitCanNotBeEmpty") },
|
|
|
+ ],
|
|
|
+ select: [{ required: true, message: proxy.t("productLibrary.pleaseSelect") }],
|
|
|
+ date: [
|
|
|
+ { required: true, message: proxy.t("productLibrary.pleaseSelectTime") },
|
|
|
+ ],
|
|
|
+ common: [
|
|
|
+ { required: true, message: proxy.t("productLibrary.pleaseSelectCascader") },
|
|
|
+ ],
|
|
|
+ // city: [{ required: true, message: "请选择城市" }],
|
|
|
+};
|
|
|
+const unitList = ref([]);
|
|
|
+const innerMethon = ref([]);
|
|
|
+const outsideMethon = ref([]);
|
|
|
+const getDict = async () => {
|
|
|
+ proxy
|
|
|
+ .post("/productClassify/tree", { parentId: "", name: "", definition: "1" })
|
|
|
+ .then((res) => {
|
|
|
+ formConfig[0].data = res.data;
|
|
|
+ });
|
|
|
+ const res = await proxy.getDictOne([
|
|
|
+ "inner_packaging_method_ehsd",
|
|
|
+ "outside_packaging_method_ehsd",
|
|
|
+ "unit",
|
|
|
+ ]);
|
|
|
+ innerMethon.value = res["inner_packaging_method_ehsd"].data.map((x) => ({
|
|
|
+ label: x.dictValue,
|
|
|
+ value: x.dictKey,
|
|
|
+ }));
|
|
|
+ outsideMethon.value = res["outside_packaging_method_ehsd"].data.map((x) => ({
|
|
|
+ label: x.dictValue,
|
|
|
+ value: x.dictKey,
|
|
|
+ }));
|
|
|
+ formConfig[4].data = res["unit"].data.map((x) => ({
|
|
|
+ label: x.dictValue,
|
|
|
+ value: x.dictKey,
|
|
|
+ }));
|
|
|
+
|
|
|
+ if (route.query.id) {
|
|
|
+ formOption.readonly = true;
|
|
|
+ formOption.hiddenSubmitBtn = true;
|
|
|
+ proxy
|
|
|
+ .post("/productInfo/detailByEhsd", { id: route.query.id })
|
|
|
+ .then((resDetail) => {
|
|
|
+ if (resDetail.data && resDetail.data.ehsdJson) {
|
|
|
+ let obj = JSON.parse(resDetail.data.ehsdJson);
|
|
|
+ formData.data = {
|
|
|
+ ...resDetail.data,
|
|
|
+ ...obj,
|
|
|
+ };
|
|
|
+ if (formData.data.innerPackMethod) {
|
|
|
+ formData.data.innerPackMethod = formData.data.innerPackMethod
|
|
|
+ .split(",")
|
|
|
+ .map((x) => proxy.dictValueLabel(x, innerMethon.value));
|
|
|
+ } else {
|
|
|
+ formData.data.innerPackMethod = [];
|
|
|
+ }
|
|
|
+ if (formData.data.outerPackMethod) {
|
|
|
+ formData.data.outerPackMethod = formData.data.outerPackMethod
|
|
|
+ .split(",")
|
|
|
+ .map((x) => proxy.dictValueLabel(x, outsideMethon.value));
|
|
|
+ } else {
|
|
|
+ formData.data.outerPackMethod = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ proxy
|
|
|
+ .post("/fileInfo/getList", { businessIdList: [route.query.id] })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.data[route.query.id] && res.data[route.query.id].length > 0) {
|
|
|
+ setTimeout(() => {
|
|
|
+ formData.data.fileList = res.data[route.query.id].map((item) => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ url: item.fileUrl,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }, 1000);
|
|
|
+ } else {
|
|
|
+ formData.data.fileList = [];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+};
|
|
|
+getDict();
|
|
|
+const onClickLeft = () => history.back();
|
|
|
+const onSubmit = () => {
|
|
|
+ console.log(formData);
|
|
|
+ formData.data.definition = "1";
|
|
|
+ formData.data.fileList = formData.data.fileList.map((item) => {
|
|
|
+ return {
|
|
|
+ url: item.url,
|
|
|
+ id: item.id,
|
|
|
+ fileName: item.fileName,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ proxy.post("/productInfo/" + route.query.type, formData.data).then(() => {
|
|
|
+ showSuccessToast(
|
|
|
+ !route.query.id
|
|
|
+ ? proxy.t("common.addSuccess")
|
|
|
+ : proxy.t("common.modifySuccess")
|
|
|
+ );
|
|
|
+ setTimeout(() => {
|
|
|
+ history.back();
|
|
|
+ }, 500);
|
|
|
+ });
|
|
|
+};
|
|
|
+const treeToList = (arr) => {
|
|
|
+ let res = []; // 用于存储递归结果(扁平数据)
|
|
|
+ // 递归函数
|
|
|
+ let fn = (source) => {
|
|
|
+ source.forEach((el) => {
|
|
|
+ res.push(el);
|
|
|
+ el.children && el.children.length > 0 ? fn(el.children) : ""; // 子级递归
|
|
|
+ });
|
|
|
+ };
|
|
|
+ fn(arr);
|
|
|
+ return res;
|
|
|
+};
|
|
|
+</script>
|