
<!--
 * @Author: zwq
 * @Date: 2023-06-29 14:12:48
 * @LastEditors: zwq
 * @LastEditTime: 2023-06-30 09:07:57
 * @Description: 
-->
<template>
  <base-table border :table-props="tableProps" :table-data="tableData" @emitFun="inputChange" />
</template>

<script>
import basicAdd from "@/mixins/basic-add";
import inputArea from "./inputArea";
import selectMember from "./selectMember";
import selectTime from "./selectTime";
import i18n from "@/i18n";
const tableProps = [
  {
    prop: "containmentLocaleName",
    label: "遏制区域设置",
    align: "center",
  },
  {
    prop: "developCountermeasuresName",
    label: "拟定对策",
    align: "center",
  },
  {
    prop: "controlleQuantity",
    label: "应受控数量",
    align: "center",
    subcomponent: inputArea,
  },
  {
    prop: "actualQuantity",
    label: "实际数量",
    align: "center",
    subcomponent: inputArea,
  },
  {
    prop: "defectQuantity",
    label: "不良数量",
    align: "center",
    subcomponent: inputArea,
  },
  {
    prop: "userName",
    label: "负责人",
    align: "center",
    subcomponent: selectMember,
  },
  {
    prop: "completionDate",
    label: "完成日期",
    align: "center",
    subcomponent: selectTime,
  },
];
export default {
  components: {
    inputArea,
    selectMember,
  },
  mixins: [basicAdd],
  props: {
    roleList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      urlOptions: {
        submitURL: "/code/startEightDisciplinePreliminaryAnalysis/",
      },
      tableProps,
      visible: false,
      tableData: [
        {
          containmentLocaleName: "装配线",
          containmentLocale: 1,
          developCountermeasuresName: "让步接收",
          developCountermeasures: 1,
          roleList: this.roleList,
        },
        {
          containmentLocaleName: "生产线",
          containmentLocale: 2,
          developCountermeasuresName: "分选返工",
          developCountermeasures: 2,
          roleList: this.roleList,
        },
        {
          containmentLocaleName: "实验室",
          containmentLocale: 3,
          developCountermeasuresName: "隔离",
          developCountermeasures: 3,
          roleList: this.roleList,
        },
        {
          containmentLocaleName: "成品在途",
          containmentLocale: 4,
          developCountermeasuresName: "退换货",
          developCountermeasures: 4,
          roleList: this.roleList,
        },
        {
          containmentLocaleName: "第三方中间商",
          containmentLocale: 5,
          developCountermeasuresName: "通知供应商",
          developCountermeasures: 5,
          roleList: this.roleList,
        },
      ],
      id: "",
    };
  },
  computed: {
    dataRule() {
      return {
        // description: [{ required: true, message: this.$t("validate.required"), trigger: "blur" }],
      };
    },
  },
  methods: {
    init(id) {
      this.id = id;
      this.visible = true;
      this.$nextTick(() => {});
    },
    inputChange(data) {
      switch (data.sType) {
        case 1:
          this.tableData[data._pageIndex - 1][data.prop] = data[data.prop];
          break;
        case 2:
          this.tableData[data._pageIndex - 1].userName = data.string
            ? data.string.split("+")[1]
            : "";
          this.tableData[data._pageIndex - 1].userId = data.string ? data.string.split("+")[0] : "";
          break;
        case 3:
          this.tableData[data._pageIndex - 1][data.prop] = data.time;
          break;
        default:
          console.log(val);
      }
    },
    formClear() {},
    // 表单提交
    dataFormSubmit() {
      console.log(this.tableData);
          let putData = {
            eightDisciplineStatus: 4,
            examineStatus: 1,
            id: this.id,
          };
          this.$http.put("/code/startEightDiscipline", putData).then(({ data }) => {
            if (data && data.code === 0) {
            } else {
              this.$message.error(data.msg);
            }
          });
        this.tableData.forEach((item) => {
          item.startEightDisciplineId = this.id;
        });
          this.$http.post("/code/startEightDisciplineTemporaryTreatmentMeasures/save/list", this.tableData)
          .then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg);
            }
            this.$message({
              message: this.$t("prompt.success"),
              type: "success",
              duration: 500,
              onClose: () => {
                this.visible = false;
                this.$emit("refreshDataList");
              },
            });
          });
    },
  },
};
</script>

<style lang="scss">
.mod-sys__menu {
  .menu-list,
  .icon-list {
    .el-input__inner,
    .el-input__suffix {
      cursor: pointer;
    }
  }
  &-icon-popover {
    width: 458px;
    overflow: hidden;
  }
  &-icon-inner {
    width: 478px;
    max-height: 258px;
    overflow-x: hidden;
    overflow-y: auto;
  }
  &-icon-list {
    width: 458px;
    padding: 0;
    margin: -8px 0 0 -8px;
    > .el-button {
      padding: 8px;
      margin: 8px 0 0 8px;
      > span {
        display: inline-block;
        vertical-align: middle;
        width: 18px;
        height: 18px;
        font-size: 18px;
      }
    }
  }
}
</style>
