<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <search-table @search="reload"></search-table>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        height="calc(100vh - 325px)"
        full-height="calc(100vh - 116px)"
        tool-class="ele-toolbar-form"
        :selection.sync="selection"
        :page-size="20"
        @columns-change="handleColumnChange"
        :cache-key="cacheKeyUrl"
      >
        <!-- 查看详情列 -->
        <template v-slot:changeCode="{ row }">
          <el-link type="primary" :underline="false" @click="handleAddOrEdit(row,'view')">
            {{ row.changeCode }}
          </el-link>
        </template>
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="handleAddOrEdit('', 'add')"
            v-if="$hasPermission('eom:contractchangerecord:save')"
          >
            新建
          </el-button>
        </template>
        <!-- 操作 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="handleAddOrEdit(row, 'update')"
            v-if="[0, 3].includes(row.approvalStatus)&&$hasPermission('eom:contractchangerecord:update')"
          >
            修改
          </el-link>
          <el-link
            type="primary"
            v-if="[0, 3].includes(row.approvalStatus)"
            :underline="false"
            icon="el-icon-plus"
            @click="sub(row)"
          >
            提交
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除此信息吗？"
            @confirm="remove([row.id])"
            v-if="[0, 3].includes(row.approvalStatus)&&$hasPermission('eom:contractchangerecord:delete')"
          >
            <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>

    <add-or-edit-dialog
      ref="addOrEditDialogRef"
      @reload="reload"
    ></add-or-edit-dialog>
    <process-submit-dialog
      :processSubmitDialogFlag.sync="processSubmitDialogFlag"
      v-if="processSubmitDialogFlag"
      ref="processSubmitDialogRef"
      @reload="reload"
    ></process-submit-dialog>
  </div>
</template>

<script>
  import addOrEditDialog from './components/addOrEditDialog.vue';
  import searchTable from './components/searchTable.vue';
  import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  import { reviewStatus } from '@/enum/dict';

  import {
    getTableList,
    deleteInformation
  } from '@/api/contractManage/contractChange.js';
  import tabMixins from '@/mixins/tableColumnsMixin';

  export default {
    mixins:[tabMixins],
    components: {
      addOrEditDialog,
      searchTable,
      processSubmitDialog
    },
    data() {
      return {
        // 加载状态
        loading: false,
        delVisible: false,
        addOrEditDialogFlag: false,
        processSubmitDialogFlag: false,
        selection: [],
        cacheKeyUrl: 'eos-6f5d0bf2-contract-contractChange',
        columnsVersion:1,
      };
    },
    computed: {
      columns() {
        // 当columnsVersion变化时会重新计算,用作更新列配置
        const version = this.columnsVersion;
        return [
          // {
          //   width: 45,
          //   type: 'selection',
          //   columnKey: 'selection',
          //   align: 'center'
          // },
          {
            width: 60,
            label: '序号',
            type: 'index',
            columnKey: 'index',
            align: 'center'
          },
          {
            minWidth: 200,
            prop: 'changeCode',
            label: '编码',
            align: 'center',
            slot: 'changeCode',
            showOverflowTooltip: true
          },
          {
            minWidth: 200,
            prop: 'contractName',
            label: '变更合同',
            slot: 'contractName',
            align: 'center',
            showOverflowTooltip: true
          },

          {
            minWidth: 200,
            prop: 'reason',
            label: '变更原因',
            align: 'center',
            showOverflowTooltip: true
          },

          {
            minWidth: 80,
            prop: 'remark',
            label: '变更描述',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            prop: 'approvalStatus',
            label: '审核状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 100,
            formatter: (_row, _column, cellValue) => {
              return reviewStatus[_row.approvalStatus];
            }
          },
          {
            minWidth: 100,
            prop: 'createUserName',
            label: '创建人',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 180,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true,
            fixed: 'right'
          }
        ];
      }
    },
    created() {},
    methods: {
      //新增、修改
      handleAddOrEdit(row = {}, type) {
        this.$refs.addOrEditDialogRef.open(row, type);
      },
      //新增、修改
      handleDetail(row = {}, type) {
        this.detailDialogFlag = true;
        this.$nextTick(() => {
          this.$refs.detailDialogRef.init(row, type);
        });
      },

      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return getTableList({
          pageNum: page,
          size: limit,
          ...where
        });
      },

      /* 刷新表格 */
      reload(where = {}) {
        this.$refs.table.reload({ page: 1, where });
      },

      remove(row) {
        deleteInformation(row).then((res) => {
          this.$message.success('删除成功！');
          this.reload();
        });
      },

      sub(res) {
        this.processSubmitDialogFlag = true;
        let key = 'eom_contract_change_approve';
        this.$nextTick(() => {
          let params = {
            businessId: res.id,
            businessKey: key,
            formCreateUserId: res.createUserId,
            variables: {
              businessCode: res.changeCode
            }
          };
          this.$refs.processSubmitDialogRef.init(params);
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  :deep(.el-link--inner) {
    margin-left: 0px !important;
  }

  .sys-organization-list {
    height: calc(100vh - 264px);
    box-sizing: border-box;
    border-width: 1px;
    border-style: solid;
    overflow: auto;
  }

  .sys-organization-list :deep(.el-tree-node__content) {
    height: 40px;

    & > .el-tree-node__expand-icon {
      margin-left: 10px;
    }
  }
</style>
