lihang
2023-07-13 7ce592bb5a5b9e0dc78786e727f042b95ebc81c8
Source/UBCS-WEB/src/components/BatchImport/ShowImportData.vue
@@ -57,11 +57,12 @@
                border
                :data="tab1Table"
                style="width: 100%"
                height="400px"
                height="40vh"
                highlight-current-row
                @current-change="resembleRowChange"
                @selection-change="tab1TableSelectChange"
                v-if="cloNamesList.length > 1"
                v-loading="tab1Loading"
              >
                <el-table-column
                  v-if="type !== 'batchApplyCode'"
@@ -75,8 +76,10 @@
                  width="100px"
                  align="center"
                >
                  <template>
                    <el-button type="text">重新编辑</el-button>
                  <template #default="{ row }">
                    <el-button type="text" @click="reEdit(row)"
                      >重新编辑</el-button
                    >
                  </template>
                </el-table-column>
                <el-table-column
@@ -101,7 +104,8 @@
                  border
                  :data="currentSelectedResemble"
                  style="width: 100%"
                  height="200px"
                  height="20vh"
                  v-loading="tab1BottomTableLoading"
                >
                  <el-table-column
                    v-for="item in resembleColumList"
@@ -136,12 +140,9 @@
            <el-tab-pane :label="tab2Name" name="tab2">
              <el-table
                border
                v-loading="tab2Loading"
                :data="tab2Table"
                :height="
                  type === 'batchApplyCode' && tab2Table.length > 0
                    ? '400px'
                    : '700px'
                "
                height="60vh"
              >
                <el-table-column
                  v-for="item in successTableColumns"
@@ -177,7 +178,7 @@
    </div>
    <template #footer>
      <div>
        <el-button size="small" type="primary" @click="submit"
        <el-button size="small" type="primary" @click="submit" :loading="submitLoading"
          >确定导入</el-button
        >
        <el-button size="small" @click="dialogVisible = false">取消</el-button>
@@ -185,10 +186,9 @@
    </template>
    <FormTemplateDialog
      ref="FormTemplateDialog"
      type="detail"
      v-bind="currentSelectedResembleRow"
      :visible.sync="currentSelectedResembleRow.visible"
      title="查看详细信息"
      :visible.sync="currentSelectedResembleRow.formTemplateVisible"
      @submit="FormTemplateSubmit"
    ></FormTemplateDialog>
  </el-dialog>
</template>
@@ -200,6 +200,7 @@
  getFormTemplate,
  getCurretnSelectedRowResemble,
  submitHistoryimport,
  addSaveCode,
} from "../../api/batchImport/index";
import ResembleQuery from "../FormTemplate/ResembleQuery.vue";
import FormTemplate from "../FormTemplate/FormTemplate.vue";
@@ -268,7 +269,7 @@
      activeTab: "tab1",
      cloNamesList: [], //列表头部字段
      localCodeClassifyOid: "",
      codeRuleOid: '',
      codeRuleOid: "",
      resembleColumList: [], //相似项查出来的列表字段
      currentSelectedResemble: [],
      currentSelectedResembleRow: {
@@ -276,9 +277,16 @@
        codeClassifyOid: "",
        rowOid: "",
        formTemplateVisible: false,
        type: "detail",
        title: "查看详细信息",
        setForm: {},
      },
      secVOList: [],
      batchApplyCodeTableData: {},
      savedList: [],
      tab1Loading: false,
      tab2Loading: false,
      tab1BottomTableLoading: false,
      submitLoading: false
    };
  },
@@ -295,50 +303,72 @@
      }
      this.isExpand = !this.isExpand;
    },
    async treeNodeClick(data) {
      console.log(data);
    async treeNodeClick(data, first) {
      if (this.type === "batchApplyCode") {
        if (first === true) {
          this.codeRuleOid = data.codeRuleOid;
          // 第一次打开直接赋值不校验
          this.batchApplyCodeTableData[data.codeRuleOid] = {
            name: data.name,
            templateOid: data.oid,
            cloNamesList: data.cloNamesList,
            codeClassifyOid: data.codeClassifyOid,
            codeRuleOid: data.codeRuleOid,
          };
          // 不是第一次打开需要优先校验
        } else if (this.localCodeClassifyOid === data.codeClassifyOid) {
          console.log("重复点击");
        } else {
          if (this.$refs.CodeApply) {
            if (!(await this.$refs.CodeApply.validate())) {
              this.$message.warning("请填写便编码申请!");
              this.activeTab = "tab2";
              this.$refs.tree.setCurrentKey(this.localCodeClassifyOid);
              return false;
            }
          }
        }
        if (!this.batchApplyCodeTableData[data.codeRuleOid]) {
          this.batchApplyCodeTableData[data.codeRuleOid] = {
            name: data.name,
            templateOid: data.oid,
            cloNamesList: data.cloNamesList,
            codeClassifyOid: data.codeClassifyOid,
            codeRuleOid: data.codeRuleOid,
          };
        }
      }
      this.localCodeClassifyOid = data.codeClassifyOid;
      this.cloNamesList = data.cloNamesList;
      this.templateOid = data.oid;
      if (this.type === "batchApplyCode") {
        this.codeRuleOid = data.codeRuleOid
        if (!this.batchApplyCodeTableData[data.codeRuleOid]) {
          this.batchApplyCodeTableData[data.codeRuleOid] = {};
        } else {
          console.log(this.$refs.CodeApply, 'this.$refs.CodeApply');
          if (this.$refs.CodeApply) {
            console.log(this.$refs.CodeApply.validate(), 'this.$refs.CodeApply.validate()');
            if (!(await this.$refs.CodeApply.validate())) {
              this.$message.warning('请填写便编码申请!')
              return false
            }
          }
          // 校验
        }
      }
      this.tab1Loading = true
      getResembleTable({
        codeClassifyOid:
          this.type === "batchApplyCode" ? data.codeRuleOid : this.templateOid,
        redisOid: this.redisOid + "-resemble",
      }).then((res) => {
        this.tab1Table = res.data.data;
        if (this.type === "batchApplyCode" && this.tab1Table.length > 0) {
        this.tab1Loading = false
        this.tab1Table = res.data.data.filter(
          (item) => !this.savedList.includes(item.oid)
        );
        if (this.type === "batchApplyCode") {
          this.batchApplyCodeTableData[data.codeRuleOid]["tab1"] =
            res.data.data;
            this.tab1Table;
        }
      });
      this.tab2Loading = true
      // 获取正确数据
      getSuccessTable({
        codeClassifyOid:
          this.type === "batchApplyCode" ? data.codeRuleOid : this.templateOid,
        redisOid: this.redisOid + "-ok",
      }).then((res) => {
        this.tab2Loading = false
        this.tab2Table = res.data.data;
        if (this.tab2Table.length > 0 && this.type === "batchApplyCode") {
          this.batchApplyCodeTableData[data.codeRuleOid]["codeApply"] = {}
          this.batchApplyCodeTableData[data.codeRuleOid]["codeApply"] = {};
          this.batchApplyCodeTableData[data.codeRuleOid]["tab2"] =
              res.data.data;
            res.data.data;
          if (this.$refs.CodeApply) {
            this.$refs.CodeApply.loading = true;
          }
@@ -356,27 +386,101 @@
      this.selectedTab1Table = selection;
    },
    resembleRowChange(row) {
      if (!row || !row.oid) {
        return;
      }
      this.tab1BottomTableLoading = true
      getCurretnSelectedRowResemble({
        redisOid: this.redisOid + "-resemble-data",
        dataOid: row.oid,
      }).then((res) => {
        this.tab1BottomTableLoading = false
        this.currentSelectedResemble = res.data.data;
      });
    },
    openFormTemlpate(row) {
      this.currentSelectedResembleRow = {
        visible: true,
        formTemplateVisible: true,
        templateOid: row.codetemplateoid,
        codeClassifyOid: this.localCodeClassifyOid,
        rowOid: row.rowOid,
        type: "detail",
        title: "查看详细信息",
        setForm: {},
      };
    },
    submit() {
      const params = {
    async submit() {
      let params = {
        classifyAttr:
          this.type === "historyImport" ? this.classifyAttr : undefined,
          this.type === "historyImport" || this.type === "batchApplyCode"
            ? this.classifyAttr
            : undefined,
        improt: this.type === "historyImport" ? true : false,
        codeImprotSaveDatVOList: [
      };
      if (this.type === "batchApplyCode") {
        if (this.$refs.CodeApply) {
          if (!(await this.$refs.CodeApply.validate())) {
            this.$message.warning("请填写便编码申请!");
            this.activeTab = "tab2";
            return false;
          }
        }
        let lookedCodeRuleOidList = Object.keys(this.batchApplyCodeTableData);
        let noLookCodeRuleOidList = this.leftTree.filter(
          (item) => !lookedCodeRuleOidList.includes(item.codeRuleOid)
        );
        let noLookName = noLookCodeRuleOidList.map((item) => item.name);
        if (noLookName.length > 0) {
          this.$message.warning(`数据${noLookName}还未曾查看,请先查看!`);
          return false;
        }
        let errorData = [];
        let successData = [];
        for (const key in this.batchApplyCodeTableData) {
          if (Object.hasOwnProperty.call(this.batchApplyCodeTableData, key)) {
            const element = this.batchApplyCodeTableData[key];
            if (element.tab1.length > 0) {
              errorData.push(element);
            }
            if (element.tab2.length > 0) {
              successData.push(element);
            }
          }
        }
        if (successData.length === 0) {
          this.$message.warning("导入的数据中没有正确的数据!");
          return;
        }
        if (errorData.length > 0) {
          await this.$confirm(
            errorData.map((item) => item.name).join("、") +
              ",这几个编码规则下的有错误数据和相似项数据没有处理,您如果继续保存的话,这些数据将会被自动舍弃,是否继续?",
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          );
        }
        params.codeImprotSaveDatVOList = successData.map((item) => {
          return {
            Clos: item.cloNamesList,
            dataList: item.tab2,
            orderDTO: {
              codeClassifyOid: item.codeClassifyOid,
              templateOid: item.templateOid,
              secDTOList: item.localSecVOList.map((itm) => {
                return {
                  secOid: itm.oid,
                  secValue: item.codeApply[itm.oid],
                };
              }),
            },
          };
        });
      } else {
        params.codeImprotSaveDatVOList = [
          {
            Clos: this.cloNamesList.map((item) => item.title),
            dataList: this.tab2Table.concat(this.selectedTab1Table),
@@ -386,14 +490,49 @@
              secDTOList: this.secDTOList,
            },
          },
        ],
      };
        ];
      }
        this.submitLoading = true
      submitHistoryimport(params).then((res) => {
        console.log(res);
        this.submitLoading = false
                console.log(res);
        if (res.data.code === 200) {
          this.$message.success(res.data.msg);
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    // 重新编辑
    reEdit(row) {
      console.log(row, "row");
      this.currentSelectedResembleRow = {
        templateOid: row.codetemplateoid,
        codeClassifyOid: row.codeclassifyid,
        rowOid: row.oid,
        formTemplateVisible: true,
        type: "add",
        title: "编辑数据后重新入库",
        setForm: row,
      };
    },
    // 直接编辑后保存
    FormTemplateSubmit(form) {
      addSaveCode(form).then((res) => {
        console.log(res);
        if (res.data.code === 200) {
          this.savedList.push(form.oid);
          this.$message.success("新增成功!");
          this.treeNodeClick(
            this.leftTree.find((item) => item.codeRuleOid === this.codeRuleOid)
          );
          this.currentSelectedResembleRow = {
            templateOid: "",
            codeClassifyOid: "",
            rowOid: "",
            formTemplateVisible: false,
            type: "detail",
            title: "查看详细信息",
            setForm: {},
          };
        }
      });
    },
@@ -407,7 +546,7 @@
      deep: true,
      handler(arr) {
        if (arr.length > 0) {
          this.treeNodeClick(arr[0]);
          this.treeNodeClick(arr[0], true);
          this.$nextTick(() => {
            this.$refs.tree.setCurrentKey(arr[0]["codeClassifyOid"]);
          });
@@ -442,6 +581,7 @@
    }
  }
  .right {
    transition: all 0.5s;
    margin-left: 20px;
    margin-top: 30px;
  }