<template>
  <div class="mod-config">
    <div>
        <span @click="favoriteFunction()">
         <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"  ></icon-svg>
        </span>
    </div>
    <el-form :inline="true" label-position="top">
      <el-form-item :label="inputSearch1">
        <el-input style="width: 110px;"  placeholder="" v-model="mainQueryData.recordTypeDb"></el-input>
      </el-form-item>
      <el-form-item :label="inputSearch2">
        <el-input style="width: 110px;"  placeholder="" v-model="mainQueryData.ruleId"></el-input>
      </el-form-item>
      <el-form-item :label="inputSearch3">
        <el-input style="width: 110px;"  placeholder="" v-model="mainQueryData.ruleDesc"></el-input>
      </el-form-item>
      <el-form-item :label="inputSearch4">
        <el-select v-model="mainQueryData.active" placeholder="请选择" style="width: 110px;">
          <el-option
            key=""
            label="全部"
            value="">
          </el-option>
          <el-option
            v-for="item in selectList.select1"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item style="margin-top: 20px;">
        <el-button @click="getDataList()" type="primary">{{buttons.search}}</el-button>
        <el-button @click="initModel()" type="primary">{{buttons.add}}</el-button>
        <el-button @click="saveColumnList()" type="primary" v-show="showDefault">{{buttons.defaultTable}}
        </el-button>
        <el-button @click="userSetting" type="primary">{{ buttons.settingTable}}</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :defaultValue="exportDefaultValue"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{buttons.download}}
        </download-excel>
      </el-form-item>

    </el-form>
    <el-table
      :height="height"
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">

      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed"
        :width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                             style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="140"
        :label="buttons.cz">
        <template slot-scope="scope">
          <a  @click="initAuthStep(scope.row)">{{buttons.reviewer}}</a>
          <a  @click="initModel(scope.row)">{{buttons.edit}}</a>
          <a  @click="delAuditRules(scope.row)">{{buttons.delete}}</a>
        </template>
      </el-table-column>
    </el-table>

    <column  v-if="visible" ref="column" @refreshData="getTableUserColumn"></column>

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-drag :title="inputSearch3" :visible.sync="setUp.reviewFlag" width="485px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="inputSearch5">
          <el-input style="width: 135px;" v-model="saveAuditRuleData.ruleId"></el-input>
        </el-form-item>
        <el-form-item :label="inputSearch6">
          <el-input style="width: 135px;" v-model="saveAuditRuleData.ruleDesc"></el-input>
        </el-form-item>
        <el-form-item :label="inputSearch7">
<!--          <el-input style="width: 135px;" v-model="saveAuditRuleData.recordTypeDb"></el-input>-->
          <el-select v-model="saveAuditRuleData.recordTypeDb" placeholder="请选择" style="width: 135px;">
            <el-option
              v-for="item in selectList.select6"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item :label="inputSearch9">-->
<!--          <el-input style="width: 135px;" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model="saveAuditRuleData.minValue"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item :label="inputSearch10">-->
<!--          <el-input style="width: 135px;" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model="saveAuditRuleData.maxValue"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item :label="inputSearch11">
          <el-input style="width: 135px;" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model="saveAuditRuleData.priority"></el-input>
        </el-form-item>
        <el-form-item :label="inputSearch8">
          <el-select v-model="saveAuditRuleData.active" placeholder="请选择" style="width: 135px;">
            <el-option
              v-for="item in selectList.select1"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item :label="inputSearch12">
          <el-input style="width: 430px;" v-model="saveAuditRuleData.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="setUp.reviewFlag = false">取消</el-button>
      <el-button type="primary" :disabled="setUp.saveButton" @click="saveAuditRules()">确定</el-button>
    </span>
    </el-dialog>

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-drag :title="inputSearch21" :visible.sync="setUp.authStepFlag" width="750px">
      <el-form :inline="true" label-position="top">
        <el-form-item >
          <el-button @click="initAuthStepModel()" type="primary">{{buttons.add}}</el-button>
        </el-form-item>
      </el-form>
      <el-table
        id="authStep"
        :height="300"
        :data="authStepList"
        border
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <el-table-column
          type="selection"
          header-align="center"
          width="40"
          align="center">
        </el-table-column>
        <el-table-column
          v-for="(item,index) in columnList1" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed"
          :width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="100"
          :label="buttons.cz">
          <template slot-scope="scope">
            <!--          <a  @click="generateData(scope.row)">{{buttons.reviewer}}</a>-->
            <a  @click="initAuthStepModel(scope.row)">{{buttons.edit}}</a>
                      <a  @click="deleteAuthStep(scope.row)">{{buttons.delete}}</a>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height: 20px;"></el-footer>
    </el-dialog>

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-drag :title="inputSearch13" :visible.sync="setUp.authStepReviewFlag" width="485px">
      <el-form :inline="true" label-position="top">
        <!--<el-form-item :label="inputSearch14">
          <el-input style="width: 135px;" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model="authStepData.stepId"></el-input>
        </el-form-item>-->
        <!--<el-form-item :label="inputSearch15">
          <el-select v-model="authStepData.firstStepFlag" placeholder="请选择" style="width: 135px;">
            <el-option
              v-for="item in selectList.select2"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>-->
        <!--<el-form-item :label="inputSearch16">
          <el-select v-model="authStepData.lastStepFlag" placeholder="请选择" style="width: 135px;">
            <el-option
              v-for="(item,index) in selectList.select2"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item :label="inputSearch17">
          <el-select @change="authTypeDbChange()" v-model="authStepData.authTypeDb" placeholder="请选择" style="width: 135px;">
            <el-option
              v-for="item in selectList.select3"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="inputSearch18" style="height: 28px;">
          <el-select v-model="authStepData.authUserId" :disabled="setUp.authUserIdFlag" placeholder="请选择" style="width: 135px;height: 28px;">
            <el-option
              v-for="(item,index) in selectList.select4"
              :key="index"
              :label="item.label"
              :value="item.value"
              >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="inputSearch19">
          <el-select v-model="authStepData.authGroupId" :disabled="setUp.authTypeDbFlag" placeholder="请选择" style="width: 135px;">
            <el-option
              v-for="item in selectList.select5"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="inputSearch20">
          <el-select v-model="authStepData.needAuthBeforePrintFlag"  placeholder="请选择" style="width: 135px;">
            <el-option
              v-for="item in selectList.select2"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="setUp.authStepReviewFlag = false">取消</el-button>
      <el-button type="primary" :disabled="setUp.saveAuthStepButton" @click="saveAuthStepModel()">确定</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>

import column from "../common/column";
  import {
    searchSysLanguagePackList,
    searchSysLanguageParam,
    searchFunctionButtonList,
    saveButtonList,
    searchSysLanguage,
    searchLanguageListByLanguageCode,
    saveSysLanguageOne
  } from "@/api/sysLanguage.js"
  import getLodop from '@/utils/LodopFuncs.js'
  import {
    saveTableDefaultList,
    saveTableUser,
    getTableDefaultListLanguage,
    getTableUserListLanguage
  } from "@/api/table.js"
  import {
    userFavoriteList,
    saveUserFavorite,
    removeUserFavorite
  } from '@/api/userFavorite.js'
import {
  getAuthRuleList,
  saveAuthRule,
  getAuthStepList,
  getUserList,
  getAuthGroupList,
  saveAuthStep,
  deleteAuthStep,
  deleteAuthRule,
  getBusinessRoleList,
} from '@/api/auditManagement/auditRules.js'
  export default {
    components: {
      column
    },
    data() {
      return {
        saveAuditRuleData :{
          recordTypeDb : '',
          ruleId : '',
          ruleDesc : '',
          site : this.$store.state.user.site,
          active : '',
          priority : 0,
          minValue : 0,
          maxValue : 0,
          remark : '',
          element1 : '',
          byElement1 : '',
          element2 : '',
          byElement2 : '',
          element3 : '',
          byElement3 : '',
          element4 : '',
          byElement4 : '',
        },
        authStepData : {
          id : 0,
          stepId : '',
          authTypeDb : '',
          authUserId : '',
          authGroupId : '',
          needAuthBeforePrintFlag : '',
          firstStepFlag : '',
          lastStepFlag : '',
        },
        authStepList : [],
        currentData : {},
        inputSearch1 : '记录类型',
        inputSearch2 : '规则编码',
        inputSearch3 : '规则描述',
        inputSearch4 : '状态',
        inputSearch5 : '规则编码',
        inputSearch6 : '规则描述',
        inputSearch7 : '记录类型',
        inputSearch8 : '状态',
        inputSearch9 : '最小金额',
        inputSearch10 : '最高金额',
        inputSearch11 : '优先级',
        inputSearch12 : '备注',
        inputSearch13 : '审批步骤信息',
        inputSearch14 : '审批步骤号',
        inputSearch15 : '最先审核',
        inputSearch16 : '最后审核',
        inputSearch17 : '类型',
        inputSearch18 : '用户名称',
        inputSearch19 : '组名称',
        inputSearch20 : '未审核打印',
        inputSearch21 : '审批步骤',
        site : this.$store.state.user.site,
        currAuditTeamData:{},
        //设置
        setUp :{
          //审核规则新增及编辑
          reviewFlag : false,
          //审核规则保存
          saveButton : false,
          //审核步骤
          authStepFlag : false,
          //审核步骤新增及编辑
          authStepReviewFlag : false,
          //审核步骤保存
          saveAuthStepButton : false,
          //用户选择select
          authUserIdFlag : false,
          //权限组选择select
          authTypeDbFlag : false,
        },
        selectList:{
          select1 : [{
            value: 'Y',
            label: '启用'
          },{
            value: 'N',
            label: '禁用'
          }],
          select2 :[{
            value: 'Y',
            label: '是'
          },{
            value: 'N',
            label: '否'
          }],
          select3 :[{
            value: 'P',
            label: '个人'
          },{
            value: 'G',
            label: '组'
          }],
          select4 : [],
          select5 : [],
          select6 : [],
        },
        mainQueryData :{
          site : this.$store.state.user.site,
          userId: this.$store.state.user.name,
          recordTypeDb : '',
          ruleId : '',
          ruleDesc : '',
          active : '',
        },
        // table高度
        height:450,
        // 是否收藏
        favorite: false,
        addLanguage: false,
        functionId: 2401,
        tableId: "auditRules2401",
        value1: true,
        visible: false,
        showDefault: false,
        // 默认table 查询参数
        queryTable: {
          functionId: 2401,
          tableId: "auditRules2401",
          languageCode: this.$i18n.locale
        },
        // 用户table 查询参数
        queryTableUser: {
          userId: this.$store.state.user.name,
          functionId: 2401,
          tableId: "auditRules2401",
          status: true,
          languageCode: this.$i18n.locale
        },
        // 语言词典查询参数
        querySysLanguageParam: {
          languageCode: this.$i18n.locale
        },
        // 语言词典集合
        sysLanguageParams: [],
        // 用户table 配置集合
        userColumnList: [],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditRules2401RecordTypeDb',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "recordTypeDb",
            headerAlign: "center",
            align: "center",
            columnLabel: "记录类型",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditRules2401RuleId',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "ruleId",
            headerAlign: "center",
            align: "center",
            columnLabel: "规则编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditTeam230RuleDesc',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "ruleDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "规则描述",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditTeam230Priority',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "priority",
            headerAlign: "center",
            align: "center",
            columnLabel: "优先级",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditTeam230MinValue',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "minValue",
            headerAlign: "center",
            align: "center",
            columnLabel: "最小金额",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditTeam230MinValue',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "maxValue",
            headerAlign: "center",
            align: "center",
            columnLabel: "最高金额",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditRules2401Active',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "active",
            headerAlign: "center",
            align: "center",
            columnLabel: "状态",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            serialNumber: 'auditRules2401Remark',
            tableId: "auditRules2401",
            tableName: "auditType",
            columnProp: "remark",
            headerAlign: "center",
            align: "center",
            columnLabel: "备注",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
        ],
        // 展示列集
        columnList1: [
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            tableId: "authStep2401",
            tableName: "authStep",
            columnProp: "stepId",
            headerAlign: "center",
            align: "center",
            columnLabel: "步骤号",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            tableId: "authStep2401",
            tableName: "authStep",
            columnProp: "authTypeDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "类型",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            tableId: "authStep2401",
            tableName: "authStep",
            columnProp: "userName",
            headerAlign: "center",
            align: "center",
            columnLabel: "用户名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            tableId: "authStep2401",
            tableName: "authStep",
            columnProp: "groupDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "组名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            tableId: "authStep2401",
            tableName: "authStep",
            columnProp: "printDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "未审批打印",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            tableId: "authStep2401",
            tableName: "authStep",
            columnProp: "firstStepDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "第一审批",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2401,
            tableId: "authStep2401",
            tableName: "authStep",
            columnProp: "lastStepDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "最后审批",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false,
          },
        ],
        // 数据集
        dataList: [],
        queryButton: {
          functionId: 2401,
          table_id: 'auditRules2401',
          languageCode: this.$i18n.locale,
          objectType: 'button'
        },
        buttons: {
          add: '新增',
          edit: '编辑',
          delete: '删除',
          cz: '操作',
          search: '查询',
          download: '导出',
          settingTable: '设置列表',
          defaultTable: '设置默认配置',
          reviewer : '审批步骤',
        },
        // 导出 start
        exportData: [],
        exportName: "页面功能语言",
        exportHeader: ["页面功能语言"],
        exportFooter: [],
        exportDefaultValue: "这一行这一列没有数据",
        // 导出 end
        buttonList: [
          // {
          //   functionId: "9001",
          //   languageValue: '添加',
          //   objectId: 'add',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '编辑',
          //   objectId: 'edit',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '删除',
          //   objectId: 'delete',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '批量删除',
          //   objectId: 'deleteList',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '操作',
          //   objectId: 'cz',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '查询',
          //   objectId: 'search',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '导出',
          //   objectId: 'download',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '设置列表',
          //   objectId: 'settingTable',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "9001",
          //   languageValue: '设置默认配置',
          //   objectId: 'defaultTable',
          //   objectType: "button",
          //   tableId: "common1001"
          // }
        ],
        languageList: [],
        languageColumnList: [],
        languageDataList: [],
        queryLanguage: {},
        // 数据集条件
        querySysLanguagePack: {
          page: 1,
          limit: 1,
          languageValue: '',
          objectType: '',
          objectId: ''
        },
        // 分页
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    mounted() {
      this.$nextTick(()=>{
        this.height = window.innerHeight - 200;
      })
    },
    activated() {
      this.getDataList()
      this.getLanguageList()
      this.initUserList()
      this.initAuthGroupList()
      this.getBusinessRoleList()
    },
    methods: {
      getBusinessRoleList(){
        let queryData = {
          active : 'Y'
        }
        this.selectList.select6 = []
        getBusinessRoleList(queryData).then(({data}) =>{
          let list = data.rows
          for (let i = 0; i < list.length; i++) {
            let selectData = {
              value : list[i].roleItemNo + "",
              label :list[i].roleDesc + '-' + list[i].roleItemNo,
            }
            this.selectList.select6.push(selectData)
          }
        })
      },
      //删除审核步骤
      deleteAuthStep(row){
        this.$confirm("确定删除该记录吗？", '删除提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(()=>{
          let delData = {
            id : row.id,
            ruleId : row.ruleId
          }
          deleteAuthStep(delData).then(({data}) => {
            if (data.code == 0) {
              this.initAuthStep(this.currentData)
            }
            this.$alert(data.msg, '操作提示', {
              confirmButtonText: '确定',
            });
          })
        }).catch(()=>{})
      },
      //保存审批步骤
      saveAuthStepModel(){
        this.setUp.saveAuthStepButton = true
        /*if(this.authStepData.stepId <= 0){
          this.$alert("请输入步骤号", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveAuthStepButton = false
            }
          });
          return
        }else*/ if(this.authStepData.authTypeDb == 'P' && this.authStepData.authUserId == ''){
          this.$alert("请选择用户", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveAuthStepButton = false
            }
          });
          return
        }else if(this.authStepData.authTypeDb == 'G' && this.authStepData.authGroupId == ''){
          this.$alert("请选择权限组", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveAuthStepButton = false
            }
          });
          return
        }
        saveAuthStep(this.authStepData).then(({data}) => {
          if (data.code == 0) {
            this.initAuthStep(this.currentData)
          }
          this.$alert(data.msg, '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              if (data.code == 0) {
                this.setUp.authStepReviewFlag = false
              }
              this.setUp.saveAuthStepButton = false
            }
          });
        })
      },
      //类型改变触发事件
      authTypeDbChange(){
        if(this.authStepData.authTypeDb == ''){
          this.authStepData.authUserId = ''
          this.authStepData.authGroupId = ''
          this.setUp.authUserIdFlag = true
          this.setUp.authTypeDbFlag = true
        }else if(this.authStepData.authTypeDb == 'P'){
          this.authStepData.authGroupId = ''
          this.setUp.authUserIdFlag = false
          this.setUp.authTypeDbFlag = true
        }else if(this.authStepData.authTypeDb == 'G'){
          this.authStepData.authUserId = ''
          this.setUp.authTypeDbFlag = false
          this.setUp.authUserIdFlag = true
        }
      },
      //获取权限组信息
      initAuthGroupList(){
        let queryData = {
          site : this.site,
        }
        getAuthGroupList(queryData).then(({data}) => {
          let resultList = data.rows
          this.selectList.select5 = []
          for (let i = 0; i < resultList.length; i++) {
            let data = {
              value: resultList[i].id,
              label: resultList[i].groupDesc
            }
            this.selectList.select5.push(data)
          }
        })
      },
      //获取用户信息
      initUserList(){
        let queryData = {
          site : this.site,
        }
        getUserList(queryData).then(({data}) => {
          let resultList = data.rows
          this.selectList.select4=[]
          for (let i = 0; i < resultList.length; i++) {
            let data = {
              value: resultList[i].userId,
              label: resultList[i].username
            }
            this.selectList.select4.push(data)
          }
        })
      },
      //审核步骤 新增及修改
      initAuthStepModel(row){
        if(row == null){
          this.authStepData.id = 0
          this.authStepData.stepId = ''
          this.authStepData.authTypeDb = 'P'
          this.authStepData.authUserId = ''
          this.authStepData.authGroupId = ''
          this.authStepData.needAuthBeforePrintFlag = 'Y'
          this.authStepData.firstStepFlag = 'Y'
          this.authStepData.lastStepFlag = 'Y'
        }else {
          this.authStepData.id = row.id
          this.authStepData.stepId = row.stepId
          this.authStepData.authTypeDb = row.authTypeDb
          this.authStepData.authUserId = parseInt(row.authUserId)
          this.authStepData.authGroupId = parseInt(row.authGroupId)
          this.authStepData.needAuthBeforePrintFlag = row.needAuthBeforePrintFlag
          this.authStepData.firstStepFlag = row.firstStepFlag
          this.authStepData.lastStepFlag = row.lastStepFlag
        }
        this.authStepData.ruleId = this.currentData.id
        this.authTypeDbChange()
        this.setUp.authStepReviewFlag = true
        this.setUp.saveAuthStepButton = false
      },
      //初始化 审批步骤
      initAuthStep(row){
        this.setUp.authStepFlag = true
        this.currentData = row
        this.authStepList = []
        let queryData = {
          ruleId : this.currentData.id
        }
        getAuthStepList(queryData).then(({data}) =>{
          this.authStepList = data.rows
        })
      },
      //删除审核规则
      delAuditRules(row){
        this.$confirm("确定删除该记录及子记录吗？", '删除提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(()=>{
          let delData = {
            id : row.id
          }
          deleteAuthRule(delData).then(({data}) => {
            if (data.code == 0) {
              this.getDataList()
            }
            this.$alert(data.msg, '操作提示', {
              confirmButtonText: '确定',
            });
          })
        }).catch(()=>{})
      },
      //保存审核规则
      saveAuditRules(){
        this.setUp.saveButton = true
        if(this.saveAuditRuleData.recordTypeDb == ''){
          this.$alert("请输入记录类型", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveButton = false
            }
          });
          return
        }else if(this.saveAuditRuleData.ruleId == ''){
          this.$alert("请输入规则编码", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveButton = false
            }
          });
          return
        }else if(this.saveAuditRuleData.ruleDesc == ''){
          this.$alert("请输入规则描述", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveButton = false
            }
          });
          return
        }/*else if(this.saveAuditRuleData.minValue <= 0){
          this.$alert("请输入最小金额", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveButton = false
            }
          });
          return
        }else if(this.saveAuditRuleData.maxValue <= 0){
          this.$alert("请输入最大金额", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveButton = false
            }
          });
          return
        }else if(this.saveAuditRuleData.minValue > this.saveAuditRuleData.maxValue){
          this.$alert("最小金额大于最大金额", '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.setUp.saveButton = false
            }
          });
          return
        }*/
        this.saveAuditRuleData.minValue = 0
        this.saveAuditRuleData.maxValue = 0
        saveAuthRule(this.saveAuditRuleData).then(({data}) => {
          if (data.code == 0) {
            this.getDataList()
          }
          this.$alert(data.msg, '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              if (data.code == 0) {
                this.setUp.reviewFlag = false
              }
              this.setUp.saveButton = false
            }
          });
        })
      },
      //初始化 审核规则新增模态框
      initModel(row){
        this.setUp.reviewFlag = true
        this.setUp.saveButton = false
        if(row == null){
          this.saveAuditRuleData.id = 0
          this.saveAuditRuleData.recordTypeDb = ''
          this.saveAuditRuleData.ruleId = ''
          this.saveAuditRuleData.ruleDesc = ''
          this.saveAuditRuleData.priority = 0
          this.saveAuditRuleData.active = 'Y'
          this.saveAuditRuleData.minValue = 0
          this.saveAuditRuleData.maxValue = 0
          this.saveAuditRuleData.element1 = ''
          this.saveAuditRuleData.byElement1 = ''
          this.saveAuditRuleData.element2 = ''
          this.saveAuditRuleData.byElement2 = ''
          this.saveAuditRuleData.element3 = ''
          this.saveAuditRuleData.byElement3 = ''
          this.saveAuditRuleData.element4 = ''
          this.saveAuditRuleData.byElement4 = ''
          this.saveAuditRuleData.remark = ''
        }else {
          this.saveAuditRuleData.id = row.id
          this.saveAuditRuleData.recordTypeDb = row.recordTypeDb
          this.saveAuditRuleData.ruleId = row.ruleId
          this.saveAuditRuleData.ruleDesc = row.ruleDesc
          this.saveAuditRuleData.priority = row.priority
          this.saveAuditRuleData.minValue = row.minValue
          this.saveAuditRuleData.maxValue = row.maxValue
          this.saveAuditRuleData.element1 = row.element1
          this.saveAuditRuleData.byElement1 = row.byElement1
          this.saveAuditRuleData.element2 = row.element2
          this.saveAuditRuleData.byElement2 = row.byElement2
          this.saveAuditRuleData.element3 = row.element3
          this.saveAuditRuleData.byElement3 = row.byElement3
          this.saveAuditRuleData.element4 = row.element4
          this.saveAuditRuleData.byElement4 = row.byElement4
          this.saveAuditRuleData.remark = row.remark
          if(row.active == "启用"){
            this.saveAuditRuleData.active = 'Y'
          }else {
            this.saveAuditRuleData.active = 'N'
          }
        }

      },
      // 打印方式
      printReport(){

        const LODOP = getLodop()
        if (LODOP) {
          var strBodyStyle = '<style>'
          strBodyStyle += 'table { border-top: 1 solid #000000; border-left: 1 solid #000000;  border-collapse:collapse;  border-spacing:0;}'
          strBodyStyle += 'caption {  line-height:2em; }'
          strBodyStyle += 'td { border-right: 1 solid #000000; border-bottom: 1 solid #000000; text-align:center; padding:2px 3px; font-size:11px;}'
          strBodyStyle += '</style>' //设置打印样式
          var strFormHtml = strBodyStyle + '<body>' + document.getElementById('commmon').innerHTML + '</body>'   //获取打印内容

          LODOP.PRINT_INIT('')  //初始化
          LODOP.PRINT_DESIGN();
          //LODOP.PREVIEW();
          //LODOP.PRINT();

          LODOP.SET_PRINT_PAGESIZE(2, 0, 0, 'A4')  //设置横向
          LODOP.ADD_PRINT_HTM('1%', '1%', '98%', '98%', strFormHtml)    //设置打印内容
          LODOP.SET_PREVIEW_WINDOW(2, 0, 0, 800, 600, '')  //设置预览窗口模式和大小
          LODOP.PREVIEW()
        }
      },
      // 校验用户是否收藏
      favoriteIsOk(){
        let userFavorite ={
          userId:this.$store.state.user.id,
          languageCode:this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) =>{
          let size = data.list.filter(item => item.menuId==this.$route.meta.menuId).length;
          if (size>0){
            this.favorite = true
          }else {
            this.favorite = false
          }
        })
      },
      // 收藏 OR 取消收藏
      favoriteFunction(){
        let userFavorite ={
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite){
          // 取消收藏
          this.$confirm(`确定取消收藏`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            removeUserFavorite(userFavorite).then(({data})=>{
              this.$message.success(data.msg)
              this.favorite = false
            })
          })
        }else {
          // 收藏
          saveUserFavorite(userFavorite).then(({data})=>{
            this.$message.success(data.msg)
            this.favorite = true
          })
        }

      },
      // 保存语言编辑
      saveLanguageList(val) {
        saveSysLanguageOne(val).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      // 编辑语言
      addLanguageFun() {
        if (this.querySysLanguagePack.languageCode) {
          this.addLanguage = true
          this.languageColumnList = []
          let query = {
            functionId: 2401,
            tableId: "common1002",
            languageCode: this.$i18n.locale
          }
          getTableDefaultListLanguage(query).then(({data}) => {
            if (data.rows.length > 0) {
              this.languageColumnList = data.rows
            }
          })
          this.languageColumnList = this.columnList
          searchLanguageListByLanguageCode(this.querySysLanguagePack).then(({data}) => {
            this.languageDataList = data.rows
          })
        } else {
          this.$message("请选中一种语言")
        }
      },
      // 获取多语言列表
      getLanguageList() {
        searchSysLanguage(this.queryLanguage).then(({data}) => {
          this.languageList = data.rows
        })
      },
      // 获取button的词典
      getFunctionButtonList() {

        searchFunctionButtonList(this.queryButton).then(({data}) => {
          if (data.data && data.data.length>0) {
            this.buttons = data.data
          }
        })
      },
      // 获取语言词典
      getSysLanguageParamList() {
        searchSysLanguageParam(this.querySysLanguageParam).then(({data}) => {
          this.sysLanguageParams = data.rows
        })
      },
      // 打开页面设置
      userSetting() {
        this.visible = true;
        let queryTable = {
          userId: this.$store.state.user.name,
          functionId: 2401,
          tableId: "auditRules2401",
          languageCode: this.$i18n.locale
        }
        this.$nextTick(() => {
          this.$refs.column.init(queryTable);
        });
      },
      // 获取 用户保存的 格式列
      getTableUserColumn() {
        getTableUserListLanguage(this.queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList = []
            this.columnList = data.rows
          } else {
            this.getColumnList()
          }

        })
      },
      // 保存 默认配置 列
      saveColumnList() {

        saveTableDefaultList(this.columnList).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.showDefault = false
          } else {
            this.$message.error(data.msg)
          }
        })
        saveTableDefaultList(this.columnList1).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.showDefault = false
          } else {
            this.$message.error(data.msg)
          }
        })
        saveButtonList(this.buttonList).then(({data}) => {
        })
        this.getFunctionButtonList()
        this.getFunctionButtonList();
        this.getColumnList()
      },
      // 获取 tableDefault 列
      getColumnList() {
        getTableDefaultListLanguage(this.queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            this.showDefault = false
            this.columnList = data.rows
          } else {
            this.showDefault = true
          }
        })
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        getAuthRuleList(this.mainQueryData).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.rows
            // this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 删除
      deleteHandle(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('//prd/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },

      fields(){
        let  json = "{"
        this.columnList.forEach((item,index) =>{
          if (index ==  this.columnList.length-1 ){
            json +="\""+item.columnLabel+"\"" +":"+"\""+item.columnProp+"\""
          }else {
            json += "\""+item.columnLabel+"\"" +":"+"\""+item.columnProp+"\""+ ","
          }
        })
        json +="}"
        let s = eval("(" + json + ")")
        return s
      },
      createExportData() {
        // 点击导出按钮之后,开始导出数据之前的执行函数,返回值为需要下载的数据
        // TODO:构造需要下载的数据返回
        if(this.dataListSelections.length>0){
          return this.dataListSelections;
        }
        return this.dataList;
      },
      startDownload() {
      //  this.exportData = this.dataList

      },
      finishDownload() {

      }
    },
    created() {
      this.getTableUserColumn()
      this.getSysLanguageParamList()
      this.getFunctionButtonList()
      this.favoriteIsOk()
    }
  }
</script>
<style scoped >
.wrapper {
  height: calc(100% - 40px);
}
  .sl-input {
    background-color: transparent;
    border: 0 !important;
    font-size: 12px !important;
    height: 12px !important;
    line-height: 14px !important;
    background-color: transparent !important;
    width: 140px;
  }

  .sl-input:focus, textarea:focus {

    outline: none;

  }
  .sl-svg{
    overflow: hidden;
    float: right;
  }

</style>
