<template>
  <Modal v-model="showTreeModal" class="zIndex-1200">
    <p slot="header">
      一键出库
    </p>
    <Form>
      <Form-item>
        <Form-item label="出库时间:">
          <DatePicker
            v-model="regdate"
            type="datetime"
            placeholder="出库时间"
            style="width:400px;"
            @on-change="_dateChange"
          />
        </Form-item>
      </Form-item>
    </Form>
    <div slot="footer">
      <Button type="ghost" style="margin-left: 8px" @click="_cancel">
        取消
      </Button>
      <Button type="primary" @click="_ok">
        确定
      </Button>
    </div>
  </Modal>
</template>
<script>
/**
 * 一键出库出库时间
 */

import { consumeRelDelivery } from '../../../../api'

export default {
  data() {
    return {
      showTreeModal: false,
      regdate: '',
      id: ''
    }
  },
  methods: {
    _open(id) {
      this.id = id
      this.regdate = new Date()
      this.showTreeModal = true
    },
    _cancel() {
      this.showTreeModal = false
    },
    _dateChange(data) {
      this.regdate = data
    },
    _ok() {
      if (!this.regdate) return this.$Message.warning('出库时间不能为空！')
      // this.$store
      //   .dispatch('LmsChemicalRelDelivery/fastOut', {
      //     orderId: this.id,
      //     regdate: this.$dateformat(this.regdate, 'yyyy-mm-dd HH:MM:ss')
      //   })
      //   .then(() => {
      //     if (this.$store.state.LmsChemicalRelDelivery.success) {
      //       this.$Message.success('出库成功!')
      //       this.$emit('on-result-change')
      //       this.showTreeModal = false
      //     }
      //   })

      const data = {
        orderId: this.id,
        regdate: this.$dateformat(this.regdate, 'yyyy-mm-dd HH:MM:ss')
      }
      this._submit(data)
    },
    _submit: async function(data) {
      const result = await consumeRelDelivery.fastOut(data)
      if (result) {
        this.$Message.success('出库成功!')
        this.$emit('on-result-change')
        this.showTreeModal = false
      }
    }
  }
}
</script>
