<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <equipment-search
        @search="reload"
        :networkCounts="networkCounts"
        ref="search"
      />
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        height="calc(100vh - 400px)"
        tool-class="ele-toolbar-form"
        cache-key="systemOrgUserTable"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar="{ row }">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="open(null, 'add')"
          >
            新建
          </el-button>

          <!-- <el-button size="small" class="ele-btn-icon" @click="handlDelete"
          >删除</el-button
        >
        <el-button
          size="small"
          @click="moveTo(checkRadioData, 'move')"
          :disabled="checkRadioData.length == 0"
          class="ele-btn-icon"
          >移动到</el-button
        > -->
        </template>
        <!-- 编码列 -->
        <template v-slot:code="{ row }">
          <el-link
            type="primary"
            :underline="false"
            @click="open(row, 'detail')"
          >
            {{ row.code }}
          </el-link>
        </template>
        <template v-slot:disposalType="{ row }">
          {{ getDictValue('设备处置方式', row.disposalType + '') }}
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            v-if="row.approvalStatus == 0"
            @click="processSubmit(row)"
          >
            提交
          </el-link>
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            v-if="row.approvalStatus == 0"
            @click="open(row, 'edit')"
          >
            编辑
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除吗？"
            @confirm="remove(row)"
            v-if="row.approvalStatus == 0"
          >
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
    <process-submit-dialog
      :processSubmitDialogFlag.sync="processSubmitDialogFlag"
      v-if="processSubmitDialogFlag"
      ref="processSubmitDialogRef"
      @reload="reload"
    ></process-submit-dialog>
    <edit ref="edit" @refresh="reload"></edit>
  </div>
</template>

<script>
import { getList, remove, submit } from '@/api/equipmentDisposal/index.js';
import processSubmitDialog from '@/components/processSubmitDialog/processSubmitDialog.vue';

import dictMixins from '@/mixins/dictMixins';
import equipmentSearch from './components/search.vue';
import edit from './components/edit';

export default {
  mixins: [dictMixins],
  components: {
    equipmentSearch,
    edit,
    processSubmitDialog
  },

  data() {
    return {
      loading: false,
      processSubmitDialogFlag:false,
      // 表格列配置
      columns: [
        // {
        //   width: 45,
        //   type: 'selection',
        //   columnKey: 'selection',
        //   align: 'center'
        // },
        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'disposalType',
          slot: 'disposalType',
          align: 'center',
          label: '处置方式',
          showOverflowTooltip: true
        },

        {
          columnKey: 'code',
          align: 'center',
          prop: 'code',
          slot: 'code',
          label: '编码',
          showOverflowTooltip: true
        },
        {
          prop: 'name',
          align: 'center',
          label: '名称',
          showOverflowTooltip: true
        },
        {
          prop: 'fixCode',
          align: 'center',
          label: '固资编码',
          showOverflowTooltip: true,
          formatter: (row, column, cellValue) => {
            return row.deviceList.map((item) => item.fixCode).toString();
          }
        },
        {
          align: 'center',
          label: '物品名称',
          showOverflowTooltip: true,
          formatter: (row, column, cellValue) => {
            return row.deviceList.map((item) => item.name).toString();
          }
        },
        {
          prop: 'createUserName',
          align: 'center',
          label: '创建人'
        },
        {
          prop: 'createTime',
          align: 'center',
          label: '创建时间'
        },
        {
          prop: 'approvalStatus',
          align: 'center',
          label: '状态',
          showOverflowTooltip: true,
          formatter: (row, column, cellValue) => {
            return cellValue == 0
              ? '草稿'
              : cellValue == 1
              ? '审核中'
              : '审核通过';
          }
        },

        {
          columnKey: 'action',
          slot: 'action',
          align: 'center',
          label: '操作',
          width: 240,
          fixed: 'right'
        }
      ],
      networkCounts: {},
      checkRadioData: [],
      QRvisible: false
    };
  },
  computed: {},
  created() {
    this.requestDict('设备处置方式');
  },
  methods: {
    /* 表格数据源 */
    datasource({ page, limit, where }) {
      console.log('------reload-------');
      // this.getNetWork(page, limit, where, order);
      return getList({
        ...where,
        pageNum: page,
        size: limit
      });
    },

    /* 刷新表格 */
    reload(where) {
      this.$refs.table.reload({ pageNum: 1, where: where });
    },
    open(row, type) {
      this.$refs.edit.open(row, type);
    },
    processSubmit(row) {
      this.processSubmitDialogFlag = true;
      this.$nextTick(() => {
        let params = {
          businessId: row.id,
          businessKey: 'device_scrap_approve',
          formCreateUserId: row.createUserId,
          variables: {
            businessCode: row.code
          },
   
        }
        this.$refs.processSubmitDialogRef.init(params);
      });
    },
    remove(row) {
      remove([row.id]).then((res) => {
        this.$message.success('删除成功！');
        this.reload();
      });
    }
  }
};
</script>
<style lang="scss" scoped>
@media print {
  #printSection {
    font-size: 34px;
    span {
      font-size: 34px;
    }
  }
}
</style>
