<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <work-search @search="reload"> </work-search>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        cache-key="patrolOrderTable"
      >
        <template v-slot:code="{ row }">
          <el-link type="primary" @click="goDetail(row)">
            {{ row.code }}
          </el-link>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link type="primary" :underline="false" icon="el-icon-edit">
            报工
          </el-link>
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="toRedeploy(row)"
          >
            转派
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 转派弹窗 -->
    <redeployOther ref="redeployOtherRef" @refresh="reload" />
  </div>
</template>

<script>
  import WorkSearch from './components/work-search.vue';
  import redeployOther from '@/views/maintenance/components/redeployOther.vue';
  import { getWorkOrderPage } from '@/api/maintenance/patrol_maintenance';
  import dictMixins from '@/mixins/dictMixins';
  export default {
    components: {
      WorkSearch,
      redeployOther
    },
    mixins: [dictMixins],
    data() {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '工单单号',
            columnKey: 'code',
            slot: 'code',
            align: 'center'
          },
          {
            prop: 'planId',
            label: '计划单号',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'planName',
            label: '巡点检名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'executeGroupName',
            label: '巡点检部门',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'executeUserName',
            label: '巡点检人员',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'createTime',
            label: '工单生成时间',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'acceptTime',
            label: '开工时间',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'finishTime',
            label: '报工时间',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            columnKey: 'orderHour',
            label: '实际工时(分钟)',
            align: 'center',
            resizable: false,
            showOverflowTooltip: true
          },
          {
            prop: 'orderStatus',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            formatter: (row) => {
              return this.getDictValue('巡点检工单状态', row.orderStatus);
            }
          },
          {
            prop: 'acceptanceStatus',
            label: '执行结果',
            align: 'center',
            showOverflowTooltip: true,
            formatter(row) {
              return { 1: '通过', 2: '不通过' }[row.acceptanceStatus];
            }
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 150,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        // 加载状态
        loading: false,
        pageType: 'add',
        dialogTitle: '',
        isBindPlan: false
      };
    },
    created() {
      this.requestDict('巡点检工单状态');
    },
    computed: {},
    methods: {
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return getWorkOrderPage({
          pageNum: page,
          size: limit,
          ...where,
          type: 4
        });
      },
      async changeEnable(row) {
        const res = await putRoles(row);
        if (res.code == 0) {
          this.$message({
            type: 'success',
            message: '修改成功',
            customClass: 'ele-message-border'
          });
          this.reload();
        }
      },
      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ page: 1, where });
      },

      goDetail({ id }) {
        this.$router.push({
          path: '/maintenance/patrol/work/details',
          query: {
            id
          }
        });
      },
      // 转派
      toRedeploy(row) {
        this.$refs.redeployOtherRef.open(row);
      }
    }
  };
</script>

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