<template>
  <div class="mod-config">
    <div>
        <span @click="favoriteFunction()">
         <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>
        </span>
    </div>
    <el-form :inline="true" :model="querySysLanguagePack" @keyup.enter.native="getDataList()">

      <el-form-item :label="inputSearch1">
        <el-input style="width: 110px;" clearable placeholder="" v-model="mainQueryData.requisitionno"></el-input>
      </el-form-item>
      <el-form-item :label="inputSearch2">
        <el-select v-model="mainQueryData.orderType" placeholder="请选择" style="width: 110px;">
          <el-option
            key=""
            label="全部"
            value="">
          </el-option>
          <el-option
            v-for="item in orderTypeList"
            :key="item.baseData"
            :label="item.baseDesc"
            :value="item.baseDesc">
          </el-option>
        </el-select>
        <!--        <el-input style="width: 110px;" clearable placeholder="" v-model="mainQueryData.orderType"></el-input>-->
      </el-form-item>
      <el-form-item :label="inputSearch3">
        <el-input style="width: 110px;" clearable placeholder="" v-model="mainQueryData.partno"></el-input>
      </el-form-item>
      <el-form-item :label="inputSearch4">
        <el-select v-model="mainQueryData.authorizeFlag" style="width: 90px;">
          <el-option value="" label="全部"></el-option>
          <el-option value="Y" label="已审批"></el-option>
          <el-option value="N" label="未审批"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList('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-button type="primary" plain @click="printReport">打印报表</el-button>-->

    </el-form>
    <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"
        :width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                             style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="100"
        :label="buttons.operating">
        <template slot-scope="scope">
          <a v-if="scope.row.strCanAuthFlag == 'Y'" @click="initReview(scope.row)">{{buttons.audit}}</a>
          <span v-else>{{buttons.audit}}</span>
          <a @click="initFileModel(scope.row)">{{buttons.appendixInfo}}</a>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[100, 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="setUp.reviewFlag" width="520px" :close-on-click-modal="false"
               v-drag>
      <el-steps :active="active" style="margin: 40px">
        <el-step v-for=" (item,index) in reviewStepList" :key="index" :title="item.userName"></el-step>

      </el-steps>

      <div style="margin-left: 0px;margin-top: -30px"  v-if="active === index"  v-for=" (item,index) in reviewStepList" :key="index">
        <el-form :inline="true" label-width="120px" label-position="top">
          <el-form-item label="审批人">
            <el-input style="width: 200px;" readonly placeholder="" :value="item.userName"></el-input>
          </el-form-item>
          <el-form-item label="审批时间">
            <el-input style="width: 200px;" readonly placeholder="" :value="item.strActAuthorizeDate"></el-input>
          </el-form-item>
          <el-form-item label="审批备注">
            <!--<el-input style="width: 200px;" :readonly = "item.userName == saveData.userId && item.authFlag != 'Y' ? false : true" placeholder="" v-model="item.remark"></el-input>-->
            <el-input type="textarea" :readonly = "( reviewStepList[index].canAuthFlag == 'Y') ? false : true " :rows="3" style="text-align: left;width: 415px;" v-model="item.remark"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"  v-if="( reviewStepList[index].canAuthFlag == 'Y') ? true : false " @click="saveReview(reviewStepList[index] ,'N')">不同意</el-button>
            <el-button type="primary"  v-if="( reviewStepList[index].canAuthFlag == 'Y') ? true : false " @click="saveReview(reviewStepList[index],'Y')">同意</el-button>
          </el-form-item>
        </el-form>
      </div>

      <span slot="footer" class="dialog-footer">
        <!--<el-button type="primary" @click="naxtStep('s')">上一步</el-button>
      <el-button type="primary" @click="naxtStep('x')">下一步</el-button>-->
    </span>
    </el-dialog>

    <el-dialog title="附件信息" :visible.sync="setUp.fileFlag" width="672px" :close-on-click-modal="false"
               :close-on-press-escape="false" v-drag>
      <el-form :inline="true" label-position="top">
        <el-table
          height="170"
          :data="fileList"
          border
          v-loading="dataListLoading"
          @selection-change="selectionChangeHandle"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnList2" :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
            header-align="center"
            align="center"
            width="50"
            :label="buttons.operating">
            <template slot-scope="scope">
              <a @click="fileDownload(scope.row)">{{ buttons.fileDownload }}</a>
            </template>
          </el-table-column>
        </el-table>
      </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 getLodop from '@/utils/LodopFuncs.js'
  import {
    saveTableDefaultList,
    saveTableUser,
    getTableDefaultListLanguage,
    getTableUserListLanguage
  } from "@/api/table.js"
  import {
    userFavoriteList, saveUserFavorite, removeUserFavorite
  } from '@/api/userFavorite.js'
  import {
    getPRHeaderList,
    updatePRHeader,
    getTblBaseDataList,
    getExportList,
    getReviewSteps,
    getFileList,
  } from '@/api/purchaseorder/procurementReview.js'
  import axios from "axios";
  import Vue from "vue";

  export default {
    components: {
      column
    },
    data() {
      return {
        fileList: [],
        active: 0,
        currentReviewStepData :{},
        reviewStepList: [],
        menuId: this.$route.meta.menuId,
        userId: this.$store.state.user.name,
        site : this.$store.state.user.site,
        saveData: {
          userId: this.$store.state.user.name,
          recordTypeDb: this.$route.meta.menuId,
          orderRef1 : '',
          orderRef2 : '',
          orderRef3 : '',
          site: this.$store.state.user.site,
          authRuleId: '',
          stepId : '',
          authTypeDb : '',
          authUserId : '',
          authGroupId : '',
          actAuthorizator : '',
          actAuthorizeDate : null,
          remark : '',
          authFlag : '',
          approveResult : '',
          approveResultComments : '',
          needAuthBeforePrintFlag : '',
          firstStepFlag : '',
          lastStepFlag : '',
        },
        orderTypeList: [],
        inputSearch1: '申请单号',
        inputSearch2: '处理类型',
        inputSearch3: '刀模编码',
        inputSearch4: '是否审批',
        inputSearch5: '审核意见',
        inputSearch6: '审核人',
        inputSearch7: '审核时间',
        inputSearch8: '附件信息',
        // table高度
        height: 450,
        // 是否收藏
        favorite: false,
        addLanguage: false,
        functionId: 2101,
        tableId: "review2101",
        value1: true,
        visible: false,
        showDefault: false,
        //设置
        setUp: {
          reviewFlag: false,
          saveButton: false,
          fileFlag : false,
        },
        mainQueryData: {
          requisitionno: '',
          orderType: '',
          partno: '',
          authorizeFlag: 'N',
          site: this.$store.state.user.site,
          userId: this.$store.state.user.name,
          strUserId: this.$store.state.user.id,
          limit: '',
          page: '',
        },
        // 默认table 查询参数
        queryTable: {
          functionId: 2101,
          tableId: "review2101",
          languageCode: this.$i18n.locale
        },
        // 用户table 查询参数
        queryTableUser: {
          userId: this.$store.state.user.name,
          functionId: 2101,
          tableId: "review2101",
          status: true,
          languageCode: this.$i18n.locale
        },
        // 语言词典查询参数
        querySysLanguageParam: {
          languageCode: this.$i18n.locale
        },
        // 语言词典集合
        sysLanguageParams: [],
        // 用户table 配置集合
        userColumnList: [],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101RequisitionNo',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "requisitionno",
            headerAlign: "center",
            align: "left",
            columnLabel: "申请单单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            // columnWidth : 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101OrderType',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "orderType",
            headerAlign: "center",
            align: "left",
            columnLabel: "处理类型",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101Partno',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "partno",
            headerAlign: "center",
            align: "left",
            columnLabel: "刀模编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101Qty',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "qty",
            headerAlign: "center",
            align: "right",
            columnLabel: "申请数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101Price',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "price",
            headerAlign: "center",
            align: "right",
            columnLabel: "预估价格",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101TotalPrice',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "totalPrice",
            headerAlign: "center",
            align: "right",
            columnLabel: "预估总价",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101Supplierid',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "supplierid",
            headerAlign: "center",
            align: "left",
            columnLabel: "供应商编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101Suppliername',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "suppliername",
            headerAlign: "center",
            align: "left",
            columnLabel: "供应商名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2101,
            serialNumber: 'review2101AuthorizeFlag',
            tableId: "review2101",
            tableName: "PRHeader",
            columnProp: "approveresult",
            headerAlign: "center",
            align: "left",
            columnLabel: "审批结果",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
        ],
        // 展示列集
        columnList1: [
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 2101,
          //   tableId: "review2101",
          //   tableName: "commonLanguage",
          //   columnProp: "functionId",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "功能编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: true,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 2101,
          //   tableId: "review2101",
          //   tableName: "commonLanguage",
          //   columnProp: "objectId",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "序列化编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: true,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 2101,
          //   tableId: "review2101",
          //   tableName: "commonLanguage",
          //   columnProp: "objectType",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "类型",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: true,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 2101,
          //   tableId: "review2101",
          //   tableName: "commonLanguage",
          //   columnProp: "languageValue",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "语言值",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: true,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 2101,
          //   tableId: "review2101",
          //   tableName: "commonLanguage",
          //   columnProp: "languageCode",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "语言编码",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: true,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false,
          // }
        ],
        // 展示列集
        columnList2: [
          {
            userId: this.$store.state.user.name,
            functionId: 2102,
            tableId: "fileDetail2102",
            tableName: "fileDetailTable",
            columnProp: "fileName",
            headerAlign: "center",
            align: "center",
            columnLabel: "文件名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2102,
            tableId: "fileDetail2102",
            tableName: "fileDetailTable",
            columnProp: "createDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "创建时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 135,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 2102,
            tableId: "fileDetail2102",
            tableName: "fileDetailTable",
            columnProp: "createdBy",
            headerAlign: "center",
            align: "center",
            columnLabel: "创建人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false,
            columnWidth: 70,
          },
        ],
        // 数据集
        dataList: [],
        queryButton: {
          functionId: 2101,
          table_id: 'review2101',
          languageCode: this.$i18n.locale,
          objectType: 'button'
        },
        buttons: {
          search: '查询',
          download: '导出',
          settingTable: '设置列表',
          defaultTable: '设置默认配置',
          operating: '操作',
          audit: '审批',
          reviewDetails: '审批详情',
          appendixInfo: '附件信息',
          fileDownload: '下载',
        },
        // 导出 start
        exportData: [],
        exportDataStandard: {
          "功能编码": "functionId",
          "序列化编码": "objectId",
          "类型": "objectType",
          "语言值": "languageValue"
        },
        exportName: "申请审核",
        exportHeader: ["申请审核"],
        exportFooter: [],
        exportDefaultValue: "这一行这一列没有数据",
        // 导出 end
        buttonList: [
          // {
          //   functionId: "2101",
          //   languageValue: '添加',
          //   objectId: 'add',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '编辑',
          //   objectId: 'edit',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '删除',
          //   objectId: 'delete',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '批量删除',
          //   objectId: 'deleteList',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '操作',
          //   objectId: 'cz',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '查询',
          //   objectId: 'search',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '导出',
          //   objectId: 'download',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '设置列表',
          //   objectId: 'settingTable',
          //   objectType: "button",
          //   tableId: "common1001"
          // },
          // {
          //   functionId: "2101",
          //   languageValue: '设置默认配置',
          //   objectId: 'defaultTable',
          //   objectType: "button",
          //   tableId: "common1001"
          // }
        ],
        languageList: [],
        languageColumnList: [],
        languageDataList: [],
        queryLanguage: {},
        // 数据集条件
        querySysLanguagePack: {
          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 - 240;
      })
    },
    activated() {
      this.getReviewStepList();
      this.getDataList()
      this.getLanguageList()
      this.initTblBaseDataList()
      // zufoeav
    },
    methods: {
      // 文件下载
      fileDownload(row) {
        axios.get('/api/ftp/file/downFtpFile/' + row.id, {
          responseType: 'blob',
          headers: {
            'Content-Type': 'application/json',
            'token':Vue.cookie.get('token')
          }
        }).then(({data}) => {

          // 不限制文件下载类型
          const blob = new Blob([data], {type: "application/octet-stream"})
          // 下载文件名称
          const fileName = row.fileName
          // a标签下载
          const linkNode = document.createElement('a')
          linkNode.download = fileName // a标签的download属性规定下载文件的名称
          linkNode.style.display = 'none'
          linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
          document.body.appendChild(linkNode)
          linkNode.click() // 模拟在按钮上的一次鼠标单击
          URL.revokeObjectURL(linkNode.href) // 释放URL 对象
          document.body.removeChild(linkNode)
        })
      },
      initFileModel(row){
        this.getFileList(row)
        this.setUp.fileFlag = true
      },
      /*naxtStep(val){
          if (val == 's' && this.active != 0){
            this.active -= 1
          }
          if(this.active < this.reviewStepList.length-1 && val == 'x' ){
            this.active += 1
          }

      },*/
      //获取申请单号文件信息
      getFileList(row){
        let jsonData = {
          site : row.site,
          type : 'PRFile',
          associatedField1 : row.requisitionno
        }
        this.fileList = []
        getFileList(jsonData).then(({data}) =>{
          if(data.code == 0){
            this.fileList = data.row
          }
        })
      },
      getReviewStepList(orderRef1) {
        this.reviewStepList = []
        let queryData = {
          recordTypeDb: this.menuId,
          site: this.site,
          orderRef1 : orderRef1,
        }
        getReviewSteps(queryData).then(({data}) => {
          this.reviewStepList = data.rows
          let list = data.rows;
          for (let i = 0; i < list.length; i++) {
            if(list[i].userName == this.userId){
              this.active = i
              break
            }
          }
        })
      },
      initTblBaseDataList() {
        let queryData = {
          type: 'orderType'
        }
        getTblBaseDataList(queryData).then(({data}) => {
          this.orderTypeList = data.rows
        })
      },
      saveReview(row ,val) {
        this.setUp.saveButton = true
        this.saveData = {}
        if(row.remark == '' && row.authFlag == null){
          this.$alert(data.msg, '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.saveButton = false
            }
          });
        }
        this.saveData.orderRef1 = this.currentReviewStepData.requisitionno
        this.saveData.approvedFlag = val
        this.saveData.site = this.site
        this.saveData.userName = row.userName
        this.saveData.authRuleId = row.authRuleId
        this.saveData.lastStepFlag = row.lastStepFlag
        this.saveData.id = row.id
        this.saveData.approveResultComments = row.approveResultComments
        this.saveData.partNo = this.currentReviewStepData.partno
        this.saveData.partdesc = this.currentReviewStepData.partdesc
        this.saveData.itemNo = this.currentReviewStepData.itemno
        this.saveData.qty = this.currentReviewStepData.qty
        this.saveData.authTypeDb = row.authTypeDb
        this.saveData.authUserId = row.authUserId
        this.saveData.authGroupId = row.authGroupId
        this.saveData.orderType = this.currentReviewStepData.orderType
        this.saveData.supplierId = this.currentReviewStepData.supplierid
        this.saveData.supplierName = this.currentReviewStepData.suppliername
        this.saveData.torNumdown = 1
        this.saveData.torNumacc = 1
        this.saveData.stepId = row.stepId
        this.saveData.remark = row.remark
        if(val == "Y"){
          if(row.lastStepFlag == 'Y'){
            this.saveData.approveResult = "审批全通过"
          }else {
            this.saveData.approveResult = "审批部分通过"
          }
        }else if(val == "N"){
          this.saveData.approveResult = "审批未通过"
        }
        updatePRHeader(this.saveData).then(({data}) => {
          if(data.code == 0){
            this.getDataList('Y')
            this.getReviewStepList(this.currentReviewStepData.requisitionno)
          }
          this.$alert(data.msg, '操作提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.saveButton = false
              if(data.code == 0){
                this.setUp.reviewFlag = false
              }
            }
          });
        })
      },
      //初始审核信息
      initReview(row) {
        this.setUp.saveButton = false
        this.setUp.reviewFlag = true
        this.currentReviewStepData = row
        this.saveData.requisitionno = row.requisitionno
        this.saveData.partNo = row.partno
        this.saveData.itemno = row.itemno
        this.saveData.qty = row.qty
        this.saveData.orderType = row.orderType
        this.saveData.suppliername = row.suppliername
        this.saveData.supplierid = row.supplierid
        this.saveData.remark = ''
        this.saveData.authorizeFlag = 'Y'
        this.getReviewStepList(this.currentReviewStepData.requisitionno)
      },
      // 打印方式
      printReport() {

        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()
        }
      },
      // 校验用户是否收藏
      favoriteIsOk(){
        let userFavorite ={
          userId:this.$store.state.user.id,
          languageCode:this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) =>{
          let size = data.list.filter(item => item.menuId==this.$route.meta.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
          })
        }

      },
      // 保存语言编辑
      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: 2101,
            tableId: "review2101",
            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;
        let queryTable = {
          userId: this.$store.state.user.name,
          functionId: 2101,
          tableId: "review2101",
          languageCode: this.$i18n.locale
        }
        this.$nextTick(() => {
          this.$refs.column.init(queryTable);
        });
      },
      // 获取 用户保存的 格式列
      getTableUserColumn() {
        getTableUserListLanguage(this.queryTableUser).then(({data}) => {
          if (data != null && 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 != null && !data.rows.length == 0) {
            this.showDefault = false
            this.columnList = data.rows
          } else {
            this.showDefault = true
          }
        })
      },
      // 获取数据列表
      getDataList(val) {
        this.dataListLoading = true
        if (val == 'Y') {
          this.pageIndex = 1
        }
        this.mainQueryData.limit = this.pageSize
        this.mainQueryData.page = this.pageIndex
        getPRHeaderList(this.mainQueryData).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
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = 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({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      createExportData() {
        // 点击导出按钮之后,开始导出数据之前的执行函数,返回值为需要下载的数据
        // TODO:构造需要下载的数据返回
        getExportList(this.mainQueryData).then(({data}) => {
          if (data && data.code === 0) {
            return data.rows.list
          }
          return this.dataList;
        })
      },
      startDownload() {
        //  this.exportData = this.dataList
        console.log("数据开始")
      },
      finishDownload() {
        console.log("数据下载完成")
      },
      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
      },
    },
    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>
