<!--
权限自助管理
@Author: linqian
@Date: 2021-07-07
-->
<template>
  <div>
    <!-- 搜索项 -->
    <search-bar ref="searchbar" :conditionForm="conditionForm" @submitSearch="receiveSearch"></search-bar>
    <!-- 操作栏 -->
    <operate-bar :pageOptList="pageOptList" @submitPageOpt="receviceOpt"></operate-bar>
    <!-- 表格 -->
    <new-table ref="table" :tableUrl="tableUrl" :tableHeader="tableHeader" :condition="condition">
      <dg-table-column label="操作" align="center" :width="180">
        <template slot-scope="{ row }">
          <div class="u-table__operation">
            <el-tooltip content="详情" effect="dark" placement="top-end">
              <i :class="'详情' | optIcon" @click="handleViewDetail(row)"></i>
            </el-tooltip>
            <el-tooltip content="编辑" effect="dark" placement="top-end" v-if="row.showEdit">
              <i :class="'编辑' | optIcon" @click="handleApplyPermission(row.applyOrdNo)"></i>
            </el-tooltip>
            <el-tooltip content="撤回" effect="dark" placement="top-end" v-if="row.showRecall">
              <i :class="'撤回' | optIcon" @click="handleRecall(row)"></i>
            </el-tooltip>
            <!--20241101 add status start-->
            <el-tooltip content="激活" effect="dark" placement="top-end" v-if="row.showActivate">
              <i :class="'激活' | optIcon" @click="handleActivate(row)"></i>
            </el-tooltip>
            <el-tooltip content="挂起" effect="dark" placement="top-end" v-if="row.showSuspend">
              <i :class="'挂起' | optIcon" @click="handleSuspend(row)"></i>
            </el-tooltip>
            <el-tooltip content="终止" effect="dark" placement="top-end" v-if="row.showStop">
              <i :class="'终止' | optIcon" @click="handleStop(row)"></i>
            </el-tooltip>
            <!--20241101 add status end-->
            <el-tooltip content="删除" effect="dark" placement="top-end" v-if="!row.showActivate">
              <i :class="'删除' | optIcon" @click="handleDelete(row)"></i>
            </el-tooltip>
          </div>
        </template>
      </dg-table-column>
    </new-table>
  </div>
</template>
<script>
import newTable from '@/components/new-table';
import { tableHeader } from './DataConfig';
import { tableUrl, delApply, recallApply, suspendApply, activateApply, stopApply} from '@/api/permission-selfhelp-manage';
import operateBar from '@/components/operate-bar';
import searchBar from '@/components/search-bar';
import { searchOpt } from '@/mixins/page-opt';
export default {
  components: {
    newTable,
    operateBar,
    searchBar
  },
  mixins: [searchOpt],
  data() {
    return {
      tableUrl,
      tableHeader,
      conditionForm: [
        {
          label: '流程标题',
          name: 'flowTitle',
          op: 'like',
          value: '',
          component: 'ElInput',
          attr: {
            placeholder: '请输入流程标题'
          }
        },
        {
          label: '审批类型',
          name: 'applyType',
          op: '=',
          value: '',
          component: 'DgSelect',
          attr: {
            placeholder: '请选择审批类型',
            enum: 'SelfAuthApplyTypeEnum'
          }
        },
        {
          label: '创建时间',
          name: 'createTime',
          op: 'between',
          type: 'DATE',
          value: '',
          component: 'DgDatePicker'
        }
      ],
      pageOptList: ['权限变更申请']
    };
  },
  computed: {},
  methods: {
    receviceOpt(btn, row) {
      if (btn == '权限变更申请') {
        this.handleApplyPermission(null);
      }
    },
    /**
     * 权限申请
     */
    handleApplyPermission(applyOrdNo) {
      const vm = this;
      const layer = this.$dgLayer({
        title: applyOrdNo ? '编辑' : '权限变更申请',
        props: {
          applyOrdNo: applyOrdNo ? applyOrdNo : '',
          type: applyOrdNo ? 'edit' : 'add'
        },
        content: require('./component/basic-form.vue'),
        area: ['1100px', '800px'],
        on: {
          success(params) {
            vm.handleSearch();
            layer.close(layer.dialogIndex);
          },
          close() {
            layer.close(layer.dialogIndex);
          }
        }
      });
    },
    handleViewDetail(row) {
      const layer = this.$dgLayer({
        title: '详情',
        props: {
          applyOrdNo: row.applyOrdNo,
          type: 'detail',
          flowStatus: row.flowStatus
        },
        content: require('./component/detail.vue'),
        area: ['1280px', '900px'],
        on: {
          success(params) {
            layer.close(layer.dialogIndex);
          },
          close() {
            layer.close(layer.dialogIndex);
          }
        }
      });
    },
    handleDelete(row) {
      this.$dgConfirm(`是否确定删除这条数据！`, '提示', {}).then(() => {
        delApply({
          applyOrdNo: row.applyOrdNo
        }).then((res) => {
          const { result, msg } = res.data;
          if (result == '200') {
            this.$message.success('删除成功！');
            this.handleSearch();
          } else {
            this.$message.warning(msg);
          }
        });
      });
    },
    handleRecall(row) {
      this.$dgConfirm(`是否确定撤回这条数据！`, '提示', {}).then(() => {
        const params = {
          applyOrdNo: row.applyOrdNo
        };
        recallApply(params).then((res) => {
          this.$message.success('撤回成功！');
          this.handleSearch();
        });
      });
    },
    // 20241101 add status start
    handleActivate(row) {
      this.$dgConfirm(`是否确定激活这条数据！`, '提示', {}).then(() => {
        const params = {
          applyOrdNo: row.applyOrdNo
        };
        activateApply(params).then((res) => {
          this.$message.success('激活成功！');
          this.handleSearch();
        });
      });
    },
    handleSuspend(row) { 
      this.$dgConfirm(`是否确定挂起这条数据！`, '提示', {}).then(() => {
        const params = {
          applyOrdNo: row.applyOrdNo
        };
        suspendApply(params).then((res) => {
          this.$message.success('挂起成功！');
          this.handleSearch();
        });
      });
    },
    handleStop(row) {
      this.$dgConfirm(`是否确定终止这条数据！`, '提示', {}).then(() => {
        const params = {
          applyOrdNo: row.applyOrdNo
        };
        stopApply(params).then((res) => {
          this.$message.success('终止成功！');
          this.handleSearch();
        });
      });
    }
    // 20241101 add status end
  },
  created() {},
  mounted() {}
};
</script>

<style lang='scss'>
</style>