<!-- 质检单 -->
<template>
  <modal v-model="modal" width="1000px" class-name="vertical-center-modal">
    <!--  表单主要内容  -->
    <div class="content" ref="print">
      <div class="title" style="text-align: center;font-size: 20px;font-weight: bold;">
        质检单
      </div>
      <div class="sub-title border"
           style="display: flex;
          justify-content: space-between;
          align-items: center;
          margin: 10px;
          font-size: 14px;
          border-bottom: 1px solid #000000;
          font-weight: bold;"
      >
        <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[tabIndex] && data[tabIndex].purchaseBillNo }}</div>
        </div>
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <div class="label">供应商：</div>
          <div class="value">{{ data[tabIndex] && data[tabIndex].supplierName }}</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[tabIndex] && data[tabIndex].materialName }}</div>
        </div>
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <div class="label">物料规格：</div>
          <div class="value">{{ data[tabIndex] && data[tabIndex].spec }}</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[tabIndex] && data[tabIndex].arriveTime }}</div>
        </div>
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <div class="label">申购数量：</div>
          <div class="value">{{ data[tabIndex] && data[tabIndex].purchaseQty }}</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[tabIndex] && data[tabIndex].inStockQty }}</div>
        </div>
        <div class="col" style="flex: 1;display: flex;align-items: center;">
          <div class="label">本次到货：</div>
          <div class="value">{{ data[tabIndex] && data[tabIndex].batchQty }}</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[tabIndex] && data[tabIndex].batchNo }}</div>
        </div>
      </div>
      <div class="sub-title border"
           style="display: flex;
          justify-content: space-between;
          align-items: center;
          margin: 10px;
          font-size: 14px;
          border-bottom: 1px solid #000000;
          font-weight: bold;"
      >
        <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[tabIndex] && data[tabIndex].adjustNum }}%</div>
        </div>
      </div>
      <div class="sub-title border"
           style="justify-content: flex-start"
      >
        <span>质检明细</span>
        <span v-if="data[tabIndex] && data[tabIndex].exemptCheckId" @click="showNoCheck">
          （<span style="color: blue;cursor: pointer;text-decoration: underline">
            免检单
          </span>）
        </span>
        <no-check-form v-model="noCheckShow" :data="formData"></no-check-form>
      </div>
      <div class="row">
        <div class="col">
          <div class="table">
            <table style="border-collapse:collapse;border:none;width: 100%;">
              <tr>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">序号</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">物料标签值</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">抽检米数</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">短少</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">抽纱</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">褶皱</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">赃物</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">破洞</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">缩水</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">质检结论</th>
                <th style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">图片</th>
              </tr>
              <tr v-for="(item, index) in (data[tabIndex] && data[tabIndex].checkDetails)" :key="index">
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ index + 1 }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.rfidCode }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.checkQty }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.lakeNum }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.drawnworkNum }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.foldNum }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.dirtNum }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.potholeNum }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.shrinkPercent }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;">{{ item.checkJudgmentStr }}</td>
                <td style="border:solid #dcdee2 1px;padding: 5px;text-align: center;position: relative;font-size: 12px;max-width: 120px;text-align: left">
                  <p
                    style="color: #0077ff;text-decoration: underline;cursor: pointer;padding: 3px 0;"
                    @click="openPic(pic)" v-for="(pic, picIndex) in (item.imageUrl && item.imageUrl.split(','))" :key="picIndex">
                    {{ pic.split('/')[pic.split('/').length - 1] }}
                  </p>
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>
    </div>
    <div class="footer" slot="footer">
      <Button @click="cfm" class="btn" :disabled="tabIndex === 0">上一页</Button>
      <Button @click="cancel" class="btn" :disabled="data.length === 0 || tabIndex === (data.length - 1)">下一页</Button>
    </div>
  </modal>
</template>

<script>
import { filePreview } from '@/libs/util'
import { GetStockExemptCheck } from '@/api/stock'
import NoCheckForm from './no-check-form'

export default {
  name: 'store-in-form',
  data () {
    return {
      modal: false,
      tabIndex: 0,
      formData: {},
      noCheckShow: false
    }
  },
  components: {
    NoCheckForm
  },
  props: {
    data: {
      type: Array | Object
    },
    value: {
      type: Boolean,
      default: false,
      require: true
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
    }
  },
  methods: {
    showNoCheck () {
      GetStockExemptCheck({
        exemptCheckId: this.data[this.tabIndex].exemptCheckId
      }).then(res => {
        if (res.code === 0) {
          this.formData = { ...res.result }
          this.noCheckShow = true
        }
      })
    },
    openPic (url) {
      filePreview(url)
    },
    cfm () {
      this.tabIndex--
    },
    cancel () {
      this.tabIndex++
    }
  }
}
</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 {
            th {
              background-color: #eeeeee;
            }
            td,th {
              padding: 5px;
              text-align: center;
              border:solid #dcdee2 1px;
              position: relative;
              font-size: 12px;
            }
          }
        }
      }
    }
  }
  .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>
