haoxuan
2024-04-29 caeb71b06d19a8ffd854c19e5e4b58f7180cdce8
src/views/employeeSalary/salaryPlan/components/addDialog.vue
@@ -35,9 +35,9 @@
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="salaryType" label="薪资类型">
        <el-form-item prop="salaryTypeId" label="薪资类型">
          <el-select
            v-model="form.salaryType"
            v-model="form.salaryTypeId"
            style="width: calc(100% - 40px)"
            placeholder="请选择车间"
          >
@@ -45,7 +45,7 @@
              v-for="item in unitList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
@@ -65,9 +65,22 @@
          >
          </el-input> -->
          <div class="formula-input" v-html="form.salaryFormulaHtml"></div>
          <el-button class="formula-btn" type="text" @click="checkFormula()"
            >检查公式</el-button
          >
          <div class="formula-btn-right">
            <el-button
              class="formula-btn-t"
              type="text"
              :disabled="form.salaryFormulaHtml.length > 0 ? false : true"
              @click="deleteFormula()"
              >清除</el-button
            >
            <el-button
              class="formula-btn"
              :disabled="form.salaryFormulaHtml.length > 0 ? false : true"
              type="text"
              @click="checkFormula()"
              >检查公式</el-button
            >
          </div>
        </el-form-item>
        <div class="formula-error">
          <span v-if="form.error == 1" class="color_blue">
@@ -129,7 +142,7 @@
                    v-if="item.type == 2"
                    class="el-icon-setting margin_left_5px cursor_pointer"
                    style="font-size: 18px; color: gray"
                    @click="handleConstSetShow(2)"
                    @click="handleConstSetShow(10)"
                  ></i>
                </div>
              </div>
@@ -156,7 +169,7 @@
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="cancel" @click="cancelMethod()">取消</el-button>
        <el-button type="primary" @click="submitForm('form')">确 定</el-button>
        <el-button type="primary" :loading="isAddloading" @click="submitForm('form')">确 定</el-button>
      </span>
    </el-dialog>
    <BomDialog
@@ -168,15 +181,15 @@
    <SilkSetDialog
      ref="silkSetDialog"
      @confirmValueSave="confirmValueSave"
      :editRow="form"
      :editRow="{wildSilkList:wildSilkList}"
      title="配置"
    ></SilkSetDialog>
    <ConstantSetDialog
      ref="constantSetDialog"
      @confirmValueSave="confirmValueSave"
      :constType="constType"
      :editRow="form"
      :title="constType == 2 ? '配置' : '输入'"
      :editRow="constType == 10?{absenteeism:absenteeism}:form"
      :title="constType == 10 ? '配置' : '输入'"
    ></ConstantSetDialog>
  </div>
</template>
@@ -208,13 +221,15 @@
      form: {
        name: "",
        workTypes: [],
        salaryType: "",
        salaryTypeId: null,
        salaryFormula: "",
        salaryFormulaHtml: "",
        error: "",
        purchaseTypeList: [1],
        cycle: '1',
      },
      // 满勤奖设置
      absenteeism:{value:1,id:null},
      // 设置野纤的生丝标准
      wildSilkList: {value:'野纤',id:null},
      activeName: 1,
      formulaName: [
        {
@@ -310,7 +325,7 @@
            trigger: ["blur", "change"],
          },
        ],
        salaryType: [
        salaryTypeId: [
          { required: true, message: "请选择", trigger: ["blur", "change"] },
        ],
        salaryFormulaHtml: [
@@ -319,11 +334,14 @@
      },
      unitList: [],
      constType: "",
      isAddloading: false,
    };
  },
  computed: {},
  created() {
    this.handleGetBomKindDictList();
    this.handleGetBomKindDictList(9);
    this.handleGetBomKindDictList(10);
    this.getSelectDataList();
  },
  mounted() {},
@@ -346,39 +364,45 @@
        this.form = {
          name: "",
          workTypes: [],
          salaryType: "",
          salaryTypeId: null,
          salaryFormula: "",
          salaryFormulaHtml: "",
          error: "",
          purchaseTypeList: [1],
          cycle: '1',
        };
        this.$nextTick(() => {
          this.$refs["form"].resetFields();
          if (this.editRow.id) {
            this.form = JSON.parse(JSON.stringify(this.editRow));
            let salaryFormula=this.form.salaryFormula?this.form.salaryFormula:''
            this.form.salaryFormulaHtml=''
            this.form.salaryFormula=''
            this.form.purchaseTypeList =[1]
            let arr=salaryFormula?salaryFormula.split(','):[]
            let formulaNameArr=this.formulaName.concat(this.formulaNameTwo).concat(this.formulaSymbol)
            if(arr.length>0){
              for(let i in arr){
                for(let j in formulaNameArr){
                  let reg2 =
                    /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
                  if (reg2.test(arr[i])) {
                    this.formulaClick({ name: "常量数字", type: 3, width: 2, },arr[i]);
                  }else if(formulaNameArr[j].name==arr[i]){
                    this.formulaClick(formulaNameArr[j])
                  }
                }
              }
            }
            let salaryFormula = this.form.salaryFormula
              ? this.form.salaryFormula
              : "";
            this.form.salaryFormulaHtml = "";
            this.form.salaryFormula = "";
            let arr = salaryFormula ? salaryFormula.split(",") : [];
            this.getSalaryFormulaHtml(arr);
          }
        });
      }
    },
    getSalaryFormulaHtml(arr) {
      let formulaNameArr = this.formulaName
        .concat(this.formulaNameTwo)
        .concat(this.formulaSymbol);
      if (arr.length > 0) {
        for (let i in arr) {
          for (let j in formulaNameArr) {
            let reg2 =
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            if (reg2.test(arr[i])) {
              this.formulaClick(
                { name: "常量数字", type: 3, width: 2 },
                arr[i]
              );
            } else if (formulaNameArr[j].name == arr[i]) {
              this.formulaClick(formulaNameArr[j]);
            }
          }
        }
      }
    },
    // 点击生产数据和考勤及补贴数据 赋值计费公式定义
@@ -396,17 +420,28 @@
          name +
          "</span>";
      }
      this.form.salaryFormula = this.form.salaryFormula + name + ",";
      this.form.salaryFormula = this.form.salaryFormula + name + ",";
      this.form.salaryFormulaHtml = this.form.salaryFormulaHtml + string;
      this.$forceUpdate();
    },
    deleteFormula() {
      let salaryFormula = this.form.salaryFormula
              ? this.form.salaryFormula
              : "";
      let arr = salaryFormula.split(",");
      arr = arr.splice(0, arr.length - 1);
      arr = arr.splice(0, arr.length - 1);
      this.form.salaryFormulaHtml = "";
      this.form.salaryFormula = "";
      this.getSalaryFormulaHtml(arr);
    },
    checkFormula() {
      if (this.form.salaryFormula) {
        let string = true;
        let isString = '+-*/';
        let arr = this.form.salaryFormula.split(",");
        arr=arr.splice(0,arr.length-1)
        for (let i=0;i<arr.length;i++) {
        let isString = "+-*/";
        let arr = this.form.salaryFormula.split(",");
        arr = arr.splice(0, arr.length - 1);
        for (let i = 0; i < arr.length; i++) {
          if (arr[i] != "") {
            // 除数不能为0, 符号那边需要有值
            if (isString.indexOf(arr[i]) != -1 || arr[i] == "(") {
@@ -431,7 +466,7 @@
              }
            } else if (arr[i] == ")") {
              if (i < arr.length - 1) {
                if (isString.indexOf(arr[i+1]) == -1) {
                if (isString.indexOf(arr[i + 1]) == -1) {
                  string = false;
                  break;
                }
@@ -454,17 +489,29 @@
        }
        if (!string) {
          this.$set(this.form,'error',2)
          this.$set(this.form, "error", 2);
        } else {
          this.$set(this.form,'error',1)
          this.$set(this.form, "error", 1);
        }
      }
    },
    confirmValueSave(form, type) {
      if (type == 1) {
        this.form.purchaseTypeList = form.purchaseTypeList;
      } else if (type == 2) {
        this.form.cycle = form.cycle+'';
      if (type == 9) {
        let wildSilkList = form.wildSilkList;
        this.handleConfirmSave([
          {
            name:wildSilkList.join(','),
            id:this.wildSilkList.id
          }
        ],type)
      } else if (type == 10) {
        let absenteeism = form.absenteeism + "";
        this.handleConfirmSave([
          {
            name:absenteeism,
            id:this.absenteeism.id
          }
        ],type)
      } else if (type == 3) {
        this.formulaClick(
          {
@@ -478,11 +525,15 @@
    },
    // 野纤数量
    handleSlikSetShow() {
      this.handleGetBomKindDictList(9);
      this.$refs.silkSetDialog.islook = true;
    },
    // 满勤奖
    handleConstSetShow(val) {
      this.constType = val;
      if(val==10){
        this.handleGetBomKindDictList(10);
      }
      this.$refs.constantSetDialog.islook = true;
    },
    // 单位
@@ -490,24 +541,66 @@
      this.handleGetBomKindDictList();
      this.$refs.editDialog.editDialogVisible = true;
    },
    handleConfirmSave(dataList) {
      saveSalaryType({
        type: 8,
        values: dataList,
      }).then((res) => {
    handleConfirmSave(dataList,val) {
      let params={}
      if(val==9||val==10){
        params={
          type: val,
          values: dataList,
        }
      }else{
        params={
          type: 8,
          values: dataList,
        }
      }
      this.isAddloading = true;
      saveSalaryType(params).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "操作成功!",
            type: "success",
          });
          this.$refs.editDialog.editDialogVisible = false;
          this.handleGetBomKindDictList();
          if(val==9){
            this.$refs.silkSetDialog.islook = false;
          }else  if(val==10){
            this.$refs.constantSetDialog.islook = false;
          }else{
            this.$refs.editDialog.editDialogVisible = false;
          }
          this.handleGetBomKindDictList(val?val:'');
        }
        this.isAddloading = false;
      }).catch(() => {
                setTimeout(() => {
                  this.isAddloading = false;
                }, 3000);
      });
    },
    handleGetBomKindDictList() {
      getSalaryTypeList({ type: 8 }).then((res) => {
        this.unitList = res.data;
    handleGetBomKindDictList(val) {
      getSalaryTypeList({ type: val?val:8 }).then((res) => {
        if(val==9){
          // 野纤的生丝标准配置
          this.wildSilkList=(res.data&&res.data.length>0)?{
            ...res.data[0],
            value:res.data[0].name.split(',')||[]
          }:{
            id:null,
            value:['野纤']
          }
        }else if(val==10){
          // 考勤配置
          this.absenteeism=(res.data&&res.data.length>0)?{
            ...res.data[0],
            value:res.data[0].name||1
          }:{
            id:null,
            value:1
          }
        }else{
          this.unitList = res.data;
        }
      });
    },
    getSelectDataList() {
@@ -531,29 +624,25 @@
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.checkFormula()
          if(this.form.error==2){
          this.checkFormula();
          if (this.form.error == 2) {
            this.$message.error("请检查计费公式定义!");
            return true;
          }
          let form = JSON.parse(JSON.stringify(this.form));
          let arr = form.salaryFormula.split(",");
           arr=arr.splice(0,arr.length-1)
           form.salaryFormula=arr.join(",")
          if (form.purchaseTypeList.length == 0) {
            this.$message.error("请点击野纤数量配置生丝标准!");
            return true;
          }
          let workTypes=[]
          if(form.workTypes&&form.workTypes.length>0){
            for(let i in form.workTypes){
          let arr = form.salaryFormula.split(",");
          arr = arr.splice(0, arr.length - 1);
          form.salaryFormula = arr.join(",");
          let workTypes = [];
          if (form.workTypes && form.workTypes.length > 0) {
            for (let i in form.workTypes) {
              workTypes.push({
                workName:form.workTypes[i].label,
                id:form.workTypes[i].value
              })
                workName: form.workTypes[i].label,
                id: form.workTypes[i].value,
              });
            }
          }
          form.workTypes=workTypes
          form.workTypes = workTypes;
          saveSalaryPlan(form).then((res) => {
            if (res.code == 200) {
              this.$message({
@@ -631,7 +720,7 @@
    }
  }
  .formula-input {
    width: calc(100% - 100px);
    width: calc(100% - 90px);
    height: 100px;
    padding: 10px 10px;
    overflow-y: auto;
@@ -639,12 +728,19 @@
    border: 1px solid #e4e7ed;
    cursor: not-allowed;
    float: left;
    margin-right: 20px;
  }
  .formula-btn {
  .formula-btn-right {
    width: 60px;
    float: left;
    margin-top: 80px;
    position: relative;
    .formula-btn-t {
      margin-left: 10px;
    }
    .formula-btn {
      margin-top: 40px;
    }
  }
  .formula-error {
    width: calc(100% - 110px);
    line-height: 28px;