<template>
    <el-dialog
      :title="titleMap[mode]"
      v-model="visible"
      :size="1000"
      destroy-on-close
      id="bigDialog"
      class="bigDialog"
      @closed="$emit('closed')"
    >
      <el-container v-loading="loading">
        <el-main style="padding: 0 20px 20px 20px">
          <el-form
          ref="dialogForm"
          :model="form"
          label-width="85px"
          label-position="right"
          :rules="rule1"
        >
          <el-row>
            <el-col :md="12" :sm="24">
              <el-form-item label="关联工段">
                <el-input v-model="form.mgroup_name" placeholder="关联工段" disabled/>
              </el-form-item>
            </el-col>
            <el-col :md="12" :sm="24">
              <el-form-item label="当前班次">
                <el-input v-model="form.shift_name" placeholder="当前班次" disabled/>
              </el-form-item>
            </el-col>
            <el-col :md="12" :sm="24">
              <el-form-item label="当前班组">
                <el-input v-model="form.team_name" placeholder="当前班组" disabled/>
              </el-form-item>
            </el-col>
            <el-col :md="12" :sm="24">
              <el-form-item label="班组组长">
                <el-input v-model="form.team_name" placeholder="班组组长" disabled/>
              </el-form-item>
            </el-col>
            <el-col :md="12" :sm="24">
              <el-form-item label="开始时间">
                <el-input v-model="form.start_time" placeholder="开始时间" disabled/>
              </el-form-item>
            </el-col>
            <el-col :md="12" :sm="24">
              <el-form-item label="结束时间">
                <el-input v-model="form.end_time" placeholder="结束时间" disabled/>
              </el-form-item>
            </el-col>
            <el-divider />
          </el-row>
        </el-form>
        <sc-form-table
          v-model="form.list"
          :addTemplate="addTemplate"
          :hideAdd="hideAdd"
          :hideDelete="hideDelete"
          placeholder="暂无数据"
        >
          <el-table-column prop="material" label="关联产物" min-width="150">
            <template #default="scope">
              <span v-if="scope.row.id">{{ scope.row.material_name }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="testitem" label="质检项目" min-width="150">
            <template #default="scope">
              <span v-if="scope.row.id">{{ scope.row.testitem_name }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="val_avg" label="平均值" min-width="150">
            <template #default="scope">
              <el-input
                v-model="scope.row.val_avg"
                placeholder="请输入内容"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="num_test" label="检验次数" min-width="150">
            <template #default="scope">
              <el-input
                v-model="scope.row.num_test"
                placeholder="请输入内容"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="num_ok" label="合格次数" min-width="150">
            <template #default="scope">
              <el-input
                v-model="scope.row.num_ok"
                placeholder="请输入内容"
              ></el-input>
            </template>
          </el-table-column>
        </sc-form-table>
        </el-main>
        <el-footer>
          <el-button type="primary" :loading="isSaveing" @click="submit">保存</el-button>
          <el-button @click="visible = false">取消</el-button>
        </el-footer>
      </el-container>
    </el-dialog>
  </template>
  
  <script>
  export default {
    emits: ["success", "closed"],
    data() {
      return {
        addTemplate: {
          material: "",
          testitem: "",
          val_avg: "",
          num_test: "",
          num_ok: "",
        },
        hideAdd:true,
        hideDelete:true,
        loading: false,
        mode: "add",
        titleMap: {
          add: "质量检验",
          edit: "质量检验",
          show: "质量检验",
        },
        form: {
          type:10,
          list:[]
        },
        rules: {
            name: [{required: true, message: "请输入", trigger: "blur"}],
            number: [{required: true, message: "请输入", trigger: "blur"}],
            keeper_name: [{required: true, message: "请输入", trigger: "blur"}],
            belong_dept: [{required: true, message: "请选择", trigger: "blur"}]
          },
        visible: false,
        isSaveing: false,
        keeperOptions: [],
        depOptions: [],
        selectionFilters: [],
        setFiltersVisible: false,
        teamOptions:[],
        shiftOptions:[],
      };
    },
    mounted() {
      //是否已经保存过
      //若新增，调用init接口，若编辑修改，调get接口
    },
    methods: {
      
      //显示
      open(mode = "add") {
        this.mode = mode;
        this.visible = true;
        return this;
      },
      getReceptionist(data) {
        this.form.leader=data.id;
        this.form.leader_name=data.name
      },
      //表单提交方法
      submit() {
        this.isSaveing = true;
            this.$API.qm.updateQuastat.req('bulk',this.form.list).then(res=>{
              this.isSaveing = false;
              this.$emit("success", this.form, this.mode);
              this.visible = false;
              this.$message.success("操作成功");
            }).catch(res=>{
              this.isSaveing = false;
            })
        // this.$refs.dialogForm.validate(async (valid) => {
        //   if (valid) {

        //   }
        // });
      },
      //表单注入数据
      setData(data) {
        Object.assign(this.form,data);
        this.getsflogItem(this.form.id);
      },
      getsflogItem(id){
        this.$API.wpm.sflog.init_test.req(id).then(res=>{
          this.form.list = res;
        })
      },
      //设置过滤项
      setFilters(filters) {
        this.selectionFilters = filters;
        this.setFiltersVisible = true;
      },
    },
  };
  </script>
  
  <style scoped>
  #bigDialog{
    width: 90%;
  }
  </style>
  