<template>
  <div>
    <div>
      <p-card title="挂起订单处理">
        <div>
          <p-grid-form ref="formTarget" :items="formItems" @submit="hanlderSubmit"> </p-grid-form>
        </div>
        <div>
          <p-table
            ref="logTable"
            style="margin-top: 10px"
            :columns="tableColumns"
            rowKey="taskId"
            :rowSelectType="1"
            :remoteUrl="remoteUrl"
            :remoteData="remoteUrl.data"
            :expandRowByClick="false"
            :dataSource.sync="dataSource"
            :loading="tabLoding"
            @selectChange="selectChange"
            :hasRowSelectCheck="true"
            dragle
            auto-width
            bordered
          >
          </p-table>
        </div>
        <div slot="extra">
          <!-- <p-button type="primary"> 重新分配 </p-button>-->
          <!-- <p-button type="primary"  @click="restoreAll"> 批量还原 </p-button> -->
          <p-button type="primary" @click="restore"> 释放还原 </p-button>
        </div>
      </p-card>
    </div>
  </div>
</template>
<script>
import { formItems, tableColumns } from './js/config'
import { selectInboundTask, taskOrverHangUp, cancelTaskHangUp } from './api'

export default {
  components: {},
  data() {
    return {
      remoteUrl: {
        url: '/kz/inbound/queryHangUp',
        method: 'post',
        data: {
          isHangUp: 40,
        },
      },
      formItems: formItems(this),
      tableColumns: tableColumns,
      dataSource: [],
      tabLoding: false,
      selectedRows: [],
      rackType: '0',
    }
  },
  created() {},
  methods: {
    hanlderSubmit(e, form) {
      e.preventDefault()
      const params = this.$refs.formTarget.form.getFieldsValue()
      this.remoteUrl.data = { ...this.remoteUrl.data, ...params }
      // this.remoteUrl.data.isHangUp = 40
      console.log(form.getFieldsValue())
    },
    rackingType(data) {
      if (data == 0) {
        this.rackType = '0'
        this.remoteUrl.url = '/kz/reportService/selectInboundTask'
      } else {
        this.rackType = '1'
        this.remoteUrl.url = '/kz/inBoundContainerService/selectContainerNoHangupInboundTask'
      }
    },

    selectChange(selectedRowKeys, selectedRows) {
      // 勾选框
      this.selectedRows = selectedRows
      // this.selectedRowKeys = selectedRowKeys
    },
    //还原
    restore() {
      if (this.selectedRows.length < 1) {
        this.$message.warning(this.$lang('请先选择数据'))
        return false
      }
      if (this.rackType == '0') {
        taskOrverHangUp({taskId:this.selectedRows[0].taskId}).then((res) => {
          if (!res.success) {
            this.$exception(res)
            return false
          }
          this.selectedRows = []
          this.$refs.logTable.reload()
          this.$message.success(this.$lang('解挂成功'))
        })
      } else {
        cancelTaskHangUp({taskId:this.selectedRows[0].taskId}).then((res) => {
          if (!res.success) {
            this.$exception(res)
            return false
          }
          this.selectedRows = []
          this.$refs.logTable.reload()
          this.$message.success(this.$lang('解挂成功'))
        })
      }
    },
  },
}
</script>
<style lang="less" scoped></style>
