<template>
  <div>
    <!-- 拣选单历史查询 -->
    <p-card title="拣选单历史查询">
      <span slot="extra">
        <!-- <p-button type="primary" style="margin-right:10px" @click="showmodel()">添加</p-button> -->
      </span>
      <p-grid-form :label-col="{ span: 8 }" :span="8" :items="config.items" @submit="hanlderSubmit" />
      <p-table
        ref="table"
        row-key="id"
        bordered
        :columns="config.columns"
        :remoteUrl="config.remoteUrl"
        :remoteParams="remoteParams"
        :rowSelectType="false"
        :doneBefore="doneBefore"
        :data-source="data"
        :scroll="{ x: 1500 }"
      >
        <template slot="operation" slot-scope="text, record">
          <!-- {{ text ? '禁用' : '启用' }} -->
          <a @click="showmodeldetailCount(text, record)">查看容器</a>
          <a-divider type="vertical" />
          <a @click="showmodelOrder(text, record)">查看订单</a>
        </template>
      </p-table>
    </p-card>

    <p-modal
      title="详情"
      width="50%"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <p-grid-form :label-col="{ span: 8 }" ref="model" :span="8" :items="config.Modelitems" @submit="hanlderSubmit" />
    </p-modal>
    <p-modal
      title="查看容器"
      width="80%"
      :visible="visibledetailCount"
      :confirm-loading="confirmLoading"
      @ok="handleCancel"
      @cancel="handleCancel"
    >
      <p-table
        row-key="id"
        bordered
        :columns="detailCount.columns"
        :rowSelectType="false"
        :remoteUrl="detailCount.remoteUrl"
        :remoteParams="detailCountremoteParams"
        :data-source="detailCountdata"
        :scroll="{ x: 1000 }"
      >
      </p-table>
    </p-modal>

    <p-modal
      title="查看订单"
      width="80%"
      :visible="visiblelist"
      :confirm-loading="confirmLoading"
      @ok="handleCancel"
      @cancel="handleCancel"
    >
      <p-table
        row-key="id"
        bordered
        :columns="Order.columns"
        :rowSelectType="false"
        :remoteUrl="Order.remoteUrl"
        :remoteParams="OrderremoteParams"
        :data-source="Ordertdata"
        :scroll="{ x: 1000 }"
      >
      </p-table>
    </p-modal>
  </div>
</template>

<script>
import config from './config.js'
const base = '/api/service-ai-eis-business-center-eistest'
import { add, deletes, update } from './api'

export default {
  data() {
    return {
      config: config(this),
      data: [],
      type: true,
      remoteParams: {
        createTimeTo: '',
        createTimeFrom: '',
      },
      detailCount: {
        columns: [
          {
            dataIndex: 'id',
            key: 'id',
            align: 'center',

            ellipsis: true,
            title: 'ID',
          },
          {
            title: '容器号',
            dataIndex: 'containerNo',
            ellipsis: true,
            align: 'center',

            key: 'containerNo',
            // customRender(text) {
            //   text == 10 && (text = '区域')
            //   text == 20 && (text = '接驳口')
            //   return text
            // }
          },
          {
            title: '批拣单ID',
            dataIndex: 'pickingOrderId',
            ellipsis: true,
            align: 'center',

            key: 'pickingOrderId',
          },
          {
            title: '站台编号',
            key: 'stationId',

            ellipsis: true,
            dataIndex: 'stationId',
            align: 'center',
          },
          {
            title: '订单池ID',
            dataIndex: 'orderPoolId',
            align: 'center',
            ellipsis: true,

            key: 'orderPoolId',
            // customRender(text) {
            //   text == 0 && (text = '不索取')
            //   text == 1 && (text = '索取')
            //   return text
            // }
          },
          {
            title: '创建时间',
            key: 'createTime',

            ellipsis: true,
            dataIndex: 'createTime',
            align: 'center',
          },
          {
            title: '任务明细数量',
            key: 'detailSize',
            ellipsis: true,
            dataIndex: 'detailSize',
            align: 'center',
          },
          {
            title: '任务完成时间',
            key: 'finishTime',
            ellipsis: true,
            dataIndex: 'finishTime',
            align: 'center',
          },
        ],
        remoteUrl: {
          url: base + '/pickingorder/getContainerByPickingOrderId',
          headers: {
            'Content-Type': 'application/JSON',
          },
          method: 'get',
        },
      },
      detailCountdata: [],
      detailCountremoteParams: {
        id: '',
      },
      Order: {
        columns: [
          {
            dataIndex: 'id',
            key: 'id',
            align: 'center',
            width: 150,
            ellipsis: true,
            title: 'id',
          },
          {
            title: '库存任务汇总单ID',
            dataIndex: 'outTaskSmyId',
            ellipsis: true,
            align: 'center',
            width: 150,
            key: 'outTaskSmyId',
            // customRender(text) {
            //   text == 10 && (text = '区域')
            //   text == 20 && (text = '接驳口')
            //   return text
            // }
          },
          {
            title: '拣选单ID',
            dataIndex: 'pickingOrderId',
            ellipsis: true,
            align: 'center',
            width: 150,
            key: 'pickingOrderId',
          },
          {
            title: '上游系统任务单ID',
            key: 'upperSystemTaskId',
            width: 150,
            ellipsis: true,
            dataIndex: 'upperSystemTaskId',
            align: 'center',
            // customRender(text) {
            //   text == 0 && (text = '未开始')
            //   text == 1 && (text = '进行中')
            //   text == 2 && (text = '已完成')
            //   text == 3 && (text = '已暂停')
            //   text == 4 && (text = '已取消')

            //   return text
            // }
          },
          {
            title: '出库任务单类型编号',
            dataIndex: 'outboundTaskTypeNo',
            align: 'center',
            ellipsis: true,
            width: 150,
            key: 'outboundTaskTypeNo',
            // customRender(text) {
            //   text == 0 && (text = '不索取')
            //   text == 1 && (text = '索取')
            //   return text
            // }
          },
          {
            title: '订单池ID',
            key: 'orderPoolId',
            width: 150,
            ellipsis: true,
            dataIndex: 'orderPoolId',
            align: 'center',
          },
          {
            title: '任务单状态',
            dataIndex: 'state',
            align: 'center',
            width: 150,
            key: 'state',
            customRender(text) {
              text == 0 && (text = '未开始')
              text == 1 && (text = '进行中')
              text == 3 && (text = '已暂停')
              text == 2 && (text = '已完成')
              return text
            },
            // 任务单状态（0未开始、1进行中、3已暂停、2已完成）
          },
          {
            title: '是否短拣',
            width: 150,
            dataIndex: 'isShortPicking',
            align: 'center',
            key: 'isShortPicking',
            customRender(text) {
              text == 0 && (text = '否')
              text == 1 && (text = '是')
              return text
            },
          },
          {
            title: '优先级',
            width: 150,
            dataIndex: 'priority',
            align: 'center',
            key: 'priority',
          },
          {
            title: '创建时间',
            dataIndex: 'expireDate',
            width: 150,
            align: 'center',
            key: 'expireDate',
          },

          {
            title: '任务开始时间',
            dataIndex: 'startTime',
            width: 150,
            align: 'center',
            key: 'startTime',
          },

          {
            title: '任务完成时间',
            dataIndex: 'finishTime',
            width: 150,
            align: 'center',
            key: 'finishTime',
          },

          {
            title: '任务明细数',
            dataIndex: 'detailCount',
            width: 150,
            align: 'center',
            key: 'detailCount',
          },
        ],
        remoteUrl: {
          url: base + '/outtaskmanager/getouttask',
          headers: {
            'Content-Type': 'application/JSON',
          },
          method: 'post',
        },
      },
      Ordertdata: [],
      OrderremoteParams: {
        pickingOrderId: '',
      },
      visible: false,
      visiblelist: false,
      visibledetailCount: false,
      confirmLoading: false,
    }
  },
  mounted() {
    // this.getinfo()
  },
  methods: {
    async showmodeldetailCount(text, record) {
      console.log(text, record)
      this.detailCountremoteParams.id = record.id
      this.visibledetailCount = true
      this.detailCountremoteParams = { ...this.detailCountremoteParams }
    },

    async showmodelOrder(text, record) {
      console.log(text, record)
      this.OrderremoteParams.pickingOrderId = record.id
      this.visiblelist = true
      this.OrderremoteParams = { ...this.OrderremoteParams }
    },
    doneBefore(res) {
      //   res.data.list.forEach(item => {
      //     item.id = item.areaNo
      //   })
      //   console.log(res)
      return res
    },
    hanlderSubmit(e, form) {
      e.preventDefault()
      form.validateFields((error, values) => {
        console.log(error, values, 'valuesvaluesvaluesvaluesvalues')
        // this.queryName = values.name
        // this.queryType = values.type
        // this.getlistCompanyByAuthId()
        if (!error) {
          this.remoteParams = { ...this.remoteParams, ...values }
        }
      })
    },
    handleOk(e) {
      console.log(this.$refs.model)
      this.$refs.model.form.validateFields(async (err, value) => {
        if (!err) {
          console.log(value)
          this.confirmLoading = true
          if (this.type) {
            let res = await update(value)
            console.log(res)
            if (res.success) {
              this.$message.success(res.message)
              this.visible = false
              this.remoteParams = { ...this.remoteParams }
            } else {
              this.$exception(res)
            }
          } else {
            let res = await add(value)
            console.log(res)
            if (res.success) {
              this.$message.success(res.message)
              this.visible = false
              this.remoteParams = { ...this.remoteParams }
            } else {
              this.$exception(res)
            }
          }

          this.confirmLoading = false
          //
        }
      })
    },
    handleCancel(e) {
      console.log('Clicked cancel button')
      this.visible = false
      this.visibledetailCount = false
      this.visiblelist = false
    },
    //点击弹出
    showmodel(data) {
      console.log(data)
      this.config.Modelitems = this.config.Modelitemsupdate1
      if (data && data.areaType == 20) {
        //接驳口
        this.config.Modelitems = this.config.Modelitemsupdate
      } else if (data && data.areaType == 10) {
        //区域
        this.config.Modelitems = this.config.Modelitemsupdate1
      }
      this.visible = true
      if (data) {
        this.config.Modelitems.forEach((item) => {
          item.name == 'areaType' && (item.disabled = true)
          item.name == 'areaNo' && (item.disabled = true)
        })
        this.$nextTick(() => {
          this.$refs.model.form.setFieldsValue(data)
        })
        this.type = true
      } else {
        this.config.Modelitemsupdate.forEach((item) => {
          item.disabled = false
        })
        this.config.Modelitems.forEach((item) => {
          item.disabled = false
        })
        console.log(this.config.Modelitems)
        this.$nextTick(() => {
          this.$refs.model.form.resetFields()
        })
        this.type = false
      }
    },
    del(text) {
      let that = this
      console.log(text)
      this.$confirm({
        title: '确定是否要删除?',
        content: '',
        async onOk() {
          let res = await deletes({ areaNo: text.areaNo })
          if (res.success) {
            that.$message.success('删除成功')
            that.remoteParams = { ...that.remoteParams }
          } else {
            that.$exception(res)
          }
        },
        onCancel() {},
      })
    },
  },
}
</script>

<style lang="less" scoped></style>
