<!-- 采购入库单 -->
<template>
  <modal v-model="modal" width="400px" class-name="vertical-center-modal">
    <div class="title" slot="header">
      请输入批量单减扣数量
    </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">
      <div class="row">
        <div class="col">
          <div class="label">当前日期：</div>
          <div class="value">
            <Input v-model="material.date" disabled/>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料编码：</div>
          <div class="value" style="display: flex">
            <Input v-model="material.materialCode" disabled style="flex: 1"/>
            <Button type="primary" @click="show = true">选择物料</Button>
            <my-modal-material ref="materialModal" :multiple="true" v-model="show" @getselectedList="getselectedList"></my-modal-material>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料名称：</div>
          <div class="value">
            <Input v-model="material.materialName" disabled/>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">减扣数量：</div>
          <div class="value">
            <Input v-model="material.quantity" type="number"/>
          </div>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
import MyModalMaterial from '_c/my-modal-form/my-modal-material'
import { AddMaterialUse } from '@/api/stock'
export default {
  name: 'store-in-form',
  data () {
    return {
      show: false,
      modal: false,
      material: {}
    }
  },
  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)
      if (n) {
        this.material = { ...this.data }
        this.material.date = this.$dayjs().format('YYYY-MM-DD')
      } else {
        this.material = {}
      }
    }
  },
  methods: {
    getselectedList (data) {
      this.material.materialCode = data[0].code
      this.material.materialName = data[0].name
    },
    cfm () {
      if (!this.material.materialCode) return this.$Message.error('请选择物料！')
      if (!this.material.quantity) return this.$Message.error('输入数量！')
      AddMaterialUse({
        materialCode: this.material.materialCode,
        quantity: this.material.quantity
      }).then(res => {
        if (res.code === 0) {
          this.$Message.info(res.msg || '操作成功！')
          this.cancel()
        }
      })
    },
    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;
      .value {
        flex: 1;
      }
      .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>
