<!-- 采购入库单 -->
<template>
  <modal v-model="modal" width="700px">
    <div class="title" slot="header">
      领料申请单
    </div>
    <div class="footer" v-if="type === 'add'" slot="footer">
      <Button @click="cfm" class="btn" type="primary">绑定并继续</Button>
      <Button @click="cancel" class="btn">取消</Button>
    </div>
    <div class="footer" v-if="type === 'form'" slot="footer">
      <Button @click="cancel" class="btn" type="primary">关闭</Button>
    </div>
    <!--  表单主要内容  -->
    <div class="content" ref="print">
      <div class="sub-title">
        <span>
          <a v-if="type === 'add'" href="#" @click="show = true" style="font-size: 14px">+选择物料</a>
        </span>
        <my-modal-material ref="materialModal" :multiple="true" v-model="show" @getselectedList="getselectedList"></my-modal-material>
      </div>

      <div class="row">
        <div class="col">
          <div class="label">物料编码：</div>
          <div class="value">{{ type === 'add'? material.code : data.materialCode }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料名称：</div>
          <div class="value">{{ type === 'add'? material.name : data.materialName }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料规格：</div>
          <div class="value">{{ type === 'add'? material.spec : data.spec }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料单位：</div>
          <div class="value" v-if="material.code || type === 'form'">米</div>
        </div>
      </div>
      <div class="row" style="margin-top: 20px">
        <div class="col">
          <div class="label">数量：</div>
          <div class="value">
            <Input v-model="material.quantity" type="number" @on-enter="cfm"/>
          </div>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
import MyModalMaterial from '_c/my-modal-form/my-modal-material'
import { CreateStockTagWeb } from '@/api/stock'
export default {
  name: 'store-in-form',
  data () {
    return {
      show: false,
      modal: false,
      material: {},
      flowList: []
    }
  },
  components: {
    MyModalMaterial
  },
  props: {
    data: {
      type: Object,
      default () {
        return {}
      }
    },
    type: {
      type: String,
      default: 'add'
    },
    value: {
      type: Boolean,
      default: false,
      require: true
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
    }
  },
  methods: {
    getselectedList (data) {
      console.log('????????????12312')
      console.log(data)
      this.material = data[0]
      this.material.materialCode = data[0].code
    },
    cfm () {
      if (!this.material.code) {
        return this.$Message.error('请选择物料')
      }
      if (!this.material.quantity) {
        return this.$Message.error('请输入数量')
      }
      CreateStockTagWeb({
        materialCode: this.material.code,
        quantity: this.material.quantity
      }).then(res => {
        if (res.code === 0) {
          this.$Message.info(res.msg || '添加成功！')
          this.material.quantity = ''
          this.$emit('getlist')
        }
      })
    },
    cancel () {
      this.material = {}
      this.modal = false
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  .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;
    }
    a {
      font-size: 12px;
    }
  }
  .row {
    padding: 0 10px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .col {
      flex: 1;
      display: flex;
      align-items: center;
      font-size: 14px;
      .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;
              }
            }
          }
        }
      }
    }
  }
  .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>
