<template>
  <div class="mod-config">
    <el-form :inline="true" :model="querySysLanguagePack" @keyup.enter.native="getDataList()">
      <el-form-item :label = "inputSearch10">
        <el-input  style="width: 110px;"  placeholder="" v-model = "queryViewIfs.transactionId"></el-input>
      </el-form-item>
      <el-form-item :label = "inputSearch1">
        <el-input  style="width: 110px;"  placeholder="" v-model = "queryViewIfs.toolId"></el-input>
      </el-form-item>
      <el-form-item :label = "inputSearch2">
        <el-input style="width: 110px;"  placeholder="" v-model = "queryViewIfs.description"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="initViewIfsTable('Y')" type="primary">{{ buttons.search }}</el-button>
        <el-button @click="saveColumnList()" type="primary" v-show="showDefault">{{ buttons.defaultTable }}
        </el-button>
        <el-button @click="userSetting" type="primary">{{ buttons.settingTable }}</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :defaultValue="exportDefaultValue"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ buttons.download }}
        </download-excel>
        <el-button v-if="isAuth(':prd:delete')" type="danger" @click="deleteHandle()"
                   :disabled="dataListSelections.length <= 0">{{ buttons.deleteList }}
        </el-button>
      </el-form-item>
    </el-form>
    <el-table
      :height="height"
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">

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

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="50"
        :label="buttons.operating">
        <template slot-scope="scope">
          <a @click="initBannersFlag(scope.row)">{{buttons.receive}}</a>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 50, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>


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


    <el-dialog title="横幅宽幅设定" :visible.sync="bannersFlag" width="325px">
      <el-form :inline="true">
        <el-form-item :label = "inputSearch8">
          <el-input style="width: 90px;text-align: left;padding: 0px 5px;" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model = "torNumacc"></el-input>
        </el-form-item>
        <el-form-item :label = "inputSearch9">
          <el-input style="width: 90px;text-align: left;padding: 0px 5px;" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model = "torNumdown"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="bannersFlag = false">取消</el-button>
      <el-button type="primary" :disabled="bannersBut" @click="saveBanners()">确定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="检验方式选择" :visible.sync="poToolFlag" width="520px">
      <el-form :inline="true">
        <el-form-item :label = "inputSearch3">
          <el-input style="width: 90px;text-align: left;padding: 0px 5px;" @change="initQtyAlert()" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model = "receiveQuantity"></el-input>
        </el-form-item>
        <el-form-item :label = "inputSearch4">
          <el-input style="width: 90px;text-align: left;padding: 0px 5px;" oninput="value=value.replace(/^\.+|[^\d.]/g,'')" v-model = "serviceLife"></el-input>
        </el-form-item>
        <!--<el-form-item >
          <el-radio v-model="radio" label="N">{{inputSearch5}}</el-radio>
          <el-radio style="margin-left: 10px;" v-model="radio" label="Y">{{inputSearch6}}</el-radio>
        </el-form-item>
        <el-form-item :label = "inputSearch7">
          <el-input :disabled="radio=='Y'?false :true" style="width: 110px;text-align: left;padding: 0px 5px;" v-model = "locationNo"></el-input>
        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" :disabled="generateFlag" @click="initMailFlag()" >{{buttons.generate}}</el-button> <!--@click="onSubmit"-->
          <el-button type="primary" >{{buttons.print}}</el-button>  <!--@click="onSubmit"-->
        </el-form-item>
        <el-table
          :data="poToolList"
          height="290"
          border
          v-loading="dataListLoading"
          @selection-change="getCurrSelectList"
          style="width: 100%;">
          <el-table-column
            type="selection"
            header-align="center"
            width="40"
            align="center">
          </el-table-column>
          <el-table-column
            v-for="(item,index) in poToolColumnList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed"
            :width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                                 style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
        </el-table>
        <el-footer style="height: 20px;background-color: #fbfbfb;" ></el-footer>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
  import column from "../common/column";
  import {
    searchSysLanguagePackList,
    searchSysLanguageParam,
    searchFunctionButtonList,
    saveButtonList,
    searchSysLanguage,
    searchLanguageListByLanguageCode,
    saveSysLanguageOne
  } from "@/api/sysLanguage.js"
  import {
    saveTableDefaultList,
    saveTableUser,
    getTableDefaultListLanguage,
    getTableUserListLanguage
  } from "@/api/table.js"

  import {
    getViewIfsList,
    getPoToolList,
    getLocationList,
    saveToolDetail,
    updateIfsTool,
    exportList,
  } from "@/api/knifemold/receive.js"

  export default {
    components: {
      column
    },
    data() {
      return {
        height: 0,
        //搜索名称
        inputSearch1 : "工具编码",
        inputSearch2 : "工具名称",
        inputSearch3 : "接收数量",
        inputSearch4 : "使用寿命",
        inputSearch5 : "IQC检验",
        inputSearch6 : "上机检验",
        inputSearch7 : "录入库位",
        inputSearch8 : "横幅",
        inputSearch9 : "宽幅",
        inputSearch10 : "接收号",
        //横幅宽幅设定
        bannersFlag : false,
        bannersBut : false,
        torNumacc : '',
        torNumdown : '',
        //生成按钮是否可用
        generateFlag : false,
        //接收数量
        receiveQuantity : '',
        //使用寿命
        serviceLife : '',
        //检验方式
        radio : '',
        //录入库位
        locationNo : '' ,
        site: this.$store.state.user.site,
        addLanguage: false,
        functionId: 1001,
        tableId: "1001viewIfsTable",
        value1: true,
        visible: false,
        showDefault: false,
        poToolFlag : false,
        poToolData : {},
        ifsToolData : {},
        queryViewIfs: {
          //接收号
          transactionId : '',
          //工具编码搜索
          toolId : "",
          //工具名称搜索
          description : "",
          //工厂搜索
          site: "",
          //行数
          limit : "",
          //页数
          page : "",
        },
        // 默认table 查询参数
        queryTable: {
          functionId: 1001,
          tableId: "1001viewIfsTable",
          languageCode: this.$i18n.locale
        },
        // 用户table 查询参数
        queryTableUser: {
          userId: this.$store.state.user.name,
          functionId: 1001,
          tableId: "1001viewIfsTable",
          status: true,
          languageCode: this.$i18n.locale
        },
        // 语言词典查询参数
        querySysLanguageParam: {
          languageCode: this.$i18n.locale
        },
        // 语言词典集合
        sysLanguageParams: [],
        // 用户table 配置集合
        userColumnList: [],
        // 展示列集
        poToolColumnList : [
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableTransactionId',
            tableId: "1001poToolTable",
            tableName: "poToolTable",
            columnProp: "toolInstanceId",
            headerAlign: "center",
            align: "center",
            columnLabel: "实例编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableToolDescription',
            tableId: "1001poToolTable",
            tableName: "poToolTable",
            columnProp: "toolDescription",
            headerAlign: "center",
            align: "center",
            columnLabel: "实例名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   serialNumber: '1001viewIfsTableTransactionId',
          //   tableId: "1001poToolTable",
          //   tableName: "poToolTable",
          //   columnProp: "status2",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "校验方式",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   serialNumber: '1001viewIfsTableTransactionId',
          //   tableId: "1001poToolTable",
          //   tableName: "poToolTable",
          //   columnProp: "status",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "是否检验",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
        ],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableTransactionId',
            tableId: "1001viewIfsTable",
            tableName: "viewIfsTable",
            columnProp: "transactionId",
            headerAlign: "center",
            align: "center",
            columnLabel: "接收号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableToolId',
            tableId: "1001viewIfsTable",
            tableName: "viewIfsTable",
            columnProp: "toolId",
            headerAlign: "center",
            align: "center",
            columnLabel: "工具编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableDescription',
            tableId: "1001viewIfsTable",
            tableName: "viewIfsTable",
            columnProp: "description",
            headerAlign: "center",
            align: "center",
            columnLabel: "工具名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   serialNumber: '1001viewIfsTableOrderNo',
          //   tableId: "1001viewIfsTable",
          //   tableName: "viewIfsTable",
          //   columnProp: "orderNo",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "采购单号",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   serialNumber: '1001viewIfsTablelineItemNo',
          //   tableId: "1001viewIfsTable",
          //   tableName: "viewIfsTable",
          //   columnProp: "lineItemNo",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "行号",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableVendorNo',
            tableId: "1001viewIfsTable",
            tableName: "viewIfsTable",
            columnProp: "vendorNo",
            headerAlign: "center",
            align: "center",
            columnLabel: "供应商编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableVendorName',
            tableId: "1001viewIfsTable",
            tableName: "viewIfsTable",
            columnProp: "vendorName",
            headerAlign: "center",
            align: "center",
            columnLabel: "供应商名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableQuantity',
            tableId: "1001viewIfsTable",
            tableName: "viewIfsTable",
            columnProp: "quantity",
            headerAlign: "center",
            align: "center",
            columnLabel: "数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 1001,
            serialNumber: '1001viewIfsTableGenerateQuantity',
            tableId: "1001viewIfsTable",
            tableName: "viewIfsTable",
            columnProp: "generateQuantity",
            headerAlign: "center",
            align: "center",
            columnLabel: "已接收数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
          },
        ],
        // 展示列集
        columnList1: [
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   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: 1001,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "objectId",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "序列化编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "objectType",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "类型",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "languageValue",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "语言值",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 1001,
          //   tableId: "common1002",
          //   tableName: "commonLanguage",
          //   columnProp: "languageCode",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "语言编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // }
        ],
        // 数据集
        dataList: [],
        currSelectList : [],
        poToolList : [],
        queryButton: {
          functionId: 1001,
          table_id: '1001viewIfsTable',
          languageCode: this.$i18n.locale,
          objectType: 'button'
        },
        buttons: {
          receive : '接收',
          add: '添加',
          edit: '编辑',
          delete: '删除',
          deleteList: '批量删除',
          operating: '操作',
          search: '查询',
          download: '导出',
          settingTable: '设置列表',
          defaultTable: '设置默认配置',
          generate : "生成",
          print : '打印',
        },
        // 导出 start
        exportData: [],
        exportDataStandard: {
          "功能编码": "functionId",
          "序列化编码": "objectId",
          "类型": "objectType",
          "语言值": "languageValue"
        },
        exportName: "工具接收",
        exportHeader: ["工具接收"],
        exportFooter: [],
        exportDefaultValue: "",
        // 导出 end
        buttonList: [
          {
            functionId: "1001",
            languageValue: '接收',
            objectId: 'receive',
            objectType: "button",
            tableId: "1001viewIfsTable"
          },
          {
            functionId: "1001",
            languageValue: '生成',
            objectId: 'generate',
            objectType: "button",
            tableId: "1001poToolTable"
          },
          {
            functionId: "1001",
            languageValue: '打印',
            objectId: 'print',
            objectType: "button",
            tableId: "1001poToolTable"
          },
          {
            functionId: "1001",
            languageValue: '关闭',
            objectId: 'shutSown',
            objectType: "button",
            tableId: "1001poToolTable"
          },
          {
            functionId: "1001",
            languageValue: '操作',
            objectId: 'operating',
            objectType: "button",
            tableId: "1001viewIfsTable"
          },
          {
            functionId: "1001",
            languageValue: '查询',
            objectId: 'search',
            objectType: "button",
            tableId: "1001viewIfsTable"
          },
          {
            functionId: "1001",
            languageValue: '导出',
            objectId: 'download',
            objectType: "button",
            tableId: "1001viewIfsTable"
          },
          {
            functionId: "1001",
            languageValue: '设置列表',
            objectId: 'settingTable',
            objectType: "button",
            tableId: "1001viewIfsTable"
          },
          {
            functionId: "1001",
            languageValue: '设置默认配置',
            objectId: 'defaultTable',
            objectType: "button",
            tableId: "1001viewIfsTable"
          },
        ],
        languageList: [],
        languageColumnList: [],
        languageDataList: [],
        queryLanguage: {},
        // 数据集条件
        querySysLanguagePack: {
          page: 1,
          limit: 1,
          languageValue: '',
          objectType: '',
          objectId: ''
        },
        // 分页
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    activated() {
      this.getDataList()
      this.initViewIfsTable();
      this.getLanguageList()
    },
    mounted() {
      this.$nextTick(() => {
        this.height = window.innerHeight - 250;
      })
    },
    watch: {
      radio() {
        this.locationNo = ''
      },
      locationNo(){
        this.locationNo = this.locationNo.toUpperCase()
      },
      poToolFlag(){
        if(this.poToolFlag == false){
          this.initViewIfsTable()
        }
      }
    },
    methods: {
      getCurrSelectList(row){
        this.currSelectList = row
      },
      //检验横幅宽幅是否存在
      saveBanners(){
        this.bannersBut = true
        if(this.torNumacc =="" || this.torNumacc <= 0){
          this.$alert('请输入正确的横幅！', '横幅', {
            confirmButtonText: '确定',
            callback: action => {
              this.bannersBut = false
            }
          });
          return
        }else if(this.torNumdown =="" || this.torNumacc <= 0){
          this.$alert('请输入正确的宽幅！', '宽幅', {
            confirmButtonText: '确定',
            callback: action => {
              this.bannersBut = false
            }
          });
          return
        }
        let updateData = {
          site : this.site,
          transactionId : this.ifsToolData.transactionId,
          torNumacc : this.torNumacc,
          torNumdown : this.torNumdown,
        }
        updateIfsTool(updateData).then(({data}) =>{
          this.bannersBut = false
          if (data.code == 0) {
            this.ifsToolData.torNumacc = this.torNumacc
            this.ifsToolData.torNumacc = this.torNumacc
            this.bannersFlag = false
            this.$message.success(data.msg)
            this.initPoToolTable()
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      //检验生成事件
      initMailFlag(){
        this.generateFlag = true
        /*if(this.radio != 'Y' && this.radio != 'N'){
          this.$alert('请选择检验方式！', '检验方式', {
            confirmButtonText: '确定',
            callback: action => {
              this.generateFlag = false
            }
          });
          return
        }else if(this.radio == 'Y' && (this.locationNo == null || this.locationNo == '')){
          this.$alert('请输入录入库位！', '录入库位', {
            confirmButtonText: '确定',
            callback: action => {
              this.generateFlag = false
            }
          });
          return
        }else*/
          if(this.receiveQuantity == null || this.receiveQuantity == '' ){
          this.$alert('请输入接收数量！', '接收数量', {
            confirmButtonText: '确定',
            callback: action => {
              this.receiveQuantity = this.ifsToolData.quantity - this.ifsToolData.generateQuantity
              this.generateFlag = false
            }
          });
          return
        }else if(this.receiveQuantity <= 0){
          this.$alert('请输入正确的接收数量！', '接收数量', {
            confirmButtonText: '确定',
            callback: action => {
              this.receiveQuantity = this.ifsToolData.quantity - this.ifsToolData.generateQuantity
              this.generateFlag = false
            }
          });
          return
        }else if(this.serviceLife == null || this.serviceLife == ''){
          this.$alert('请输入使用寿命！', '使用寿命', {
            confirmButtonText: '确定',
            callback: action => {
              this.serviceLife = 0
              this.generateFlag = false
            }
          });
          return
        }else if(this.serviceLife <= 0){
          this.$alert('请输入正确的使用寿命！', '使用寿命', {
            confirmButtonText: '确定',
            callback: action => {
              this.serviceLife = 0
              this.generateFlag = false
            }
          });
          return
        }
        if(this.radio == 'N'){
          this.saveToolInstanceId()
        }else{
          let queryLocation = {
            site : this.site,
            locationid : this.locationNo,
            limit : 1,
            page : 1,
          }
          this.saveToolInstanceId()
          // this.initLocationFlag(queryLocation)
        }
      },
      //保存接收信息
      saveToolInstanceId(){
        let status;
        if(this.radio == "Y"){
          status = "出库"
        }else{
          status = "已启用"
        }
        let saveData = {
          site : this.site,
          toolId : this.ifsToolData.toolId,
          description : this.ifsToolData.description,
          userName : this.$store.state.user.name,
          locationId : this.locationNo,
          vendorNo : this.ifsToolData.vendorNo,
          status : status,
          estUseQty : this.serviceLife,
          torNumacc : this.ifsToolData.torNumacc,
          torNumdown : this.ifsToolData.torNumdown,
          transactionId : this.ifsToolData.transactionId,
          receiveQuantity : this.receiveQuantity,
          type : this.radio,
          orderNo : this.ifsToolData.orderNo,
          releaseNo : this.ifsToolData.releaseNo,
          sequenceNo : this.ifsToolData.sequenceNo,
          lineItemNo : this.ifsToolData.lineItemNo,
          vendorName : this.ifsToolData.vendorName,
        }
        let currQty = this.receiveQuantity
        saveToolDetail(saveData).then(({data}) =>{
          this.generateFlag = false
          if (data.code == 0) {
            this.ifsToolData.generateQuantity += parseInt(currQty)
            this.initPoToolTable()
          } else {
          }
          this.$alert(data.msg, '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.addPRDetailFlag = false
              this.bannersBut = false
            }
          });
        })
      },
      //校验是否存在库位
      async initLocationFlag(queryLocation){
        let locationFlag
        await getLocationList(queryLocation).then(({data}) =>{
          if (data && data.code === 0) {
            let list = data.rows.list
            if(list.length >0){
              this.saveToolInstanceId()
            }else {
              this.$alert('请输入正确的库位！', '录入库位', {
                confirmButtonText: '确定',
                callback: action => {
                  this.serviceLife = 0
                  this.generateFlag = false
                }
              });
            }
          }
        })
        return locationFlag
      },
      //判断是否超过接收总数量
      initQtyAlert(){
        if(this.receiveQuantity > this.ifsToolData.quantity - this.ifsToolData.generateQuantity){
          this.$alert('超过当前接收数量！', '接收数量', {
            confirmButtonText: '确定',
            callback: action => {
              this.receiveQuantity =  this.ifsToolData.quantity - this.ifsToolData.generateQuantity
            }
          });
        }
      },
      //校验横幅宽幅是否存在
      initBannersFlag(row){
        this.ifsToolData = row
        if(this.ifsToolData.torNumacc == null || this.ifsToolData.torNumacc == "" || this.ifsToolData.torNumdown == null || this.ifsToolData.torNumdown == ""){
          this.torNumacc = ''
          this.torNumdown = ''
          this.bannersFlag = true;
        }else {
          this.torNumacc = this.ifsToolData.torNumacc
          this.torNumdown = this.ifsToolData.torNumdown
          this.initPoToolTable()
        }
      },
      initPoToolTable(){
        //是否显示加载效果
        this.poToolFlag = true
        this.dataListLoading = true
        let queryPoTool = {
          //  工具编码
          toolId : this.ifsToolData.toolId,
          //  工厂
          site : this.site,
          //  接收号
          toolInstanceId : this.ifsToolData.transactionId,
        }
        this.receiveQuantity = this.ifsToolData.quantity - this.ifsToolData.generateQuantity
        this.serviceLife = 0
        this.radio = '0'
        this.locationNo = ''
        this.generateFlag = false
        getPoToolList(queryPoTool).then(({data}) =>{
          if (data && data.code === 0) {
            this.poToolList = data.rows
          } else {
            this.poToolList = []
          }
          this.dataListLoading = false
        })
      },
      // 获取数据列表
      initViewIfsTable(val) {
        if(val == "Y"){
          this.pageIndex = 1
        }
        //是否显示加载效果
        this.dataListLoading = true
        //显示数据条数
        this.queryViewIfs.limit = this.pageSize
        //分页页面
        this.queryViewIfs.page = this.pageIndex
        //设置工厂
        this.queryViewIfs.site = this.site
        //

        getViewIfsList(this.queryViewIfs).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.rows.list
            this.totalPage = data.rows.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 收藏
      favorites() {

      },
      // 保存语言编辑
      saveLanguageList(val) {
        saveSysLanguageOne(val).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      // 编辑语言
      addLanguageFun() {
        if (this.querySysLanguagePack.languageCode) {
          this.addLanguage = true
          this.languageColumnList = []
          let query = {
            functionId: 1001,
            tableId: "common1002",
            languageCode: this.$i18n.locale
          }
          getTableDefaultListLanguage(query).then(({data}) => {
            if (data.rows.length > 0) {
              this.languageColumnList = data.rows
            }
          })
          this.languageColumnList = this.columnList
          searchLanguageListByLanguageCode(this.querySysLanguagePack).then(({data}) => {
            this.languageDataList = data.rows
          })
        } else {
          this.$message("请选中一种语言")
        }
      },
      // 获取多语言列表
      getLanguageList() {
        searchSysLanguage(this.queryLanguage).then(({data}) => {
          this.languageList = data.rows
        })
      },
      // 获取button的词典
      getFunctionButtonList() {
        searchFunctionButtonList(this.queryButton).then(({data}) => {
          console.log(data.data)
          if (data.data.length>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;
        this.getTableUserAll()
      },
      // 获取 用户的配置
      getTableUserAll() {
        let queryTable = {
          userId: this.$store.state.user.name,
          functionId: 1001,
          tableId: this.tableId,
          languageCode: this.$i18n.locale
        }
        this.visible = true;
        this.$nextTick(() => {

          this.$refs.column.init(queryTable);
        });
      },

      // 获取 用户保存的 格式列
      getTableUserColumn() {
        getTableUserListLanguage(this.queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList = []
            this.columnList = data.rows
          } else {
            this.getColumnList()
          }

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

        saveTableDefaultList(this.columnList).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.showDefault = false
          } else {
            this.$message.error(data.msg)
          }
        })
        saveTableDefaultList(this.columnList1).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.showDefault = false
          } else {
            this.$message.error(data.msg)
          }
        })
        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.querySysLanguagePack.limit = this.pageSize
        this.querySysLanguagePack.page = this.pageIndex
        searchSysLanguagePackList(this.querySysLanguagePack).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.initViewIfsTable()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.initViewIfsTable()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 删除
      deleteHandle(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('//prd/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      fields(){
        console.log(this.columnList)
        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 + ")")
        console.log(s)

        return s
      },
      createExportData() {
        // 点击导出按钮之后,开始导出数据之前的执行函数,返回值为需要下载的数据
        // TODO:构造需要下载的数据返回
        exportList(this.queryViewIfs).then(({data}) => {
          if (data && data.code === 0) {
            return data.rows.list;
          }
        })
        return this.dataList;
      },
      startDownload() {
        //  this.exportData = this.dataList
        console.log("数据开始")
      },
      finishDownload() {
        console.log("数据下载完成")
      }
    },
    created() {
      this.getTableUserColumn()
      this.getSysLanguageParamList()
      this.getFunctionButtonList()
    }
  }
</script>
<style>
  .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;

  }

</style>
