<!-- 绑定RFID -->
<template>
  <modal v-model="modal" class-name="vertical-center-modal" width="500px">
    <div class="title" slot="header">
      绑定RFID
    </div>
    <div class="footer" slot="footer">
      <Button @click="cfm" class="btn" type="primary">确认</Button>
      <Button @click="cancel" class="btn">取消</Button>
    </div>
    <!--  表单主要内容  -->
    <div class="content" ref="print" @keyup.enter="cfm">
      <div class="row">
        <div class="col">
          <div class="label">物料编码：</div>
          <div class="value">{{ data.materialCode }}</div>
        </div>
      </div>
      <div class="row">
        <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.quantity }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">合同编号：</div>
          <div class="value">{{ data.purchaseBillNo }}</div>
        </div>
      </div><div class="row">
      <div class="col">
        <div class="label">供应商：</div>
        <div class="value">{{ data.supplierName }}</div>
      </div>
    </div>
      <div class="row" style="margin-top: 10px">
        <div class="col">
          <div class="label">RFID标签值：</div>
          <div class="value" style="width: 80%">
            <Input v-model="rfid" disabled/>
          </div>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
import { BandingStockInRfidCode } from '@/api/stock'
export default {
  name: 'bind-rfid-form',
  data () {
    return {
      modal: false
    }
  },
  components: {
  },
  props: {
    rfid: {},
    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)
      if (n) {}
    }
  },
  methods: {
    cfm () {
      if (this.rfid) {
        BandingStockInRfidCode({
          stockTagId: this.data.id,
          rfidCode: this.rfid
        }).then(res => {
          if (res.code === 0) {
            this.$emit('getlist')
            this.modal = false
          }
        })
      } else {
        this.$Message.error('未扫描到RFID标签')
      }
    },
    cancel () {
      this.modal = false
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  padding: 10px 0;
  .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;
    }
  }
}
</style>
