<!--
 * @Date: 2022-08-11 08:49:46
 * @LastEditors: 陈禹琨 cyk910622@163.com
 * @LastEditTime: 2022-08-16 14:01:42
 * @FilePath: \upcloud-base-fe-wms\src\views\kzyWMS\outBound\check\innerCheckNew\components\viewtaskModel\viewtasksModel.vue
 * @Description: cyk
-->
<template>
  <div>
    <p-modal
      title="查看任务"
      :visible="ViewTasksVisible"
      width="90%"
      :enlargeable="true"
      :draggable="true"
      :destroyOnClose="true"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <div class="title">
        <div class="right">当前复核台 {{ stationCode }}</div>
        <div class="total">
          总数:
          <span class="red"> {{ total }}</span>
        </div>
      </div>

      <p-grid-form ref="form" :span="8" :labelCol="{ span: 6 }" :items="config.items" @submit="handleSubmit" />
      <p-table
        ref="table"
        :rowSelectType="1"
        row-key="pickTaskId"
        :remoteUrl="{ url: SERVICE_DATA_API_BASE + '/search/page', method: 'post' }"
        :hasRowSelectCheck="true"
        :columns="config.columns"
        :remoteBefore="remoteBefore"
        :doneBefore="doneBefore"
        :scroll="{ x: true }"
        @dblclickRow="dblclickRow"
        @selectChange="selectChange"
        :remoteParams="remoteParams"
        :data-source="data"
      />
      <!-- <p-grid-form ref="radio" :span="24" :labelCol="{ span: 8 }" :items="config.itemsRadio" /> -->
    </p-modal>
  </div>
</template>

<script>
import config from '../config/viewtasksModel.js'
import { SERVICE_DATA_API_BASE } from '@/config/serviceSettings'
export default {
  name: 'Paused',
  props: {
    ViewTasksVisible: {
      type: Boolean,
      default: false
    },
    stationCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      total: 0,
      selectedRows: [],
      selectedRowKeys: [],
      stationCode1: null,
      warehouse: this.$store.state.user.warehouse,
      SERVICE_DATA_API_BASE,
      remoteParams: {},
      data: [],
      items: [],
      type: true,
      config: config(this)
    }
  },
  methods: {
    selectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    handleSubmit(e, form) {
      e.preventDefault()
      this.$refs.form.form.validateFields((err, values) => {
        if (!err) {
          //   this.getData(values) //分页查询所有列表
          console.log(values)
          this.remoteParams = { ...this.remoteParams, ...values }
        }
      })
    },
    handleOk() {
      console.log(this.selectedRows)
      //   console.log(this.stationCode)
      if (this.selectedRows.length == 0) {
        this.$message.warning('请选择数据!')
        return
      }
      let station = this.selectedRows[0].stationCode
      if (station != this.stationCode) {
        this.$message.warning(`只能索取当前复核台${this.stationCode}!`)
        return
      }
      this.$emit('setContainerCodeValue', this.selectedRows[0].containerCode)
    },
    handleCancel() {
      this.$emit('hideModel')
    },
    dblclickRow(event, activeID, rowRecord) {
      let station = rowRecord.stationCode
      if (station != this.stationCode) {
        this.$message.warning(`只能索取当前复核台${this.stationCode}!`)
        return
      }
      this.$emit('setContainerCodeValue', this.selectedRows[0].containerCode)
    },
    remoteBefore(vn, params) {
      let p = { ...params }
      let pp = { ...params.data }
      delete pp.pageNum
      delete pp.pageSize
      console.log(this.stationCode1, this.stationCode)
      p.data = {
        num: '754688251704512512',
        pageNum: params.data.pageNum,
        pageSize: params.data.pageSize,
        params: { ...pp, warehouseId: this.warehouse.warehouseId, stationCode: this.type ? this.stationCode : '' }
        // stationCode:this.stationCode
      }
      return p
    },
    doneBefore(res) {
      console.log(res)
      if (res.success) {
        this.total = res.data.totalCount
      }
      return res
    }
  }
}
</script>

<style scoped>
.title {
  width: 100%;
  height: 50px;
  /* display: flex; */
  justify-content: end;
  margin-right: 10%;
  font-size: 20px;
  font-weight: bold;
  padding: 0 5% 0 5%;
}
.right {
  float: left;
}
.total {
  float: right;
}
.red {
  color: red;
}
</style>
