<template>
  <div class="testdiv">
    <div class="divborder newSearchDiv" style="margin:0px;">
      <div>
        <div class="filter">
          <label >{{$t('1950491')}}：</label>
          <Cascader :data="datalevel" :value="leveldata" v-model="sectionid" trigger="click" @on-change="handlelevelchange" change-on-select class="searchSelect"></Cascader>
        </div>
        <div class="filter">
          <label >{{$t('100307')}}：</label>
          <Select v-model="productid" label-in-value @on-change="routechange" clearable filterable class="searchSelect">
              <Option v-for="item in products" :value="item.id" :key="item.id">{{ item.name+"【"+ item.code +"】" }}</Option>
          </Select>
        </div>
        <!-- <div class="filter">
          <label >{{$t('500006')}}:</label>
          <Select v-model="routeid" label-in-value  clearable style="width:200px;" >
              <Option v-for="item in routes" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div> -->
        <div class="filter">
          <label >{{$t('920165')}}：</label>
          <Select v-model="materialid" label-in-value clearable filterable class="searchSelect" >
              <Option v-for="item in materials" :value="item.id" :key="item.id">{{ item.name+"【"+ item.pn +"】" + "【" + item.spec + "】" }}</Option>
          </Select>
        </div>
         <div class="filter">
                <label >{{$t('1950501')}}：</label>
                <Select v-model="checktype" label-in-value clearable class="searchSelect" >
                    <Option v-for="item in checktypeList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                    <!--<Option value="5" key="5">{{$t(930033)}}</Option>
                    <Option value="2" key="2">{{$t(930034)}}</Option>
                    <Option value="3" key="3">{{$t(930035)}}</Option>
                    <Option value="6" key="6">{{$t(930036)}}</Option>
                    <Option value="1" key="1">{{$t(950367)}}</Option>
                    <Option value="4" key="4">{{$t(930037)}}</Option>
                    <Option value="7" key="7">{{$t(600233)}}</Option>-->
                </Select>
            </div>
        <!-- 次级搜索条件--隐藏 -->
      <div v-show="!morecondition">
        <div>
            <div class="filter">
            <label >{{$t('1950502')}}：</label>
            <Select v-model="testroom" label-in-value clearable class="searchSelect" >
                <Option v-for="item in testrooms" :value="item.key" :key="item.key">{{ item.value }}</Option>
            </Select>
          </div>
           <div class="filter">
                <label >{{$t('800195')}}：</label>
                <Select v-model="result" label-in-value clearable class="searchSelect" >
                    <Option value="1" key="1">{{$t('1950546')}}</Option>
                    <Option value="2" key="2">{{$t('1950549')}}</Option>
                    <Option value="3" key="3">{{$t('1950550')}}</Option>
                </Select>
            </div>

            <div class="filter">
                <label >{{$t('200054')}}：</label>
                <Select v-model="checkstatus" label-in-value clearable class="searchSelect" >
                    <Option :value="1" :key="1">{{$t('1950634')}}</Option>
                    <Option :value="3" :key="3">{{$t('1950594')}}</Option>
                    <Option :value="4" :key="4">{{$t('1950635')}}</Option>
                    <Option :value="2" :key="2">{{$t('1950504')}}</Option>
                </Select>
            </div>
            <div class="filter">
              <label >{{$t('800008')}}：</label>
              <Input class="searchInput" type="text" id="input1" v-model="sn" />
            </div>
            </div>
            <div>
             <div class="filter">
              <label>{{$t('1046')}}：</label>
              <DatePicker
                id="日期"
                type="datetimerange"
                v-model="daterange"
                confirm
                placeholder=""
                class="searchInput MaxWidth "
                format="yyyy-MM-dd HH:mm:ss"
                @on-change="selectdate"
              ></DatePicker>
          </div>
            </div>
      </div>
      </div>
      <div class="searchBtn">
        <Button type="primary" class="twoWord" icon="ios-search" @click="search(1,pagesize)">{{$t('1001')}}</Button>
        <Button type="success" class="twoWord" icon="md-pricetags"  @click="recieveorchecking(1)">{{$t('1950630')}}</Button>
        <!--<Button type="success" icon="md-add-circle"  @click="sendtest()">{{$t('1950505')}}</Button>-->
        <Button type="success" class="twoWord" icon="md-add-circle"  @click="add()">{{$t('1950506')}}</Button>
        <!--<Button type="warning" icon="ios-create-outline"  @click="edit()">{{$t('1003')}}</Button>-->
        <Button type="warning" class="twoWord" icon="ios-create-outline"  @click="testedit()">{{$t('1003')}}</Button>
        <Button type="error" class="twoWord intervalRight" icon="md-close-circle"  @click="dele()">{{$t('1004')}}</Button>
        <Button type="success" class="fourWord" icon="md-build"  @click="recieveorchecking(2)">{{$t('1950631')}}</Button>
        <Button type="primary" class="fourWord" icon="ios-cloud-download" @click="downexcel()">{{$t('1007')}}</Button>
      </div>
     <!-- 更多条件 按钮 -->
      <MoreConbtn @getCon="morecondition = !morecondition" :morecondition="morecondition"></MoreConbtn>
    </div>
    <div class="divborder newTableDiv">
      <Table
        class="tableClass"
        width='100%'
        @on-current-change="handleRowChange"
        @on-selection-change="handleSelectRow"
        highlight-row
        :data="tableData1"
        :columns="tableColumns1"
      ></Table>
      <div class="pageDiv">
        <div class="pageDirection">
          <Page
            :total="total"
            :current="page"
            @on-change="changePage"
            show-elevator
            show-sizer
            show-total
            @on-page-size-change="handlePageSize"
            :page-size-opts="[10,20,30,40,100]"
          ></Page>
        </div>
      </div>
    </div>

    <div class="divborder" v-show="detailshow">
      <label>{{$t('1950494') + ':'}}</label>
      <template>
          <Table :columns="columns1" :data="tableData2">
          </Table>
      </template>
    </div>

    <div>
      <Modal class="newModalClass" v-model="ngmodal" :styles="{width:'950px'}">
        <div class="modal_body" style="padding-right:40px;height:400px!important;">
          <div class="divboder">
            <label><i>*</i>{{$t('1950601')}}：</label>
            <div style="float:left;height:100%;padding-left:5px;overflow-y:scroll">
                <Table class="tableClass" :columns="ngcolumns" :data="ngtableData"></Table>
            </div>
          </div>
        </div>
        <div slot="footer">
          <template>
            <Poptip placement="left" width="300px" style="margin-right:10px;">
              <Button type="primary" :loading="loading4">
                <span v-if="!loading4">{{$t('1950549')}}</span>
                <span v-else>{{$t('1950549')}}</span>
              </Button>
              <div class="api" slot="content">
                <div class="filter">
                  <label style="width:120px"><i>*</i>{{$t('1950626')}}：</label>
                  <InputNumber class="searchInput" v-model="quantity"/>
                </div>
                <Button type="primary" :loading="loading4" @click="adddata1">
                  <span v-if="!loading4">{{$t('900306')}}</span>
                  <span v-else>{{$t('900306')}}</span>
                </Button>
              </div>
            </Poptip>
          </template>
          <Button type="primary" :loading="loading5" @click="adddata2">
            <span v-if="!loading5">{{$t('1950550')}}</span>
            <span v-else>{{$t('1950550')}}</span>
          </Button>
        </div>
      </Modal>
    </div>

    <Modal class="newModalClass" :title='title1' v-model="editmodal" :styles="{width:'700px'}">
      <div class="modal_body">
            <div class="filter">
                <label ><i>*</i>{{$t('1950491')}}：</label>
                <Cascader class="searchInput" :data="datalevel1" :value="leveldata1" v-model="editsectionid" trigger="click" @on-change="handleeditlevelchange" change-on-select></Cascader>
            </div>
            <div class="filter">
                <label ><i>*</i>{{$t('100307')}}：</label>
                <Select v-model="editobj.productid" label-in-value @on-change="editroutechange" clearable class="searchSelect" >
                    <Option v-for="item in editproducts" :value="item.id" :key="item.id">{{ item.name+"【"+ item.code +"】" }}</Option>
                </Select>
            </div>
            <div class="filter">
                <label >{{$t('920165')}}：</label>
                <Select v-model="editobj.materialid" label-in-value clearable class="searchSelect" >
                    <Option v-for="item in editmaterials" :value="item.id" :key="item.id">{{ item.name+"【"+ item.pn +"】" + "【" + item.spec + "】" }}</Option>
                </Select>
            </div>
             <div class="filter">
                <label >{{$t('1950501')}}：</label>
                <Select v-model="editobj.checktype" label-in-value clearable class="searchSelect">
                    <Option v-for="item in checktypeList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                    <!--<Option value="5" key="5">{{$t(930033)}}</Option>
                    <Option value="2" key="2">{{$t(930034)}}</Option>
                    <Option value="3" key="3">{{$t(930035)}}</Option>
                    <Option value="6" key="6">{{$t(930036)}}</Option>
                    <Option value="1" key="1">{{$t(950367)}}</Option>
                    <Option value="4" key="4">{{$t(930037)}}</Option>
                    <Option value="7" key="7">{{$t(600233)}}</Option>-->
                </Select>
            </div>
            <div class="filter">
                <label ><i>*</i>{{$t('1950507')}}：</label>
                <Select v-model="editobj.testroom" label-in-value clearable class="searchSelect" >
                    <Option v-for="item in edittestrooms" :value="item.key" :key="item.key">{{ item.value }}</Option>
                </Select>
            </div>
            <div class="filter">
              <label >{{$t('800008')}}：</label>
              <Input class="searchInput" type="text" id="input1" v-model="editobj.sn"/>
            </div>
            <div class="filter">
              <label >{{$t('90000015')}}：</label>
              <InputNumber id="input1" v-model="editobj.number" class="searchInput"/>
            </div>
      </div>
      <div slot="footer">
        <Button type="text" size="large" @click="cancle">{{$t('1033')}}</Button>
        <Button type="primary" v-if="type===1" :loading="loading1" @click="sendtestdata">
            <span v-if="!loading1">{{$t('1950505')}}</span>
            <span v-else>Loading...</span>
        </Button>
        <Button type="primary" v-if="type===2" :loading="loading2" @click="editdata">
            <span v-if="!loading2">{{$t('1003')}}</span>
            <span v-else>Loading...</span>
        </Button>
        <!--<Button type="primary" v-if="type===1" size="large" @click="sendtestdata">{{$t('1950505')}}</Button>
        <Button type="primary" v-if="type===2" size="large" @click="editdata">{{$t('1003')}}</Button>-->
      </div>
    </Modal>

    <Modal class="newModalClass" :title='title2' v-model="testmodal" :styles="{width:'1200px'}">
      <div class="modal_body" style="width:1200px!important;padding:0 0px;height:600px!important;">
        <div class="divboder">
          <label style="font-size:14px;font-weight:700;">{{$t('300018')}}</label>
          <div style="width:1200px;float:left;height:20%;padding-left:5px;">
              <div class="filter">
                  <label ><i>*</i>{{$t('1950502')}}：</label>
                  <Select v-model="testobj.testroom" label-in-value clearable class="searchSelect MaxWidth" :disabled="testtype===2">
                      <Option v-for="item in edittestrooms" :value="item.key" :key="item.key">{{ item.value }}</Option>
                  </Select>
              </div>
              <div class="filter">
                <label >{{$t('800008')}}：</label>
                <Input class="searchInput MaxWidth" type="text" id="input1" v-model="testobj.sn" disabled="disabled"/>
              </div>
              <div class="filter" v-show="testtype===2">
                  <label ><i>*</i>{{$t('800195')}}：</label>
                  <Select v-model="testobj.result" label-in-value clearable class="searchSelect" :disabled="true">
                    <Option :value="1" :key="1">{{$t('1950546')}}</Option>
                    <Option :value="2" :key="2">{{$t('1950549')}}</Option>
                    <Option :value="3" :key="3">{{$t('1950550')}}</Option>
                  </Select>
              </div>
              <div class="filter">
                <span v-for="(item, i) in testobj.parameters">
                  <label>{{item.name}}:</label>
                  <Input class="searchInput" type="text" disabled="disabled" :value="item.result"/>
                </span>
              </div>
          </div>
        </div>
        <div class="divboder">
          <label style="font-size:14px;font-weight:700;">{{$t('1950508')}}</label>
          <div :class='table_scrollx?"testing_table":""' style="width:1120px;float:left;padding-left:5px;">
              <template>
                  <Table :columns="testcolumns" :data="testtableData" ref="detailTable" :max-height="300">
                      <template slot-scope="{ row, index }" slot="xuhao">
                          <span>{{ row.xuhao }}</span>
                      </template>
                      <template slot-scope="{ row, index }" slot="item">
                          <span>{{ row.item }}</span>
                      </template>
                      <template slot-scope="{ row, index }" slot="standard">
                          <span>{{ row.standard }}</span>
                      </template>
                      <template slot-scope="{ row, index }" slot="min_value">
                          <span>{{ row.min_value }}</span>
                      </template>
                      <template slot-scope="{ row, index }" slot="max_value">
                          <span>{{ row.max_value }}</span>
                      </template>
                      <template slot-scope="{ row, index }" slot="range">
                          <span>{{ row.range }}</span>
                      </template>

                      <template v-for="(item, i) in testobj.number" slot-scope="{ row, index }" :slot="'min_value'+(i+1)">
                        <span v-show="testtableData[index].checktype === 2 && testtableData[index].valuecategory === 2">
                          <inputNumber class="publicinput" type="text" :class="{active_class:((testtableData[index]['min_value'+(i+1)])?(testtableData[index]['min_value'+(i+1)]<row.min_value || testtableData[index]['min_value'+(i+1)]>row.max_value):false)}" v-model="testtableData[index]['min_value'+(i+1)]" style="width:100px" @blur.native.capture="getrange(index, i+1)"/>
                        </span>
                      </template>
                      <template v-for="(item, i) in testobj.number" slot-scope="{ row, index }" :slot="'max_value'+(i+1)">
                        <span v-show="testtableData[index].checktype === 2 && testtableData[index].valuecategory === 2">
                          <inputNumber class="publicinput" type="text" :class="{active_class:((testtableData[index]['max_value'+(i+1)])?(testtableData[index]['max_value'+(i+1)]<row.min_value || testtableData[index]['max_value'+(i+1)]>row.max_value):false)}" v-model="testtableData[index]['max_value'+(i+1)]" style="width:100px" @blur.native.capture="getrange(index, i+1)"/>
                        </span>
                      </template>
                      <template v-for="(item, i) in testobj.number" slot-scope="{ row, index }" :slot="'value'+(i+1)">
                        <span v-if="testtableData[index].checktype === 1">
                          <RadioGroup v-model="testtableData[index]['value'+(i+1)]">
                            <Radio label="OK" style="width:30px">OK</Radio>
                            <Radio label="NG" style="width:30px">NG</Radio>
                          </RadioGroup>
                        </span>
                        <span v-else-if="testtableData[index].checktype === 2">
                          <inputNumber :disabled="testtableData[index].checktype === 2 && testtableData[index].valuecategory === 2" class="publicinput" type="text"  :class="{active_class:((testtableData[index]['value'+(i+1)])?(testtableData[index]['value'+(i+1)]<row.min_value || testtableData[index]['value'+(i+1)]>row.max_value):false)}" v-model="testtableData[index]['value'+(i+1)]" style="width:100px;"/>
                        </span>
                        <span v-else-if="testtableData[index].checktype === 0">
                          <input class="publicinput" type="text" v-model="testtableData[index]['value'+(i+1)]" style="width:100px"/>
                        </span>
                      </template>
                      <template v-for="(item, i) in testobj.number" slot-scope="{ row, index }" :slot="'range'+(i+1)">
                        <span v-show="testtableData[index].checktype === 2 && testtableData[index].valuecategory === 2">
                          <inputNumber :disabled="true" class="publicinput" type="text" v-model="testtableData[index]['range'+(i+1)]" :class="{active_class:((testtableData[index]['range'+(i+1)]) ? testtableData[index]['range'+(i+1)] > testtableData[index]['range'] : false)}" style="width:100px;font-color:black;"/>
                        </span>
                      </template>
                  </Table>
              </template>
          </div>
        </div>
        <div class="divboder">
          <label style="font-size:14px;font-weight:700;width:100px">{{$t('1950524')}}</label>
          <div style="width:1120px;">
            <div class="core1">
              <label style="width:100px">{{$t('600528')}}：</label>
            </div>
            <div class="core2">
              <div class="demo-upload-list" v-for="item in uploadList" style="margin-left:5px;vertical-align:top">
                <template v-if="item.status === 'finished'">
                    <img :src="host+item.url">
                    <div class="demo-upload-list-cover">
                        <Icon type="ios-eye-outline" @click.native="handleView(item.url)"></Icon>
                        <Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
                    </div>
                </template>
                <template v-else>
                    <Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>
                </template>
              </div>
              <Upload
                ref="upload"
                :action="host+'qms/Upload/NewUploadImage'"
                :show-upload-list="false"
                :default-file-list="defaultList"
                :on-success="handleSuccess_image"
                :format="['jpg','jpeg','png','gif']"
                :on-format-error="handleFormatError_image"
                :on-exceeded-size="handleMaxSize"
                :before-upload="handleBeforeUpload"
                multiple
                type="drag"
                style="display: inline-block;width:80px;vertical-align:top;margin-left:5px;">
                <div style="width: 80px;height:80px;line-height: 80px;">
                    <Icon type="ios-camera" size="30"></Icon>
                </div>
              </Upload>
            </div>
            <div class="chartdiv1">
              <label style="width:100px">{{$t('600276')}}：</label>
            </div>
            <div class="chartdiv2">
              <template>
                <Upload
                    ref="uploadfile"
                    :action="host+'qms/Upload/NewUploadImage'"
                    :on-success="handleSuccess_file"
                    :on-format-error="handleFormatError_file"
                    :on-exceeded-size="handleMaxSize_file"
                    :before-upload="handleBeforeUpload_file"
                    style="display: inline-block;vertical-align:top;margin-left:5px"
                    multiple
                    type="drag">
                    <div style="padding: 5px 0;width:200px">
                        <Icon type="ios-cloud-upload" size="20" style="color: #3399ff"></Icon>
                        <p>{{$t('1950525')}}</p>
                    </div>
                </Upload>
              </template>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer">
        <Button type="text" size="large" @click="cancle">{{$t('1033')}}</Button>
        <Button type="primary" :loading="loading3" @click="checkdata" v-show="testtype===1">
            <span v-if="!loading3">{{$t('1950509')}}</span>
            <span v-else>Loading...</span>
        </Button>
        <Button type="primary" :loading="loading3" @click="checkdata" v-show="testtype===2">
            <span v-if="!loading3">{{$t('1003')}}</span>
            <span v-else>Loading...</span>
        </Button>
        <!--<Button type="primary" size="large" @click="adddata">{{$t('1950509')}}</Button>-->
      </div>
    </Modal>
    <Modal :title="$t('1950515')" v-model="visible">
      <img :src="imgName" v-if="visible" style="width: 100%">
    </Modal>

    <Modal class="newModalClass" :title="$t('1950515')" v-model="carousel" :styles="{top: '40px',width:'900px',height:'400px'}">
      <div class="modal_body" style="width:100% !important;height: 400px !important; padding:0 10px;overflow: hidden;">
        <Carousel v-if="carousel" v-model="carouselValue">
          <CarouselItem v-for="(item,index) in carouselData" :key="index">
            <span style="font-size: 0;width: 848px;height: 400px;display: table-cell;text-align: center;vertical-align: middle;">
              <img alt="" :src="host + item.url" style="max-width: 100%;max-height: 100%;" />
            </span>
            <span v-show="false">{{index}}</span>
          </CarouselItem>
        </Carousel>
      </div>
    </Modal>

    <Modal class="newModalClass" :title="$t('1950516')" v-model="carousel_file" :styles="{top: '40px',width:'500px',height:'300px'}">
      <div class="modal_body" style="width:100% !important;height: 300px !important; padding:0 10px;">
        <div v-for="(item,index) in carouselData_file" :key="index">
            <div class="divborder">
                <a :href="host + item.url" target="_blank" style="max-width: 100%;max-height: 100%;padding-right:10px" >{{item.name}}</a>
                <Button type="primary" icon="ios-cloud-download" @click="downfile(item.url, item.name)">{{$t('900758')}}</Button>
            </div>
        </div>
      </div>
    </Modal>

  </div>
</template>

<script>
import axios from '@/libs/api.request'
import moment from 'moment'
export default{
    data () {
        return {
            headers: {
                token: localStorage.getItem('token'),
                timestamp: localStorage.getItem('timestamp'),
                nonce: localStorage.getItem('nonce'),
                sign: localStorage.getItem('sign')
            },
            table_scrollx: false,
            morecondition: false,
            title1: this.$t('1002'),
            tableData1: [],
            tableData: [],
            tableData2: [],
            testtableData: [],
            editmodal: false,
            page: 1,
            pagesize: 10,
            total: 0,
            testcolumns: [
                {
                    type: 'index',
                    title: this.$t('1008'),
                    slot: 'xuhao',
                    width: 70
                },
                {
                    title: this.$t('901048'),
                    slot: 'item'
                },
                {
                    title: this.$t('950245'),
                    slot: 'standard'
                },
                {
                    title: this.$t('200060'),
                    slot: 'min_value'
                },
                {
                    title: this.$t('200059'),
                    slot: 'max_value'
                }
            ],
            columns1: [
                {
                    type: 'index',
                    title: this.$t('1008'),
                    key: 'xuhao',
                    width: 70
                },
                {
                    title: this.$t('901048'),
                    key: 'item'
                },
                {
                    title: this.$t('950245'),
                    key: 'standard'
                },
                {
                    title: this.$t('200060'),
                    key: 'min_value'
                },
                {
                    title: this.$t('200059'),
                    key: 'max_value'
                },
                {
                    title: this.$t('1950621'),
                    key: 'item_range'
                },
                {
                    title: this.$t('800195'),
                    key: 'result'
                },
                {
                    title: this.$t('8000030'), // 实际最小值
                    key: 'lowerlimit'
                },
                {
                    title: this.$t('8000031'), // 实际最大值
                    key: 'upperlimit'
                },
                {
                    title: this.$t('1950610'), // 单值
                    key: 'value'
                },
                {
                    title: this.$t('1950620'), // 极差
                    key: 'range'
                }
            ],
            tableColumns1: [
                {
                    type: 'selection',
                    width: 50,
                    align: 'center'
                },
                {
                    title: this.$t('1008'),
                    key: 'xuhao',
                    slot: 'xuhao',
                    render: (h, params) => {
                        return h(
                            'span',
                            params.index + (this.page - 1) * this.pagesize + 1
                        )
                    },
                    width: 70
                },
                {
                    title: this.$t('100089'),
                    key: 'productcode'
                },
                {
                    title: this.$t('100088'),
                    key: 'productname'
                },
                // {
                //   title: this.$t('500006'),
                //   key: 'routename',
                //   width: 150
                // },
                {
                    title: this.$t('100390'),
                    key: 'materialpn'
                },
                {
                    title: this.$t('100391'),
                    key: 'materialname'
                },
                {
                    title: this.$t('100392'),
                    key: 'materialspec'
                },
                {
                    title: this.$t('1950510'),
                    key: 'sectionname'
                },
                {
                    title: this.$t('1950502'),
                    key: 'testroom_value'
                },
                {
                    title: this.$t('90000015'),
                    key: 'number'
                },
                {
                    title: this.$t('1950627'),
                    key: 'quantity',
                    width: 150
                },
                {
                    title: this.$t('800008'),
                    key: 'sn'
                },
                {
                    title: this.$t('1950501'),
                    key: 'checktype_value'
                },
                {
                    title: this.$t('1950614'),
                    key: 'reason'
                },
                {
                    title: this.$t('200054'),
                    key: 'checkstatus_value'
                },
                {
                    title: this.$t('800195'),
                    key: 'result'
                },
                {
                    title: this.$t('1045'),
                    key: 'images',
                    align: 'center',
                    render: (h, params) => {
                        if (params.row.images.length > 0) {
                            return h('div', [
                                h('A', {
                                    props: {
                                        // type: 'primary',
                                        // size: 'small'
                                    },
                                    style: {
                                        // marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.showImages(params.index, params.row.images)
                                        }
                                    }
                                }, this.$t('1950519'))
                            ])
                        } else {
                            return h('span', {
                            }, this.$t('1950519'))
                        }
                    }
                },
                {
                    title: this.$t('1950521'),
                    key: 'files',
                    align: 'center',
                    render: (h, params) => {
                        if (params.row.files.length > 0) {
                            return h('div', [
                                h('A', {
                                    props: {
                                        // type: 'primary',
                                        // size: 'small'
                                    },
                                    style: {
                                        // marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.showFiles(params.index, params.row.files)
                                        }
                                    }
                                }, this.$t('1950520'))
                            ])
                        } else {
                            return h('span', {
                            }, this.$t('1950520'))
                        }
                    }
                },
                {
                    title: this.$t('1950511'),
                    key: 'send_user'
                },
                {
                    title: this.$t('1950512'),
                    key: 'send_time'
                },
                {
                    title: this.$t('1950636'),
                    key: 'recieve_user'
                },
                {
                    title: this.$t('1950637'),
                    key: 'recieve_time'
                },
                {
                    title: this.$t('1950638'),
                    key: 'checking_user'
                },
                {
                    title: this.$t('1950639'),
                    key: 'checking_time',
                    width: 150
                },
                {
                    title: this.$t('1950492'),
                    key: 'check_user'
                },
                {
                    title: this.$t('1950493'),
                    key: 'check_time'
                }
            ],
            editobj: {},
            sectionid: [],
            editsectionid: [],
            products: [],
            productid: '',
            type: 0,
            dtStart: '',
            dtEnd: '',
            daterange: '',
            detailshow: false,
            routeid: 0,
            sn: '',
            routes: [],
            editroutes: [],
            host: axios.publicPath,
            materialid: 0,
            materials: [],
            leveldata: [],
            datalevel: [],
            leveldata1: [],
            datalevel1: [],
            checktype: 0,
            checkstatus: 1,
            testroom: '',
            testrooms: [],
            result: '',
            editproducts: [],
            edittestrooms: [],
            editmaterials: [],
            title2: '',
            testmodal: false,
            testobj: {},
            loading1: false,
            loading2: false,
            loading3: false,
            loading4: false,
            loading5: false,
            defaultList: [],
            imgName: '',
            visible: false,
            uploadList: [],
            uploadList1: [],
            carousel: false,
            carouselData: [],
            carousel_file: false,
            carouselData_file: [],
            ngmodal: false,
            ngtableData: [],
            ngcolumns: [
                {
                    title: this.$t('1008'),
                    key: 'xuhao',
                    render: (h, params) => {
                        return h(
                            'span',
                            params.index + 1
                        )
                    },
                    width: 70
                },
                {
                    title: this.$t('901048'),
                    key: 'item'
                },
                {
                    title: this.$t('950245'),
                    key: 'standard'
                },
                {
                    title: this.$t('200060'),
                    key: 'min_value'
                },
                {
                    title: this.$t('200059'),
                    key: 'max_value'
                },
                {
                    title: this.$t('1950619'),
                    key: 'range'
                },
                {
                    title: this.$t('1950610'),
                    key: 'value'
                },
                {
                    title: this.$t('8000030'),
                    key: 'lowerlimit'
                },
                {
                    title: this.$t('8000031'),
                    key: 'upperlimit'
                },
                {
                    title: this.$t('1950620'),
                    key: 'actual_range'
                },
                {
                    title: this.$t('800195'),
                    key: 'result'
                }
            ],
            resultData: {},
            testtype: 0,
            quantity: 1,
            selectids: [],
            checktypeList: [],
            editChecktypeList: [],
        }
    },
    created () {
        var nowtime = Date.parse(new Date()) / 1000
        var oldtime = nowtime - 86400 * 7
        this.daterange = [this.datetrans(oldtime) + '00:00:00', this.datetrans(nowtime) + '23:59:59']
        this.selectdate(this.daterange)
        this.search(1, 10)
        this.initlevel()
        this.inittestrooms()
        this.initchecktypeList()
        // 格式化表格样式
        this.tableColumns1 = this.$time.initTableTitle(this.tableColumns1)
    },
    methods: {
        initchecktypeList () {
            axios.request({
                url: '/qms/TypeCount/GetTypeCounts?page=1&pagesize=10000',
                method: 'get'
            }).then(res => {
                res.data.data.forEach(ele => {
                    this.checktypeList.push({id:ele.type_code, name:ele.type_name})
                    this.editChecktypeList.push({id:ele.type_code, name:ele.type_name})
                });
            })      
        },
        recieveorchecking (state) {
            if (this.selectids === undefined || this.selectids === null || this.selectids === [] || JSON.stringify(this.selectids) === '[]') {
                this.$Message.error((this.$t('1017')))
                return false
            } else {
                this.$Modal.confirm({
                    title: this.$t('1124'),
                    content: state === 1 ? this.$t('1950632') : this.$t('1950633'),
                    onOk: () => {
                        let parameter = {
                            ids: this.selectids
                        }
                        axios.request({
                            url: state === 1 ? '/qms/SendTestCollection/Recieve' : '/qms/SendTestCollection/StartCheck',
                            data: parameter,
                            method: 'post'
                        }).then(res => {
                            if (res.data.ret === 1) {
                                this.obj = {}
                                this.selectids = []
                                this.search(this.page, this.pagesize)
                                this.$Message.success(this.$t('1'))
                            } else {
                                this.$Message.error(this.$t(res.data.msg))
                            }
                        })
                    }
                })
            }
        },
        getrange (index, i) {
            var maxValue = this.testtableData[index]['max_value' + i]
            var minValue = this.testtableData[index]['min_value' + i]
            if (maxValue !== '' && maxValue !== null && maxValue !== undefined && minValue !== '' && minValue !== null && minValue !== undefined) {
                this.testtableData[index]['range' + i] = Math.round((this.testtableData[index]['max_value' + i] - this.testtableData[index]['min_value' + i]) * 10000) / 10000
                this.testtableData[index]['value' + i] = Math.round((this.testtableData[index]['max_value' + i] + this.testtableData[index]['min_value' + i]) / 2 * 10000) / 10000
            } else {
                this.testtableData[index]['range' + i] = ''
            }
        },
        testedit () {
            this.initedittestrooms()
            this.editobj = {}
            axios.request({
                url: '/qms/SendTestCollection/GetUpdateDetails?id=' + this.obj.id,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1) {
                    var data = res.data.data
                    this.testmodal = true
                    this.testtype = 2
                    this.testobj.sn = data.sn
                    this.testobj.testroom = data.testroom
                    this.testobj.id = this.obj.id
                    this.testobj.number = data.number
                    this.testobj.result = data.result
                    this.testobj.parameters = data.parameters
                    this.GetValueColums1(data.details)
                    this.$refs.upload.fileList = data.images
                    this.uploadList = data.images
                    this.$refs.uploadfile.fileList = data.files
                    this.quantity = this.obj.quantity >= 1 ? this.obj.quantity : 1
                } else {
                    this.$Message.error(this.$t(res.data.msg))
                }
            })
        },
        GetValueColums1 (details) {
            var cloumnLength = this.testobj.number
            this.testcolumns = [
                {
                    type: 'index',
                    title: this.$t('1008'),
                    slot: 'xuhao',
                    width: 70,
                    fixed: 'left'
                },
                {
                    title: this.$t('901048'),
                    slot: 'item',
                    minWidth: 120,
                    fixed: 'left'
                },
                {
                    title: this.$t('950245'),
                    slot: 'standard',
                    minWidth: 120,
                    fixed: 'left'
                },
                {
                    title: this.$t('200060'),
                    slot: 'min_value',
                    minWidth: 80,
                    fixed: 'left'
                },
                {
                    title: this.$t('200059'),
                    slot: 'max_value',
                    minWidth: 80,
                    fixed: 'left'
                },
                {
                    title: this.$t('8000032'),
                    slot: 'range',
                    minWidth: 80,
                    fixed: 'left'
                }
            ]
            this.testtableData = []
            axios.request({
                url: '/qms/SendTestCollection/GetSendTestUpdateItems?id=' + this.obj.id,
                method: 'get'
            })
                .then(res => {
                    if (res.data.ret === 1) {
                        var isMaxMin = false
                        res.data.data.details.forEach(element => {
                            if (element.checktype === 2 && element.valuecategory === 2) {
                                isMaxMin = true
                            }
                        });

                        for (var i = 1; i <= cloumnLength; i++) {
                            this.testcolumns.push({
                                title: 'NO.' + i,
                                key: 'NO.' + i,
                                slot: 'NO.' + i,
                                align: 'center',
                                children: isMaxMin ? [
                                    {
                                        title: this.$t('500082'), // 最小值
                                        key: 'min_value' + i,
                                        slot: 'min_value' + i,
                                        align: 'center',
                                        minWidth: 120
                                    },
                                    {
                                        title: this.$t('500081'), // 最大值
                                        key: 'max_value' + i,
                                        slot: 'max_value' + i,
                                        align: 'center',
                                        minWidth: 120
                                    },
                                    {
                                        title: this.$t('1950610'), // 单值
                                        key: 'value' + i,
                                        slot: 'value' + i,
                                        align: 'center',
                                        minWidth: 120
                                    },
                                    {
                                        title: this.$t('8000032'), // 极差
                                        key: 'range' + i,
                                        slot: 'range' + i,
                                        align: 'center',
                                        minWidth: 120
                                    }
                                ] : [
                                    {
                                        title: this.$t('1950610'), // 单值
                                        key: 'value' + i,
                                        slot: 'value' + i,
                                        align: 'center',
                                        minWidth: 120
                                    }
                                ]
                            })
                        }

                        res.data.data.details.forEach((item, index) => {
                            let data = {
                                itemid: item.itemid,
                                item: item.item,
                                standard: item.standard,
                                min_value: item.checktype === 2 ? (item.min_value === -999999999 ? '' : item.min_value) : '',
                                max_value: item.checktype === 2 ? (item.max_value === 999999999 ? '' : item.max_value) : '',
                                checktype: item.checktype,
                                result: item.result,
                                value: item.value,
                                range: (item.checktype === 2 && item.valuecategory === 2) ? item.range : '',
                                upperlimit: item.upperlimit,
                                lowerlimit: item.lowerlimit,
                                valuecategory: item.valuecategory
                            }
                            if (item.checktype === 2) {
                                for (var i = 1; i <= cloumnLength; i++) {
                                    data['value' + i] = null
                                    data['max_value' + i] = null
                                    data['min_value' + i] = null
                                    data['range' + i] = null
                                    details.forEach(detail => {
                                        if (detail.index === i && detail.itemid === item.itemid) {
                                            data['value' + i] = detail.value
                                            data['max_value' + i] = detail.upperlimit
                                            data['min_value' + i] = detail.lowerlimit
                                            data['range' + i] = detail.range
                                        }
                                    })
                                }
                            } else if (item.checktype === 1) {
                                for (var i = 1; i <= cloumnLength; i++) {
                                    data['value' + i] = 'OK'
                                    details.forEach(detail => {
                                        if (detail.index === i && detail.itemid === item.itemid) {
                                            data['value' + i] = detail.result
                                        }
                                    })
                                }
                            }
                            this.testtableData.push(data)
                        })
                        this.detailshow = false
                        this.detailshow = true
                        // 处理滚动条样式bug
                        setTimeout(() => {
                            var scrollx = this.$refs.detailTable.$refs.body.classList.contains('ivu-table-overflowX'); // 100px
                            if (scrollx) {
                                this.table_scrollx = true
                            } else {
                                this.table_scrollx = false
                            }
                        }, 500)
                    } else {
                        this.$Message.error(this.$t(res.data.msg))
                    }
                })
        },
        downfile (url, name) {
            if (url && url != undefined) {
                window.location.href = axios.publicPath + '' + url
            }
        },
        showImages (index, imageurls) {
            this.carouselData = imageurls
            this.carousel = true
        },
        showFiles (index, files) {
            this.carouselData_file = files
            this.carousel_file = true
        },
        handlelevelchange (value) {
            this.leveldata = value
            var sectionid = value[value.length - 1]
            this.initproducts(sectionid)
        },
        handleeditlevelchange (value) {
            this.leveldata = value
            var sectionid = value[value.length - 1]
            this.initeditproducts(sectionid)
        },
        initeditsectionid () {
            axios.request({
                url: '/qms/SendTestCollection/GetParentSection?sectionid=' + this.editobj.sectionid,
                method: 'get'
            })
                .then(res => {
                    this.editsectionid = res.data.data
                })
        },
        initgeteditsectionid () {
            axios.request({
                url: '/qms/SendTestCollection/GetParentSection?sectionid=' + this.editobj.sectionid,
                method: 'get'
            })
                .then(res => {
                    this.editsectionid = res.data.data
                    this.initgeteditproducts(this.editobj.sectionid, this.editobj.productid)
                })
        },
        sendtest () {
            this.editobj = {}
            this.editsectionid = []
            this.type = 1
            this.title1 = this.$t('1950505')
            this.initedittestrooms()
            this.initeditlevel()
            this.editmodal = true
        },
        sendtestdata () {
            let data = this.editobj
            data.sectionid = this.editsectionid[this.editsectionid.length - 1]
            this.loading1 = true
            axios.request({
                url: '/qms/SendTestCollection/SendTest',
                data,
                method: 'post'
            })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.editmodal = false
                        this.editsectionid = []
                        this.$Message.success(this.$t('1950513'))
                        this.search(this.page, this.pagesize)
                    } else {
                        this.$Message.error(this.$t(res.data.msg))
                    }
                    this.loading1 = false
                }).catch(() => {
                    this.loading1 = false
                })
        },
        GetValueColums (resdata) {
            var cloumnLength = this.testobj.number
            this.testcolumns = [
                {
                    type: 'index',
                    title: this.$t('1008'),
                    slot: 'xuhao',
                    width: 70,
                    fixed: 'left'
                },
                {
                    title: this.$t('901048'),
                    slot: 'item',
                    minWidth: 120,
                    fixed: 'left'
                },
                {
                    title: this.$t('950245'),
                    slot: 'standard',
                    minWidth: 120,
                    fixed: 'left'
                },
                {
                    title: this.$t('200060'),
                    slot: 'min_value',
                    minWidth: 80,
                    fixed: 'left'
                },
                {
                    title: this.$t('200059'),
                    slot: 'max_value',
                    minWidth: 80,
                    fixed: 'left'
                },
                {
                    title: this.$t('8000032'),
                    slot: 'range',
                    minWidth: 80,
                    fixed: 'left'
                }
            ]
            var isMaxMin = false
            resdata.details.forEach(element => {
                if (element.checktype === 2 && element.valuecategory === 2) {
                    isMaxMin = true
                }
            });
            for (var i = 1; i <= cloumnLength; i++) {
                this.testcolumns.push({
                    title: 'NO.' + i,
                    key: 'NO.' + i,
                    slot: 'NO.' + i,
                    align: 'center',
                    children: isMaxMin ? [
                        {
                            title: this.$t('500082'), // 最小值
                            key: 'min_value' + i,
                            slot: 'min_value' + i,
                            align: 'center',
                            minWidth: 120
                        },
                        {
                            title: this.$t('500081'), // 最大值
                            key: 'max_value' + i,
                            slot: 'max_value' + i,
                            align: 'center',
                            minWidth: 120
                        },
                        {
                            title: this.$t('1950610'), // 单值
                            key: 'value' + i,
                            slot: 'value' + i,
                            align: 'center',
                            minWidth: 120
                        },
                        {
                            title: this.$t('8000032'), // 极差
                            key: 'range' + i,
                            slot: 'range' + i,
                            align: 'center',
                            minWidth: 120
                        }
                    ] : [
                        {
                            title: this.$t('1950610'), // 单值
                            key: 'value' + i,
                            slot: 'value' + i,
                            align: 'center',
                            minWidth: 120
                        }
                    ]
                })
            }
            this.testtableData = []
            resdata.details.forEach(item => {
                if (item) {
                    let data = {
                        itemid: item.itemid,
                        item: item.item,
                        standard: item.standard,
                        min_value: item.checktype === 2 ? (item.min_value === -999999999 ? '' : item.min_value) : '',
                        max_value: item.checktype === 2 ? (item.max_value === 999999999 ? '' : item.max_value) : '',
                        checktype: item.checktype,
                        result: item.result,
                        value: item.value,
                        range: (item.checktype === 2 && item.valuecategory === 2) ? item.range : '',
                        upperlimit: item.upperlimit,
                        lowerlimit: item.lowerlimit,
                        valuecategory: item.valuecategory
                    }
                    if (item.checktype === 2) {
                        for (var j = 1; j <= cloumnLength; j++) {
                            data['min_value' + j] = null
                            data['max_value' + j] = null
                            data['value' + j] = null
                            data['range' + j] = null
                        }
                    } else {
                        for (var j = 1; j <= cloumnLength; j++) {
                            data['value' + j] = 'OK'
                        }
                    }
                    this.testtableData.push(data)
                }
            })
            this.detailshow = false
            this.detailshow = true

            // 处理滚动条样式bug
            setTimeout(() => {
                var scrollx = this.$refs.detailTable.$refs.body.classList.contains('ivu-table-overflowX'); // 100px
                if (scrollx) {
                    this.table_scrollx = true
                } else {
                    this.table_scrollx = false
                }
            }, 500)
        },
        inittestrooms () {
            axios.request({
                url: '/qms/SendTestCollection/GetTestRoomDict',
                method: 'get'
            })
                .then(res => {
                    this.testrooms = res.data.data
                })
        },
        initedittestrooms () {
            axios.request({
                url: '/qms/SendTestCollection/GetTestRoomDict',
                method: 'get'
            })
                .then(res => {
                    this.edittestrooms = res.data.data
                })
        },
        initlevel () {
            axios.request({
                url: '/qms/InspectStandard/GetSectionTree',
                method: 'get'
            }).then(res => {
                const arr = []
                this.datalevel = res.data.data
                arr.push(res.data.data[0].value)
                this.leveldata = arr
            })
        },
        initeditlevel () {
            axios.request({
                url: '/qms/InspectStandard/GetSectionTree',
                method: 'get'
            }).then(res => {
                const arr = []
                this.datalevel1 = res.data.data
                arr.push(res.data.data[0].value)
                this.leveldata1 = arr
            })
        },
        initmaterials () {
            this.materials = [{ id: 0, name: '', pn: '', spec: '' }]
            axios.request({
                url: '/config/Material/GetSonMaterialsByProduct?productid=' + this.productid,
                method: 'get'
            }).then(res => {
                this.materials = res.data.data
            })
        },
        initeditmaterials () {
            this.editmaterials = [{ id: 0, name: '', pn: '', spec: '' }]
            axios.request({
                url: '/config/Material/GetSonMaterialsByProduct?productid=' + this.editobj.productid,
                method: 'get'
            }).then(res => {
                this.editmaterials = res.data.data
            })
        },
        geteditmaterials (productid, materialid) {
            axios.request({
                url: '/config/Material/GetSonMaterialsByProduct?productid=' + productid,
                method: 'get'
            }).then(res => {
                this.editobj.materialid = materialid
                this.editmaterials = res.data.data
            })
        },
        routechange () {
            this.routes = [{ id: 0, name: '' }]
            var sectionid = this.sectionid[this.sectionid.length - 1]
            axios.request({
                url: '/qms/ManualCollection/GetSectionRoutes?productid=' + this.productid + '&sectionid=' + sectionid,
                method: 'get'
            }).then(res => {
                this.routes = res.data.data
            })
            this.initmaterials()
        },
        editroutechange () {
            this.editroutes = [{ id: 0, name: '' }]
            var sectionid = this.editsectionid[this.editsectionid.length - 1]
            axios.request({
                url: '/qms/ManualCollection/GetSectionRoutes?productid=' + this.editobj.productid + '&sectionid=' + sectionid,
                method: 'get'
            }).then(res => {
                this.editroutes = res.data.data
            })
            this.initeditmaterials()
        },
        geteditroutechange (productid, materialid) {
            var sectionid = this.editsectionid[this.editsectionid.length - 1]
            axios.request({
                url: '/qms/ManualCollection/GetSectionRoutes?productid=' + productid + '&sectionid=' + sectionid,
                method: 'get'
            }).then(res => {
                this.editroutes = res.data.data
            })
            this.geteditmaterials(productid, materialid)
        },
        datetrans (date) {
            if (date === '' || date === undefined || date === 0 || date === null) {
                return ''
            }
            date = new Date(date * 1000)
            var Y = date.getFullYear() + '-'
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
            var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' '
            return Y + M + D
        },
        searchdetail () {
            this.tableData2 = []
            if (this.obj.traceid === undefined || this.obj.traceid === null || this.obj.traceid === 0) {
                return false
            } else {
                axios
                    .request({
                        url: '/qms/ManualCollection/GetDetailList?id=' + this.obj.traceid,
                        method: 'get'
                    })
                    .then(res => {
                        this.mockTableData2(res.data.data)
                    })
            }
        },
        mockTableData2 (tablelist) {
            let data = []
            tablelist.forEach(item => {
                if (item) {
                    data.push({
                        itemid: item.itemid,
                        item: item.item,
                        standard: item.standard,
                        min_value: item.checktype === 2 ? (item.min_value === -999999999 ? '' : item.min_value) : '',
                        max_value: item.checktype === 2 ? (item.max_value === 999999999 ? '' : item.max_value) : '',
                        checktype: item.checktype,
                        result: item.result,
                        value: item.value,
                        lowerlimit: (item.checktype === 2 && item.valuecategory === 2) ? item.lowerlimit : '',
                        upperlimit: (item.checktype === 2 && item.valuecategory === 2) ? item.upperlimit : '',
                        range: (item.checktype === 2 && item.valuecategory === 2) ? item.range : '',
                        item_range: (item.checktype === 2 && item.valuecategory === 2) ? item.item_range : ''
                    })
                }
            })
            this.tableData2 = data
        },
        selectdate (e) {
            this.dtStart = e[0]
            this.dtEnd = e[1]
            let last_str = this.dtEnd.split(' ')[1]
            if (last_str === '00:00:00') {
                this.dtEnd = moment(this.dtEnd).format('YYYY-MM-DD') + ' 23:59:59'
                this.daterange = [this.dtStart, this.dtEnd]
            }
        },
        cancle () {
            this.editobj = {}
            this.editmodal = false
            this.testmodal = false
            this.testobj = {}
            this.type = 0
            this.editsectionid = []
            this.resultData = {}
            this.quantity = 1
            this.search(this.page, this.pagesize)
        },
        add () {
            this.title2 = this.$t('1950509')
            this.testobj = {}
            this.testtableData = []
            this.$refs.upload.fileList = []
            this.$refs.uploadfile.fileList = []
            this.uploadList = []
            this.testtype = 1
            this.initedittestrooms()
            this.searchTestData()
            this.quantity = 1
        },
        searchTestData () {
            if (this.obj.id === undefined || this.obj.id === null || this.obj.id === 0) {
                this.$Message.error((this.$t('1017')))
                return false
            }
            axios.request({
                url: '/qms/SendTestCollection/GetTestItems?id=' + this.obj.id,
                method: 'get'
            })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.testmodal = true
                        var datalist = res.data.data
                        this.testobj.sn = datalist.sn
                        this.testobj.testroom = datalist.testroom
                        this.testobj.id = this.obj.id
                        this.testobj.number = this.obj.number
                        this.testobj.parameters = datalist.parameters
                        this.GetValueColums(res.data.data)
                        // this.mockTestTableData1(datalist.details)
                    } else {
                        this.$Message.error(this.$t(res.data.msg))
                    }
                })
        },
        edit () {
            if (JSON.stringify(this.obj) === '{}' || this.obj === null || this.obj === undefined) {
                this.$Message.error(this.$t('1043'))
                return false
            }
            this.editsectionid = []
            this.title1 = this.$t('1003')
            this.editobj = this.obj
            this.type = 2
            this.initedittestrooms()
            this.initeditlevel()
            this.initgeteditsectionid()
            this.editmodal = true
        },
        checkdata () {
            var details = this.testtableData
            let data = {
                id: this.testobj.id,
                testroom: this.testobj.testroom,
                result: '1',
                number: this.testobj.number
            }
            data.images = []
            data.files = []
            data.details = []
            var total = data.number

            var spcCheck = false;
            var ngList = []
            var isMaxMin = false
            for (var i = 1; i <= total; i++) {
                details.forEach((ele, index) => {
                    var detail = {
                        index: i,
                        itemid: ele.itemid,
                        checktype: ele.checktype
                    }
                    if (ele.checktype === 2) {
                        detail.value = ele['value' + i]
                        detail.upperlimit = ele['max_value' + i]
                        detail.lowerlimit = ele['min_value' + i]
                        detail.result = ''
                        if (ele.valuecategory === 1) {
                            if ((this.obj.checktype === 6 || this.obj.checktype === '6') && (detail.value === null || detail.value === undefined || detail.value === '')) {
                                spcCheck = true
                            }
                            if ((detail.value > ele.max_value && ele.max_value !== '') || (detail.value < ele.min_value && ele.min_value !== '')) {
                                if (detail.value !== null && detail.value !== undefined && detail.value !== '') {
                                    ngList.push({
                                        item: ele.item,
                                        standard: ele.standard,
                                        checktype: ele.checktype,
                                        min_value: ele.min_value,
                                        max_value: ele.max_value,
                                        result: 'NG',
                                        value: detail.value,
                                        upperlimit: '',
                                        lowerlimit: '',
                                        range: '',
                                        actual_range: ''
                                    })
                                }
                            }
                        } else if (ele.valuecategory === 2) {
                            isMaxMin = true
                            if ((this.obj.checktype === 6 || this.obj.checktype === '6') &&
                (detail.value === null || detail.value === undefined || detail.value === '' ||
                detail.upperlimit === null || detail.upperlimit === undefined || detail.upperlimit === '' ||
                detail.lowerlimit === null || detail.lowerlimit === undefined || detail.lowerlimit === '')) {
                                spcCheck = true
                            }
                            if ((detail.upperlimit > ele.max_value || detail.lowerlimit < ele.min_value || (detail.upperlimit - detail.lowerlimit) > ele.range ||
                  detail.upperlimit < ele.min_value || detail.lowerlimit > ele.max_value ||
                  (detail.value > ele.max_value && ele.max_value !== '') || (detail.value < ele.min_value && ele.min_value !== '')) &&
                  detail.upperlimit !== null && detail.upperlimit !== undefined && detail.upperlimit !== '' &&
                  detail.lowerlimit !== null && detail.lowerlimit !== undefined && detail.lowerlimit !== '') {
                                ngList.push({
                                    item: ele.item,
                                    standard: ele.standard,
                                    checktype: ele.checktype,
                                    min_value: ele.min_value,
                                    max_value: ele.max_value,
                                    result: 'NG',
                                    value: detail.value,
                                    upperlimit: detail.upperlimit,
                                    lowerlimit: detail.lowerlimit,
                                    range: ele.range,
                                    actual_range: ele['range' + i]
                                })
                            }
                        }
                    } else if (ele.checktype === 1) {
                        detail.value = null
                        detail.result = ele['value' + i]
                        if (detail.result !== null && detail.result !== undefined && detail.result !== '') {
                            if (detail.result.toUpperCase() === 'NG') {
                                ngList.push({
                                    item: ele.item,
                                    standard: ele.standard,
                                    checktype: ele.checktype,
                                    min_value: ele.min_value,
                                    max_value: ele.max_value,
                                    result: 'NG',
                                    value: detail.value,
                                    upperlimit: '',
                                    lowerlimit: '',
                                    range: '',
                                    actual_range: ''
                                })
                            }
                        }
                    }
                    data.details.push(detail)
                })
            }
            if (spcCheck) {
                this.$Message.error((this.$t(1950628)))
                return
            }
            this.$refs.upload.fileList.forEach(ele => {
                var image = {
                    size: ele.size,
                    name: ele.name,
                    url: ele.url
                }
                data.images.push(image)
            })
            this.$refs.uploadfile.fileList.forEach(ele => {
                var file = {
                    size: ele.size,
                    name: ele.name,
                    url: ele.url
                }
                data.files.push(file)
            })
            this.resultData = data
            if (ngList.length > 0) {
                if (isMaxMin) {
                    this.ngcolumns = [
                        {
                            title: this.$t('1008'),
                            key: 'xuhao',
                            render: (h, params) => {
                                return h(
                                    'span',
                                    params.index + 1
                                )
                            },
                            width: 70
                        },
                        {
                            title: this.$t('901048'),
                            key: 'item'
                        },
                        {
                            title: this.$t('950245'),
                            key: 'standard'
                        },
                        {
                            title: this.$t('200060'),
                            key: 'min_value'
                        },
                        {
                            title: this.$t('200059'),
                            key: 'max_value'
                        },
                        {
                            title: this.$t('1950619'),
                            key: 'range'
                        },
                        {
                            title: this.$t('1950610'),
                            key: 'value'
                        },
                        {
                            title: this.$t('8000030'),
                            key: 'lowerlimit'
                        },
                        {
                            title: this.$t('8000031'),
                            key: 'upperlimit'
                        },
                        {
                            title: this.$t('1950620'),
                            key: 'actual_range'
                        },
                        {
                            title: this.$t('800195'),
                            key: 'result'
                        }
                    ]
                } else {
                    this.ngcolumns = [
                        {
                            title: this.$t('1008'),
                            key: 'xuhao',
                            render: (h, params) => {
                                return h(
                                    'span',
                                    params.index + 1
                                )
                            },
                            width: 70
                        },
                        {
                            title: this.$t('901048'),
                            key: 'item'
                        },
                        {
                            title: this.$t('950245'),
                            key: 'standard'
                        },
                        {
                            title: this.$t('200060'),
                            key: 'min_value'
                        },
                        {
                            title: this.$t('200059'),
                            key: 'max_value'
                        },
                        {
                            title: this.$t('1950610'),
                            key: 'value'
                        },
                        {
                            title: this.$t('800195'),
                            key: 'result'
                        }
                    ]
                }
                this.showNg(ngList)
                return
            }

            this.adddata()
        },
        showNg (ngList) {
            if (this.fullscreen) {
                this.isNeedFullScreen = true
                this.handleFullScreen1()
            }
            this.ngmodal = true
            this.ngtableData = []
            ngList.forEach(item => {
                this.ngtableData.push({
                    // id: item.id,
                    // itemid: item.itemid,
                    // checktype: item.checktype,
                    item: item.item,
                    standard: item.standard,
                    min_value: item.checktype === 2 ? (item.min_value === -999999999 ? '' : item.min_value) : '',
                    max_value: item.checktype === 2 ? (item.max_value === 999999999 ? '' : item.max_value) : '',
                    result: 'NG',
                    value: item.value,
                    upperlimit: item.upperlimit,
                    lowerlimit: item.lowerlimit,
                    range: item.range,
                    actual_range: item.actual_range
                })
            })
        },
        adddata () {
            var data = this.resultData
            data.quantity = this.quantity
            this.loading3 = true
            this.loading4 = true
            this.loading5 = true
            var reqUrl = ''
            if (this.testtype === 1) {
                reqUrl = '/qms/SendTestCollection/AddTrace'
            } else if (this.testtype === 2) {
                reqUrl = '/qms/SendTestCollection/Update'
            } else {
                this.$Message.error(this.$t('1161'))
                return
            }
            axios.request({
                url: reqUrl,
                data,
                method: 'post'
            }).then(res => {
                if (res.data.ret === 1) {
                    this.editmodal = false
                    this.resultData = {}
                    this.testtableData = []
                    this.$refs.upload.fileList = []
                    this.$refs.uploadfile.fileList = []
                    this.uploadList = []
                    this.testcolumns = [
                        {
                            type: 'index',
                            title: this.$t('1008'),
                            slot: 'xuhao',
                            width: 70
                        },
                        {
                            title: this.$t('901048'),
                            slot: 'item',
                            minWidth: 150
                        },
                        {
                            title: this.$t('950245'),
                            slot: 'standard',
                            minWidth: 150
                        },
                        {
                            title: this.$t('200060'),
                            slot: 'min_value',
                            minWidth: 80
                        },
                        {
                            title: this.$t('200059'),
                            slot: 'max_value',
                            minWidth: 80
                        }
                    ]
                    this.testobj = {}
                    this.testmodal = false
                    this.quantity = 1
                    this.$Message.success(this.$t('1055'))
                    this.search(this.page, this.pagesize)
                } else {
                    this.resultData = {}
                    this.quantity = 1
                    this.$Message.error(this.$t(res.data.msg))
                }
                this.loading3 = false
                this.loading4 = false
                this.loading5 = false
                this.ngmodal = false
            }).catch(() => {
                this.ngmodal = false
                this.resultData = {}
                this.loading3 = false
                this.loading4 = false
                this.loading5 = false
            })
        },
        adddata1 () {
            this.resultData.result = '2'
            this.adddata()
        },
        adddata2 () {
            this.resultData.result = '3'
            this.adddata()
        },
        editdata () {
            let data = this.editobj
            data.id = this.obj.id
            data.sectionid = this.editsectionid[this.editsectionid.length - 1]
            this.loading2 = true
            axios.request({
                url: '/qms/SendTestCollection/Edit',
                data,
                method: 'post'
            }).then(res => {
                if (res.data.ret === 1) {
                    this.editmodal = false
                    this.editsectionid = []
                    this.$Message.success(this.$t('1060'))
                    this.search(this.page, this.pagesize)
                } else {
                    this.$Message.error(this.$t(res.data.msg))
                }
                this.loading2 = false
            }).catch(() => {
                this.loading2 = false
            })
        },
        dele () {
            if (this.obj.id === undefined || this.obj.id === null || this.obj.id === 0) {
                this.$Message.error((this.$t('1017')))
                return false
            } else {
                this.$Modal.confirm({
                    title: this.$t('1018'),
                    content: '',
                    width: '290px',
                    closable: true,
                    okText: this.$t('1004'),
                    onOk: () => {
                        axios.request({
                            url: '/qms/SendTestCollection/Delete?id=' + this.obj.id,
                            method: 'get'
                        }).then(res => {
                            if (res.data.ret === 1) {
                                this.page = 1
                                this.search(this.page, this.pagesize)
                                this.$Message.success(this.$t('1058'))
                            } else {
                                this.$Message.error(this.$t(res.data.msg))
                            }
                        })
                    }
                })
            }
        },
        initproducts (sectionid) {
            this.products = [{ id: 0, name: '', code: '' }]
            axios.request({
                url: '/qms/InspectStandard/GetProductsBySectionId?reverselevel=2&sectionid=' + sectionid,
                method: 'get'
            }).then(res => {
                this.products = res.data.data
            })
        },
        initeditproducts (sectionid) {
            this.editproducts = [{ id: 0, name: '', code: '' }]
            axios.request({
                url: '/qms/InspectStandard/GetProductsBySectionId?sectionid=' + sectionid,
                method: 'get'
            }).then(res => {
                this.editproducts = res.data.data
            })
        },
        initgeteditproducts (sectionid, productid) {
            axios.request({
                url: '/qms/InspectStandard/GetProductsBySectionId?sectionid=' + sectionid,
                method: 'get'
            }).then(res => {
                this.editobj.productid = productid
                this.editproducts = res.data.data
                this.geteditroutechange(productid, this.editobj.materialid)
            })
        },
        search (page, pagesize) {
            var params = {
                page: page,
                pagesize: pagesize,
                productid: this.productid,
                sectionid: this.sectionid[this.sectionid.length - 1],
                routeid: this.routeid,
                materialid: this.materialid,
                starttime: this.dtStart,
                endtime: this.dtEnd,
                sn: this.sn,
                checktype: this.checktype,
                checkstatus: this.checkstatus,
                testroom: this.testroom,
                result: this.result
            }
            axios.request({
                url: '/qms/SendTestCollection/GetPageList',
                params,
                method: 'get'
            })
                .then(res => {
                    this.page = page
                    this.pagesize = pagesize
                    this.total = res.data.total
                    this.mockTableData1(res.data.data)
                })
            this.obj = {}
            this.tableData2 = []
            this.detailshow = false
        },
        mockTableData1 (tablelist) {
            let data = []
            tablelist.forEach(item => {
                if (item) {
                    var checktype_value = ''
                    var checkstatus_value = ''
                    /*switch (item.checktype) {
                    case 1:
                        checktype_value = this.$t(950367)
                        break
                    case 2:
                        checktype_value = this.$t(930034)
                        break
                    case 3:
                        checktype_value = this.$t(930035)
                        break
                    case 4:
                        checktype_value = this.$t(930037)
                        break
                    case 5:
                        checktype_value = this.$t(930033)
                        break
                    case 6:
                        checktype_value = this.$t(930036)
                        break
                    case 7:
                        checktype_value = this.$t(600233)
                        break
                    }*/
                    switch (item.checkstatus) {
                    case 1:
                        checkstatus_value = this.$t(1950634)
                        break
                    case 2:
                        checkstatus_value = this.$t(1950504)
                        break
                    case 3:
                        checkstatus_value = this.$t(1950594)
                        break
                    case 4:
                        checkstatus_value = this.$t(1950635)
                        break
                    }
                    this.checktypeList.forEach(ele=>{
                        if(ele.id === item.checktype){
                            checktype_value = ele.name
                        }
                    })
                    data.push({
                        id: item.id,
                        traceid: item.traceid,
                        productid: item.productid,
                        productcode: item.productcode,
                        productname: item.productname,
                        materialid: item.materialid,
                        materialpn: item.materialpn,
                        materialname: item.materialname,
                        materialspec: item.materialspec,
                        sectionid: item.sectionid,
                        sectionname: item.sectionname,
                        routeid: item.routeid,
                        routename: item.routename,
                        testroom: item.testroom,
                        testroom_value: item.testroom_value,
                        sn: item.sn,
                        checktype: item.checktype,
                        checktype_value: checktype_value,
                        checkstatus: item.checkstatus,
                        checkstatus_value: checkstatus_value,
                        result: item.result === '1' ? this.$t('1950546') : (item.result === '2' ? this.$t('1950549') : (item.result === '3' ? this.$t('1950550') : '')),
                        send_mid: item.send_mid,
                        send_user: item.send_user,
                        send_time: item.send_time,
                        check_mid: item.check_mid,
                        check_user: item.check_user,
                        check_time: item.check_time,
                        images: item.images,
                        files: item.files,
                        number: item.number,
                        reason: item.reason,
                        quantity: (item.checkstatus === 2 && item.result === '2') ? item.quantity : '',
                        recieve_mid: item.recieve_mid,
                        recieve_user: item.recieve_user,
                        recieve_time: item.recieve_time,
                        checking_mid: item.checking_mid,
                        checking_user: item.checking_user,
                        checking_time: item.checking_time
                    })
                }
            })
            this.tableData1 = data
        },
        downexcel () {
            var params = {
                productid: this.productid,
                sectionid: this.sectionid[this.sectionid.length - 1],
                routeid: this.routeid,
                materialid: this.materialid,
                starttime: this.dtStart,
                endtime: this.dtEnd,
                sn: this.sn,
                checktype: this.checktype,
                checkstatus: this.checkstatus,
                testroom: this.testroom,
                result: this.result,
                toexcel: '1'
            }
            axios.request({
                url: '/qms/SendTestCollection/GetPageList',
                params,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1) {
                    window.location.href = axios.publicPath + '' + res.data.data
                } else {
                    this.$Message.error(this.$t(res.data.msg))
                }
            })
        },
        changecondition () {
            this.morecondition = !this.morecondition
        },
        handlePageSize (value) {
            this.pagesize = value
            this.tableData1 = this.search(this.page, this.pagesize)
        },
        changePage (value) {
            this.page = value
            this.tableData1 = this.search(this.page, this.pagesize)
        },
        handleRowChange (currentRow, oldCurrentRow) {
            this.obj = currentRow
            this.detailshow = true
            this.searchdetail()
        },
        handleView (name) {
            this.imgName = this.host + name
            this.visible = true
        },
        handleRemove (file) {
            const fileList = this.$refs.upload.fileList
            const flist = this.uploadList
            this.$refs.upload.fileList.splice(fileList.indexOf(file), 1)
            this.uploadList.splice(flist.indexOf(file), 1)
        },
        handleSuccess_image (res, file) {
            file.url = res.url
            file.name = res.name
            if (this.testtype === 1) {
                var uploadfile = file
                uploadfile.url = res.url
                this.uploadList.push(uploadfile)
            }
        },
        handleFormatError_image (file) {
            this.$Message.error(file.name + ' ' + this.$t('950395'))
        },
        handleMaxSize (file) {
            this.$Message.error('File  ' + file.name + ' is too large, no more than 2M.')
        },
        handleBeforeUpload () {
            return true
        },
        handleSuccess_file (res, file) {
            file.url = res.url
            file.name = res.name
        },
        handleFormatError_file (file) {
            this.$Message.error(file.name + ' ' + this.$t('950395'))
        },
        handleMaxSize_file (file) {
            this.$Message.error('File  ' + file.name + ' is too large, no more than 2M.')
        },
        handleBeforeUpload_file () {
            return true
        },
        handleSelectRow: function (data) {
            this.selectids = []
            for (var i in data) {
                if (this.selectids.indexOf(data[i].id) < 0) {
                    this.selectids.push(data[i].id)
                }
            }
        }
    }
}

</script>
<style lang="less" scoped>
.demo-upload-list{
    display: inline-block;
    width: 80px;
    height: 80px;
    text-align: center;
    line-height: 80px;
    border: 1px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,.2);
    margin-right: 4px;
}
.demo-upload-list img{
    width: 100%;
    height: 100%;
}
.demo-upload-list-cover{
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,.6);
}
.demo-upload-list:hover .demo-upload-list-cover{
    display: block;
}
.demo-upload-list-cover i{
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
}

.core1{
    width: 15%;
    height: 100%;
    border:0px solid #979797;
    border-radius: 5px;
    padding: 0px;
    margin: 0px;
    overflow-y: auto;
    overflow-x: hidden;
    float:left;
    background: #ffffff;
}
.core2{
    width: 35%;
    height: 100%;
    border:0px solid #979797;
    border-radius: 5px;
    padding: 0px;
    overflow-y: auto;
    overflow-x: hidden;
    float:left;
    background: #ffffff;
}
.chartdiv1{
    width: 15%;
    height: 100%;
    border:0px solid #979797;
    border-radius: 5px;
    padding: 0px;
    overflow-y: auto;
    overflow-x: hidden;
    float:left;
    // background: #ffffff;
}
.chartdiv2{
    width: 35%;
    height: 100%;
    border:0px solid #979797;
    border-radius: 5px;
    padding: 0px;
    overflow-y: auto;
    overflow-x: hidden;
    float:right;
    // background: #ffffff;
}

.active_class{
  border:red 1px solid;
}
</style>

<style lang="less">
    .testing_table{
        .ivu-table-fixed-body{
          height:auto!important;
          max-height:211px!important;
      }
    }
</style>
