<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">容器码</label>
        <el-input v-model="query.stockCode" clearable placeholder="容器码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">容器类型</label>
        <el-input v-model="query.stockTypeCode" clearable placeholder="容器类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">起点位置</label>
        <el-input v-model="query.startSlotCode" clearable placeholder="起点位置" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">终点位置</label>
        <el-input v-model="query.endSlotCode" clearable placeholder="终点位置" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">容器当前位置</label>
        <el-input v-model="query.slotCode" clearable placeholder="容器当前位置" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">任务状态</label>
        <el-select
            v-model="query.status"
            clearable
            size="small"
            placeholder="状态"
            class="filter-item"
            style="width: 150px"
            @change="crud.toQuery"
        >
          <el-option
              v-for="item in dict.task_status"
              :key="item.id"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
<!--        <el-input v-model="query.status" clearable placeholder="任务状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <label class="el-form-item-label">任务类型</label>
        <el-input v-model="query.type" clearable placeholder="任务类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">下游任务号</label>
        <el-input v-model="query.jobId" clearable placeholder="下游任务号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">返回报文</label>
        <el-input v-model="query.jobMessage" clearable placeholder="返回报文" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <date-range-picker
            v-model="query.jobMessageTime"
            start-placeholder="jobMessageTimeStart"
            end-placeholder="jobMessageTimeStart"
            class="date-item"
        />
        <date-range-picker
            v-model="query.createTime"
            start-placeholder="createTimeStart"
            end-placeholder="createTimeStart"
            class="date-item"
        />
        <date-range-picker
            v-model="query.startTime"
            start-placeholder="startTimeStart"
            end-placeholder="startTimeStart"
            class="date-item"
        />
        <date-range-picker
            v-model="query.endTime"
            start-placeholder="endTimeStart"
            end-placeholder="endTimeStart"
            class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="容器码" prop="stockCode">
            <el-input v-model="form.stockCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="容器类型" prop="stockTypeCode">
            <el-input v-model="form.stockTypeCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="起点位置" prop="startSlotCode">
            <el-input v-model="form.startSlotCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="终点位置" prop="endSlotCode">
            <el-input v-model="form.endSlotCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="容器当前位置" prop="slotCode">
            <el-input v-model="form.slotCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="任务状态" prop="status">
            <el-select v-model="form.status" filterable placeholder="请选择">
              <el-option
                  v-for="item in dict.task_status"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="任务类型">
            <el-input v-model="form.type" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="工作类型" prop="jobType">
            <el-input v-model="form.jobType" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="任务ID" />
        <el-table-column prop="stockCode" label="容器码" />
        <el-table-column prop="stockTypeCode" label="容器类型" />
        <el-table-column prop="startSlotCode" label="起点位置" />
        <el-table-column prop="endSlotCode" label="终点位置" />
        <el-table-column prop="slotCode" label="容器当前位置" />
        <el-table-column prop="status" label="任务状态" />
        <el-table-column prop="type" label="任务类型" />
        <el-table-column prop="jobId" label="下游任务号" />
        <el-table-column prop="jobType" label="工作类型" />
        <el-table-column prop="jobPriority" label="优先级" />
        <el-table-column prop="jobPriorityType" label="强制优先级" />
        <el-table-column prop="jobForce" label="任务组" />
        <el-table-column prop="jobForceAsc" label="任务组执行顺序" />
        <el-table-column prop="jobMessage" label="返回报文" />
        <el-table-column prop="jobMessageTime" label="变动时间" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="startTime" label="开始时间" />
        <el-table-column prop="endTime" label="完成时间" />
        <el-table-column v-if="checkPer(['admin','agvTask:edit','agvTask:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
                :data="scope.row"
                :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudAgvTask from '@/api/agvTask'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, stockCode: null, stockTypeCode: null, startSlotCode: null, endSlotCode: null, slotCode: null, status: null, type: null, jobId: null, jobType: null, jobPriority: null, jobPriorityType: null, jobForce: null, jobForceAsc: null, jobMessage: null, jobMessageTime: null, createTime: null, startTime: null, endTime: null }
export default {
  name: 'AgvTask',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['base_staus', 'task_status'],
  cruds() {
    return CRUD({ title: 'agvTask', url: 'api/agvTask', idField: 'id', sort: 'id,desc', crudMethod: { ...crudAgvTask }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'agvTask:add'],
        edit: ['admin', 'agvTask:edit'],
        del: ['admin', 'agvTask:del']
      },
      rules: {
        stockCode: [
          { required: true, message: '容器码不能为空', trigger: 'blur' }
        ],
        stockTypeCode: [
          { required: true, message: '容器类型不能为空', trigger: 'blur' }
        ],
        startSlotCode: [
          { required: true, message: '起点位置不能为空', trigger: 'blur' }
        ],
        endSlotCode: [
          { required: true, message: '终点位置不能为空', trigger: 'blur' }
        ],
        slotCode: [
          { required: true, message: '容器当前位置不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '任务状态不能为空', trigger: 'blur' }
        ],
        jobType: [
          { required: true, message: '工作类型不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'stockCode', display_name: '容器码' },
        { key: 'stockTypeCode', display_name: '容器类型' },
        { key: 'startSlotCode', display_name: '起点位置' },
        { key: 'endSlotCode', display_name: '终点位置' },
        { key: 'slotCode', display_name: '容器当前位置' },
        { key: 'status', display_name: '任务状态' },
        { key: 'type', display_name: '任务类型' },
        { key: 'jobId', display_name: '下游任务号' },
        { key: 'jobMessage', display_name: '返回报文' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
