<template>
  <div class="other">
    <el-form label-width="120px" ref="form" :model="form">
      <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="4">
          <el-form-item label="是否来料检验" prop="isComeCheck">
            <el-radio v-model="form.isComeCheck" :label="1">是</el-radio>
            <el-radio v-model="form.isComeCheck" :label="0">否</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="form.isComeCheck ==1 ">
          <el-form-item label="物料级别" prop="checkFormula">
            <el-select
              style="width: 100%"
              v-model="form.levelItem"
              placeholder="请选择"
            >
              <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 == 1">
          <el-form-item label="抽检比例" prop="checkProportion">
            <el-input
              type="number"
              :min="0.00"
              v-model="form.checkProportion"
              placeholder="请输入"
              clearable
            >
            <template slot="append">%</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" v-if="form.isComeCheck ==1 ">
          <el-form-item label="质检方案" prop="">
            <el-select
              style="width: 100%"
              v-model="form.qualityTemplateIds"
              filterable
              multiple
            >
              <el-option
                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>
  </div>
</template>

<script>
import { getQualityTemplate } from '@/api/material/list.js';
import {getByCode} from "@/api/system/dictionary-data";
  export default {
    props: {
      form: {
        type: Object,
        default: {}
      }
    },
    components: {},
    data() {
      return {
        qualityTemplateList:[],
        levelOptions:[],
      };
    },
    watch: {},
    created() {
      this.getQualityTemplateList();
      this.getDictList('level_type');
    },
    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]]
          };
        });
      },
      getQualityTemplateList() {
        getQualityTemplate().then(res => {
          this.qualityTemplateList = res
        })
      }
    }
  };
</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>
