<!-- 物料设置 -->
<template>
  <modal v-model="modal" width="500px">
    <div class="title" slot="header">
      {{ type }}
    </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">{{ type }}数量：</div>
          <div class="value">
            <Input v-model="form.quantity" type="number" style="width: 100%"/>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">领料人：</div>
          <div class="value">
            <Select filterable :transfer="true" v-model="form.operateUser">
              <Option v-for="option in userList" :value="option.value" :key="option.value">{{ option.label || '未知' }}</Option>
            </Select>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">备注：</div>
          <div class="value">
            <Input v-model="form.remark" type="textarea" style="width: 100%"/>
          </div>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
import { GetUserPageList } from '@/api/user'

export default {
  data () {
    return {
      form: {},
      modal: false,
      userList: []
    }
  },
  components: {
  },
  props: {
    value: {
      type: Boolean,
      default: false,
      require: true
    },
    type: {
      type: String,
      default: '入库'
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
      if (!n) {
        this.form = {}
      } else {
        this.getUserPageList()
      }
    }
  },
  methods: {
    getUserPageList () {
      GetUserPageList({
        pageIndex: 1,
        pageSize: 9999
      }).then(res => {
        if (res.code === 0) {
          let list = res.result.list.map(item => {
            return {
              label: item.realName,
              value: item.id
            }
          })
          this.userList = list
        }
      })
    },
    cfm () {
      let quantity = Number.parseFloat(this.form.quantity)
      if (quantity) {
        this.$emit('confirm', this.form)
      } else {
        this.$Message.error('数量必须大于0！')
      }
    },
    cancel () {
      this.form = {}
      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;
    }
  }
  .row {
    padding: 0 20px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .col {
      flex: 1;
      display: flex;
      align-items: center;
      .label {
        width: 60px;
      }
      .value {
        flex: 1;
      }
    }
  }
}
</style>
