<template>
  <div>
    <Modal v-model="showModal" title="出库单详情" width="1200">
      <!--内容-->
      <div>
        <Row>
          <!--查询-->
          <Col span="24" />
          <Form id="search-form" inline onsubmit="return false" :label-width="70">
            <Form-item label="申请单号:">
              <Input v-model="formObj.num" placeholder="请输入申请单号" style="width:180px" @on-enter="_search" /></Input>
            </Form-item>
            <Form-item label="申请内容:">
              <Input v-model="formObj.remark" placeholder="请输入申请内容" style="width:180px" @on-enter="_search" /></Input>
            </Form-item>
            <Form-item label="申请人:">
              <Input v-model="formObj.applyer" placeholder="请输入申请人" style="width:180px" @on-enter="_search" /></Input>
            </Form-item>
            <Form-item label="申请时间:">
              <Date-picker
                ref="Dates"
                type="daterange"
                placeholder="操作时间"
                style="width:200px;"
                @on-change="_dateChange"
              />
            </Form-item>
            <Form-item style="margin-left: -70px">
              <Button type="primary" @click="_search">
                搜索
              </Button>
            </Form-item>
          </Form>

          </Col>
          <Col span="24" />
          <element-table
            ref="pageTable"
            :page-columns="pageColumns"
            :table-height="400"
            :get-page="getPage"
            :icon-msg="iconMsg"
            click="true"
            :opt-col-width="70"
            @on-result-change="_tableResultChange"
          >
            <el-table-column
              v-for="item in pageColumns"
              :key="item.key"
              show-overflow-tooltip
              sortable
              :prop="item.key"
              :label="item.title"
              :min-width="item.width"
              :fixed="item.fixed?item.fixed:undefined"
            >
              <template slot-scope="scope">
                <div v-if="item.detail">
                  <a @click.stop="_detailModal(scope.row.id)">{{ scope.row[item.key] }}</a>
                </div>
                <div v-else-if="item.date">
                  {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd'):'' }}
                </div>
                <div v-else>
                  {{ scope.row[item.key] }}
                </div>
              </template>
            </el-table-column>
          </element-table>
          </Col>
          <Col span="24" />
                    <OutPurchaseOrderOutStock ref="outStock" />
          </Col>
        </Row>
        <FastOut ref="fastOutModal" @on-result-change="_page" />
      </div>
    </Modal>
  </div>
</template>
<script>
import { consumeDeliveryOrder } from '../../../../api'
import OutPurchaseOrderOutStock from './LmsChemicalOutPurchaseOrderOutStock.vue'
import FastOut from './FastOut'

export default {
  components: {
    OutPurchaseOrderOutStock,
    FastOut
  },
  data() {
    return {
      showModal: false,
      pageColumns: [
        { title: '申请单号', key: 'num', width: 180 },
        { title: '申请内容', key: 'remark', width: 200 },
        { title: '创建人', key: 'applyer', width: 120 },
        { title: '创建时间', key: 'ctime', width: 140, date: true }
      ],
      getPage: {},
      iconMsg: [{ type: 'pt-a-submit', id: '', name: '一键出库' }],
      formObj: {
        num: '',
        remark: '',
        applyer: '',
        beginDate: '',
        endDate: ''
      }
    }
  },
  methods: {
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          break
        case 'selectIds':
          this.selectIds = data
          break
        case 'select':
          this._rowChange(data)
          break
        case 'click':
          this._rowChange(data)
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData)
          break
        default:
          this._page()
      }
    },
    _iconClick(res, data) {
      switch (res) {
        case '一键出库':
          this._fastOut(data)
          break
      }
    },
    _openPurchaseOrder() {
      this.formObj = this.$resetFields(this.formObj)
      this.$refs.Dates.handleClear()
      this.showModal = true
      this._page()
    },
    _dateChange(data) {
      this.formObj.beginDate = data[0]
      this.formObj.endDate = data[1]
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await consumeDeliveryOrder.pageWaitDelivery(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
        this.$refs.outStock._init()
      }
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
      this.$refs.outStock.getPage = {}
    },
    _rowChange(currentRow, oldCurrentRow) {
      this.$refs.outStock._open(currentRow)
    },
    // 快速出库
    _fastOut(data) {
      this.$refs.fastOutModal._open(data.id)
      // this.$Modal.confirm({
      //   title: '提示',
      //   content: '确定要一键出库？',
      //   onOk: () => {
      //     this.$store.dispatch('LmsChemicalRelDelivery/fastOut', data.id).then(() => {
      //       if (this.$store.state.LmsChemicalRelDelivery.success) {
      //         this.$Message.success('一键出库成功！');
      //         this._page();
      //         this.$refs.outStock.getPage = {};
      //         this.$emit('on-result-change');
      //       }
      //     });
      //   }
      // });
    }
  }
}
</script>
