<!--
 * @Author: Liugh
 * @Date: 2021-05-25 13:49:40
 * @LastEditTime: 2021-05-25 14:36:52
 * @LastEditors: Do not edit
 * @FilePath: \auth-web\src\pages\log-manage\err-auth-earlywarning-manage\auth-earlywarning-plan.vue
 * @Description: 鉴权风险检测
-->
<template>
  <main>
    <!-- 搜索项 -->
    <search-bar ref="searchbar" :conditionForm="conditionForm" @submitSearch="receiveSearch"></search-bar>
    <!-- 表格 -->
    <new-table
      ref="table"
      :tableUrl="tableUrl"
      :tableHeader="RiskDetectionPlan"
      :condition="condition"
      :sortProps="sort"
      :tableOptList="tableOptList"
      @submitTableOpt="receviceOpt"
    >
    </new-table>
  </main>
</template>

<script>
import searchBar from '@/components/search-bar';
import newTable from '@/components/new-table';
import { RiskDetectionPlan } from '../DataConfig';
import { authRiskDetectionUrl, getAuthRiskDetail } from '@/api/log-manage';
import Detail from '@/pages/log-manage/auth-risk-detection/detail';
import Editor from '@/pages/log-manage/auth-risk-detection/edit';
import { searchOpt } from '@/mixins/page-opt';
export default {
  name: 'auth-risk-detection',
  props: {},
  components: { newTable, searchBar },
  mixins: [ searchOpt ],
  data() {
    return {
      RiskDetectionPlan,
      conditionForm: [
        {
          label: '方案状态',
          name: 'state',
          op: '=',
          component: 'DgSelect',
          attr: {
            enum: 'ProgrammeStateEnum'
          }
        }
      ],
      sort: {
        updateTime: 'DESC'
      },
      tableOptList: ['详情','修改'],
      tableUrl: authRiskDetectionUrl
    };
  },
  methods: {
    receviceOpt(opt, row) {
      if (opt == '修改') {
        this.handleEdit(row);
      } else if (opt == '详情') {
        this.handleDetail(row);
      }
    },
    handleEdit({ id }) {
      const that = this;
      getAuthRiskDetail(id)
        .then((res) => {
          const formData = res;
          const layer = that.$dgLayer({
            title: '修改',
            shade: [0.4, '#FFF'],
            area: ['830px', '660px'],
            content: Editor,
            props: {
              formData
            },
            on: {
              success(bool = false) {
                layer.close(layer.dialogIndex);
                if (bool) {
                  that.handleSearch();
                }
              }
            }
          });
        })
        .catch((error) => {
          that.$message.error('详情获取失败');
        });
    },
    handleDetail({ id }) {
      const that = this;
      getAuthRiskDetail(id)
        .then((res) => {
          const layer = that.$dgLayer({
            title: '详情',
            shade: [0.4, '#FFF'],
            content: Detail,
            area: ['830px', '660px'],
            props: { sizeForm: res },
            on: {
              success() {
                layer.close(layer.dialogIndex);
              }
            }
          });
        })
        .catch((error) => {
          that.$message.error('详情获取失败');
        });
    }
  }
};
</script>
