<!-- 采购入库单 -->
<!--虽然在tag里引用了但未使用，打印已改成vue-easy-print-->
<template>
  <modal v-model="modal" :footer-hide="true" width="700px">
    <!--  表单主要内容  -->
    <div class="content" ref="print">
      <div class="title">
        采购入库单
      </div>
      <div class="sub-title border">
        <span>入库信息</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料编码：</div>
          <div class="value">{{ data.materialCode }}</div>
        </div>
        <div class="col">
          <div class="label">物料名称：</div>
          <div class="value">{{ data.materialName }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料规格：</div>
          <div class="value">{{ data.spec }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">到货数量：</div>
          <div class="value">{{ data.quantity }}</div>
        </div>
        <div class="col">
          <div class="label">抽检比例：</div>
          <div class="value">{{ data.checkPercent }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>质检明细</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="table">
            <table>
              <tr>
                <th>序号</th>
                <th>物料标签值</th>
                <th>抽检米数</th>
                <th>短少</th>
                <th>抽纱</th>
                <th>褶皱</th>
                <th>赃物</th>
                <th>破洞</th>
                <th>缩水</th>
                <th>质检结论</th>
              </tr>
              <tr
                v-for="(item, index) in data.quantityCheckDetails"
                :key="index"
                :class="
                  item.checkJudgment === '不合格' ? 'red' :
                  item.checkJudgment === '目测合格' ? 'orange' : 'green'"
              >
                <td>{{ index }}</td>
                <td>{{ item.rfidCode }}</td>
                <td>{{ item.quantity }}</td>
                <td>{{ item.lakeNum }}</td>
                <td>{{ item.drawnworkNum }}</td>
                <td>{{ item.foldNum }}</td>
                <td>{{ item.dirtNum }}</td>
                <td>{{ item.potholeNum }}</td>
                <td>{{ item.shrinkPercent }}</td>
                <td>{{ item.checkJudgment }}</td>
              </tr>
            </table>
          </div>
        </div>
      </div>
    </div>
    <div class="footer">
      <Button @click="cancel" class="btn" type="primary" style="background-color: #9D9D9D;">关闭</Button>
      <Button @click="cfm" class="btn" type="primary">打印</Button>
    </div>
    <vue-easy-print ref="print">
      <template>
        <div class="content" ref="print">
          <div class="title">
            采购入库单
          </div>
          <div class="sub-title border">
            <span>入库信息</span>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">物料编码：</div>
              <div class="value">{{ data.materialCode }}</div>
            </div>
            <div class="col">
              <div class="label">物料名称：</div>
              <div class="value">{{ data.materialName }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">物料规格：</div>
              <div class="value">{{ data.spec }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">到货数量：</div>
              <div class="value">{{ data.quantity }}</div>
            </div>
            <div class="col">
              <div class="label">抽检比例：</div>
              <div class="value">{{ data.checkPercent }}</div>
            </div>
          </div>
          <div class="sub-title border">
            <span>质检明细</span>
          </div>
          <div class="row">
            <div class="col">
              <div class="table">
                <table>
                  <tr>
                    <th>序号</th>
                    <th>物料标签值</th>
                    <th>抽检米数</th>
                    <th>短少</th>
                    <th>抽纱</th>
                    <th>褶皱</th>
                    <th>赃物</th>
                    <th>破洞</th>
                    <th>缩水</th>
                    <th>质检结论</th>
                  </tr>
                  <tr
                    v-for="(item, index) in data.quantityCheckDetails"
                    :key="index"
                    :class="
                  item.checkJudgment === '不合格' ? 'red' :
                  item.checkJudgment === '目测合格' ? 'orange' : 'green'"
                  >
                    <td>{{ index }}</td>
                    <td>{{ item.rfidCode }}</td>
                    <td>{{ item.quantity }}</td>
                    <td>{{ item.lakeNum }}</td>
                    <td>{{ item.drawnworkNum }}</td>
                    <td>{{ item.foldNum }}</td>
                    <td>{{ item.dirtNum }}</td>
                    <td>{{ item.potholeNum }}</td>
                    <td>{{ item.shrinkPercent }}</td>
                    <td>{{ item.checkJudgment }}</td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </div>
      </template>
    </vue-easy-print>
  </modal>
</template>

<script>
import VueEasyPrint from 'vue-easy-print'
export default {
  name: 'quality-form',
  data () {
    return {
      modal: false
    }
  },
  components: {
    VueEasyPrint
  },
  props: {
    data: {
      type: Object,
      default () {
        return {}
      }
    },
    value: {
      type: Boolean,
      default: false,
      require: true
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
    }
  },
  methods: {
    cfm () {
      // 虽然在tag里引用了，但未使用
      this.$refs.print.print()
    },
    cancel () {
      this.modal = false
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  .title {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
  }
  .sub-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px;
    font-size: 14px;
    font-weight: bold;
    &.border {
      border-bottom: 1px solid #000000;
    }
    .go {
      font-size: 10px;
      font-weight: normal;
      color: #0000ff;
    }
  }
  .row {
    padding: 0 20px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .col {
      flex: 1;
      display: flex;
      align-items: center;
      .table {
        width: 100%;
        table {
          border-collapse:collapse;
          border:none;
          width: 100%;
          tr {
            td,th {
              padding: 5px;
              text-align: center;
              border:solid #dcdee2 1px;
              position: relative;
              font-size: 12px;
              th {
                background-color: #eeeeee;
              }
            }
            &.green {
              color: #4B7902;
            }
            &.red {
              color: red;
            }
            &.orange {
              color: #B8741A;
            }
          }
        }
      }
    }
  }
  .card {
    margin-bottom: 5px;
    background-color: #FFFFFF;
    border: 1px solid rgba(215, 215, 215, 1);
    border-radius: 5px;
    .border {
      border-bottom: 1px solid #5d6c7b;
    }
    .line {
      width: 100%;
      border-bottom: 1px solid #5d6c7b;
    }
  }
}
.footer {
  padding-top: 2vw;
  width: 100%;
  display: flex;
  justify-content: center;
  .btn {
    border: none;
    width: 9vw;
    min-width: 100px;
    height: 2vw;
    min-height: 32px;
    font-size: .8vw;
    &:first-child {
      margin-right: 30px;
    }
  }
}
</style>
