fuliqi
2025-01-16 e5fae45afc610c0cbc5620f2e9138e2188dcf243
src/views/system/contract/contract/index.vue
@@ -23,7 +23,6 @@
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8" style="margin-top: 10px">
      <el-col :span="1.5">
        <el-button
@@ -88,8 +87,8 @@
      :before-close="handleClose"
      size="40%">
      <div style="margin-left: 20px;">
        <el-form :inline = "true" :model="form" class="table-expand" >
          <el-form-item label="合同名称" prop="name" >
        <el-form :inline="true" :model="form" class="table-expand">
          <el-form-item label="合同名称" prop="name">
            <el-input v-model="form.name" style="width: 600px;"></el-input>
          </el-form-item>
          <el-form-item label="公司名称" prop="unitId">
@@ -171,13 +170,104 @@
            </el-link
            >
            <div style="text-align: right; margin-top: 10px">
              <el-button type="primary" @click="handleImportRule">导入规则</el-button>
              <el-button type="primary" @click="submitForm">提交</el-button>
            </div>
          </el-collapse>
        </el-form>
      </div>
    </el-drawer>
    <!-- 导入规则对话框 -->
    <el-dialog
      :title="importRule.title"
      :visible.sync="importRule.open"
      width="1000px"
      append-to-body
    >
      <el-form ref="importRule" :model="importRule" :rules="importRuleRules" label-width="80px">
        <!--            <div class="row-right" style="margin-left: 80px">-->
        <!--              <div class="margin-5">-->
        <el-upload
          ref="importRuleUpload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="importRule.headers"
          :action="importRule.url"
          :disabled="importRule.isUploading"
          :file-list="fileList"
          :before-upload="beforeUpload"
          drag
          style="text-align: center"
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">
            将文件拖到此处,或<em>点击上传</em>
          </div>
          <div class="el-upload__tip text-center" slot="tip">
            <span>仅允许导入xls、xlsx格式文件。</span>
            <el-link
              type="primary"
              :underline="false"
              style="font-size: 0.7vw; vertical-align: baseline"
              @click="importTemplate"
            >下载模板
            </el-link
            >
          </div>
        </el-upload>
        <!--              </div>-->
        <!--            </div>-->
        <el-divider content-position="left">考核结果应用规则</el-divider>
        <div class="row-warp">
          <div
            class="row"
            v-for="(item, index) in importRule.ruleList"
            :key="index"
          >
            <div class="row-left" style="flex: 0.7">
              <div class="block">
                <el-form-item label="考核条件" prop="ruleList">
                  <el-input
                    v-model="item.scoreCondition"
                    style="width: 250px"
                  />
                </el-form-item>
              </div>
            </div>
            <div class="row-right">
              <div class="margin-5">
                <el-form-item label="规则描述" prop="ruleList">
                  <el-input
                    type="textarea"
                    v-model="item.description"
                    style="width: 300px"
                  />
                  <el-button
                    style="margin-left: 50px"
                    type="danger"
                    icon="el-icon-delete"
                    circle
                    @click="deleteImportRule(index)"
                  ></el-button>
                </el-form-item>
              </div>
            </div>
          </div>
        </div>
        <el-button
          style="margin-left: 50px"
          type="success"
          icon="el-icon-plus"
          circle
          @click="addImportRule"
        ></el-button>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="importRule.open = false">取 消</el-button>
        <el-button type="primary" @click="submitImportRule">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 合同导入对话框 -->
    <el-dialog
      :title="upload.title"
@@ -324,6 +414,7 @@
import {deptSelect} from "../../../../api/system/dept";
import {getToken} from "@/utils/auth";
import {ImagePreview} from "@/components/ImagePreview";
import {importRule} from "../../../../api/platform/contract";
export default {
  name: "Contract",
@@ -334,6 +425,7 @@
        name: '',
        status: ''
      },
      fileList: [],
      drawer: false,
      direction: 'rtl',
      loading: false,
@@ -355,6 +447,21 @@
        startTime: "",
        endTime: "",
      },
      // 规则导入参数
      importRule: {
        // 是否显示弹出层(合同导入)
        open: false,
        // 弹出层标题(合同导入)
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/contract/updateRule",
        ruleList: [],
      },
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
@@ -416,6 +523,17 @@
          },
        ],
      },
      // 表单校验
      importRuleRules: {
        ruleList: [
          {
            type: "array",
            required: true,
            message: "考核结果应用规则不能为空",
            trigger: "submit",
          },
        ],
      },
    };
  },
  created() {
@@ -424,6 +542,11 @@
    this.selectDept();
  },
  methods: {
    beforeUpload(file) {
      this.importRule.file = file
      this.fileList = [file]
      return false
    },
    handleClose(done) {
      this.$confirm('确认关闭?')
        .then(_ => {
@@ -438,8 +561,17 @@
        description: "",
      });
    },
    addImportRule() {
      this.importRule.ruleList.push({
        scoreCondition: "",
        description: "",
      });
    },
    deleteRule(index) {
      this.upload.ruleList.splice(index, 1);
    },
    deleteImportRule(index) {
      this.importRule.ruleList.splice(index, 1);
    },
    submitForm() {
      this.form.startTime = this.form.timezone[0]
@@ -460,6 +592,12 @@
      this.upload.title = "合同导入";
      this.upload.open = true;
    },
    /** 导入按钮操作 */
    handleImportRule() {
      this.resetImportRule();
      this.importRule.title = "规则导入";
      this.importRule.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download("system/contract/importTemplate", {}, `合同导入模板.xlsx`);
@@ -467,6 +605,22 @@
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传中处理
    handleRuleUploadProgress(event, file, fileList) {
      this.importRule.isUploading = true;
    },
    // 文件上传成功处理
    handleRuleSuccess(response, file, fileList) {
      this.importRule.open = false;
      this.importRule.isUploading = false;
      this.$refs.importRule.clearFiles();
      if (response.code != 200) {
        this.$message.warning(response.msg);
      } else {
        this.$message.success(response.msg);
      }
      this.getList();
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
@@ -479,6 +633,27 @@
        this.$message.success(response.msg);
      }
      this.getList();
    },
    // 提交导入规则
    submitImportRule() {
      let that = this;
      that.importRule.id = this.form.id
      that.importRule.ruleList = JSON.stringify(this.importRule.ruleList);
      that.loading = true;
      that.importRule.open = false;
      const file = this.importRule.file;
      let formData = new FormData()
      if(file) {
        formData.append("file", file)
      }
      formData.append('id', this.form.id);
      formData.append('ruleList', this.importRule.ruleList);
      importRule(formData).then(res => {
        this.$message.success("导入成功")
        that.loading = false;
        that.getRuleListById(that.importRule.id)
      })
      // that.resetImportRule();
    },
    // 提交上传文件
    submitFileForm() {
@@ -493,6 +668,20 @@
            that.reset();
          });
        }
      });
    },
    getRuleListById(id) {
      getRuleListByContractId(id).then((response) => {
        this.ruleData = response.data;
        if (this.ruleData) {
          this.ruleName = this.ruleData.map((item) => {
            return item.ruleName;
          });
          this.ruleName = [...new Set(this.ruleName)];
        }
      });
      getMoneyRulesByContractId(id).then((response) => {
        this.moneyRules = response.data;
      });
    },
    // 时间选择发生变化
@@ -554,8 +743,7 @@
    },
    /** 详情按钮操作 */
    handleDetail(item) {
      this.form = {
      }
      this.form = {}
      this.form.name = item.name
      this.form.unitId = item.unitId
      this.form.startTime = item.startTime
@@ -581,13 +769,38 @@
    handleDownload(data) {
      this.$download.resource(data);
    },
    resetImportRule() {
      this.importRule = {
        // 是否显示弹出层(合同导入)
        open: false,
        // 弹出层标题(合同导入)
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/contract/updateRule",
        ruleList: [],
      };
      this.resetForm("importRule");
    },
    reset() {
      this.upload = {
        // 是否显示弹出层(合同导入)
        open: false,
        name: undefined,
        unitId: undefined,
        timezone: undefined,
        // 弹出层标题(合同导入)
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/contract/importData",
        ruleList: [],
        unitId: "",
        startTime: "",
        endTime: "",
      };
      this.resetForm("form");
    },