fuliqi
2024-12-08 0311359d2b04fc7176509b00a383dce057443001
src/views/system/contract/contract/index.vue
@@ -87,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">
@@ -170,7 +170,7 @@
            </el-link
            >
            <div style="text-align: right; margin-top: 10px">
<!--              <el-button type="primary" @click="handleImportRule">导入规则</el-button>-->
              <el-button type="primary" @click="handleImportRule">导入规则</el-button>
              <el-button type="primary" @click="submitForm">提交</el-button>
            </div>
          </el-collapse>
@@ -184,46 +184,44 @@
      width="1000px"
      append-to-body
    >
      <el-form ref="form" :model="upload" :rules="rules" label-width="80px">
            <div class="row-right" style="margin-left: 80px">
              <div class="margin-5">
                <el-upload
                  ref="upload"
                  :limit="1"
                  accept=".xlsx, .xls"
                  :headers="upload.headers"
                  :action="upload.url"
                  :disabled="upload.isUploading"
                  :on-progress="handleFileUploadProgress"
                  :on-success="handleFileSuccess"
                  :data="upload"
                  :auto-upload="false"
                  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: 12px; vertical-align: baseline"
                      @click="importTemplate"
                    >下载模板
                    </el-link
                    >
                  </div>
                </el-upload>
              </div>
            </div>
      <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 upload.ruleList"
            v-for="(item, index) in importRule.ruleList"
            :key="index"
          >
            <div class="row-left" style="flex: 0.7">
@@ -249,7 +247,7 @@
                    type="danger"
                    icon="el-icon-delete"
                    circle
                    @click="deleteRule(index)"
                    @click="deleteImportRule(index)"
                  ></el-button>
                </el-form-item>
              </div>
@@ -261,13 +259,13 @@
          type="success"
          icon="el-icon-plus"
          circle
          @click="addRule"
          @click="addImportRule"
        ></el-button>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="upload.open = false">取 消</el-button>
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="importRule.open = false">取 消</el-button>
        <el-button type="primary" @click="submitImportRule">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 合同导入对话框 -->
@@ -416,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",
@@ -426,6 +425,7 @@
        name: '',
        status: ''
      },
      fileList: [],
      drawer: false,
      direction: 'rtl',
      loading: false,
@@ -461,6 +461,7 @@
        url: process.env.VUE_APP_BASE_API + "/system/contract/updateRule",
        ruleList: [],
      },
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
@@ -522,6 +523,17 @@
          },
        ],
      },
      // 表单校验
      importRuleRules: {
        ruleList: [
          {
            type: "array",
            required: true,
            message: "考核结果应用规则不能为空",
            trigger: "submit",
          },
        ],
      },
    };
  },
  created() {
@@ -530,6 +542,11 @@
    this.selectDept();
  },
  methods: {
    beforeUpload(file) {
      this.importRule.file = file
      this.fileList = [file]
      return false
    },
    handleClose(done) {
      this.$confirm('确认关闭?')
        .then(_ => {
@@ -544,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]
@@ -568,6 +594,7 @@
    },
    /** 导入按钮操作 */
    handleImportRule() {
      this.resetImportRule();
      this.importRule.title = "规则导入";
      this.importRule.open = true;
    },
@@ -578,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) {
@@ -590,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() {
@@ -604,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;
      });
    },
    // 时间选择发生变化
@@ -665,8 +743,7 @@
    },
    /** 详情按钮操作 */
    handleDetail(item) {
      this.form = {
      }
      this.form = {}
      this.form.name = item.name
      this.form.unitId = item.unitId
      this.form.startTime = item.startTime
@@ -692,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");
    },