Bläddra i källkod

供应商模块

cz 2 år sedan
förälder
incheckning
3d595ab8aa

+ 458 - 0
src/views/purchaseManage/purchaseManage/purchase/index.vue

@@ -0,0 +1,458 @@
+<template>
+  <div class="tenant">
+    <!-- <Banner /> -->
+    <div class="content">
+      <byTable
+        :source="sourceList.data"
+        :pagination="sourceList.pagination"
+        :config="config"
+        :loading="loading"
+        highlight-current-row
+        :selectConfig="selectConfig"
+        :table-events="{
+          //element talbe事件都能传
+          select: selectRow,
+          'select-all': selectRow,
+        }"
+        :action-list="[
+          {
+            text: '采购',
+            disabled: selectData.length === 0,
+            action: () => start(),
+          },
+        ]"
+        @get-list="getList"
+      >
+        <template #fileSlot="{ item }">
+          <div
+            style="cursor: pointer; color: #409eff"
+            @click="handleClickFile(item)"
+          >
+            {{ item.fileName }}
+          </div>
+        </template>
+      </byTable>
+    </div>
+    <el-dialog
+      :title="modalType == 'add' ? '添加供应商' : '编辑供应商'"
+      v-model="dialogVisible"
+      width="800"
+      v-loading="loading"
+    >
+      <byForm
+        :formConfig="formConfig"
+        :formOption="formOption"
+        v-model="formData.data"
+        :rules="rules"
+        ref="byform"
+      >
+        <template #address>
+          <el-row :gutter="10" style="width: 100%">
+            <el-col :span="8">
+              <el-select v-model="formData.data.aa" placeholder="国家">
+                <el-option v-for="item in 3" label="ceshi" value="1">
+                </el-option>
+              </el-select>
+            </el-col>
+            <el-col :span="8">
+              <el-select v-model="formData.data.aa" placeholder="省/洲">
+                <el-option v-for="item in 3" label="ceshi" value="1">
+                </el-option>
+              </el-select>
+            </el-col>
+            <el-col :span="8">
+              <el-select v-model="formData.data.aa" placeholder="城市">
+                <el-option v-for="item in 3" label="ceshi" value="1">
+                </el-option>
+              </el-select>
+            </el-col>
+          </el-row>
+          <el-row style="margin-top: 20px; width: 100%">
+            <el-col :span="24">
+              <el-input v-model="formData.data.bb" type="textarea"> </el-input>
+            </el-col>
+          </el-row>
+        </template>
+
+        <template #contact>
+          <el-row :gutter="10" style="width: 100%">
+            <el-col :span="8">
+              <el-input v-model="formData.data.aa" placeholder="联系人">
+              </el-input>
+            </el-col>
+            <el-col :span="16">
+              <el-input v-model="formData.data.aa" placeholder="联系电话">
+              </el-input>
+            </el-col>
+          </el-row>
+        </template>
+
+        <template #fileSlot>
+          <div>
+            <el-upload
+              v-model:fileList="fileList"
+              class="upload-demo"
+              action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
+              :limit="3"
+              :data="uploadData"
+              :on-preview="handlePreview"
+              :on-remove="handleRemove"
+              :on-success="handleSuccess"
+              :before-upload="handleBeforeUpload"
+              accept=".pdf"
+            >
+              <el-button type="primary">选择</el-button>
+              <template #file>
+                <div>
+                  <div style="margin-top: 15px">
+                    <el-tag
+                      class="ml-2"
+                      type="info"
+                      v-for="(item, index) in fileList"
+                      :key="index"
+                      closable
+                      @close="handleClose(index)"
+                      >{{ item.fileName }}</el-tag
+                    >
+                  </div>
+                </div>
+              </template>
+            </el-upload>
+          </div>
+        </template>
+      </byForm>
+      <template #footer>
+        <el-button @click="dialogVisible = false" size="large">取 消</el-button>
+        <el-button
+          type="primary"
+          @click="submitForm('byform')"
+          size="large"
+          :loading="submitLoading"
+        >
+          确 定
+        </el-button>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+  
+<script setup>
+/* eslint-disable vue/no-unused-components */
+import { ElMessage, ElMessageBox } from "element-plus";
+import byTable from "@/components/byTable/index";
+import byForm from "@/components/byForm/index";
+import FileUpload from "@/components/FileUpload/index";
+import { computed, defineComponent, ref } from "vue";
+import { getToken } from "@/utils/auth";
+
+const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 上传文件服务器地址
+const headers = ref({ Authorization: "Bearer " + getToken() });
+const uploadData = ref({});
+const loading = ref(false);
+const submitLoading = ref(false);
+const sourceList = ref({
+  data: [],
+  pagination: {
+    total: 3,
+    pageNum: 1,
+    pageSize: 10,
+  },
+});
+let dialogVisible = ref(false);
+let modalType = ref("add");
+let fileList = ref([]);
+let rules = ref({
+  name: [{ required: true, message: "请输入供应商名称", trigger: "blur" }],
+});
+const { proxy } = getCurrentInstance();
+const selectConfig = reactive([
+  {
+    label: "申购状态",
+    prop: "type",
+    data: [
+      {
+        label: "产品",
+        value: "1",
+      },
+      {
+        label: "物料",
+        value: "2",
+      },
+    ],
+  },
+]);
+const config = computed(() => {
+  return [
+    {
+      type: "selection",
+      attrs: {
+        label: "角色名称",
+        prop: "remark",
+        width: 50,
+      },
+    },
+    {
+      attrs: {
+        label: "申购单号",
+        prop: "name",
+      },
+    },
+    {
+      attrs: {
+        label: "物品类型",
+        prop: "remarks",
+      },
+    },
+
+    {
+      attrs: {
+        label: "物品编码",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "物品名称",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "规格",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "单位",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "申购数量",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "申购状态",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "申购人",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "申购时间",
+        prop: "remarks",
+      },
+    },
+    {
+      attrs: {
+        label: "操作",
+        width: "200",
+        align: "right",
+      },
+      // 渲染 el-button,一般用在最后一列。
+      renderHTML(row) {
+        return [
+          {
+            attrs: {
+              label: "采购",
+              type: "primary",
+              text: true,
+            },
+            el: "button",
+            click() {
+              getDtl(row);
+            },
+          },
+        ];
+      },
+    },
+  ];
+});
+
+let formData = reactive({
+  data: {
+    type: "1",
+  },
+});
+const formOption = reactive({
+  inline: true,
+  labelWidth: 100,
+  itemWidth: 100,
+  rules: [],
+});
+const byform = ref(null);
+const formConfig = computed(() => {
+  return [
+    {
+      type: "radio",
+      prop: "name",
+      label: "供应商类型",
+      required: true,
+      border: true,
+      data: [
+        { label: "贸易商", value: "1" },
+        { label: "工厂", value: "2" },
+      ],
+    },
+    {
+      type: "input",
+      prop: "name",
+      label: "供应商名称",
+      required: true,
+    },
+    {
+      type: "slot",
+      slotName: "address",
+      label: "地址",
+      required: true,
+    },
+    {
+      type: "slot",
+      slotName: "contact",
+      label: "联系信息",
+      required: true,
+    },
+    {
+      type: "slot",
+      slotName: "fileSlot",
+      label: "上传附件",
+    },
+    {
+      type: "input",
+      label: "备注",
+      prop: "remakes",
+      itemType: "textarea",
+    },
+  ];
+});
+const getList = async (req) => {
+  sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
+  loading.value = true;
+  proxy
+    .post("/productInfo/page", sourceList.value.pagination)
+    .then((message) => {
+      console.log(message);
+      sourceList.value.data = message.rows;
+      sourceList.value.pagination.total = message.total;
+      setTimeout(() => {
+        loading.value = false;
+      }, 200);
+    });
+};
+// const openModal = () => {
+//  proxy.$router.push({
+
+//  })
+// };
+
+const submitForm = () => {
+  if (fileList.value.length > 0) {
+    byform.value.handleSubmit((valid) => {
+      formData.data.fileList = fileList.value;
+      submitLoading.value = true;
+      proxy.post("/productionProcesses/" + modalType.value, formData.data).then(
+        (res) => {
+          ElMessage({
+            message: modalType.value == "add" ? "添加成功" : "编辑成功",
+            type: "success",
+          });
+          fileList.value = [];
+          dialogVisible.value = false;
+          submitLoading.value = false;
+          getList();
+        },
+        (err) => {
+          console.log(err, "aswwwww");
+          submitLoading.value = false;
+        }
+      );
+    });
+  } else {
+    return ElMessage({
+      message: "请上传附件!",
+      type: "info",
+    });
+  }
+};
+
+const getDtl = (row) => {
+  modalType.value = "edit";
+  proxy.post("/productionProcesses/detail", { id: row.id }).then((res) => {
+    fileList.value = [
+      {
+        id: "",
+        fileName: res.fileName,
+        path: "",
+      },
+    ];
+    formData.data = res;
+    dialogVisible.value = true;
+  });
+};
+const handleBeforeUpload = async (file) => {
+  const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
+  uploadData.value = res.uploadBody;
+  fileList.value = [
+    {
+      id: res.id,
+      fileName: res.fileName,
+      path: res.fileUrl,
+    },
+  ];
+};
+const handleClickFile = (row) => {
+  ElMessage({
+    message: "数据请求中,请稍后!",
+    type: "success",
+  });
+  let id = row.id;
+  proxy.post("/fileInfo/getList", { businessIdList: [id] }).then((res) => {
+    const file = res[id][0];
+    window.open(file.fileUrl, "_blank");
+  });
+};
+
+const handlePreview = (file) => {
+  console.log(file);
+};
+const handleSuccess = (file) => {
+  console.log(file);
+};
+const handleRemove = (file) => {
+  fileList.value = [];
+};
+const handleClose = (index) => {
+  fileList.value.splice(index, 1);
+};
+getList();
+const selectData = ref([]);
+const selectRow = (data) => {
+  selectData.value = data;
+};
+
+const start = () => {
+  console.log(selectData.value.length, "22");
+  // if (selectData.value.length > 0) {
+  // } else {
+  //   return ElMessage({
+  //     message: "请勾选数据!",
+  //     type: "info",
+  //   });
+  // }
+};
+</script>
+  
+<style lang="scss" scoped>
+.tenant {
+  padding: 20px;
+}
+</style>

+ 166 - 73
src/views/purchaseManage/supplier/supplier/index.vue

@@ -21,12 +21,10 @@
         ]"
         @get-list="getList"
       >
-        <template #fileSlot="{ item }">
-          <div
-            style="cursor: pointer; color: #409eff"
-            @click="handleClickFile(item)"
-          >
-            {{ item.fileName }}
+        <template #address="{ item }">
+          <div>
+            {{ item.countryName }}, {{ item.provinceName }} ,
+            {{ item.cityName }}, {{ item.areaDetail }}
           </div>
         </template>
       </byTable>
@@ -45,42 +43,81 @@
         ref="byform"
       >
         <template #address>
-          <el-row :gutter="10" style="width: 100%">
+          <el-row :gutter="10" style="width: 100%; margin-left: -15px">
             <el-col :span="8">
-              <el-select v-model="formData.data.aa" placeholder="国家">
-                <el-option v-for="item in 3" label="ceshi" value="1">
-                </el-option>
-              </el-select>
+              <el-form-item prop="countryId">
+                <el-select
+                  v-model="formData.data.countryId"
+                  placeholder="国家"
+                  @change="(val) => getCityData(val, '20', true)"
+                >
+                  <el-option
+                    v-for="item in countryData"
+                    :label="item.chineseName"
+                    :value="item.id"
+                  >
+                  </el-option>
+                </el-select>
+              </el-form-item>
             </el-col>
             <el-col :span="8">
-              <el-select v-model="formData.data.aa" placeholder="省/洲">
-                <el-option v-for="item in 3" label="ceshi" value="1">
-                </el-option>
-              </el-select>
+              <el-form-item prop="provinceId">
+                <el-select
+                  v-model="formData.data.provinceId"
+                  placeholder="省/洲"
+                  @change="(val) => getCityData(val, '30', true)"
+                >
+                  <el-option
+                    v-for="item in provinceData"
+                    :label="item.name"
+                    :value="item.id"
+                  >
+                  </el-option>
+                </el-select>
+              </el-form-item>
             </el-col>
             <el-col :span="8">
-              <el-select v-model="formData.data.aa" placeholder="城市">
-                <el-option v-for="item in 3" label="ceshi" value="1">
-                </el-option>
-              </el-select>
+              <el-form-item prop="cityId">
+                <el-select v-model="formData.data.cityId" placeholder="城市">
+                  <el-option
+                    v-for="item in cityData"
+                    :label="item.name"
+                    :value="item.id"
+                  >
+                  </el-option>
+                </el-select>
+              </el-form-item>
             </el-col>
           </el-row>
-          <el-row style="margin-top: 20px; width: 100%">
+          <el-row style="margin-top: 20px; width: 100%; margin-left: -10px">
             <el-col :span="24">
-              <el-input v-model="formData.data.bb" type="textarea"> </el-input>
+              <el-form-item prop="areaDetail">
+                <el-input v-model="formData.data.areaDetail" type="textarea">
+                </el-input>
+              </el-form-item>
             </el-col>
           </el-row>
         </template>
 
         <template #contact>
-          <el-row :gutter="10" style="width: 100%">
+          <el-row :gutter="10" style="width: 100%; margin-left: -15px">
             <el-col :span="8">
-              <el-input v-model="formData.data.aa" placeholder="联系人">
-              </el-input>
+              <el-form-item prop="contactPerson">
+                <el-input
+                  v-model="formData.data.contactPerson"
+                  placeholder="联系人"
+                >
+                </el-input>
+              </el-form-item>
             </el-col>
             <el-col :span="16">
-              <el-input v-model="formData.data.aa" placeholder="联系电话">
-              </el-input>
+              <el-form-item prop="contactNumber">
+                <el-input
+                  v-model="formData.data.contactNumber"
+                  placeholder="联系电话"
+                >
+                </el-input>
+              </el-form-item>
             </el-col>
           </el-row>
         </template>
@@ -154,6 +191,8 @@ const sourceList = ref({
     total: 3,
     pageNum: 1,
     pageSize: 10,
+    type: "",
+    keyword: "",
   },
 });
 let dialogVisible = ref(false);
@@ -161,6 +200,15 @@ let modalType = ref("add");
 let fileList = ref([]);
 let rules = ref({
   name: [{ required: true, message: "请输入供应商名称", trigger: "blur" }],
+  type: [{ required: true, message: "请选择供应商类型", trigger: "change" }],
+  countryId: [{ required: true, message: "请选择国家", trigger: "change" }],
+  provinceId: [{ required: true, message: "请选择省/洲", trigger: "change" }],
+  cityId: [{ required: true, message: "请选择城市", trigger: "change" }],
+  areaDetail: [{ required: true, message: "请输入详细地址", trigger: "blur" }],
+  contactPerson: [{ required: true, message: "请输入联系人", trigger: "blur" }],
+  contactNumber: [
+    { required: true, message: "请输入联系电话", trigger: "blur" },
+  ],
 });
 const { proxy } = getCurrentInstance();
 const selectConfig = reactive([
@@ -169,11 +217,11 @@ const selectConfig = reactive([
     prop: "type",
     data: [
       {
-        label: "普通车间",
+        label: "贸易商",
         value: "1",
       },
       {
-        label: "半自动化车间",
+        label: "工厂",
         value: "2",
       },
     ],
@@ -184,39 +232,50 @@ const config = computed(() => {
     {
       attrs: {
         label: "供应商类型",
-        prop: "name",
+        prop: "type",
+      },
+      render(type) {
+        return type === 1 ? "贸易商" : "工厂";
       },
     },
     {
       attrs: {
         label: "供应商编码",
-        prop: "remarks",
+        prop: "code",
       },
     },
     {
       attrs: {
         label: "供应商名称",
-        prop: "remarks",
+        prop: "name",
       },
     },
     {
       attrs: {
         label: "所在城市",
         prop: "remarks",
+        slot: "address",
       },
     },
     {
       attrs: {
         label: "联系人",
-        prop: "remarks",
+        prop: "contactPerson",
       },
     },
     {
       attrs: {
         label: "联系人电话",
-        prop: "remarks",
+        prop: "contactNumber",
+      },
+    },
+    {
+      attrs: {
+        label: "备注",
+        prop: "remark",
       },
     },
+
     {
       attrs: {
         label: "操作",
@@ -257,7 +316,7 @@ const config = computed(() => {
               ).then(() => {
                 // 删除
                 proxy
-                  .post("/productionProcesses/delete", {
+                  .post("/supplierInfo/delete", {
                     id: row.id,
                   })
                   .then((res) => {
@@ -292,7 +351,7 @@ const formConfig = computed(() => {
   return [
     {
       type: "radio",
-      prop: "name",
+      prop: "type",
       label: "供应商类型",
       required: true,
       border: true,
@@ -310,12 +369,14 @@ const formConfig = computed(() => {
     {
       type: "slot",
       slotName: "address",
+      prop: "countryId",
       label: "地址",
       required: true,
     },
     {
       type: "slot",
       slotName: "contact",
+      prop: "contactPerson",
       label: "联系信息",
       required: true,
     },
@@ -327,7 +388,7 @@ const formConfig = computed(() => {
     {
       type: "input",
       label: "备注",
-      prop: "remakes",
+      prop: "remark",
       itemType: "textarea",
     },
   ];
@@ -336,7 +397,7 @@ const getList = async (req) => {
   sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
   loading.value = true;
   proxy
-    .post("/productionProcesses/page", sourceList.value.pagination)
+    .post("/supplierInfo/page", sourceList.value.pagination)
     .then((message) => {
       console.log(message);
       sourceList.value.data = message.rows;
@@ -349,49 +410,58 @@ const getList = async (req) => {
 const openModal = () => {
   dialogVisible.value = true;
   modalType.value = "add";
-  formData.data = {};
+  formData.data = {
+    type: "1",
+    countryId: "China",
+  };
+  getCityData(formData.data.countryId, "20");
 };
 
 const submitForm = () => {
-  if (fileList.value.length > 0) {
-    byform.value.handleSubmit((valid) => {
-      formData.data.fileList = fileList.value;
-      submitLoading.value = true;
-      proxy.post("/productionProcesses/" + modalType.value, formData.data).then(
-        (res) => {
-          ElMessage({
-            message: modalType.value == "add" ? "添加成功" : "编辑成功",
-            type: "success",
-          });
-          fileList.value = [];
-          dialogVisible.value = false;
-          submitLoading.value = false;
-          getList();
-        },
-        (err) => {
-          console.log(err, "aswwwww");
-          submitLoading.value = false;
-        }
-      );
-    });
-  } else {
-    return ElMessage({
-      message: "请上传附件!",
-      type: "info",
-    });
-  }
+  byform.value.handleSubmit((valid) => {
+    // if (fileList.value.length > 0) {
+    //   formData.data.fileList = fileList.value;
+
+    // } else {
+    //   return ElMessage({
+    //     message: "请上传附件!",
+    //     type: "info",
+    //   });
+    // }
+
+    submitLoading.value = true;
+    proxy.post("/supplierInfo/" + modalType.value, formData.data).then(
+      (res) => {
+        ElMessage({
+          message: modalType.value == "add" ? "添加成功" : "编辑成功",
+          type: "success",
+        });
+        fileList.value = [];
+        dialogVisible.value = false;
+        submitLoading.value = false;
+        getList();
+      },
+      (err) => {
+        console.log(err, "aswwwww");
+        submitLoading.value = false;
+      }
+    );
+  });
 };
 
 const getDtl = (row) => {
   modalType.value = "edit";
-  proxy.post("/productionProcesses/detail", { id: row.id }).then((res) => {
-    fileList.value = [
-      {
-        id: "",
-        fileName: res.fileName,
-        path: "",
-      },
-    ];
+  proxy.post("/supplierInfo/detail", { id: row.id }).then((res) => {
+    getCityData(res.countryId, "20");
+    getCityData(res.provinceId, "30");
+    // fileList.value = [
+    //   {
+    //     id: "",
+    //     fileName: res.fileName,
+    //     path: "",
+    //   },
+    // ];
+    res.type = res.type + "";
     formData.data = res;
     dialogVisible.value = true;
   });
@@ -431,6 +501,29 @@ const handleRemove = (file) => {
 const handleClose = (index) => {
   fileList.value.splice(index, 1);
 };
+const countryData = ref([]);
+const provinceData = ref([]);
+const cityData = ref([]);
+
+const getCityData = (id, type, isChange) => {
+  proxy.post("/areaInfo/list", { parentId: id }).then((res) => {
+    if (type === "20") {
+      provinceData.value = res;
+      if (isChange) {
+        formData.data.provinceId = "";
+        formData.data.cityId = "";
+      }
+    } else if (type === "30") {
+      cityData.value = res;
+      if (isChange) {
+        formData.data.cityId = "";
+      }
+    } else {
+      countryData.value = res;
+    }
+  });
+};
+getCityData("0");
 getList();
 </script>
   

+ 215 - 90
src/views/purchaseManage/supplier/supplyPrice/index.vue

@@ -45,7 +45,7 @@
         ref="byform"
       >
         <template #details>
-          <div>
+          <div style="width: 100%">
             <el-button type="primary" @click="openProduct = true">
               添加货品
             </el-button>
@@ -57,21 +57,21 @@
               label-width="0px"
               style="margin-top: 15px"
             >
-              <el-table :data="formData.data.goodsList">
-                <el-table-column prop="productCode" label="货品编码" />
-                <el-table-column prop="productName" label="货品名称" />
-                <el-table-column prop="productName" label="规格型号" />
-                <el-table-column prop="productUnit" label="单位" />
-                <el-table-column prop="quantity" label="供应单价" width="150">
+              <el-table :data="formData.data.supplierPriceList">
+                <el-table-column prop="code" label="货品编码" />
+                <el-table-column prop="name" label="货品名称" min-width="150" />
+                <el-table-column prop="spec" label="规格型号" />
+                <el-table-column prop="unit" label="单位" />
+                <el-table-column prop="price" label="供应单价" min-width="150">
                   <template #default="{ row, $index }">
                     <el-form-item
-                      :prop="'goodsList.' + $index + '.quantity'"
-                      :rules="rules.quantity"
+                      :prop="'supplierPriceList.' + $index + '.price'"
+                      :rules="rules.price"
                       :inline-message="true"
                     >
                       <el-input-number
-                        v-model="row.quantity"
-                        :precision="2"
+                        v-model="row.price"
+                        :precision="4"
                         :controls="false"
                         :min="1"
                       />
@@ -147,7 +147,10 @@ let openProduct = ref(false);
 let modalType = ref("add");
 let fileList = ref([]);
 let rules = ref({
-  name: [{ required: true, message: "请输入供应价格名称", trigger: "blur" }],
+  supplierInfoId: [
+    { required: true, message: "请选择供应商", trigger: "change" },
+  ],
+  price: [{ required: true, message: "请输入供应单价", trigger: "blur" }],
 });
 const { proxy } = getCurrentInstance();
 const selectConfig = reactive([
@@ -170,38 +173,62 @@ const config = computed(() => {
   return [
     {
       attrs: {
-        label: "供应价格类型",
-        prop: "name",
+        label: "货品类型",
+        prop: "definition",
+      },
+      render(definition) {
+        return definition === 1 ? "产品" : definition === 2 ? "物料" : "";
+      },
+    },
+    {
+      attrs: {
+        label: "所属分类",
+        prop: "productClassifyName",
+      },
+    },
+    {
+      attrs: {
+        label: "货品编码",
+        prop: "productCode",
+      },
+    },
+    {
+      attrs: {
+        label: "货品名称",
+        prop: "productName",
       },
     },
     {
       attrs: {
-        label: "供应价格编码",
-        prop: "remarks",
+        label: "规格型号",
+        prop: "productSpec",
       },
     },
     {
       attrs: {
-        label: "供应价格名称",
-        prop: "remarks",
+        label: "单位",
+        prop: "productUnit",
       },
     },
     {
       attrs: {
-        label: "所在城市",
-        prop: "remarks",
+        label: "供应商类型",
+        prop: "supplierType",
+      },
+      render(supplierType) {
+        return supplierType === 1 ? "贸易商" : supplierType === 2 ? "工厂" : "";
       },
     },
     {
       attrs: {
-        label: "联系人",
-        prop: "remarks",
+        label: "供应商名称",
+        prop: "supplierName",
       },
     },
     {
       attrs: {
-        label: "联系人电话",
-        prop: "remarks",
+        label: "供应单价",
+        prop: "price",
       },
     },
     {
@@ -244,7 +271,7 @@ const config = computed(() => {
               ).then(() => {
                 // 删除
                 proxy
-                  .post("/productionProcesses/delete", {
+                  .post("/supplierPrice/delete", {
                     id: row.id,
                   })
                   .then((res) => {
@@ -265,7 +292,7 @@ const config = computed(() => {
 
 let formData = reactive({
   data: {
-    goodsList: [],
+    supplierPriceList: [],
   },
 });
 const formOption = reactive({
@@ -275,38 +302,38 @@ const formOption = reactive({
   rules: [],
 });
 const byform = ref(null);
-const formConfig = computed(() => {
-  return [
-    // {
-    //   type: "radio",
-    //   prop: "name",
-    //   label: "供应价格类型",
-    //   required: true,
-    //   border: true,
-    //   data: [
-    //     { label: "贸易商", value: "1" },
-    //     { label: "工厂", value: "2" },
-    //   ],
-    // },
-    {
-      type: "select",
-      prop: "name",
-      label: "供应商",
-      required: true,
-    },
-    {
-      type: "slot",
-      slotName: "details",
-      label: "供应明细",
-      required: true,
+const formConfig = reactive([
+  {
+    type: "select",
+    prop: "supplierInfoId",
+    label: "供应商",
+    required: true,
+    disabled: false,
+    isLoad: {
+      url: "/supplierInfo/page",
+      req: {
+        pageNum: 1,
+        pageSize: 9999,
+      },
+      labelKey: "name",
+      labelVal: "id",
+      method: "post",
+      resUrl: "rows",
     },
-  ];
-});
+  },
+  {
+    type: "slot",
+    slotName: "details",
+    prop: "supplierPriceList",
+    label: "供应明细",
+    required: true,
+  },
+]);
 const getList = async (req) => {
   sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
   loading.value = true;
   proxy
-    .post("/productionProcesses/page", sourceList.value.pagination)
+    .post("/supplierPrice/page", sourceList.value.pagination)
     .then((message) => {
       console.log(message);
       sourceList.value.data = message.rows;
@@ -319,53 +346,149 @@ const getList = async (req) => {
 const openModal = () => {
   dialogVisible.value = true;
   modalType.value = "add";
+  formConfig[0].disabled = false;
   formData.data = {
-    goodsList: [],
+    supplierPriceList: [],
+    renewWhileItExists: false,
   };
 };
 
 const submitForm = () => {
-  if (formData.data.goodsList.length > 0) {
-    byform.value.handleSubmit((valid) => {
-      submitLoading.value = true;
-      proxy.post("/productionProcesses/" + modalType.value, formData.data).then(
-        (res) => {
-          ElMessage({
-            message: modalType.value == "add" ? "添加成功" : "编辑成功",
-            type: "success",
-          });
-          fileList.value = [];
-          dialogVisible.value = false;
-          submitLoading.value = false;
-          getList();
-        },
-        (err) => {
-          console.log(err, "aswwwww");
-          submitLoading.value = false;
+  byform.value.handleSubmit((valid) => {
+    if (formData.data.supplierPriceList.length > 0) {
+      proxy.$refs.tableForm.validate((vaild) => {
+        if (vaild) {
+          if (!formData.data.id) {
+            const submitData = {
+              ...formData.data,
+              supplierPriceList: formData.data.supplierPriceList.map((x) => ({
+                productInfoId: x.productInfoId,
+                price: x.price,
+              })),
+            };
+            submitLoading.value = true;
+            proxy.post("/supplierPrice/" + modalType.value, submitData).then(
+              (res) => {
+                if (res.addSuccess) {
+                  ElMessage({
+                    message: modalType.value == "add" ? "添加成功" : "编辑成功",
+                    type: "success",
+                  });
+                  getList();
+                  dialogVisible.value = false;
+                  submitLoading.value = false;
+                } else {
+                  ElMessage({
+                    message: `已存在供应价格,价格为${res.existSupplierPriceList[0].price}`,
+                    type: "info",
+                  });
+                  ElMessageBox.confirm(
+                    "继续提交将修改已存在的单价数据, 是否继续?",
+                    "提示",
+                    {
+                      confirmButtonText: "确定",
+                      cancelButtonText: "取消",
+                      type: "warning",
+                    }
+                  )
+                    .then(() => {
+                      const arr = [];
+                      for (
+                        let i = 0;
+                        i < formData.data.supplierPriceList.length;
+                        i++
+                      ) {
+                        const iele = formData.data.supplierPriceList[i];
+                        for (
+                          let j = 0;
+                          j < res.existSupplierPriceList.length;
+                          j++
+                        ) {
+                          const jele = res.existSupplierPriceList[j];
+                          if (iele.productInfoId === jele.productInfoId) {
+                            jele.price = iele.price;
+                            arr.push(jele);
+                          }
+                        }
+                      }
+                      formData.data.supplierPriceList = arr.map((x) => ({
+                        productInfoId: x.productInfoId,
+                        price: x.price,
+                      }));
+                      formData.data.renewWhileItExists = true;
+                      proxy
+                        .post(
+                          "/supplierPrice/" + modalType.value,
+                          formData.data
+                        )
+                        .then((res) => {
+                          if (res.addSuccess) {
+                            ElMessage({
+                              message: "修改成功",
+                              type: "success",
+                            });
+                            getList();
+                            dialogVisible.value = false;
+                            submitLoading.value = false;
+                          }
+                        });
+                    })
+                    .catch(() => {});
+                }
+              },
+              (err) => {
+                submitLoading.value = false;
+              }
+            );
+          } else {
+            formData.data.supplierInfoId = formData.data.supplierInfoIdCopy;
+            formData.data.productInfoId =
+              formData.data.supplierPriceList[0].productInfoId;
+            formData.data.price = formData.data.supplierPriceList[0].price;
+            delete formData.data.supplierPriceList;
+            delete formData.data.supplierInfoIdCopy;
+            proxy
+              .post("/supplierPrice/" + modalType.value, formData.data)
+              .then((res) => {
+                ElMessage({
+                  message: "修改成功",
+                  type: "success",
+                });
+                getList();
+                dialogVisible.value = false;
+                submitLoading.value = false;
+              });
+          }
         }
-      );
-    });
-  } else {
-    return ElMessage({
-      message: "请添加供应明细!",
-      type: "info",
-    });
-  }
+      });
+    } else {
+      return ElMessage({
+        message: "请添加供应明细!",
+        type: "info",
+      });
+    }
+  });
 };
 
 const getDtl = (row) => {
   modalType.value = "edit";
-  proxy.post("/productionProcesses/detail", { id: row.id }).then((res) => {
-    fileList.value = [
+  formConfig[0].disabled = true;
+  dialogVisible.value = true;
+  formData.data = {
+    id: row.id,
+    supplierInfoIdCopy: row.supplierInfoId,
+    supplierInfoId: row.supplierName,
+    supplierPriceList: [
       {
-        id: "",
-        fileName: res.fileName,
-        path: "",
+        productInfoId: row.productInfoId,
+        name: row.productName,
+        code: row.productCode,
+        unit: row.productUnit,
+        spec: row.productSpec,
+        price: row.price,
       },
-    ];
-    formData.data = res;
-    dialogVisible.value = true;
-  });
+    ],
+  };
 };
 
 // const handleClickFile = (row) => {
@@ -381,7 +504,7 @@ const getDtl = (row) => {
 // };
 
 const handleRemove = (index) => {
-  formData.data.goodsList.splice(index, 1);
+  formData.data.supplierPriceList.splice(index, 1);
   return ElMessage({
     message: "删除成功!",
     type: "success",
@@ -389,12 +512,14 @@ const handleRemove = (index) => {
 };
 
 const pushGoods = (goods) => {
-  formData.data.goodsList = formData.data.goodsList.concat(goods);
+  const arr = goods.map((x) => ({ ...x, productInfoId: x.id, price: "" }));
+  formData.data.supplierPriceList = formData.data.supplierPriceList.concat(arr);
   return ElMessage({
     message: "添加成功!",
     type: "success",
   });
 };
+
 getList();
 </script>