<template>
  <div class="mod-config">
    <el-row>
      <el-col :span="24">
        <div>
        <span @click="favoriteFunction()">
         <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>
        </span>
        </div>
        <el-button @click="getDataList()" type="primary">查询</el-button>
        <el-button @click="initModel()" type="primary">新增</el-button>
<!--        <el-button @click="saveColumnList()" type="primary" v-show="showDefault">设置默认配置</el-button>-->
<!--        <el-button @click="userSetting" type="primary">设置列表</el-button>-->
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :defaultValue="exportDefaultValue"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          导出
        </download-excel>

        <el-button v-if="isAuth(':prd:delete')" type="danger" @click="deleteHandle()"
                   :disabled="dataListSelections.length <= 0">{{ buttons.deleteList}}
        </el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form :inline="true" label-position="top">
          <el-form-item :label="inputLabel.headerInput.label1">
            <el-input style="width: 100px;" v-model="queryHeaderData.locationId"></el-input>
          </el-form-item>
          <el-form-item :label="inputLabel.headerInput.label2">
            <el-input style="width: 100px;" v-model="queryHeaderData.locationName"></el-input>
          </el-form-item>
          <el-form-item :label="inputLabel.headerInput.label3">
            <el-select v-model="queryHeaderData.warehouseId" placeholder="请选择" style="width: 115px;">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in selectList.select2"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="inputLabel.headerInput.label4">
            <el-select v-model="queryHeaderData.active" placeholder="请选择" style="width: 115px;">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in selectList.select1"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-table
          id="commmon"
          :height="height"
          :data="dataList"
          border
          v-loading="dataListLoading"
          @selection-change="selectionChangeHandle"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?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-column
            fixed="right"
            header-align="center"
            align="center"
            width="90"
            :label="操作">
            <template slot-scope="scope">
              <a @click="initModel(scope.row)">编辑</a>
              <a @click="delHeaderData(scope.row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="queryHeaderData.page"
          :page-sizes="[5, 10, 20]"
          :page-size="queryHeaderData.size"
          :total="queryHeaderData.totalCount"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </el-col>
    </el-row>
    <column v-if="visible" ref="column" @refreshData="getTableUserColumn"></column>

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-drag
               :title="inputLabel.headerInput.label5" :visible.sync="setUp.reviewFlag" width="325px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="inputLabel.headerInput.label1">
          <el-input style="width: 130px;" :readonly="setUp.readonlyFlag?'readonly':false" v-model="saveHeaderData.locationId"></el-input>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label2">
          <el-input style="width: 130px;" v-model="saveHeaderData.locationName"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item :label="inputLabel.headerInput.label3">
          <el-select v-model="saveHeaderData.warehouseId" :disabled="setUp.readonlyFlag?'disabled':false" placeholder="请选择" style="width: 130px;">
            <el-option
              v-for="item in selectList.select2"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label4">
          <el-select v-model="saveHeaderData.active" :disabled="setUp.readonlyFlag?'disabled':false" placeholder="请选择" style="width: 130px;">
            <el-option
              v-for="item in selectList.select1"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label8">
          <el-input style="width: 130px;" :readonly="setUp.readonlyFlag?'readonly':false" v-model="saveHeaderData.hold"></el-input>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label9">
          <el-input style="width: 130px;" :readonly="setUp.readonlyFlag?'readonly':false" v-model="saveHeaderData.row"></el-input>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label10">
          <el-input style="width: 130px;" :readonly="setUp.readonlyFlag?'readonly':false" v-model="saveHeaderData.storey"></el-input>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label11">
          <el-input style="width: 130px;" :readonly="setUp.readonlyFlag?'readonly':false" v-model="saveHeaderData.box"></el-input>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label6">
          <span style="cursor: pointer"  slot="label" @click="queryLocationGruop"><a>位置组编码</a></span>
          <el-input style="width: 130px;" readonly v-model="saveHeaderData.locationGroupId"></el-input>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label7">
          <el-input style="width: 130px;" readonly v-model="saveHeaderData.locationGroupDesc"></el-input>
        </el-form-item>
        <el-form-item :label="inputLabel.headerInput.label12">
          <el-input style="width: 130px;" v-model="saveHeaderData.locationType"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
            <el-button type="primary" :disabled="setUp.saveButton" @click="saveHeaderFunction()">确定</el-button>
            <el-button type="primary" @click="setUp.reviewFlag = false">取消</el-button>

    </span>
    </el-dialog>

    <!-- 新增时位置组编码选择dialog-->
    <el-dialog title="物料选择" :close-on-click-modal="false" v-drag :visible.sync="localtionGruopFlag" width="520px">
      <div class="rq">
        <el-form :inline="true" label-position="top" :model="locationGruopModalData">
          <el-form-item :label="'物料编码'">
            <el-input v-model="locationGruopModalData.locationGroupId" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'物料名称'">
            <el-input v-model="locationGruopModalData.locationGroupDesc" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="queryLocationGruop">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :height="300"
          :data="locationGruopDataList"
          @row-dblclick="getRowData"
          border
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in locationGruop_colum" :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>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="localtionGruopFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

  </div>
</template>

<script>

  import column from "../common/column";
  import {
    searchSysLanguagePackList,
    searchSysLanguageParam,
    searchFunctionButtonList,
    saveButtonList,
    searchSysLanguage,
    searchLanguageListByLanguageCode,
    saveSysLanguageOne
  } from "@/api/sysLanguage.js"
  import getLodop from '@/utils/LodopFuncs.js'
  import {
    saveTableDefaultList,
    saveTableUser,
    getTableDefaultListLanguage,
    getTableUserListLanguage,
    removerDefault,
    removerUser
  } from "@/api/table.js"
  import {
    userFavoriteList,
    saveUserFavorite,
    removeUserFavorite,
  } from '@/api/userFavorite.js'
  import {
    getWarehouseList,
    getLocationList,
    saveLocation,
    delLocation,
    queryAllLocationGruopList
  } from '@/api/warehouse/location.js'

  export default {
    components: {
      column
    },
    data() {
      return {
        saveHeaderData: {
          id: 0,  // 业务字段，0=新增，1=编辑 - rqrq
          site: '',  // 业务字段，工厂编码 - rqrq
          locationId: '',
          locationName: '',
          warehouseId: '',
          active: '',
          hide: '',  // 是否隐藏 - rqrq
          locationGroupId: '',
          locationGroupDesc: '',  // 业务字段，库位组描述 - rqrq
          locationType:'',
          hold:'',
          row:'',
          storey:'',
          box:'',
        },
        locationGruopModalData: {
          locationGroupId: '',
          locationGroupDesc: ''
        },
        locationGruopDataList: [],
        localtionGruopFlag: false,
        queryHeaderData: {
          site: this.$store.state.user.site,
          locationId: '',
          locationName: '',
          warehouseId: '',
          active: '',
          page:1,
          size:5,
          totalCount:0
        },
        setUp: {
          reviewFlag: false,
          saveButton: false,
          reviewFlag1: false,
          readonlyFlag: false,
        },
        inputLabel: {
          headerInput: {
            label1: '库位编码',
            label2: '库位名称',
            label3: '仓库名称',
            label4: '状态',
            label5: '库位信息',
            label6: '位置组编码',
            label7: '位置组描述',
            label8: '货舱',
            label9: '行',
            label10: '层',
            label11: '箱',
            label12: '库位类型'
          },
        },
        selectList: {
          select1: [{
            value: 'Y',
            label: '启用'
          }, {
            value: 'N',
            label: '禁用'
          }],
          select2: [],
        },
        site: this.$store.state.user.site,
        userName: this.$store.state.user.name,
        // table高度
        height: 450,
        // 是否收藏
        favorite: false,
        addLanguage: false,
        functionId: this.$route.meta.menuId,
        tableId: this.$route.meta.menuId + 'LOTI01',
        value1: true,
        visible: false,
        showDefault: false,
        // 默认table 查询参数
        queryTable: {
          functionId: this.$route.meta.menuId,
          tableId: this.$route.meta.menuId + 'LOTI01',
          languageCode: this.$i18n.locale
        },
        // 用户table 查询参数
        queryTableUser: {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: this.$route.meta.menuId + 'LOTI01',
          status: true,
          languageCode: this.$i18n.locale
        },
        // 语言词典查询参数
        querySysLanguageParam: {
          languageCode: this.$i18n.locale
        },
        // 语言词典集合
        sysLanguageParams: [],
        // 用户table 配置集合
        userColumnList: [],
        // 展示列集
        locationGruop_colum:[
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601locationGroupId',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationGruopTable",
            columnProp: "locationGroupId",
            headerAlign: "center",
            align: "center",
            columnLabel: "位置组编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601locationGroupDesc',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationGruopTable",
            columnProp: "locationGroupDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "位置组描述",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601locationType',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationGruopTable",
            columnProp: "locationType",
            headerAlign: "center",
            align: "center",
            columnLabel: "位置组描述",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          }
        ],
        columnList: [
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601LocationId',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "locationId",
            headerAlign: "center",
            align: "center",
            columnLabel: "库位编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601LocationName',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "locationName",
            headerAlign: "center",
            align: "center",
            columnLabel: "库位名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601WarehouseId',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "warehouseId",
            headerAlign: "center",
            align: "center",
            columnLabel: "仓库编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601WarehouseName',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "warehouseName",
            headerAlign: "center",
            align: "center",
            columnLabel: "仓库名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601StrlocationGroupDesc',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "locationGroupDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "位置组描述",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601StrlocationGroupDesc',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "locationType",
            headerAlign: "center",
            align: "center",
            columnLabel: "库房类型",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601StrActive',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "hold",
            headerAlign: "center",
            align: "center",
            columnLabel: "货舱",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601StrActive',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "row",
            headerAlign: "center",
            align: "center",
            columnLabel: "行",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601StrActive',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "storey",
            headerAlign: "center",
            align: "center",
            columnLabel: "层",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601StrActive',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "box",
            headerAlign: "center",
            align: "center",
            columnLabel: "箱",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            serialNumber: 'location2601StrActive',
            tableId: this.$route.meta.menuId + 'LOTI01',
            tableName: "locationTable",
            columnProp: "active",
            headerAlign: "center",
            align: "center",
            columnLabel: "状态",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
        ],
        // 展示列集
        columnList1: [
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: this.$route.meta.menuId,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "functionId",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "功能编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: this.$route.meta.menuId,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "objectId",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "序列化编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: '',
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: this.$route.meta.menuId,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "objectType",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "类型",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: '',
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: this.$route.meta.menuId,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "languageValue",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "语言值",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: '',
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: this.$route.meta.menuId,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "languageCode",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "语言编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: '',
          // }
        ],
        // 数据集
        dataList: [],
        queryButton: {
          functionId: this.$route.meta.menuId,
          tableId: this.$route.meta.menuId + 'LOTI01',
          languageCode: this.$i18n.locale,
          objectType: 'button'
        },
        buttons: {
          add: '新增',
          edit: '编辑',
          delete: '删除',
          deleteList: '批量删除',
          cz: '操作',
          search: '查询',
          download: '导出',
          settingTable: '设置列表',
          defaultTable: '设置默认配置'
        },
        // 导出 start
        exportData: [],
        exportName: "页面功能语言",
        exportHeader: ["页面功能语言"],
        exportFooter: [],
        exportDefaultValue: "",
        // 导出 end
        buttonList: [
          {
            languageValue: '新增',
            objectId: 'add',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '编辑',
            objectId: 'edit',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '删除',
            objectId: 'delete',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '批量删除',
            objectId: 'deleteList',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '操作',
            objectId: 'cz',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '查询',
            objectId: 'search',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '导出',
            objectId: 'download',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '设置列表',
            objectId: 'settingTable',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          },
          {
            languageValue: '设置默认配置',
            objectId: 'defaultTable',
            objectType: "button",
            tableId: this.$route.meta.menuId + 'LOTI01',
          }
        ],
        languageList: [],
        languageColumnList: [],
        languageDataList: [],
        queryLanguage: {},
        // 数据集条件
        querySysLanguagePack: {
          functionId: '',
          page: 1,
          limit: 1,
          languageValue: '',
          objectType: '',
          objectId: ''
        },
        // 分页
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.height = window.innerHeight - 220;
      })
    },
    activated() {
      this.getDataList()
      this.getSelectList()
      this.getLanguageList()
    },
    methods: {
      getSelectList() {
        let jsonData = {
          site: this.site,
          active: 'Y'
        }
        this.selectList.select2 = []
        getWarehouseList(jsonData).then(({data}) => {
          let list = data.rows
          if (list.length > 0) {
            for (let i = 0; i < list.length; i++) {
              let selectData = {
                value: list[i].wareHouseId,
                label: list[i].wareHouseName,
              }
              this.selectList.select2.push(selectData);
            }
          }
        })
      },
      delHeaderData(row) {
        this.$confirm(`确定删除该记录?`, '操作提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let jsonData = {
            site: row.site,
            locationId: row.locationId,
            warehouseId: row.warehouseId
          }
          delLocation(jsonData).then(({data}) => {
            if (data.code == 0) {
              this.$message.success(data.msg)
              this.getDataList()
            } else {
              this.$alert(data.msg, '操作提示', {
                confirmButtonText: '确定',
                callback: action => {

                }
              });
            }
          })
        })
      },
      saveHeaderFunction() {
        this.setUp.saveButton = true
        if (!this.saveHeaderData.locationId) {
          this.$message.warning('请输入库位编码!')
          this.setUp.saveButton = false
          return
        }
        if (!this.saveHeaderData.warehouseId) {
          this.$message.warning('请选择仓库名称!')
          this.setUp.saveButton = false
          return
        }
        if (!this.saveHeaderData.hold) {
          this.$message.warning('请输入货舱!!')
          this.setUp.saveButton = false
          return
        }
        if (!this.saveHeaderData.row) {
          this.$message.warning('请输入行!')
          this.setUp.saveButton = false
          return
        }
        if (!this.saveHeaderData.storey) {
          this.$message.warning('请输入层!')
          this.setUp.saveButton = false
          return
        }
        if (!this.saveHeaderData.box) {
          this.$message.warning('请输入箱!')
          this.setUp.saveButton = false
          return
        }
        if (!this.saveHeaderData.locationGroupId) {
          this.$message.warning('请选择位置组编码!')
          this.setUp.saveButton = false
          return
        }
        saveLocation(this.saveHeaderData).then(({data}) => {
          this.setUp.saveButton = false
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.getDataList()
            this.setUp.reviewFlag = false
          } else {
            this.$alert(data.msg, '操作提示', {
              confirmButtonText: '确定',
              callback: action => {

              }
            });
          }
        })
      },
      initModel(row) {
        console.log("1 =" + row)
        this.setUp.reviewFlag = true
        this.setUp.saveButton = false
        this.setUp.readonlyFlag = false
        this.saveHeaderData.id = 0
        this.saveHeaderData.site = localStorage.getItem('site')
        this.saveHeaderData.locationId = ''
        this.saveHeaderData.locationName = ''
        this.saveHeaderData.warehouseId = ''
        this.saveHeaderData.active = 'Y'
        this.saveHeaderData.hide = 'N'
        this.saveHeaderData.locationGroupId = ''
        this.saveHeaderData.locationGroupDesc = ''
        this.saveHeaderData.hold = ''
        this.saveHeaderData.row = ''
        this.saveHeaderData.storey = ''
        this.saveHeaderData.box = ''
        this.saveHeaderData.locationType = ''
        if (row) {
          console.log("2 =" + row)
          this.setUp.readonlyFlag = true
          this.saveHeaderData.id = 1
          this.saveHeaderData.locationId = row.locationId
          this.saveHeaderData.locationName = row.locationName
          this.saveHeaderData.warehouseId = row.warehouseId
          this.saveHeaderData.active = row.active
          this.saveHeaderData.hold = row.hold
          this.saveHeaderData.row = row.row
          this.saveHeaderData.storey = row.storey
          this.saveHeaderData.box = row.box
          this.saveHeaderData.locationGroupId = row.locationGroupId
          for (let i = 0; i<this.dataList.length;i++){
            if (this.saveHeaderData.locationGroupId == this.dataList[i].locationGroupId){
              this.saveHeaderData.locationGroupDesc = this.dataList[i].locationGroupDesc
              break;
            }
          }
          this.saveHeaderData.locationType = row.locationType
        }
      },
      // 打印方式
      printReport() {
        alert(this.$store.state.user.site)
        //
        // const LODOP = getLodop()
        // if (LODOP) {
        //   var strBodyStyle = '<style>'
        //   strBodyStyle += 'table { border-top: 1 solid #000000; border-left: 1 solid #000000;  border-collapse:collapse;  border-spacing:0;}'
        //   strBodyStyle += 'caption {  line-height:2em; }'
        //   strBodyStyle += 'td { border-right: 1 solid #000000; border-bottom: 1 solid #000000; text-align:center; padding:2px 3px; font-size:11px;}'
        //   strBodyStyle += '</style>' //设置打印样式
        //   var strFormHtml = strBodyStyle + '<body>' + document.getElementById('commmon').innerHTML + '</body>'   //获取打印内容
        //
        //   LODOP.PRINT_INIT('')  //初始化
        //   LODOP.PRINT_DESIGN();
        //   //LODOP.PREVIEW();
        //   //LODOP.PRINT();
        //
        //   LODOP.SET_PRINT_PAGESIZE(2, 0, 0, 'A4')  //设置横向
        //   LODOP.ADD_PRINT_HTM('1%', '1%', '98%', '98%', strFormHtml)    //设置打印内容
        //   LODOP.SET_PREVIEW_WINDOW(2, 0, 0, 800, 600, '')  //设置预览窗口模式和大小
        //   LODOP.PREVIEW()
        // }
      },
      queryLocationGruop(){
        queryAllLocationGruopList(this.locationGruopModalData).then(({data})=>{
          if (data.code==0){
            this.$message.success(data.rows)
            this.locationGruopDataList = data.rows
            this.localtionGruopFlag = true
          }
        })
      },
      getRowData(row){
        this.saveHeaderData.locationGroupId = row.locationGroupId
        this.saveHeaderData.locationGroupDesc = row.locationGroupDesc
        //this.saveHeaderData.locationType = row.locationType
        this.localtionGruopFlag = false
      },
      // 校验用户是否收藏
      favoriteIsOk() {
        let userFavorite = {
          userId: this.$store.state.user.id,
          languageCode: this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) => {
          let size = data.list.filter(item => item.userId == userFavorite.menuId).length;
          if (size > 0) {
            this.favorite = true
          } else {
            this.favorite = false
          }
        })
      },
      // 收藏 OR 取消收藏
      favoriteFunction() {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          // 取消收藏
          this.$confirm(`确定取消收藏`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            removeUserFavorite(userFavorite).then(({data}) => {
              this.$message.success(data.msg)
              this.favorite = false
            })
          })
        } else {
          // 收藏
          saveUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = true
          })
        }

      },
      // 获取多语言列表
      getLanguageList() {
        searchSysLanguage(this.queryLanguage).then(({data}) => {
          this.languageList = data.rows
        })
      },
      // 获取button的词典
      getFunctionButtonList() {
        searchFunctionButtonList(this.queryButton).then(({data}) => {
          if (data.code == 0) {
            this.buttons = data.data
          } else {
            // saveButtonList(this.buttonList).then(({data}) => {
            // })
          }
        })
      },
      // 获取语言词典
      getSysLanguageParamList() {
        searchSysLanguageParam(this.querySysLanguageParam).then(({data}) => {
          this.sysLanguageParams = data.rows
        })
      },
      // 打开页面设置
      userSetting() {
        this.visible = true;
        let queryTable = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: this.$route.meta.menuId + 'LOTI01',
          languageCode: this.$i18n.locale
        }
        this.$nextTick(() => {
          this.$refs.column.init(queryTable);
        });
      },
      // 获取 用户保存的 格式列
      getTableUserColumn() {
        getTableUserListLanguage(this.queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList = []
            this.columnList = data.rows
          } else {
            this.getColumnList()
          }

        })
      },
      // 保存 默认配置 列
      async saveColumnList() {
        // 删除所有的该页面下保存的数据
        if (this.userColumnList) {
          //删除 user自定义的数据
          await removerUser(this.queryTable)
        }
        // 删除默认配置
        await removerDefault(this.queryTable)
        // 保存页面 table属性
        let sumColumnList = this.columnList.concat(this.columnList1);
        sumColumnList = sumColumnList.map(item => {
          return item = {
            tableId: item.tableId,
            tableName: item.tableName,
            columnProp: item.columnProp,
            columnLabel: item.columnLabel,
            columnHidden: false,
            columnImage: false,
            columnSortable: item.columnSortable,
            columnWidth: null,
            format: null,
            functionId: this.$route.meta.menuId,
            sortLv: 0,
            status: true,
            fixed: '',
            serialNumber: null,
            columnType: null,
            align: null
          }
        })

        await saveTableDefaultList(sumColumnList)
        // 保存页面 button label title 属性
        let buttons = this.buttonList.map(item => {
          return item = {
            functionId: this.$route.meta.menuId,
            languageValue: item.languageValue,
            objectId: item.objectId,
            objectType: item.objectType,
            tableId: item.tableId
          }
        })
        await saveButtonList(buttons)
        this.getFunctionButtonList()
        this.getColumnList()
      },
      // 获取 tableDefault 列
      getColumnList() {
        getTableDefaultListLanguage(this.queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            // this.showDefault = false
            this.columnList = data.rows
          } else {
            // this.showDefault = true
          }
        })
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.dataList = []
        // this.totalPage = 0
        getLocationList(this.queryHeaderData).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.queryHeaderData.page = data.page.currPage
            this.queryHeaderData.size = data.page.pageSize
            this.queryHeaderData.totalCount = data.page.totalCount
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.queryHeaderData.size = val
        this.queryHeaderData.page = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.queryHeaderData.page = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 删除
      deleteHandle(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('//prd/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message.success('操作成功')
              this.getDataList()
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 导出
      fields() {
        let json = "{"
        this.columnList.forEach((item, index) => {
          if (index == this.columnList.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")
        return s
      },
      createExportData() {
        // 点击导出按钮之后,开始导出数据之前的执行函数,返回值为需要下载的数据
        // TODO:构造需要下载的数据返回
        if (this.dataListSelections.length > 0) {
          return this.dataListSelections;
        }
        return this.dataList;
      },
      startDownload() {
        //  this.exportData = this.dataList

      },
      finishDownload() {

      }
    },
    created() {
      this.getTableUserColumn()
      this.getSysLanguageParamList()
      this.getFunctionButtonList()
      this.favoriteIsOk()
    }
  }
</script>
<style scoped>
  .wrapper {
    height: calc(100% - 40px);
  }

  .sl-input {
    background-color: transparent;
    border: 0 !important;
    font-size: 12px !important;
    height: 12px !important;
    line-height: 14px !important;
    background-color: transparent !important;
    width: 140px;
  }

  .sl-input:focus, textarea:focus {

    outline: none;

  }

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

</style>
