<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <notes-search @search="reload"> </notes-search>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        cache-key="systemRoleTable"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit()"
          >
            新建
          </el-button>
          <el-button
            size="small"
            type="primary"
            class="ele-btn-icon"
            @click="goDetail({ id: 12 })"
          >
            详情
          </el-button>
        </template>
        <!-- 	     <template v-slot:enable="{ row }">
	       <el-switch
	         v-model="row.enable"
	         active-color="#13ce66"
	         inactive-color="#ff4949"
	         :active-value="1"
	         :inactive-value="0"
	         @change="changeEnable(row)"
	       >
	       </el-switch>
	     </template> -->
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="openEdit(row)"
          >
            撤回
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>

    <!-- 新建或编辑弹窗 -->
    <AddDialog
      ref="addDialogRef"
      :dialogTitle="addDialogTitle"
      :deviceInfo="deviceInfo"
      :infoData="infoData"
      @refresh="reload"
    />

    <DetailsDialog
      ref="detailsDialogRef"
      :dialogTitle="detailsDialogTitle"
      :infoData="infoData"
      :repairInfoLogs="repairInfoLogs"
    />
  </div>
</template>

<script>
  import { getPage } from '@/api/maintenance/repair';
  // import AddPatrolPlanDialog from '@/components/addPatrolPlanDialog'
  import NotesSearch from './components/notes-search.vue';
  import AddDialog from './components/addDialog.vue';
  import DetailsDialog from '../components/RepairDetailsDialog.vue';
  export default {
    components: {
      NotesSearch,
      AddDialog,
      DetailsDialog
      // AddPatrolPlanDialog
    },
    data () {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '报修记录编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'deviceId',
            label: '设备编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'enable',
            label: '设备名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'sourceType',
            label: '报修类型',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'from',
            label: '来源',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'sourceCode',
            label: '来源编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'requestUserId',
            label: '报修人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'createTime',
            label: '报修时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row, _column, cellValue) => {
              return this.$util.toDateString(cellValue);
            }
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 230,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        // 加载状态
        loading: false,
        infoData: {},
        repairInfoLogs: [],
        addDialogTitle: '新增报修记录',
        detailsDialogTitle: '报修记录详情',
        deviceInfo: {} //设备信息
      };
    },
    computed: {},
    methods: {
      /* 表格数据源 */
      datasource ({ page, limit, where, order }) {
        return getPage({ pageNum: page, size: limit, ...where });
      },
      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 });
      },

      openEdit (row) {
        this.addDialogTitle = '新增报修记录';
        this.$refs.addDialogRef.addRepairNotesDialog = true;
      },

      goDetail (row) {
        row.tabLabel = '维修信息';
        row.title = '报修记录详情';
        row.workOrderCode = row.id;
        this.$refs.detailsDialogRef.init(row);
        // this.$router.push({
        //   path: '/maintenance/patrol/plan/details',
        //   // query: {
        //   //   id
        //   // }
        // })
      }
    }
  };
</script>

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