<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-button @click="getData()" type="primary" style="margin-left: 2px;margin-top: 0px">{{ buttons.search }}
      </el-button>
      <el-button @click="addModal()" type="primary" :disabled="authAdd"
                 style="margin-left: 2px;margin-top: 0px">{{ buttons.add }}
      </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">
        {{ buttons.download }}
      </download-excel>

    </el-form>
    <el-table
      :height="height"
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="180"
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" v-if="scope.row.active=='Y'"
             @click="accessSiteModel(scope.row)">{{ buttons.role }}</a>
          <a type="text" size="small" v-if="!authEdit" @click="editSite(scope.row)">{{ buttons.update }}</a>
          <a type="text" size="small" @click="getCompanyInformation(scope.row)">{{ buttons.companyInformation }}</a>
          <!--          //v-if="jumpFlag"-->
        </template>
      </el-table-column>
      <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"
        :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>
    <el-dialog :title=labels.factoryInformation :close-on-click-modal="false" v-drag :visible.sync="siteFlag"
               width="630px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.site">
          <el-input v-model="siteData.siteID" :disabled="siteInputFlag" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.siteName_cn>
          <el-input v-model="siteData.siteName" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.siteName_en>
          <el-input v-model="siteData.siteNameE" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.postCode>
          <el-input v-model="siteData.postCode" style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item>
          <span slot="label" style="" @click="getBaseList(1003)"><a herf="#">{{ labels.company }}</a></span>
          <el-input v-model="siteData.companyID" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.referenceCustomerID>
          <el-input v-model="siteData.referenceCustomerID" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.active>
          <el-select filterable v-model="siteData.active" style="width: 130px">
            <el-option label="是" value="Y"></el-option>
            <el-option label="否" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label=labels.shipTime>
          <el-time-picker
            format="HH:mm:ss"
            style="width: 130px"
            v-model="siteData.shipTime"
            placeholder="请选择"
            value-format="HH:mm:ss">
          </el-time-picker>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label=labels.contactName>
          <el-input v-model="siteData.contactName" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.phoneNo>
          <el-input v-model="siteData.phoneNo" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.email>
          <el-input v-model="siteData.email" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label=labels.faxNo>
          <el-input v-model="siteData.faxNo" style="width: 130px"></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=labels.address>
          <el-input v-model="siteData.address" type="textarea" :autosize="{ minRows: 1, maxRows: 6}"
                    style="width: 562px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">

        <el-form-item :label=labels.addressE>
          <el-input v-model="siteData.addressE" type="textarea" :autosize="{ minRows: 1, maxRows: 6}"
                    style="width: 562px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label=labels.website>
          <el-input v-model="siteData.website" type="textarea" :autosize="{ minRows: 1, maxRows: 6}"
                    style="width: 562px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="siteSave()">{{ buttons.save }}</el-button>
        <el-button type="primary" @click="siteFlag = false">{{ buttons.close }}</el-button>
      </el-footer>
    </el-dialog>
    <!-- 动态列    -->
    <column v-if="visible" ref="column" @refreshData="getTableUserColumn" v-drag></column>

    <!--  授权  -->
    <el-dialog
      style="font-size: 12px"
      v-drag
      :title="'工厂授权'"
      :visible.sync="accessSiteVisible"
      width="518px"
      :append-to-body="true">
      <el-transfer class="rq" v-model="accessSiteList" filterable :props="{
      key: 'username',
      label: 'userDisplay'
      }" :data="userList" :titles="['未授权', '已授权']"></el-transfer>
      <span slot="footer" class="dialog-footer">
        <div style="margin-top: 5px">
                <el-button type="primary" @click="saveAccessSite()">确定</el-button>
                <el-button @click="accessSiteVisible = false" type="primary">取消</el-button>
        </div>

    </span>
    </el-dialog>

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

<script>

import column from "@/views/modules/common/column";
import {
  getSiteData,
  getCompanyData,
  siteSave,
  searchAccessSiteListBySite,
  saveAccessSiteForSite
} from "@/api/base/site.js"
import {
  searchFunctionButtonList,
} from "@/api/sysLanguage.js"
import {
  getTableDefaultListLanguage,
  getTableUserListLanguage,
} from "@/api/table.js"
import Chooselist from '@/views/modules/common/Chooselist'
import {siteList} from "../../../api/base/site";

var functionId = '100001002';

export default {
  name: "factoryInformation",
  components: {
    column, Chooselist
  },
  data() {
    return {
      rowSite: '',
      accessSiteVisible: false,
      accessSiteList: [],
      userList: [],
      queryTable: {
        functionId: this.$route.meta.menuId,
        tableId: "100001002Table",
        languageCode: this.$i18n.locale
      },
      // 用户table 查询参数
      queryTableUser: {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: "100001002Table",
        status: true,
        languageCode: this.$i18n.locale
      },
      jumpFlag: true,
      authEdit: false,
      authAdd: false,
      authDelete: false,
      menuId: this.$route.meta.menuId,
      tagNo: '',
      // 导出 start
      exportData: [],
      exportName: "工厂信息" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["工厂信息"],
      exportFooter: [],
      // 导出 end

      dataListLoading: false,
      // 多语言 start
      // 用户table 配置集合
      buttonList: [
        {
          functionId: functionId,
          languageValue: '查询',
          objectId: 'search',
          objectType: 'button',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '新增',
          objectId: 'add',
          objectType: 'button',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '导出',
          objectId: 'download',
          objectType: 'button',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '修改',
          objectId: 'update',
          objectType: 'button',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '查看会计单位信息',
          objectId: 'companyInformation',
          objectType: 'button',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '保存',
          objectId: 'save',
          objectType: 'button',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '关闭',
          objectId: 'close',
          objectType: 'button',
          tableId: '*',
        },
      ],
      labelsList: [
        {
          functionId: functionId,
          languageValue: '工厂编码',
          objectId: 'site',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '工厂信息',
          objectId: 'factoryInformation',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '工厂名称（中文）',
          objectId: 'siteName_cn',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '工厂名称（英文）',
          objectId: 'siteName_en',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '邮政编码',
          objectId: 'postCode',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '会计单位',
          objectId: 'company',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '参照客户编码',
          objectId: 'referenceCustomerID',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '在用',
          objectId: 'active',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '发货时间',
          objectId: 'shipTime',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '联系人',
          objectId: 'contactName',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '电话',
          objectId: 'phoneNo',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: 'email',
          objectId: 'email',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '传真',
          objectId: 'faxNo',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '地址(中文)',
          objectId: 'address',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '地址(英文)',
          objectId: 'addressE',
          objectType: 'label',
          tableId: '*',
        }, {
          functionId: functionId,
          languageValue: '公司网站',
          objectId: 'website',
          objectType: 'label',
          tableId: '*',
        },
      ],
      labels: {
        site: '工厂编码',
        factoryInformation: '工厂信息',
        siteName_cn: '工厂名称（中文）',
        siteName_en: '工厂名称（英文）',
        postCode: '邮政编码',
        company: '会计单位',
        referenceCustomerID: '参照客户编码',
        active: '在用',
        shipTime: '发货时间',
        contactName: '联系人',
        phoneNo: '电话',
        email: 'email',
        faxNo: '传真',
        address: '地址(中文)',
        addressE: '地址(英文)',
        website: '公司网站',
      },
      buttons: {
        search: '查询',
        add: '新增',
        download: '导出',
        update: '修改',
        companyInformation: '查看会计单位信息',
        save: '保存',
        close: '关闭',
        role: '授权',
      },
      queryButton: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'button'
      },
      queryLabel: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'label'
      },

      visible: false,
      // 多语言 end
      height: 200,
      siteFlag: false,
      siteInputFlag: true,
      siteData: {
        add: '',
        siteID: '',
        siteName: '',
        siteNameE: '',
        companyID: '',
        postCode: '',
        address: '',
        addressE: '',
        website: '',
        contactName: '',
        phoneNo: '',
        faxNo: '',
        email: '',
        active: 'Y',
        shipTime: '',
        referenceCustomerID: '',
      },
      dataList: [],
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableSiteID',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "siteID",
          headerAlign: "center",
          align: "left",
          columnLabel: "工厂编码",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 10,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableSiteName',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "siteName",
          headerAlign: "center",
          align: "left",
          columnLabel: "工厂名称",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 20,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableSiteNameE',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "siteNameE",
          headerAlign: "center",
          align: "left",
          columnLabel: "工厂名称(英文)",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 30,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableCompanyID',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "companyID",
          headerAlign: "center",
          align: "left",
          columnLabel: "会计单位",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 40,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableCompanyName',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "companyName",
          headerAlign: "center",
          align: "left",
          columnLabel: "会计单位名称",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 50,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableAddress',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "address",
          headerAlign: "center",
          align: "left",
          columnLabel: "地址",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 60,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableAddressE',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "addressE",
          headerAlign: "center",
          align: "left",
          columnLabel: "地址(英文)",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 70,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableWebsite',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "website",
          headerAlign: "center",
          align: "left",
          columnLabel: "公司网址",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 80,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableContactName',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "contactName",
          headerAlign: "center",
          align: "left",
          columnLabel: "联系人",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 90,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TablePostCode',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "postCode",
          headerAlign: "center",
          align: "left",
          columnLabel: "邮政编码",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 100,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TablePhoneNo',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "phoneNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "电话",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 110,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableFaxNo',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "faxNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "传真",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 120,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableEmail',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "email  ",
          headerAlign: "center",
          align: "left",
          columnLabel: "Email",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 130,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableActive',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "active",
          headerAlign: "center",
          align: "left",
          columnLabel: "在用",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 140,
          status: true,
          fixed: '',
          columnWidth: 50
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100001002,
          serialNumber: '100001002TableShipTime',
          tableId: "100001002Table",
          tableName: "工厂信息表",
          columnProp: "shipTime",
          headerAlign: "center",
          align: "left",
          columnLabel: "发货时间",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 150,
          status: true,
          fixed: '',
          columnWidth: 120
        }
      ],
    }
  },

  mounted() {
    this.$nextTick(() => {
      this.height = window.innerHeight - 140;
    })
  },
  watch: {
    '$route'(to, from) {
      if (localStorage.getItem('factoryInformation') != undefined) {
        this.getData();
      }
    }
  },
  methods: {
    getBaseData(val) {

      this.$nextTick(() => {
        if (this.tagNo === 1003) {
          this.siteData.companyID = val.CompanyID
        }
      })

    },
    // 获取基础数据列表
    getBaseList(val) {
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = "";
        if (val === 1003 && this.siteData.companyID) {
          strVal = this.siteData.companyID
        }
        this.$refs.baseList.init(val, strVal)
      })
    },
    getData() {
      let data = {};
      if (localStorage.getItem('factoryInformation') != undefined) {
        data = JSON.parse(localStorage.getItem('factoryInformation'));
      }
      localStorage.removeItem('factoryInformation');
      getSiteData(data).then(({data}) => {
        this.dataList = data.rows
      })
    },
    addModal() {
      this.siteData = {
        add: '',
        siteID: '',
        siteName: '',
        siteNameE: '',
        companyID: '',
        postCode: '',
        address: '',
        addressE: '',
        website: '',
        contactName: '',
        phoneNo: '',
        faxNo: '',
        email: '',
        active: 'Y',
        shipTime: '',
        referenceCustomerID: '',

      },
        this.siteData.add = 0;
      this.siteInputFlag = false;
      this.siteData.active = 'Y';
      this.siteFlag = true;
    },
    editSite(row) {
      this.siteData = JSON.parse(JSON.stringify(row));
      this.siteData.add = 1;
      this.siteInputFlag = true;
      this.siteFlag = true;
    },
    siteSave() {
      siteSave(this.siteData).then(({data}) => {
        if (this.siteData.companyID == '' || this.siteData.companyID == null) {
          this.$alert("请选择会计单位！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.siteData.siteID == '' || this.siteData.siteID == null) {
          this.$alert("请输入工厂编码！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        if (this.siteData.siteName == '' || this.siteData.siteName == null) {
          this.$alert("请输入工厂名称！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }

        if (data && data.code == 200) {
          this.siteFlag = false
          this.getData();
          this.$message.success('操作成功')
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },
    saveAccessSite() {
      let accessSiteList = []
      for (let i = 0; i < this.accessSiteList.length; i++) {
        let inData = {
          site: this.rowSite,
          userid: this.accessSiteList[i]
        }
        accessSiteList.push(inData)
      }
      let saveData = {
        site: this.rowSite,
        accessSiteList: accessSiteList,
      }
      saveAccessSiteForSite(saveData).then(({data}) => {
        if (data && data.code === 0) {
          this.$message.success('操作成功')
          this.accessSiteVisible = false
        } else {
          this.$message.error(data.msg)
        }
      })
    },
    //导出excel
    createExportData() {

      return this.dataList;

    },
    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
    getCompanyInformation(row) {
      let inData = {companyID: row.companyID, companyName: row.companyName};
      localStorage.setItem('companyInformation', JSON.stringify(inData))
      this.$router.replace('base-companyInformation')
    },

    //获取按钮的权限数据
    getButtonAuthData() {
      let updateFlag = this.isAuth(this.menuId + ":revise");
      let fullControFlag = this.isAuth(this.menuId + ":fullContro");
      let deleteFlag = this.isAuth(this.menuId + ":remove");
      //处理页面的权限数据
      this.authEdit = !updateFlag || !fullControFlag;
      this.authAdd = !fullControFlag;
      this.authDelete = !deleteFlag;

      //跳转页面
      let menList = JSON.parse(sessionStorage.getItem('dynamicMenuRoutes') || '[]').filter(item => item.path == 'base-companyInformation')
      if (menList.length > 0) {
        this.jumpFlag = false
      }
    },

    accessSiteModel(row) {
      searchAccessSiteListBySite({
        site: row.siteID,
      }).then(({data}) => {
        this.accessSiteList = data.accessSiteList
        this.userList = data.userList
      })
      this.rowSite = row.siteID
      this.accessSiteVisible = true;
    },

    //多语言
    getMultiLanguageList() {
      //首先查询当前按钮的多语言
      searchFunctionButtonList(this.queryButton).then(({data}) => {
        if (data.code == 0) {
          this.buttons = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
      //其次查询当前标签的多语言
      searchFunctionButtonList(this.queryLabel).then(({data}) => {
        if (data.code == 0) {
          this.labels = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
    },
    // 打开页面设置
    userSetting() {
      this.visible = true;
      let queryTable = {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: this.queryTable.tableId,
        languageCode: this.$i18n.locale
      }
      this.$nextTick(() => {
        this.$refs.column.init(queryTable);
      });
    },
    // 获取 用户保存的 格式列
    getTableUserColumn(tableId) {
      console.log(tableId)
      getTableUserListLanguage(this.queryTableUser).then(({data}) => {
        if (data.rows.length > 0) {
          //this.columnList = []
          this.columnList = data.rows
        } else {
          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
        }
      })
    },
    getSiteDataDemo(params){
      params.no = 1
      params.size = 1
      // this.$message.success(params)
      siteList(params).then(({data})=>{
        if (data && data.code === 0){
          this.$message.success(data.msg)
        }else {
          this.$message.warning(data.msg)
        }
      }).catch((error)=>{
        this.$message.error(error)
      })
    }
  },
  created() {
    this.getMultiLanguageList()//刷新按钮
    this.getData();
    //获取按钮的权限
    this.getButtonAuthData();
    this.getTableUserColumn()
  },
  activated() {
    this.$store.commit("sift/commitSearchFunction",this.getSiteDataDemo)
  }
}
</script>

<style>


.el-textarea__inner {
  padding: 5px 5px;
}

</style>
