<!-- 转仓 -->
<template>
  <modal v-model="modal" width="500px" class-name="vertical-center-modal">
    <div class="title" slot="header">
      转仓
    </div>
    <div class="footer" slot="footer">
      <Button @click="cfm" class="btn" type="primary">确认转仓</Button>
    </div>
    <!--  表单主要内容  -->
    <div class="content" ref="print">
      <div class="row">
        <div class="col">
          <div class="label" style="font-weight: bold;">面料信息</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">面料名称：</div>
          <div class="value" style="display: flex">
            {{ data.materialName }}
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">规格：</div>
          <div class="value">
            {{ data.spec }}
          </div>
        </div>
        <div class="col">
          <div class="label">编码：</div>
          <div class="value">
            {{ data.materialCode }}
          </div>
        </div>
        <div class="col"></div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">所属人：</div>
          <div class="value">
            {{ data.userName }}
          </div>
        </div>
        <div class="col">
          <div class="label">现场库存卷数：</div>
          <div class="value">
            {{ data.count }}
          </div>
        </div>
        <div class="col">
          <div class="label">现场库存米数：</div>
          <div class="value">
            {{ data.quantity }}
          </div>
        </div>
      </div>
      <div class="row" style="margin-top: 20px">
        <div class="col">
          <div class="label" style="font-weight: bold;line-height: 32px;">
            所属人信息
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">所属人：</div>
          <div class="value">
            <Select filterable :transfer="true" v-model="material.toUserId">
              <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">
            <DatePicker
              v-model="material.dt"
              type="date"
              placeholder="请选择时间"
              style="width: 100%;"
            ></DatePicker>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">转仓卷数：</div>
          <div class="value">
            <Input v-model="material.count" type="number" />
          </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 { TransferUserStock } from '@/api/stock'
import { GetUserPageList } from '@/api/user'
export default {
  name: 'store-in-form',
  data () {
    return {
      show: false,
      modal: false,
      material: {},
      userList: []
    }
  },
  components: {},
  props: {
    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) {
        this.material.id = this.data.id
        this.material.toUserId = this.data.userId
        this.getUserPageList()
      } else {
        this.material = {}
      }
    }
  },
  methods: {
    getselectedList (data) {
      this.material.materialCode = data[0].code
      this.material.materialName = data[0].name
      this.material.spec = data[0].spec
    },
    getUserPageList () {
      GetUserPageList({
        pageIndex: 1,
        pageSize: 9999,
        takeUser: true
      }).then(res => {
        if (res.code === 0) {
          let list = res.result.list.map(item => {
            return {
              label: item.realName,
              value: item.id
            }
          })
          this.userList = list
        }
      })
    },
    cfm () {
      if (!this.material.toUserId) return this.$Message.error('请选择所属人！')
      if (!this.material.dt) return this.$Message.error('请选择提交时间！')
      if (!this.material.count) return this.$Message.error('请输入卷量！')
      if (!this.material.quantity) return this.$Message.error('请输入数量！')
      if (this.material.count < 0)
        return this.$Message.error('转仓卷数不能小于0！')

      if (this.material.quantity < 0)
        return this.$Message.error('转仓米数不能小于0！')
      TransferUserStock({
        ...this.material
      }).then(res => {
        if (res.code === 0) {
          this.$Message.info(res.msg || '操作成功！')
          this.$emit('getlist')
          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;
    line-height: 32px;
    .col {
      flex: 1;
      display: flex;
      align-items: center;
      .label {
        min-width: 60px;
      }
      .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>
