<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="'类别编码'">
        <el-input v-model="searchData.familyID"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'类别名称'">
        <el-input v-model="searchData.familyName"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="doEmpty()">清空</el-button>
        <el-button type="primary" @click="getDataList()">查询</el-button>
        <el-button type="primary" @click="addModal()">新增</el-button>
      </el-form-item>
      <el-form-item  :label="' '">
        <el-button type="primary" icon="el-icon-upload" @click="qcUpload()">导入</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
      v-loading="dataListLoading"
      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="160"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="detailModal(scope.row)">检验模板</a>
          <a type="text" size="small" @click="deletePropertiesModel(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, 1000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 类别属性新增/修改 -->
    <el-dialog title="类别属性设置"  :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="430px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(1042)"><a herf="#">类别编码</a></span>
          <el-input v-model="modalData.familyID" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="类别名称:">
          <el-input v-model="modalData.familyName" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="备注:">
          <el-input v-model="modalData.attributeRemark" style="width: 120px"></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">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 检验模板 -->
    <el-dialog title="检验模板清单" :close-on-click-modal="false" v-drag :visible.sync="detailModelFlag" width="1500px">
      <el-form :inline="true"  label-position="top"  @keyup.enter.native="getDataList()">
        <el-form-item :label="'类别编码'">
          <el-input v-model="detailData.familyID"  readonly style="width: 100px"></el-input>
        </el-form-item>
        <el-form-item :label="'类别名称'">
          <el-input v-model="detailData.familyName"  readonly style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item  :label="' '">
          <el-button  type="primary" @click="addFastModal()">新增</el-button>
        </el-form-item>
      </el-form>
      <!-- 检验项目展示列表 -->
      <div class="rq ">
        <el-table
          :height="300"
          :data="detailList"
          border
          v-loading="dataListLoading"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnDetailList" :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
            prop=""
            header-align="center"
            align="center"
            min-width="150"
            label="检验水平">
            <template slot-scope="scope">
              <el-button type="primary" @click="chooseLevel(scope.row)" style="width:35%" >点击选择</el-button>
              <el-input v-model="scope.row.samplingLevelDesc" readonly style="width:60%;"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="center"
            min-width="60"
            label="检验周期(h)">
            <template slot-scope="scope">
              <el-input v-model="scope.row.inspectionCycle" type="number" style="height: 11px;padding: 0px " allow-create>;width:98%"</el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="center"
            min-width="150"
            label="抽样方案">
            <template slot-scope="scope">
              <el-button type="primary" @click="chooseProgrammeRow(scope.row)" style="width:35%" >点击选择</el-button>
              <el-input v-model="scope.row.samplingProgrammeDesc" readonly style="width:60%;"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="center"
            min-width="60"
            label="AQL">
            <template slot-scope="scope">
              <el-input v-model="scope.row.aql" type="number" style="height: 11px;padding: 0px " allow-create>;width:98%"</el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="center"
            min-width="60"
            label="AC">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ac" type="number" style="height: 11px;padding: 0px " allow-create>;width:98%"</el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="center"
            min-width="60"
            label="RE">
            <template slot-scope="scope">
              <el-input v-model="scope.row.re" type="number" style="height: 11px;padding: 0px " allow-create>;width:98%"</el-input>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            header-align="center"
            align="center"
            width="80"
            label="操作">
            <template slot-scope="scope">
              <a type="text" size="small"  @click="deletePartAttributeDetails(scope.row)">删除模板</a>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveDetail()">保存</el-button>
        <el-button type="primary" @click="detailModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 检验模板->快速新增 -->
    <el-dialog title="新增" @close="refreshDetailList" :close-on-click-modal="false" v-drag :visible.sync="fastAddFlag" width="800px">
      <div style="font-size: 12px">
        <el-form :inline="true"  label-position="top" :model="detailData">
          <el-form-item :label="'模板编码'">
            <el-input v-model="detailData.templateId"  style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'模板名称'">
            <el-input v-model="detailData.templateName"  style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item label="检验类型">
            <el-select v-model="detailData.inspectionTypeNo" placeholder="请选择">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for = "i in options"
                :key = "i.inspectionTypeNo"
                :label = "i.inspectionTypeName"
                :value = "i.inspectionTypeNo">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="checkInspectionType()">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-container style="margin-top: -12px;">
        <el-main style="width: 300px">
          <span  style="font-size: 12px" >可选模板：</span>
          <el-table
            height="300px"
            :data="itemList1"
            border
            @row-click="clickItem1"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              prop="templateId"
              header-align="center"
              align="left"
              min-width="110"
              label="模板编码">
            </el-table-column>
            <el-table-column
              prop="templateName"
              header-align="center"
              align="left"
              min-width="170"
              label="模板名称">
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 100px">
          <div style="margin-top: 100px">
            <el-button type="primary" @click="addItem()">添加>></el-button>
          </div>
          <div style="margin-top: 20px">
            <el-button type="primary" @click="deleteItem()">删除<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 300px">
          <span  style="font-size: 12px" >已有模板：</span>
          <el-table
            height="300px"
            :data="itemList2"
            border
            @row-click="clickItem2"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              prop="templateId"
              header-align="center"
              align="left"
              min-width="110"
              label="模板编码">
            </el-table-column>
            <el-table-column
              prop="templateName"
              header-align="center"
              align="left"
              min-width="170"
              label="模板名称">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
      <el-footer  style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="fastAddFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
    <!-- 导入 -->
    <qcUpload ref="qcUpload" @refreshPageTables="getDataList()" v-drag></qcUpload>
  </div>
</template>

<script>
  import {
    qcFamilyAttributeSearch, // 查询类别属性
    qcFamilyAttributeSave, // 新增类别属性
    qcFamilyAttributeDelete, // 删除类别属性
    InspectionTypeSearch, // 搜索所有检验类型
    savePartAttributeDetails, // 新增分类属性模板
    deletePartAttributeDetails, // 删除分类属性模板
    searchPartAttributeDetails, // 查询物料属性模板
    saveAttributeDetailed, // 新增物料属性模板详情
    getItemLists // 获取模板列表
  } from "@/api/qc/qc.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  import qcUpload from "./qc_upload";
  export default {
    components: {
      Chooselist,
      qcUpload
    },
    watch: {

    },
    data () {
      return {
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "根据类别设置检验模板" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["根据类别设置检验模板"],
        exportFooter: [],
        exportList:[],
        // 导出 end
        tagNo:'',
        searchData: {
          familyID: '',
          familyName: '',
          attributeType: 'B',
          page: 1,
          limit: 10,
        },
        height: 200,
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        // addDetailModalFlag:false,
        modalFlag:false,
        modalDisableFlag:false,
        modalData:{
          flag: '',
          familyID: '',
          familyName: '',
          supplierNo: '',
          supplierDesc: '',
          attributeRemark: '',
          createBy: this.$store.state.user.name,
          attributeType: 'B',
        },
        detailData:{
          site: this.$store.state.user.site,
          familyID: '',
          familyName: '',
          attributeNo: '',
          attributeType: 'B',
          inspectionTypeNo: '',
          templateId: '',
          templateName: '',
          createBy: this.$store.state.user.name
        },
        columnList: [
          {
            columnProp: 'familyID',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料类别编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'familyName',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料类别名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'attributeRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'createTime',
            headerAlign: "center",
            align: "left",
            columnLabel: '操作时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'createBy',
            headerAlign: "center",
            align: "left",
            columnLabel: '操作人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
        ],
        detailModelFlag:false,
        detailList: [],
        dataListLoading: false,
        dataList:[],
        // 展示列集
        columnDetailList: [
          {
            columnProp: 'templateId',
            headerAlign: "center",
            align: "left",
            columnLabel: '模板编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'templateName',
            headerAlign: "center",
            align: "left",
            columnLabel: '模板名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'inspectionTypeName',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'templateRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'templateVersion',
            headerAlign: "center",
            align: "left",
            columnLabel: '版本号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
        ],
        // 快速添加
        fastAddFlag:false,
        itemList1:[],
        itemList2:[],
        itemListRow1:{},
        itemListRow2:{},
        options: [],
        tempProgrammeRow:'',
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },
    created () {
      this.getDataList()
      this.favoriteIsOk()
    },
    methods: {
      // 查询检验类型
      InspectionTypeSearch(){
        InspectionTypeSearch().then(({data}) => {
          if (data.code === 0) {
            this.options = data.rows
          }
        })
      },
      // 清空搜索栏
      doEmpty(){
        this.searchData = {
          codeNo: '',
          codeDesc: '',
          active:'',
          familyName:'',
          functionType:'D',
          inspectionTypeName:'',
          page: 1,
          limit: 10,
        }
      },
      chooseLevel(row){
        this.tempLevelRow = row;
        this.getBaseList(1048);
      },
      chooseProgrammeRow(row){
        this.tempProgrammeRow = row;
        this.getBaseList(1051);
      },
      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 1042) {
            strVal = this.modalData.familyID
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1048) {
            strVal = this.tempLevelRow.samplingLevelNo
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1051) {
            strVal = this.tempProgrammeRow.samplingProgrammeNo
            this.$refs.baseList.init(val, strVal)
          }
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 1042) {
          this.modalData.familyID = val.FamilyID
          this.modalData.familyName = val.FamilyName
        }
        if (this.tagNo === 1048) {
          this.tempLevelRow.samplingLevelNo = val.sampling_level_no
          this.tempLevelRow.samplingLevelDesc = val.sampling_level_desc
        }
        if (this.tagNo === 1051) {
          this.tempProgrammeRow.samplingProgrammeNo = val.sampling_programme_no
          this.tempProgrammeRow.samplingProgrammeDesc = val.sampling_programme_desc
        }
      },
      // 获取数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        qcFamilyAttributeSearch(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
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      addModal(){
        this.modalData={
          flag: '1',
          familyID: '',
          familyName: '',
          supplierNo: '',
          supplierDesc: '',
          attributeRemark: '',
          createBy: this.$store.state.user.name,
          attributeType: 'B',
        };
        this.modalDisableFlag = false;
        this.modalFlag = true;
      },
      // 删除
      deletePropertiesModel (row) {
        this.$confirm(`是否删除这个分类属性?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          qcFamilyAttributeDelete(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.familyID == '' || this.modalData.familyID == null) {
          this.$alert('请选择物料分类编码！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.familyName == '' || this.modalData.familyName == null) {
          this.$alert('请选择物料分类名称！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.modalData.flag=='1'){
          qcFamilyAttributeSave(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.modalFlag=false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },
      // 保存属性模板
      saveDetail(){
        for (let i = 0; i < this.detailList.length; i++) {
          saveAttributeDetailed(this.detailList[i]).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.detailModelFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              }).then(() => {
                return false
              })
            }
          })
        }
      },
      //打开分类模板清单
      detailModal(row){
        this.detailData.familyID = row.familyID
        this.detailData.attributeNo = row.familyID
        this.detailData.partDesc = row.partDesc
        searchPartAttributeDetails(this.detailData).then(({data}) => {
          this.detailList = data.rows
        })
        this.detailModelFlag = true;
      },
      // // 普通新增
      // addDetailModal(){
      //   this.detailData.itemNo = '';
      //   this.detailData.itemDesc = '';
      //   this.addDetailModalFlag = true;
      // },
      checkInspectionType(){
        getItemLists(this.detailData).then(({data}) => {
          this.itemList1 = data.row1;
          this.itemList2 = data.row2;
        })
      },
      // 快速新增
      addFastModal(){
        this.itemListRow2 = null
        this.itemListRow1 = null
        this.InspectionTypeSearch()
        getItemLists(this.detailData).then(({data}) => {
          this.itemList1 = data.row1;
          this.itemList2 = data.row2;
        })
        this.fastAddFlag = true;
      },
      clickItem1(row){
        this.itemListRow1 = JSON.parse(JSON.stringify(row));
      },
      clickItem2(row){
        this.itemListRow2 = JSON.parse(JSON.stringify(row));
      },
      // 添加模板
      addItem(){
        if(this.itemListRow1 == null){
          this.$alert("请选择可选模板！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        let inData={
          attributeNo: this.detailData.familyID,
          templateId: this.itemListRow1.templateId,
          attributeType: this.detailData.attributeType,
          site: this.$store.state.user.site
        }
        savePartAttributeDetails(inData).then(({data}) => {
          if (data && data.code == 0) {
            getItemLists(this.detailData).then(({data}) => {
              this.itemList1=data.row1;
              this.itemList2=data.row2;
            })
            this.itemListRow1=null
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      // 删除项目
      deleteItem(){
        if(this.itemListRow2 == null){
          this.$alert("请选择已选模板！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        let inData = {
          attributeNo:this.detailData.familyID,
          templateId: this.itemListRow2.templateId,
          site:this.$store.state.user.site
        }
        deletePartAttributeDetails(inData).then(({data}) => {
          if (data && data.code === 0) {
            getItemLists(this.detailData).then(({data}) => {
              this.itemList1 = data.row1;
              this.itemList2 = data.row2;
            })
            this.itemListRow2 = null
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      // 关闭后刷新列表
      refreshDetailList(){
        searchPartAttributeDetails(this.detailData).then(({data}) => {
          this.detailList = data.rows
        })
      },
      // 删除物料属性中的模板
      deletePartAttributeDetails(row){
        this.$confirm(`是否删除这个检验模板?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deletePartAttributeDetails(row).then(({data}) => {
            if (data && data.code === 0) {
              searchPartAttributeDetails(this.detailData).then(({data}) => {
                this.detailList = data.rows
              })
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

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

        })
      },
      // 收藏 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
          })
        }
      },

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

        return this.exportList;
      },
      startDownload() {
        //  this.exportData = this.dataList

      },
      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
      },
      // 导出 end

      // 导入
      qcUpload(){
        let currentData = {
          flag: 'familyAttribute',
          createBy: this.$store.state.user.name,
          site: this.$store.state.user.site,
        };
        //打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.qcUpload.init(currentData);
        })
      },

    }
  }
</script>
