<!-- 采购入库单 -->
<!--被inventory-record-old引用但未使用,打印已改成vue-easy-print-->
<template>
  <modal v-model="modal" width="700px">
    <!--  表单主要内容  -->
    <div class="content" ref="print" id="print">
      <div class="title" style="text-align: center;font-size: 20px;font-weight: bold;">
        盘点记录
        <span v-if="data.type">({{ data.type }})</span>
      </div>
      <div class="sub-title border"
        style="display: flex;
          justify-content: space-between;
          align-items: center;margin: 10px;font-size: 14px;
          font-weight: bold;border-bottom: 1px solid #000000;"
      >
        <span>申购信息</span>
      </div>
      <div class="row"
          style="padding: 0 20px;
          margin-bottom: 5px;
          display: flex;justify-content: space-between;
          align-items: center;">
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <div class="label">盘点时间：</div>
          <div class="value">{{ data.time }}</div>
        </div>
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <div class="label">操作人：</div>
          <div class="value">{{ data.operUser }}</div>
        </div>
      </div>
      <div class="row"
           style="padding: 0 20px;
            margin-bottom: 5px;
            display: flex;justify-content: space-between;
            align-items: center;"
      >
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <div class="label">是否异常：</div>
          <div class="value">{{ data.isError }}</div>
        </div>
      </div>
      <div class="sub-title border"
           style="display: flex;
          justify-content: space-between;
          align-items: center;margin: 10px;font-size: 14px;
          font-weight: bold;border-bottom: 1px solid #000000;"
      >
        <span>盘点明细</span>
      </div>
      <div class="row"
           style="padding: 0 20px;
            margin-bottom: 5px;
            display: flex;justify-content: space-between;
            align-items: center;"
      >
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <!-- 日盘 -->
          <div class="table" style="width: 100%;" v-if="data.type === '每日盘点'">
            <table style="border-collapse:collapse;border:none;width: 100%;">
              <tr>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">序号</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料标签</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料编码</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料名称</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">库存数量</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点数量</th>
              </tr>
              <tr
                v-for="(item, index) in list" :key="index"
                :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
              >
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ index + 1 }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.rfidCode }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialCode }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialName }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.quantity }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkQuantity }}</td>
              </tr>
            </table>
            <div class="no-print page">
              <Page :total="params.total" @on-change="changePage" show-elevator :page-size="6"/>
            </div>
          </div>
          <!-- 人工盘点 -->
          <div class="table" v-if="data.type === '人工盘点'">
            <table style="border-collapse:collapse;border:none;width: 100%;">
              <tr>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">序号</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料编码</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料名称</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料数</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">理论库存</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点库存</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">查看明细</th>
              </tr>
              <tr
                v-for="(item, index) in list" :key="index"
                :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
              >
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ index + 1 }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialCode }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialName }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.tagCount }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.quantity }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkQuantity }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;"><a href="#" @click="toDetail(item)">查看明细</a></td>
              </tr>
            </table>
            <div class="no-print page">
              <Page :total="params.total" @on-change="changePage" show-elevator :page-size="6"/>
            </div>
          </div>
          <!-- 自动盘点 -->
          <div class="table" v-if="data.type === '自动盘点'">
            <table style="border-collapse:collapse;border:none;width: 100%;">
              <tr>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">序号</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料编码</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料名称</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">库存件数</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">库存数量</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点件数</th>
                <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点数量</th>
              </tr>
              <tr
                  v-for="(item, index) in list" :key="index"
                  :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
              >
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ index + 1 }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialCode }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialName }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.tagCount }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.quantity }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkTagCount }}</td>
                <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkQuantity }}</td>
              </tr>
            </table>
            <div class="no-print page">
              <Page :total="params.total" @on-change="changePage" show-elevator :page-size="6"/>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="footer" slot="footer">
      <Button @click="cfm" class="btn" type="primary">打印</Button>
      <Button @click="cancel" class="btn">关闭</Button>
    </div>
    <vue-easy-print ref="print">
      <template>
        <div class="content" ref="print">
          <div class="title" style="text-align: center;font-size: 20px;font-weight: bold;">
            盘点记录
            <span v-if="data.type">({{ data.type }})</span>
          </div>
          <div class="sub-title border"
               style="display: flex;
          justify-content: space-between;
          align-items: center;margin: 10px;font-size: 14px;
          font-weight: bold;border-bottom: 1px solid #000000;"
          >
            <span>申购信息</span>
          </div>
          <div class="row"
               style="padding: 0 20px;
          margin-bottom: 5px;
          display: flex;justify-content: space-between;
          align-items: center;">
            <div class="col" style="flex: 1;display: flex;align-items: center;">
              <div class="label">盘点时间：</div>
              <div class="value">{{ data.time }}</div>
            </div>
            <div class="col" style="flex: 1;display: flex;align-items: center;">
              <div class="label">操作人：</div>
              <div class="value">{{ data.operUser }}</div>
            </div>
          </div>
          <div class="row"
               style="padding: 0 20px;
            margin-bottom: 5px;
            display: flex;justify-content: space-between;
            align-items: center;"
          >
            <div class="col" style="flex: 1;display: flex;align-items: center;">
              <div class="label">是否异常：</div>
              <div class="value">{{ data.isError }}</div>
            </div>
          </div>
          <div class="sub-title border"
               style="display: flex;
          justify-content: space-between;
          align-items: center;margin: 10px;font-size: 14px;
          font-weight: bold;border-bottom: 1px solid #000000;"
          >
            <span>盘点明细</span>
          </div>
          <div class="row"
               style="padding: 0 20px;
            margin-bottom: 5px;
            display: flex;justify-content: space-between;
            align-items: center;"
          >
            <div class="col" style="flex: 1;display: flex;align-items: center;">
              <!-- 日盘 -->
              <div class="table" style="width: 100%;" v-if="data.type === '每日盘点'">
                <table style="border-collapse:collapse;border:none;width: 100%;">
                  <tr>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">序号</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料标签</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料编码</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料名称</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">库存数量</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点数量</th>
                  </tr>
                  <tr
                    v-for="(item, index) in list" :key="index"
                    :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
                  >
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ index + 1 }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.rfidCode }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialCode }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialName }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.quantity }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkQuantity }}</td>
                  </tr>
                </table>
                <div class="no-print page">
                  <Page :total="params.total" @on-change="changePage" show-elevator :page-size="6"/>
                </div>
              </div>
              <!-- 人工盘点 -->
              <div class="table" v-if="data.type === '人工盘点'">
                <table style="border-collapse:collapse;border:none;width: 100%;">
                  <tr>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">序号</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料编码</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料名称</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料数</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">理论库存</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点库存</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">查看明细</th>
                  </tr>
                  <tr
                    v-for="(item, index) in list" :key="index"
                    :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
                  >
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ index + 1 }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialCode }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialName }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.tagCount }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.quantity }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkQuantity }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;"><a href="#" @click="toDetail(item)">查看明细</a></td>
                  </tr>
                </table>
                <div class="no-print page">
                  <Page :total="params.total" @on-change="changePage" show-elevator :page-size="6"/>
                </div>
              </div>
              <!-- 自动盘点 -->
              <div class="table" v-if="data.type === '自动盘点'">
                <table style="border-collapse:collapse;border:none;width: 100%;">
                  <tr>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">序号</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料编码</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">物料名称</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">库存件数</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">库存数量</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点件数</th>
                    <th style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">盘点数量</th>
                  </tr>
                  <tr
                    v-for="(item, index) in list" :key="index"
                    :class="
                    item.quantity === item.checkQuantity ? 'green' :
                    item.quantity > item.checkQuantity ? 'red' :
                    'err'"
                  >
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ index + 1 }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialCode }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.materialName }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.tagCount }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.quantity }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkTagCount }}</td>
                    <td style="padding: 5px;text-align: center;border:solid #dcdee2 1px;position: relative;font-size: 12px;">{{ item.checkQuantity }}</td>
                  </tr>
                </table>
                <div class="no-print page">
                  <Page :total="params.total" @on-change="changePage" show-elevator :page-size="6"/>
                </div>
              </div>
            </div>
          </div>
        </div>
      </template>
    </vue-easy-print>
    <template>
      <record-material-form v-model="selfShow" :data="selfData"></record-material-form>
    </template>
  </modal>
</template>

<script>
import VueEasyPrint from 'vue-easy-print'
// import print from 'print-js'
import { GetCheckDetailPageList } from '@/api/stock'
import RecordMaterialForm from './record-material-form'
export default {
  name: 'record-form',
  data () {
    return {
      modal: false,
      selfShow: false,
      selfData: {},
      currentData: {},
      list: [],
      params: {
        pageIndex: 1,
        pageSize: 6,
        total: 0
      }
    }
  },
  components: {
    RecordMaterialForm,
    VueEasyPrint
  },
  props: {
    value: {
      type: Boolean,
      default: false,
      require: true
    },
    data: {
      type: Object,
      default () {
        return {}
      }
    },
    materialCode: {
      type: String
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
      if (n) {
        this.params.pageIndex = 1
        this.getList()
      } else {
        this.list = []
      }
    }
  },
  methods: {
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getList () {
      let params = {
        id: this.data.id,
        ...this.params
      }
      GetCheckDetailPageList(params).then(res => {
        if (res.code === 0) {
          this.list = res.result.list
          this.params.total = res.result.totalCount
        }
      })
    },
    toDetail (item) {
      this.selfData = {
        ...this.data,
        ...item
      }
      this.selfShow = true
    },
    cfm () {
      this.$refs.print.print()
      // print({
      //   printable: 'print', // // 文档来源：pdf或图像的url，html元素的id或json数据的对象
      //   type: 'html', // 可打印的类型。可用的打印选项包括：pdf，html，图像，json和raw-html。
      //   targetStyles: ['*'] // 库在打印HTML元素时处理任何样式
      // })
    },
    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;
    }
  }
}
</style>
