<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" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buDesc" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in userBuList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buDesc">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'项目阶段'">
        <el-select v-model="searchData.projectPhase" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in projectPhaseList"
            :key = "i.projectPhase"
            :label = "i.projectPhase"
            :value = "i.projectPhase">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'项目分类'">
        <el-select v-model="searchData.projectCategory" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in projectCategoryList"
            :key = "i.projectCategory"
            :label = "i.projectCategory"
            :value = "i.projectCategory">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'文档类型ID'">
        <span slot="label" style="" @click="getBaseList(1056,1)"><a herf="#">文档类型ID</a></span>
        <el-input v-model="searchData.documentTypeId" style="width: 120px" clearable></el-input>
      </el-form-item>
      <el-form-item :label="'文档类型'">
        <el-input v-model="searchData.documentType" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" @click="getDataList()">查询</el-button>
        <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <el-table
      :height="height"
      :data="dataList"
      border
      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==''?false:item.fixed"
        :min-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="操作">
        <template slot-scope="scope">
          <a v-if="!authUpdate" type="text" size="small" @click="updateModal(scope.row)">修改</a>
          <a v-if="!authDelete" type="text" size="small" @click="deleteBuDocument(scope.row)">删除</a>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <el-dialog title="BU文档清单" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="425px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="BU" prop="bu" :rules="rules.bu">
          <el-select v-model="modalData.bu" placeholder="请选择" :disabled="modalDisableFlag" style="width: 110px">
            <el-option
              v-for = "i in userBuList"
              :key = "i.buNo"
              :label = "i.buDesc"
              :value = "i.buNo">
              <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;width: 60px">
                {{ i.buDesc }}
              </span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目阶段" prop="projectPhase" :rules="rules.projectPhase">
          <el-select v-model="modalData.projectPhase" placeholder="请选择" clearable style="width: 140px" @input="handleInput">
            <el-option
              v-for = "i in projectPhaseList"
              :key = "i.projectPhase"
              :label = "i.projectPhase"
              :value = "i.projectPhase">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目分类" prop="projectCategory" :rules="rules.projectCategoryType">
          <el-select v-model="modalData.projectCategory" placeholder="请选择" clearable style="width: 110px" @input="handleInput">
            <el-option
              v-for = "i in projectCategoryList"
              :key = "i.projectCategory"
              :label = "i.projectCategory"
              :value = "i.projectCategory">
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="是否在用" prop="active" :rules="rules.activeType">-->
<!--          <el-select filterable v-model="modalData.active" style="width: 140px">-->
<!--            <el-option label="是" value="Y"></el-option>-->
<!--            <el-option label="否" value="N"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="documentTypeId" :rules="rules.documentTypeIdType" v-if="!disableButton">
          <span slot="label" style="" @click="getBaseList(1056,2)"><a herf="#">文档类型ID</a></span>
          <el-input v-model="modalData.documentTypeId" disabled style="width: 110px"></el-input>
        </el-form-item>
        <el-form-item label="文档类型ID" prop="documentTypeId" :rules="rules.documentTypeIdType" v-if="disableButton">
          <el-input v-model="modalData.documentTypeId" disabled style="width: 110px"></el-input>
        </el-form-item>
<!--        <el-form-item label="文档类型ID" prop="documentTypeId" :rules="rules.documentTypeIdType">-->
<!--          <el-input v-model="modalData.documentTypeId" style="width: 230px"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="文档类型" prop="documentType" :rules="rules.documentTypeType">
          <el-input v-model="modalData.documentType" disabled style="width: 264px"></el-input>
        </el-form-item>
        <el-form-item label="责任部门" prop="responsibleDepartment" :rules="rules.responsibleDepartmentType">
          <el-input v-model="modalData.responsibleDepartment" disabled style="width: 110px"></el-input>
        </el-form-item>
        <el-form-item label="预计完成天数" prop="estimatedCompletionDays" :rules="rules.estimatedCompletionDaysType">
          <el-input v-model="modalData.estimatedCompletionDays" disabled style="width: 140px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveData()">保存</el-button>
        <el-button type="primary" @click="modalFlag = false;disableButton = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>

  </div>
</template>

<script>
  import {
    eamBuDocumentSearch,
    eamBuDocumentSave,
    eamBuDocumentEdit,
    eamBuDocumentDelete,
    getSiteAndBuByUserName
  } from "@/api/eam/eam.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  import {
    getTableDefaultListLanguage,
    getTableUserListLanguage,
  } from "@/api/table.js"
  import {EventBus} from "../../../main";
  import {queryEamBuDocument} from "../../../api/eam/eam";

  export default {
    components: {
      Chooselist
    },
    watch: {
      searchData: {
        deep: true,
        handler: function (newV, oldV) {
          this.searchData.documentTypeId = this.searchData.documentTypeId.toUpperCase()
        }
      },
    },
    data () {
      return {
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "BU文档清单" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["BU文档清单"],
        exportFooter: [],
        exportList:[],
        // 导出 end
        tagNo:'',
        tagNo1:'',
        searchData: {
          site: this.$store.state.user.site,
          userName: this.$store.state.user.name,
          projectCategory: '',
          documentTypeId: '',
          documentType: '',
          buDesc: '',
          responsibleDepartment: '',
          estimatedCompletionDays: '',
          projectPhase: '',
          // active: 'Y',
          page: 1,
          limit: 10,
        },
        height: 200,
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        dataList: [],
        selectTypeFlag: [],
        dataListSelections: [],
        modalFlag:false,
        modalDisableFlag:false,
        disableButton: false,
        isDataModified: false,
        modalData:{
          flag:'',
          bu: '',
          site: this.$store.state.user.site,
          documentTypeId:'',
          projectCategory:'',
          projectPhase:'',
          // active:'',
          createBy: this.$store.state.user.name,
          updateBy: this.$store.state.user.name,
        },
        modalCompareData:{
          flag:'',
          bu: '',
          site: this.$store.state.user.site,
          documentTypeId:'',
          projectCategory:'',
          projectPhase:'',
          // active:'',
          createBy: this.$store.state.user.name,
          updateBy: this.$store.state.user.name,
        },
        departmentList:[],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1BuDesc',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'buDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: 'BU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1ProjectPhase',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'projectPhase',
            headerAlign: "center",
            align: "left",
            columnLabel: '项目阶段',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1ProjectCategory',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'projectCategory',
            headerAlign: "center",
            align: "left",
            columnLabel: '项目分类',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1DocumentTypeId',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'documentTypeId',
            headerAlign: "center",
            align: "center",
            columnLabel: '文档类型ID',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1DocumentType',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'documentType',
            headerAlign: "center",
            align: "left",
            columnLabel: '文档类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1ResponsibleDepartment',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'responsibleDepartment',
            headerAlign: "center",
            align: "left",
            columnLabel: '责任部门',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1EstimatedCompletionDays',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'estimatedCompletionDays',
            headerAlign: "center",
            align: "left",
            columnLabel: '预计完成天数',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1CreateDate',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'createDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '创建时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1CreateBy',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'createBy',
            headerAlign: "center",
            align: "left",
            columnLabel: '创建人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1UpdateDate',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'updateDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '更新时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 401002,
            serialNumber: '401002Table1UpdateBy',
            tableId: "401002Table1",
            tableName: "BU文档清单表",
            columnProp: 'updateBy',
            headerAlign: "center",
            align: "left",
            columnLabel: '更新人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
        ],
        levelList: [],
        rules:{
          projectPhase:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          projectCategoryType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          documentTypeIdType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          documentTypeType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          responsibleDepartmentType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          estimatedCompletionDaysType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          activeType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          bu:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ]
        },
        projectCategoryList: [
          {
            projectCategory: 'Low Risk',
          },
          {
            projectCategory: 'High Risk',
          },
          {
            projectCategory: 'Sustaining',
          }
        ],
        projectPhaseList: [
          {
            projectPhase: 'Sample',
          },
          {
            projectPhase: 'Mass Production',
          },
        ],
        userBuList: [],
        authSearch: false,
        authSave: false,
        authUpdate: false,
        authDelete: false,
        menuId: this.$route.meta.menuId,
      }
    },

    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
      EventBus.$on('updateBuDocumentList', () => {
        this.getDataList();
      });
    },

    activated() {
      this.$store.commit("sift/commitSearchFunction",this.queryDataList)
    },

    created () {
      // 按钮控制
      this.getButtonAuthData()
      // 获取用户的 site 和 bu
      this.getSiteAndBuByUserName()
      // 校验用户是否收藏
      this.favoriteIsOk()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      if (!this.authSearch) {
        // 获取数据列表
        this.getDataList()
      }
      this.$refs.eamDocumentTypeDefinition.$on('getDataList', this.getDataList)
    },

    methods: {
      // 获取用户的bu
      getSiteAndBuByUserName () {
        let tempData = {
          username: this.$store.state.user.name,
        }
        getSiteAndBuByUserName(tempData).then(({data}) => {
          if (data.code === 0) {
            this.userBuList = data.rows
          }
        })
      },

      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.tagNo1 = type
        this.$nextTick(() => {
          let strVal = ''
          let conSql = ''
          if (val === 1056 ) {
            if (type === 1) {
              strVal = this.searchData.documentTypeId
              conSql = " and a.site = '" + this.$store.state.user.site + "'"
            } else {
              strVal = this.modalData.documentTypeId
              conSql = " and a.site = '" + this.$store.state.user.site + "'"
            }
            this.$refs.baseList.init(val, strVal, conSql)
          }

        })
      },

      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 1056) {
          if (this.tagNo1 === 2) {
            this.modalData.documentTypeId = val.document_type_id
            this.modalData.documentType = val.document_type
            this.modalData.responsibleDepartment = val.responsible_department
            this.modalData.estimatedCompletionDays = val.estimated_completion_days
          }
          if (this.tagNo1 === 1) {
            this.searchData.documentTypeId = val.document_type_id
          }
        }
      },

      // 校验用户是否收藏
      favoriteIsOk () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          languageCode: this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) => {
          for (let i = 0; i < data.list.length; i++) {
            if (this.$route.meta.menuId === data.list[i].menuId) {
              this.favorite = true
            }
          }
        })
      },

      // 收藏 OR 取消收藏
      favoriteFunction () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          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
          })
        }
      },

      //导出excel
      async createExportData () {
        this.searchData.limit = -1
        this.searchData.page = 1
        await eamBuDocumentSearch(this.searchData).then(({data}) => {
          this.exportList = data.page.list
        })
        return this.exportList
      },

      startDownload () {},

      finishDownload () {},

      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
      },

      // 获取数据列表

      // 获取数据列表
      getDataList (params) {
        this.selectTypeFlag = params
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        eamBuDocumentSearch(this.searchData).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            for (let i = 0; i < this.dataList.length; i++) {
              this.dataList[i].responsibleDepartment = this.dataList[i].roleDesc
            }
          }
        })
      },
      queryDataList (params) {
        this.selectTypeFlag = params
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        if (params !== null && params !== undefined) {
          params.limit = this.pageSize
          params.page = this.pageIndex
          params.site = this.$store.state.user.site
          params.userName = this.$store.state.user.name
        } else {
          params = this.searchData
        }
        queryEamBuDocument(params).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            for (let i = 0; i < this.dataList.length; i++) {
              this.dataList[i].responsibleDepartment = this.dataList[i].roleDesc
            }
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        if (this.selectTypeFlag !== null && this.selectTypeFlag !== undefined) {
          this.queryDataList(this.selectTypeFlag)
        } else {
          this.getDataList()
        }
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        if (this.selectTypeFlag !== null && this.selectTypeFlag !== undefined) {
          this.queryDataList(this.selectTypeFlag)
        } else {
          this.getDataList()
        }
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },

      addModal () {
        this.modalData = {
          flag: '1',
          bu: this.userBuList[0].buNo,
          site: this.$store.state.user.site,
          documentTypeId: '',
          documentType: '',
          projectCategory: '',
          responsibleDepartment: '',
          estimatedCompletionDays: '',
          projectPhase: '',
          // active: 'Y',
          createBy: this.$store.state.user.name,
          updateBy: this.$store.state.user.name,
        }
        this.modalDisableFlag = false
        this.modalFlag = true
      },

      updateModal (row) {
        this.modalData = {
          flag: '2',
          site: row.site,
          id: row.id,
          bu: row.site + '_' + row.buNo,
          documentTypeId: row.documentTypeId,
          documentType: row.documentType,
          projectCategory: row.projectCategory,
          responsibleDepartment: row.responsibleDepartment,
          estimatedCompletionDays: row.estimatedCompletionDays,
          projectPhase: row.projectPhase,
          // active: row.active,
          createBy: this.$store.state.user.name,
          updateBy: this.$store.state.user.name,
        }
        this.modalCompareData = {
          flag: '2',
          site: this.modalData.site,
          id: this.modalData.id,
          bu: this.modalData.bu,
          documentTypeId: this.modalData.documentTypeId,
          documentType: this.modalData.documentType,
          projectCategory: this.modalData.projectCategory,
          responsibleDepartment: this.modalData.responsibleDepartment,
          estimatedCompletionDays: this.modalData.estimatedCompletionDays,
          projectPhase: this.modalData.projectPhase,
          // active: this.modalData.active,
          createBy: this.modalData.createBy,
          updateBy: this.modalData.updateBy,
        }
        this.disableButton = true
        this.modalDisableFlag = true
        this.modalFlag = true
      },

      // 删除
      deleteBuDocument (row) {
        this.$confirm(`是否删除这个BU文档清单?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          eamBuDocumentDelete(row).then(({data}) => {
            if (data && data.code === '0') {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      saveData () {
        if (this.modalData.bu === '' || this.modalData.bu == null) {
          this.$message.warning('请选择BU！')
          return
        }
        if (this.modalData.documentTypeId === '' || this.modalData.documentTypeId == null) {
          this.$message.warning('请输入文档类型ID！')
          return
        }
        if (this.modalData.documentType === '' || this.modalData.documentType == null) {
          this.$message.warning('请输入文档类型！')
          return
        }
        if (this.modalData.projectCategory === '' || this.modalData.projectCategory == null) {
          this.$message.warning('请选择项目分类！')
          return
        }
        if (this.modalData.responsibleDepartment === '' || this.modalData.responsibleDepartment == null) {
          this.$message.warning('请输入责任部门！')
          return
        }
        if (this.modalData.estimatedCompletionDays === '' || this.modalData.estimatedCompletionDays == null) {
          this.$message.warning('请输入预计完成天数！')
          return
        }
        // if (this.modalData.active === '' || this.modalData.active == null) {
        //   this.$message.warning('选择是否在用！')
        //   return
        // }
        if (this.modalData.flag === '1') {
          eamBuDocumentSave(this.modalData).then(({data}) => {
            if (data && data.code === '0') {
              this.getDataList()
              this.modalFlag=false
              this.disableButton = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        } else {
          if (this.modalCompareData.projectCategory !== this.modalData.projectCategory || this.modalCompareData.projectPhase !== this.modalData.projectPhase) {
            // 用户进行了修改，可以继续保存数据
            // 向后端发送保存请求的逻辑
            eamBuDocumentEdit(this.modalData).then(({data}) => {
              if (data && data.code === '0') {
                EventBus.$emit('updateProjectInfo');
                this.getDataList()
                this.modalFlag=false
                this.disableButton = false
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {}
                })
              } else {
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            })
            this.modalCompareData.projectPhase = ''
            this.modalCompareData.projectCategory = ''
          } else {
            // 用户没有修改数据，不需要保存
            this.modalCompareData.projectPhase = ''
            this.modalCompareData.projectCategory = ''
            this.modalFlag = false;
            this.disableButton = false;
          }
        }
      },

      // 动态列开始 获取 用户保存的 格式列
      async getTableUserColumn(tableId, columnId) {
        let queryTableUser = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          status: true,
          languageCode: this.$i18n.locale
        }
        await getTableUserListLanguage(queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList1 = []
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.detailColumnList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            this.getColumnList(tableId, columnId)
          }
        })
      },

      // 获取 tableDefault 列
      async getColumnList (tableId, columnId) {
        let queryTable= {
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          languageCode: this.$i18n.locale
        }
        await getTableDefaultListLanguage(queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.detailColumnList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            // this.showDefault = true.
          }
        })
      },
      //获取按钮的权限数据
      getButtonAuthData () {
        let searchFlag = this.isAuth(this.menuId+":search")
        let saveFlag = this.isAuth(this.menuId+":save")
        let updateFlag = this.isAuth(this.menuId+":update")
        let deleteFlag = this.isAuth(this.menuId+":delete")
        //处理页面的权限数据
        this.authSearch = !searchFlag
        this.authSave = !saveFlag
        this.authUpdate = !updateFlag
        this.authDelete = !deleteFlag
      },
      handleInput() {
        this.isDataModified = true;
      }
    }
  }
</script>
<style scoped>
  .disabled-link {
    pointer-events: none; /* 禁止点击 */
    color: gray; /* 可选，改变颜色来显示不可点击状态 */
    text-decoration: none; /* 可选，去掉链接的下划线 */
  }
</style>
