<!-- 采购入库单 -->
<!--被record-form引用，打印已改成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.time }}</div>
        </div>
        <div class="col">
          <div class="label">操作人：</div>
          <div class="value">{{ data.operUser }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">是否异常：</div>
          <div class="value">{{ data.isError }}</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>
              </tr>
              <tr
                v-for="(item, index) in list" :key="index"
                :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
              >
                <td>{{ index }}</td>
                <td>{{ item.rfidCode }}</td>
                <td>{{ item.quantity }}</td>
                <td>{{ item.checkQuantity }}</td>
                <td>{{ item.inStorageDay }}</td>
              </tr>
            </table>
            <div class="no-print page">
              <Page :total="params.total" @on-change="changePage" show-elevator />
            </div>
          </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.time }}</div>
            </div>
            <div class="col">
              <div class="label">操作人：</div>
              <div class="value">{{ data.operUser }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">是否异常：</div>
              <div class="value">{{ data.isError }}</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>
                  </tr>
                  <tr
                    v-for="(item, index) in list" :key="index"
                    :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
                  >
                    <td>{{ index }}</td>
                    <td>{{ item.rfidCode }}</td>
                    <td>{{ item.quantity }}</td>
                    <td>{{ item.checkQuantity }}</td>
                    <td>{{ item.inStorageDay }}</td>
                  </tr>
                </table>
                <div class="no-print page">
                  <Page :total="params.total" @on-change="changePage" show-elevator />
                </div>
              </div>
            </div>
          </div>
        </div>
      </template>
    </vue-easy-print>
  </modal>
</template>

<script>
import VueEasyPrint from 'vue-easy-print'
import { GetCheckDetailPageList } from '@/api/stock'

export default {
  name: 'record-form',
  data () {
    return {
      list: [],
      modal: false,
      params: {
        pageIndex: 1,
        pageSize: 6,
        total: 0
      }
    }
  },
  components: {
    VueEasyPrint
  },
  props: {
    value: {
      type: Boolean,
      default: false,
      require: true
    },
    data: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
      if (n) {
        this.getList()
      }
    }
  },
  methods: {
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getList () {
      let params = {
        id: this.data.id,
        materialCode: this.data.materialCode,
        ...this.params
      }
      GetCheckDetailPageList(params).then(res => {
        if (res.code === 0) {
          this.list = res.result.list
          this.params.total = res.result.totalCount
        }
      })
    },
    cfm () {
      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 {
            &.red {
              td {
                color: red;
                &:first-child {
                  color: #000;
                }
              }
            }
            &.err {
              td {
                color: orange;
                &:first-child {
                  color: #000;
                }
              }
            }
            &.green {
              td {
                color: green;
                &:first-child {
                  color: #000;
                }
              }
            }
            td,th {
              padding: 5px;
              text-align: center;
              border:solid #dcdee2 1px;
              position: relative;
              font-size: 12px;
              th {
                background-color: #eeeeee;
              }
            }
          }
        }
        .page {
          padding-top: 20px;
          text-align: center;
        }
      }
    }
  }
  .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>
