<template>
  <div class="mod-config">
    <!-- 查询条件 -->
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'客户编码'">
        <el-input v-model="searchData.customerNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'客户名称'">
        <el-input v-model="searchData.customerDesc" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'跟单员'">
        <el-input v-model="searchData.trackerName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'产品编码'">
        <el-input v-model="searchData.testPartNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'产品名称'">
        <el-input v-model="searchData.partName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'要求交付日期'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item style="margin-top: 23px;">
        <laber style="margin-left: 0px;font-size: 19px">&#10142</laber>
      </el-form-item>
      <el-form-item :label="' '">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'项目编码'">
        <el-input v-model="searchData.projectId" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'项目名称'">
        <el-input v-model="searchData.projectName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'工程师'">
        <el-input v-model="searchData.engineerName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'优先等级'">
        <el-select v-model="searchData.priorityLevel" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="紧急" value="紧急"></el-option>
          <el-option label="一般" value="一般"></el-option>
          <el-option label="不紧急" value="不紧急"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'状态'">
        <el-select v-model="searchData.proofingStatus" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="草稿" value="草稿"></el-option>
          <el-option label="下达" value="下达"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="getDataList()">查询</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="' '">
        <el-button @click="proofingResultModal()" class="el-button el-button--primary el-button--medium">录入打样结果</el-button>
        <el-button @click="submitProofingModal()" class="el-button el-button--primary el-button--medium">录入送样信息</el-button>
        <el-button @click="customerResponseModal()" class="el-button el-button--primary el-button--medium">客户回复</el-button>
      </el-form-item>
    </el-form>

    <!-- 打样列表 -->
    <el-table
      :height="height"
      :data="dataList"
      border
      ref="proofingTable"
      @row-click="proofingClickRow"
      @selection-change="selectionProofing"
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        :selectable="selectFlag"
        width="50">
      </el-table-column>
      <el-table-column
        prop="proofingResultStatus"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <span v-show="scope.row.proofingResultStatus === 'C'">已创建</span>
          <span v-show="scope.row.proofingResultStatus === 'E'">已录入</span>
          <span v-show="scope.row.proofingResultStatus === 'S'">已送样</span>
          <span v-show="scope.row.proofingResultStatus === 'R'">已回复</span>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed === ''?false:item.fixed"
        :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>

    <selectDiv ref="selectDiv"></selectDiv>

    <!-- 分页插件 -->
    <el-pagination style="margin-top: 0px"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 录入打样结果模态框 -->
    <el-dialog title="录入打样结果" :close-on-click-modal="false" v-drag :visible.sync="enterResultModalFlag" width="785px">
      <el-form :inline="true" label-position="top" :model="enterResultData" :rules="enterResultRules" style="margin-left: 0px;margin-top: 10px;">
        <el-form-item label="实际交付日期" prop="actualityDeliveryDate" :rules="enterResultRules.actualityDeliveryDate">
          <el-date-picker v-model="enterResultData.actualityDeliveryDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择日期" style="width: 200px"></el-date-picker>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="enterResultData" :rules="enterResultRules" style="margin-left:0px;margin-top: 5px;">
        <el-form-item label="打样结果信息" prop="proofingResultInformation" :rules="enterResultRules.proofingResultInformation">
          <el-input type="textarea" v-model="enterResultData.proofingResultInformation" :rows="3" resize='none' maxlength="300" show-word-limit style="width: 500px;height: 30px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="enterResultData" style="margin-left: 0px;margin-top: 60px;">
        <el-form :inline="true" label-position="top" style="margin-top: 5px">
          <el-button type="primary" @click="uploadFile()">上传文件</el-button>
        </el-form>
        <el-table
          :height="200"
          :data="enterResultData.fileContentList"
          border
          v-loading="dataListLoading"
          style="width: 100%">
          <el-table-column
            v-for="(item,index) in fileColumnList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed===''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            header-align="center"
            align="center"
            width="100"
            label="操作">
            <template slot-scope="scope">
              <a @click="deleteFile(scope.row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveProofingResult()">保存</el-button>
        <el-button type="primary" @click="closeProofingResultModal()">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 录入送样信息模态框 -->
    <el-dialog title="录入送样信息" :close-on-click-modal="false" v-drag :visible.sync="submitResultModalFlag" width="620px">
      <el-form :inline="true" label-position="top" :model="submitResultData" :rules="submitResultRules" style="margin-left: 0px;margin-top: 10px;">
        <el-form-item label="实际提交客户日期" prop="actualitySubmissionDate" :rules="submitResultRules.actualitySubmissionDate">
          <el-date-picker v-model="submitResultData.actualitySubmissionDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择日期" style="width: 200px"></el-date-picker>
        </el-form-item>
        <el-form-item label="提交方式" prop="submissionMethod" :rules="submitResultRules.submissionMethod">
          <el-select v-model="submitResultData.submissionMethod" style="width: 221px">
            <el-option label="邮件" value="邮件"></el-option>
            <el-option label="口头" value="口头"></el-option>
            <el-option label="微信" value="微信"></el-option>
            <el-option label="其它" value="其它"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="submitResultData" style="margin-left:0px;margin-top: 5px;">
        <el-form-item label="提交备注">
          <el-input type="textarea" v-model="submitResultData.submissionRemark" :rows="3" resize='none' maxlength="300" show-word-limit style="width: 456px;height: 30px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 60px;text-align:center">
        <el-button type="primary" @click="saveSubmitResult()">保存</el-button>
        <el-button type="primary" @click="submitResultModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 客户回复模态框 -->
    <el-dialog title="客户回复" :close-on-click-modal="false" v-drag :visible.sync="customerResponseModalFlag" width="620px">
      <el-form :inline="true" label-position="top" :model="customerResponseData" :rules="customerResponseRules" style="margin-left: 0px;margin-top: 10px;">
        <el-form-item label="实际回复日期" prop="actualityReplyDate" :rules="customerResponseRules.actualityReplyDate">
          <el-date-picker v-model="customerResponseData.actualityReplyDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择日期" style="width: 185px"></el-date-picker>
        </el-form-item>
        <el-form-item label="客户确认结果" prop="confirmResults" :rules="customerResponseRules.confirmResults">
          <el-select v-model="customerResponseData.confirmResults" style="width: 185px">
            <el-option label="接受" value="接受"></el-option>
            <el-option label="不接受" value="不接受"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户确认人" prop="confirmBy" :rules="customerResponseRules.confirmBy">
          <el-input v-model="customerResponseData.confirmBy" style="width: 185px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="customerResponseData" style="margin-left:0px;margin-top: 5px;">
        <el-form-item label="客户回复信息">
          <el-input type="textarea" v-model="customerResponseData.confirmInformation" :rows="3" resize='none' maxlength="300" show-word-limit style="width: 595px;height: 30px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 60px;text-align:center">
        <el-button type="primary" @click="saveCustomerResponse()">保存</el-button>
        <el-button type="primary" @click="customerResponseModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 上传文件的modal -->
    <proofingUploadFile ref="proofingUploadFile" @refreshPageTables="getFileContentData()" v-drag></proofingUploadFile>
  </div>
</template>

<script>
  import {
    proofingInformationSearch, // 打样信息列表查询
    getFileContentList, // 获取报价单附件列表
    batchDeleteProofingFile, // 批量文件删除
    saveProofingResult, // 保存打样结果
    saveSubmitResult, // 保存提交结果
    saveCustomerResponse, // 保存客户回复
    checkProofingStatus, // 检查打样进度
    closeModalDeleteFile, // 关闭模态框删除文件
  } from '@/api/proofing/proofingInformation.js'
  import proofingUploadFile from "./proofing_upload_file"
  export default {
    components: {
      proofingUploadFile
    },
    watch: {
      searchData: {
        deep: true,
        handler: function (newV, oldV) {
          this.searchData.customerNo = this.searchData.customerNo.toUpperCase()
          this.searchData.projectId = this.searchData.projectId.toUpperCase()
        }
      },
      modalData: {
        deep: true,
        handler: function (newV, oldV) {
          this.modalData.customerNo = this.modalData.customerNo.toUpperCase()
          this.modalData.projectId = this.modalData.projectId.toUpperCase()
          this.modalData.proofingNo = this.modalData.proofingNo.toUpperCase()
        }
      }
    },
    data () {
      return {
        // 导出
        exportData: [],
        exportName: '设备分类' + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ['设备分类'],
        exportFooter: [],
        resultList: [],
        // ======== 行高 ========
        height: 200,
        // ======== 分页 ========
        pageIndex: 1,
        pageSize: 50,
        totalPage: 0,
        selectedDataNum: 0,
        // 条件查询
        searchData: {
          site: this.$store.state.user.site,
          customerNo: '',
          customerDesc: '',
          trackerName: '',
          testPartNo: '',
          partName: '',
          proofingStatus: '',
          startDate: '',
          endDate: '',
          projectId: '',
          projectName: '',
          engineerName: '',
          priorityLevel: '',
          page: 1,
          limit: 10
        },
        // 其它
        dataListLoading: false,
        // ======== 数据对象 ========
        modalData: {
          flag: '',
          title: '',
          site: this.$store.state.user.site,
          quotationNo: '',
          customerNo: '',
          customerDesc: '',
          projectId: '',
          projectName: '',
          tracker: '',
          trackerName: '',
          quoter: '',
          quoterName: '',
          quotationStatus: '',
          testPartNo: '',
          partName: '',
          priorityLevel: '',
          requiredCompletionDate: '',
          remark: '',
          technicalConsiderations: '',
          customerResponsiblePerson: '',
          customerResponsiblePersonPhone: '',
          nextToDo: '',
          actualityQuotationDate: '',
          quotationResultInformation: '',
          actualitySubmissionDate: '',
          submissionMethod: '',
          submissionRemark: '',
          actualityReplyDate: '',
          confirmResults: '',
          confirmBy: '',
          confirmInformation: '',
          proofingResultStatus: '',
          createDate: '',
          createBy: '',
          updateDate: '',
          updateBy: ''
        },
        quotationResultData: {
          actualityQuotationDate: '',
          quotationResultInformation: '',
          actualitySubmissionDate: '',
          submissionMethod: '',
          submissionRemark: '',
          confirmResults: '',
          actualityReplyDate: '',
          confirmBy: '',
          confirmInformation: '',
          proofingResultStatus: '',
        },
        enterResultData: {
          site: this.$store.state.user.site,
          proofingNo: '',
          actualityDeliveryDate: '',
          proofingResultInformation: '',
          updateBy: this.$store.state.user.name,
          proofingResultStatus: '',
          fileContentList: []
        },
        submitResultData: {
          site: this.$store.state.user.site,
          quotationNo: '',
          actualitySubmissionDate: '',
          submissionMethod: '',
          submissionRemark: '',
          updateBy: this.$store.state.user.name,
          proofingResultStatus: ''
        },
        customerResponseData: {
          site: this.$store.state.user.site,
          quotationNo: '',
          actualityReplyDate: '',
          confirmResults: '',
          confirmBy: '',
          confirmInformation: '',
          updateBy: this.$store.state.user.name,
          proofingResultStatus: ''
        },
        // ======== 数据列表 ========
        dataList: [],
        // ======== 列表表头 ========
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1ProofingNo',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'proofingNo',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '打样单号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1CustomerNo',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'customerNo',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '客户编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1CustomerDesc',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'customerDesc',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '客户名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1ProjectId',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'projectId',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '项目编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1ProjectName',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'projectName',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '项目名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1TrackerName',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'trackerName',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '跟单员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1EngineerName',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'engineerName',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '工程师',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1TestPartNo',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'testPartNo',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '项目料号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1PartName',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'partName',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '物料名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1PriorityLevel',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'priorityLevel',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '优先等级',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1ProofingNumber',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'proofingNumber',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '打样数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1RequiredDeliveryDate',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'requiredDeliveryDate',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '要求交付日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 160
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1ProofingStatus',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'proofingStatus',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '状态',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1CreateDate',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'createDate',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '创建时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 160
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1CreateBy',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'createBy',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '创建人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1UpdateDate',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'updateDate',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '更新时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 160
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table1UpdateBy',
            tableId: '103001Table1',
            tableName: '打样信息表',
            columnProp: 'updateBy',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '更新人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          }
        ],
        fileColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 102001,
            serialNumber: '102001Table2FileName',
            tableId: '102001Table2',
            tableName: '文件信息表',
            columnProp: 'fileName',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '文件名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          },
          {
            userId: this.$store.state.user.name,
            functionId: 102001,
            serialNumber: '102001Table2FileRemark',
            tableId: '102001Table2',
            tableName: '文件信息表',
            columnProp: 'fileRemark',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 240
          },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 102001,
          //   serialNumber: '102001Table2OrderRef3',
          //   tableId: '102001Table2',
          //   tableName: '文件信息表',
          //   columnProp: 'orderRef3',
          //   headerAlign: 'center',
          //   align: 'center',
          //   columnLabel: '文件描述',
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: '',
          //   columnWidth: 120
          // },
          {
            userId: this.$store.state.user.name,
            functionId: 102001,
            serialNumber: '102001Table2CreateDate',
            tableId: '102001Table2',
            tableName: '文件信息表',
            columnProp: 'createDate',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '上传时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          },
          {
            userId: this.$store.state.user.name,
            functionId: 102001,
            serialNumber: '102001Table2CreatedBy',
            tableId: '102001Table2',
            tableName: '文件信息表',
            columnProp: 'createdBy',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '上传人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          }
        ],
        // ======== 必填规则 ========
        rules: {
          customerDesc: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          trackerName: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          projectName: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          quoterName: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          partName: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          priorityLevel: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          requiredCompletionDate: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ]
        },
        enterResultRules: {
          actualityDeliveryDate: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          proofingResultInformation: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ]
        },
        submitResultRules: {
          actualitySubmissionDate: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          submissionMethod: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ]
        },
        customerResponseRules: {
          actualityReplyDate: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          confirmResults: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          confirmBy: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ]
        },
        // ======== 复选数据集 ========
        proofingSelections: [],
        // ======== 选中的当前行数据 ========
        proofingCurrentRow: {},
        // ======== 模态框开关控制 ========
        modalFlag: false,
        modalDisableFlag: false,
        enterResultModalFlag: false,
        submitResultModalFlag: false,
        customerResponseModalFlag: false,
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },
    created () {
      this.getDataList()
    },
    methods: {
      // ======== 分页相关方法 ========
      /**
       * 每页数
       * @param val
       */
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      /**
       * 当前页
       * @param val
       */
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },

      // ======== 复选框操作相关方法 ========
      /**
       * 未知
       * @returns {boolean}
       */
      selectFlag () {
        return true;
      },

      // ======== 列表数据刷新方法 ========
      /**
       * 获取数据列表
       */
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        proofingInformationSearch(this.searchData).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            this.$refs.selectDiv.setLengthAll( this.dataList.length)
            // 判断是否全部存在数据
            if(this.totalPage > 0){
              // 设置选中行
              this.$refs.proofingTable.setCurrentRow(this.dataList[0])
              this.proofingClickRow(this.dataList[0])
            }
          }
          this.dataListLoading = false
        })
      },

      // ======== 列表操作方法 ========
      /**
       * 单机选中打样信息
       * @param row
       */
      proofingClickRow (row) {
        this.$refs.proofingTable.toggleRowSelection(row)
        this.proofingCurrentRow = JSON.parse(JSON.stringify(row))
      },
      /**
       * 复选打样信息
       * @param val
       */
      selectionProofing (val) {
        this.proofingSelections = val
        this.$refs.selectDiv.setLengthselected(this.proofingSelections.length)
      },

      // ======== 报价结果相关方法 ========
      /**
       * 录入打样结果
       */
      proofingResultModal () {
        // 判断是否选中打样单
        if (this.proofingSelections == null || this.proofingSelections.length <= 0) {
          this.$message.warning('请勾选打样单！')
          return
        }
        let tempData = {
          currentStatus: 'C',
          informationList: this.proofingSelections,
        }
        // 检查打样单状态
        checkProofingStatus(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.flag === 1) { // 状态一致
              this.packProofingResultModal()
            } else { // 状态不同
              this.$message.warning('选中的打样单进度不一致或与按钮不符，请确认！')
            }
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      /**
       * 封装录入方法
       */
      packProofingResultModal () {
        // 重置对象
        this.enterResultData = {
          site: this.$store.state.user.site,
          proofingNo: '',
          actualityDeliveryDate: '',
          proofingResultInformation: '',
          proofingResultStatus: 'E',
          fileContentList: [],
          updateBy: this.$store.state.user.name
        }
        // 获得选中的打样号
        this.proofingSelections.forEach(val => {
          this.enterResultData.proofingNo += ';' + val.proofingNo
        })
        this.enterResultData.proofingNo = this.enterResultData.proofingNo.substring(1)
        this.enterResultModalFlag = true
      },
      /**
       * 保存打样结果
       */
      saveProofingResult () {
        if (this.enterResultData.actualityDeliveryDate === '' || this.enterResultData.actualityDeliveryDate == null) {
          this.$message.warning('请选择实际交付日期！')
          return
        }
        if (this.enterResultData.proofingResultInformation === '' || this.enterResultData.proofingResultInformation == null) {
          this.$message.warning('请填写打样结果信息！')
          return
        }
        if (this.proofingSelections.length > 1) {
          this.$confirm(`是否录入多条打样结果?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            saveProofingResult(this.enterResultData).then(({data}) => {
              if (data && data.code === 0) {
                this.getDataList()
                this.enterResultModalFlag = false
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {}
                })
              } else {
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            })
          }).catch(() => {
          })
        } else {
          saveProofingResult(this.enterResultData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.enterResultModalFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },
      /**
       * 关闭报价结果模态框
       */
      closeProofingResultModal () {
        // 删除已上传的文件
        let tempData = {
          orderRef1: this.enterResultData.site,
          proofingNo: this.enterResultData.proofingNo
        }
        closeModalDeleteFile(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.enterResultModalFlag = false
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },


      /**
       * 录入送样信息
       */
      submitProofingModal () {
        // 判断是否选中打样单
        if (this.proofingSelections == null || this.proofingSelections.length <= 0) {
          this.$message.warning('请勾选打样单！')
          return
        }
        let tempData = {
          currentStatus: 'E',
          informationList: this.proofingSelections,
        }
        // 检查打样单状态
        checkProofingStatus(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.flag === 1) { // 状态一致
              this.packSubmitProofingModal()
            } else { // 状态不同
              this.$message.warning('选中的打样单进度不一致或与按钮不符，请确认！')
            }
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      /**
       * 封装送样方法
       */
      packSubmitProofingModal () {
        this.submitResultData = {
          site: this.$store.state.user.site,
          proofingNo: '',
          actualitySendSamplesDate: '',
          sendSamplesMethod: '',
          deliverGoodsInformation: '',
          deliverGoodsRemark: '',
          proofingResultStatus: 'S',
          updateBy: this.$store.state.user.name,
        }
        // 获得选中的打样号
        this.proofingSelections.forEach(val => {
          this.submitResultData.proofingNo += ';' + val.proofingNo
        })
        this.submitResultData.proofingNo = this.submitResultData.proofingNo.substring(1)
        this.submitResultModalFlag = true
      },
      /**
       * 保存送样结果
       */
      saveSubmitResult () {
        if (this.submitResultData.actualitySendSamplesDate === '' || this.submitResultData.actualitySendSamplesDate == null) {
          this.$message.warning('请选择实际送样日期！')
          return
        }
        if (this.submitResultData.sendSamplesMethod === '' || this.submitResultData.sendSamplesMethod == null) {
          this.$message.warning('请选择提交方式！')
          return
        }
        if (this.proofingSelections.length > 1) {
          this.$confirm(`是否录入多条送样信息?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            saveSubmitResult(this.submitResultData).then(({data}) => {
              if (data && data.code === 0) {
                this.getDataList()
                this.submitResultModalFlag = false
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {}
                })
              } else {
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            })
          }).catch(() => {
          })
        }
      },


      /**
       * 客户回复
       */
      customerResponseModal () {
        // 判断是否选中打样单
        if (this.proofingSelections == null || this.proofingSelections.length <= 0) {
          this.$message.warning('请勾选打样单！')
          return
        }
        let tempData = {
          currentStatus: 'S',
          informationList: this.proofingSelections,
        }
        // 检查打样单状态
        checkProofingStatus(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.flag === 1) { // 状态一致
              this.packCustomerResponseModal()
            } else { // 状态不同
              this.$message.warning('选中的打样单进度不一致或与按钮不符，请确认！')
            }
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      /**
       * 封装回复方法
       */
      packCustomerResponseModal () {
        this.customerResponseData = {
          site: this.$store.state.user.site,
          proofingNo: '',
          actualityReplyDate: '',
          confirmResults: '',
          confirmBy: '',
          confirmInformation: '',
          proofingResultStatus: 'R',
          updateBy: this.$store.state.user.name
        }
        // 获得选中的打样号
        this.proofingSelections.forEach(val => {
          this.customerResponseData.proofingNo += ';' + val.proofingNo
        })
        this.customerResponseData.proofingNo = this.customerResponseData.proofingNo.substring(1)
        this.customerResponseModalFlag = true
      },
      /**
       * 保存客户回复
       */
      saveCustomerResponse () {
        if (this.customerResponseData.actualityReplyDate === '' || this.customerResponseData.actualityReplyDate == null) {
          this.$message.warning('请选择实际回复日期！')
          return
        }
        if (this.customerResponseData.confirmResults === '' || this.customerResponseData.confirmResults == null) {
          this.$message.warning('请选择客户确认结果！')
          return
        }
        if (this.customerResponseData.confirmBy === '' || this.customerResponseData.confirmBy == null) {
          this.$message.warning('请填写客户确认人！')
          return
        }
        if (this.proofingSelections.length > 1) {
          this.$confirm(`是否提交多条客户回复?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            saveCustomerResponse(this.customerResponseData).then(({data}) => {
              if (data && data.code === 0) {
                this.getDataList()
                this.customerResponseModalFlag = false
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {}
                })
              } else {
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            })
          }).catch(() => {
          })
        }
      },

      // ======== 报价单附件的相关方法 ========
      /**
       * 获取报价单附件列表
       */
      getFileContentData () {
        let currentData = {
          orderRef1: this.$store.state.user.site,
          orderRef2: this.enterResultData.proofingNo.split(';')[0]
        }
        getFileContentList(currentData).then(({data}) => {
          if (data && data.code === 0) {
            this.enterResultData.fileContentList = data.rows
          } else {
            this.enterResultData.fileContentList = []
          }
        })
      },
      /**
       * 上传文件
       */
      uploadFile () {
        let currentData = {
          titleCon: '批量打样附件上传',
          site: this.$store.state.user.site,
          createBy: this.$store.state.user.name,
          proofingNo: this.enterResultData.proofingNo,
          fileRemark: '',
          folder: 'proofingFile',
        }
        //打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.proofingUploadFile.init(currentData)
        })
      },
      /**
       * 文件删除
       * @param row
       */
      deleteFile (row) {
        this.$confirm('确定要删除此文件?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let tempData = {
            id: row.id,
            fileName: row.fileName,
            orderRef1: row.orderRef1,
            orderRef2: row.orderRef2,
            orderRef3: row.orderRef3,
            proofingNo: this.enterResultData.proofingNo
          }
          batchDeleteProofingFile(tempData).then(({data}) => {
            if (data && data.code === 0) {
              this.getFileContentData()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      // ======== 导出相关方法 ========
      /**
       * 导出excel
       */
      async createExportData () {
        this.searchData.limit = -1
        this.searchData.page = 1
        await proofingInformationSearch(this.searchData).then(({data}) => {
          this.resultList = data.page.list
        })
        return this.resultList
      },
      startDownload () {
      },
      finishDownload () {
      },
      fields () {
        let json = '{'
        this.columnList.forEach((item, index) => {
          if (index == this.columnList.length - 1) {
            json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"'
          } else {
            json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"' + ','
          }
        })
        json += '}'
        let s = eval('(' + json + ')')
        return s
      }
    }
  }
</script>

<style scoped lang="scss">
/deep/ .customer-tab .el-tabs__content {
  padding: 0px !important;
  height: 459px;
}
</style>

