<template>
  <div class="other">
    <fieldset :disabled="disabled" style="border: none; padding: 0; margin: 0;">
    <el-form label-width="130px" ref="form" :model="formModel" :rules="rules">
      <div class="divider">
        <div class="title">
          <div class="ele-bg-primary"></div>
          <span>质量配置</span>
        </div>
        <div class="ele-bg-primary ele-width"></div>
      </div>
      <el-row :gutter="24">
        <el-col :span="8" v-for="(item, index) in formList" :key="index">
          <el-form-item
            :label="
              item.dataType == 1
                ? '是否采购来料检验'
                : item.dataType == 2
                ? '是否委外来料检验'
                : '是否受托来料检验'
            "
            prop="isComeCheck"
          >
            <el-radio v-model="item.isComeCheck" :label="1" :disabled="disabled">是</el-radio>
            <el-radio v-model="item.isComeCheck" :label="0" :disabled="disabled">否</el-radio>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="6" v-if="form.isComeCheck == 1">
          <el-form-item label="检验标准" prop="inspectionStandards"> -->
        <!-- 计量 计重 -->
        <!-- <el-select
              style="width: 100%"
              v-model="form.inspectionStandards"
              placeholder="请选择"
            >
              <el-option
                v-for="item in inspectionStandardsList"
                :label="item.label"
                :value="item.value"
                :key="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="6" v-if="form.isComeCheck == 1">
          <el-form-item label="物料级别" prop="levelItem">
            <el-select
              style="width: 100%"
              v-model="form.levelItem"
              placeholder="请选择"
              disabled
            >
              <el-option
                v-for="item in levelOptions"
                :label="item.label"
                :value="item.value"
                :key="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="form.isComeCheck == 1">
          <el-form-item label="检验方式" prop="checkFormula">
            <DictSelection
              dictName="检验方案"
              clearable
              v-model="form.checkFormula"
            >
            </DictSelection>
          </el-form-item>
        </el-col>
        <el-col
          :span="6"
          v-if="form.isComeCheck == 1 && form.checkFormula == 2"
        >
          <el-form-item label="取样数量" prop="sampleProportion">
            <el-input
              type="number"
              :min="0.0"
              v-model="form.sampleProportion"
              placeholder="请输入"
              style="width: calc(100% - 85px)"
              clearable
            >
            </el-input>
            <DictSelection
              style="width: 85px"
              dictName="计量单位"
              placeholder=" "
              v-model="form.sampleProportionUnit"
            ></DictSelection>
          </el-form-item>
        </el-col>

        <el-col :span="8" v-if="form.isComeCheck == 1">
          <el-form-item label="质检方案" prop="qualityTemplateIds">
            <el-select
              style="width: 100%"
              v-model="form.qualityTemplateIds"
              filterable
              multiple
              :multiple-limit="1"
            >
              <el-option
                @click.native="qualityTemplateIdsChange(item)"
                v-for="item in qualityTemplateList"
                :key="item.id"
                :value="item.id"
                :label="item.qualitySchemeTemplateName"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
      </el-row>
    </el-form>
    </fieldset>
  </div>
</template>

<script>
  import { getQualityTemplate } from '@/api/material/list.js';
  import { getByCode } from '@/api/system/dictionary-data';
  export default {
    props: {
      form: {
        type: Array,
        default: () => []
      },
      disabled: {
        type: Boolean,
        default: false
      }
    },
    components: {},
    computed: {
      formList() {
        return Array.isArray(this.form) ? this.form : [];
      },
      formModel() {
        return {
          list: this.formList
        };
      }
    },
    data() {
      return {
        qualityTemplateList: [],
        levelOptions: [
          {
            label: '特级',
            value: '特级'
          },
          {
            label: '一级',
            value: '一级'
          },
          {
            label: '二级',
            value: '二级'
          },
          {
            label: '三级',
            value: '三级'
          }
        ],
        inspectionStandardsList: [],
        rules: {
          checkFormula: [
            {
              required: true,
              message: '请选择检验方式',
              trigger: 'change'
            }
          ],
          qualityTemplateIds: [
            {
              required: true,
              message: '请选择质检方案',
              trigger: 'change'
            }
          ]
        }
      };
    },
    watch: {},
    created() {
      this.getQualityTemplateList();

      this.getDictListIqoCode('iqo_code');
    },
    methods: {
      // async getDictList(code) {
      //   // debugger;
      //   let { data: res } = await getByCode(code);
      //   this.levelOptions = res.map((item) => {
      //     let values = Object.keys(item);
      //     return {
      //       value: Number(values[0]),
      //       label: item[values[0]]
      //     };
      //   });
      // },
      qualityTemplateIdsChange(data) {
        this.form.sampleProportion = data.sampleProportion;
        this.form.sampleProportionUnit = data.sampleProportionUnit;
      },
      levelChange(val) {
        this.form.levelItem = val;
      },
      async getDictListIqoCode(code) {
        let { data: res } = await getByCode(code);
        this.inspectionStandardsList = res.map((item) => {
          let values = Object.keys(item);
          return {
            value: Number(values[0]),
            label: item[values[0]]
          };
        });
      },
      getQualityTemplateList() {
        getQualityTemplate({
          type: this.form.dataType == 1 ? 1 : this.form.dataType == 2 ? 6 : 5,
          status: 1,
          size: 999
        }).then((res) => {
          console.log(res, 'res');
          this.qualityTemplateList = res.list;
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .other {
    background: #fff;
    padding: 1px 17px;
  }
  .divider {
    margin: 0px 0 20px;
    .title {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      div {
        width: 8px;
        height: 20px;
        margin-right: 10px;
      }
      span {
        font-size: 20px;
      }
    }
    .ele-width {
      width: 100%;
      height: 2px;
    }
  }
  .form-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .line-select {
      margin-left: 15px;
    }
  }
</style>
