<template>
  <div>
    <div class="borderless">
      <div class="customer-head">
        <div class="customer-back">
          <el-button
            type="danger"
            style="border: none;background: none;color: red"
            icon="el-icon-arrow-left"
            @click="backToList"
            >返回列表
          </el-button>
        </div>
        <el-button
          class="el-button--small-yh add-customer-btn"
          type="primary"
          size="small"
          @click="editCustomer"
          >保存数据
        </el-button>
      </div>
      <containerTitle
        title="基础资料"
        style="margin-top: 60px"
      ></containerTitle>
      <basic-container>
        <avue-form
          ref="form"
          class="trading-form"
          v-model="form"
          :option="option"
        >
        </avue-form>
      </basic-container>
      <containerTitle title="事业编考试的记录"></containerTitle>
      <basic-container>
        <avue-crud
          ref="crud"
          :option="option2"
          :data="dataList"
          :table-loading="loading"
          @saveColumn="saveColumn"
          :cell-style="cellStyle"
        >
          <template slot="menuLeft">
            <el-button
              type="primary"
              @click="dataList.push({ $cellEdit: true })"
              size="small"
              :disabled="detailData.status == 1"
              >新增
            </el-button>
          </template>
          <template slot="menu" slot-scope="{ row, index }">
            <el-button
              size="small"
              type="text"
              @click="rowCell(row, index)"
              :disabled="detailData.status == 1"
              >编辑</el-button
            >
            <el-button
              size="small"
              type="text"
              @click="rowDel(row, index)"
              :disabled="detailData.status == 1"
              >删除</el-button
            >
          </template>
        </avue-crud>
      </basic-container>
    </div>
  </div>
</template>

<script>
import { detail, submit, delItem } from "@/api/basicData/facultyManagement";
import { addAllsalary, addAllsalary2 } from "@/util/calculate";
export default {
  name: "index",
  data() {
    return {
      form: {},
      dataList: [],
      option: {
        menuBtn: false,
        labelWidth: 140,
        column: [
          {
            label: "姓名",
            prop: "cname",
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 6
          },
          {
            label: "身份证",
            prop: "idNumber",
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 6
          },
          {
            label: "性别",
            prop: "gender",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=sex",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "联系电话",
            prop: "phone",
            span: 6
          },
          {
            label: "入职时间",
            prop: "joiningDate",
            type: "date",
            valueFormat: "yyyy-MM-dd",
            span: 6
          },
          {
            label: "转正时间",
            prop: "birthdate",
            type: "date",
            valueFormat: "yyyy-MM-dd",
            span: 6
          },
          {
            label: "校龄开始日期",
            prop: "schoolAgeSalaryDate",
            type: "month",
            valueFormat: "yyyy-MM-dd",
            span: 6
          },
          {
            label: "校龄",
            prop: "schoolAge",
            type: "number",
            controls: false,
            precision: 0,
            minRows: 0,
            span: 6
          },
          {
            label: "所在部门",
            prop: "inSection",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=in_section",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 6
          },
          {
            label: "级部",
            prop: "department",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=department",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "班级",
            prop: "inStaffRoom",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=in_staff_room",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "职务",
            prop: "compileCategory",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=compile_category",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "职工类别",
            prop: "staffType",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=staff_type",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "授课类别",
            prop: "classType",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=class_type",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            row: true,
            span: 6
          },
          {
            label: "工资拨付标准",
            prop: "salaryWithdrawalStandard",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "职级工资",
            prop: "rankWithdrawalStandard",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "履约奖",
            prop: "performanceAward",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "校龄工资",
            prop: "schoolAgeSalary",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "增资",
            prop: "capitalIncrease",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "学历工资",
            prop: "educationSalary",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "职级等级工资",
            prop: "rankSalary",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "工资基数工资",
            prop: "salaryBase",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "工作量工资",
            prop: "workloadSalary",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "双休日工作量工资标准",
            prop: "doubleCease",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "虚拟工作量工资标准",
            prop: "virtualWorkloadSalary",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "日常考核工资",
            prop: "dailyAssessmentCriteria",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "日常考核等级工资",
            prop: "dailyAssessmentSalary",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "虚拟日常考核标准",
            prop: "virtualDailyAssessmentCriteria",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "学期绩效工资",
            prop: "termPerformanceSalary",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          // {
          //   label: "领导干部补贴工资",
          //   prop: "leadingCadreSubsidy",
          //   precision: 2,
          //   type: "number",
          //   controls: false,
          //   span: 6
          // },
          {
            label: "领导干部考核补贴工资",
            prop: "assessLeadingCadreSubsidy",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          // {
          //   label: "备课组长补贴",
          //   prop: "prepareLessons",
          //   precision: 2,
          //   type: "number",
          //   controls: false,
          //   span: 6
          // },
          {
            label: "备课组长考核补贴标准",
            prop: "assessPrepareLessons",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          // {
          //   label: "教研组长补贴",
          //   prop: "teachingResearch",
          //   precision: 2,
          //   type: "number",
          //   controls: false,
          //   span: 6
          // },
          {
            label: "教研组长补贴",
            prop: "assessTeachingResearch",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "班主任补贴标准",
            prop: "teacherSubsidy",
            precision: 2,
            type: "number",
            controls: false,
            span: 6
          },
          {
            label: "班主任考核补贴标准",
            prop: "teacherAssessSubsidy",
            precision: 2,
            type: "number",
            controls: false,
            row: true,
            span: 6
          },
          {
            label: "教师类别",
            prop: "salaryWithdrawalStandardName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Salary_allocation_standard",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 6
          },
          {
            label: "职级拨付标准",
            prop: "rankWithdrawalStandardName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Level_Allocation_Criteria",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "履约奖标准",
            prop: "performanceAwardName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Performance_Award_Criteria",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "增资标准",
            prop: "capitalIncreaseName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Capital_increase_standard",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "学历",
            prop: "code",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=marital_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "职级等级",
            prop: "rankSalaryName",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=Grade_salary",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },

          {
            label: "工资基数",
            prop: "salaryBaseName",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=Wage_base",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },

          {
            label: "工作量标准",
            prop: "workloadSalaryName",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=Workload_Wages",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },

          {
            label: "日常考核标准",
            prop: "dailyAssessmentCriteriaName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Daily_Assessment_Criteria",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },

          {
            label: "日常考核等级",
            prop: "dailyAssessmentSalaryName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Daily_assessment_grade_salary",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },

          {
            label: "学期绩效标准",
            prop: "termPerformanceSalaryName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Term_Performance_Pay",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          // {
          //   label: "领导干部补贴标准",
          //   prop: "leadingCadreSubsidyName",
          //   type: "select",
          //   dicUrl:
          //     "/api/blade-system/dict-biz/dictionary?code=Standards_for_subsidies_for_leading_cadres",
          //   props: {
          //     label: "dictValue",
          //     value: "dictValue"
          //   },
          //   span: 6
          // },
          {
            label: "领导干部补贴标准",
            prop: "assessLeadingCadreSubsidyName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Standards_for_subsidies_for_leading_cadres",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          // {
          //   label: "备课组长补贴标准",
          //   prop: "prepareLessonsName",
          //   type: "select",
          //   dicUrl:
          //     "/api/blade-system/dict-biz/dictionary?code=Standard_for_Leader_of_Lesson_Preparation",
          //   props: {
          //     label: "dictValue",
          //     value: "dictValue"
          //   },
          //   span: 6
          // },
          {
            label: "备课组长补贴标准",
            prop: "assessPrepareLessonsName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Standard_for_Leader_of_Lesson_Preparation",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          // {
          //   label: "教研组长补贴标准",
          //   prop: "teachingResearchName",
          //   type: "select",
          //   dicUrl:
          //     "/api/blade-system/dict-biz/dictionary?code=Standard_for_Teacher-Leader",
          //   props: {
          //     label: "dictValue",
          //     value: "dictValue"
          //   },
          //   span: 6
          // },
          {
            label: "教研组长考核补贴标准",
            prop: "assessTeachingResearchName",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=Standard_for_Teacher-Leader",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            row: true,
            span: 6
          },
          {
            label: "正班、副班",
            prop: "doubleTeachers",
            type: "radio",
            dataType: "string",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=double_teachers",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "是否享受公办待遇",
            prop: "enjoyOfficeTreatment",
            type: "radio",
            dataType: "string",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=TF_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "备注",
            prop: "remarks",
            type: "textarea",
            span: 24,
            minRows: 2
          }
        ]
      },
      option2: {
        align: "center",
        addBtn: false,
        refreshBtn: false,
        editBtn: false,
        delBtn: false,
        border: true,
        menuWidth: 120,
        stripe: true,
        column: [
          {
            label: "考试日期",
            prop: "birthdate",
            type: "date",
            valueFormat: "yyyy-MM-dd",
            cell: true
          },
          {
            label: "备注",
            prop: "remarks",
            cell: true
          }
        ]
      }
    };
  },
  props: {
    detailData: {
      type: Object
    }
  },
  created() {
    if (this.detailData.id) {
      this.getDetail(this.detailData.id);
    }
    if (this.detailData.status == 1) {
      this.option.disabled = true;
    }
  },
  methods: {
    cellStyle() {
      return "padding:0;height:40px;";
    },
    getDetail(id) {
      detail(id)
        .then(res => {
          this.form = res.data.data;
          this.dataList = res.data.data.causeList;
        })
        .finally(() => {
          // this.loading = false;
          // this.showBut = true;
          // this.pageLoading = false;
        });
    },
    rowCell(row, index) {
      if (row.$cellEdit == true) {
        this.$set(row, "$cellEdit", false);
      } else {
        this.$set(row, "$cellEdit", true);
      }
    },
    rowDel(row, index) {
      this.$confirm("确定删除数据?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        if (row.id) {
          delItem(row.id).then(res => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.dataList.splice(index, 1);
          });
        } else {
          this.$message({
            type: "success",
            message: "删除成功!"
          });
          this.dataList.splice(index, 1);
        }
      });
    },
    //修改提交触发
    editCustomer() {
      this.$refs["form"].validate((valid, done) => {
        done();
        if (valid) {
          const num = addAllsalary(
            this.form.salaryWithdrawalStandard,
            this.form.rankWithdrawalStandard,
            this.form.virtualWorkloadSalary
          );
          const num2 = addAllsalary2(
            this.form.salaryBase,
            this.form.workloadSalary,
            this.form.dailyAssessmentCriteria,
            this.form.termPerformanceSalary
          );
          if (num != num2) {
            return this.$message.error(
              "拨付金额" + num + "不等于标准金额" + num2
            );
          }
          submit({ ...this.form, causeList: this.dataList })
            .then(res => {
              this.$message.success("保存成功");
              this.form = res.data.data;
              this.dataList = res.data.data.causeList;
            })
            .finally(() => {});
        } else {
          return false;
        }
      });
    },
    //返回列表
    backToList() {
      this.$emit("goBack");
    }
  }
};
</script>

<style lang="scss" scoped>
.trading-form ::v-deep .el-form-item {
  margin-bottom: 8px !important;
}
::v-deep .el-form-item__error {
  display: none !important;
}
.img-form ::v-deep .el-form-item {
  height: 150px;
  line-height: 150px;
  margin-bottom: 8px !important;
}
.img-form ::v-deep .avue-upload__icon {
  font-size: 20px;
  width: 150px;
  height: 150px;
  line-height: 150px;
}
</style>
