<template>
    <div class="entryWrap" id="entry">
        <div class="expand" id="full" @click="handleFullScreen">
            <Icon type="md-expand" size="50" />
        </div>
        <div class="entryItem">
            <div class="choose">
                <p class="selectTitle">1.{{ $t("800082") }}</p>
                <div class="row">
                    <p
                        class="options"
                        v-for="(item, index) in lineList"
                        @click="linechange(index)"
                        :class="{ active: a == index }"
                    >
                        {{ item.title }}
                    </p>
                </div>
            </div>
            <div class="choose">
                <p class="selectTitle">2.{{ $t("1052") }}</p>
                <div class="row">
                    <p
                        class="options"
                        v-for="(item, index) in stationList"
                        @click="stationchange(index)"
                        :class="{ active: b == index }"
                    >
                        {{ item.title }}
                    </p>
                </div>
            </div>
        </div>
        <div class="entryItem">
            <div class="choose">
                <p class="selectTitle">3.{{ $t("100217") }}</p>
                <div class="row">
                    <p
                        class="options"
                        v-for="(item, index) in productList"
                        @click="productchange(index)"
                        :class="{ active: c == index }"
                    >
                        {{ item.name + "【" + item.code + "】" }}
                    </p>
                </div>
            </div>
            <div class="choose">
                <p class="selectTitle">4.{{ $t("8063") }}</p>
                <div class="row">
                    <p
                        class="options"
                        v-for="(item, index) in materialList"
                        @click="materialchange(index)"
                        :class="{ active: d == index }"
                    >
                        {{ item.name }}
                    </p>
                </div>
            </div>
        </div>
        <div class="entryItem">
            <div class="choose">
                <p class="selectTitle">5.工件编号</p>
                <div class="row">
                    <input
                        class="erweima"
                        type="text"
                        v-model="qrcode"
                        @keyup.enter="savedata"
                    />
                </div>
            </div>
        </div>
        <div class="entryItem">
            <div class="choose">
                <p class="selectTitle">6.{{ $t("90000017") }}</p>
                <div class="row">
                    <p
                        class="options"
                        v-for="(item, index) in checktypeList"
                        @click="checktypechange(index)"
                        :class="{ active: e == index }"
                    >
                        {{ item.name }}
                    </p>
                </div>
                <div class="row1" v-show="this.checktype.id === 7">
                    <div class="number row1">
                        <p class="inputlabel">{{ $t("950228") + ":" }}</p>
                    </div>
                    <input class="erweima" type="text" v-model="reason" />
                </div>
            </div>
        </div>
        <div class="entryItem">
            <div class="choose">
                <p class="selectTitle">7.{{ $t("90000020") }}</p>
                <div
                    :class="table_scrollx ? 'collection_table' : ''"
                    style="
                        width: 100%;
                        height: 100%;
                        padding-left: 5px;
                    "
                >
                    <template style="overflow-x: scroll; overflow-y: hidden">
                        <Table
                            :columns="columns"
                            :data="tableData"
                            v-show="detailshow"
                            class="Manual_inspection_table"
                            :max-height="500"
                            ref="detailTable"
                        >
                            <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 resultData.number"
                                slot-scope="{ row, index }"
                                :slot="'min_value' + (i + 1)"
                            >
                                <span
                                    v-show="
                                        tableData[index].checktype === 2 &&
                                        tableData[index].valuecategory === 2
                                    "
                                >
                                    <inputNumber
                                        class="publicinput"
                                        :class="{
                                            active_class: tableData[index][
                                                'min_value' + (i + 1)
                                            ]
                                                ? tableData[index][
                                                      'min_value' + (i + 1)
                                                  ] < row.min_value ||
                                                  tableData[index][
                                                      'min_value' + (i + 1)
                                                  ] > row.max_value
                                                : false,
                                        }"
                                        type="text"
                                        v-model="
                                            tableData[index][
                                                'min_value' + (i + 1)
                                            ]
                                        "
                                        style="width: 100px"
                                        @blur.native.capture="
                                            getrange(index, i + 1)
                                        "
                                    />
                                </span>
                            </template>
                            <template
                                v-for="(item, i) in resultData.number"
                                slot-scope="{ row, index }"
                                :slot="'max_value' + (i + 1)"
                            >
                                <span
                                    v-show="
                                        tableData[index].checktype === 2 &&
                                        tableData[index].valuecategory === 2
                                    "
                                >
                                    <inputNumber
                                        class="publicinput"
                                        type="text"
                                        v-model="
                                            tableData[index][
                                                'max_value' + (i + 1)
                                            ]
                                        "
                                        :class="{
                                            active_class: tableData[index][
                                                'max_value' + (i + 1)
                                            ]
                                                ? tableData[index][
                                                      'max_value' + (i + 1)
                                                  ] < row.min_value ||
                                                  tableData[index][
                                                      'max_value' + (i + 1)
                                                  ] > row.max_value
                                                : false,
                                        }"
                                        style="width: 100px"
                                        @blur.native.capture="
                                            getrange(index, i + 1)
                                        "
                                    />
                                </span>
                            </template>
                            <template
                                v-for="(item, i) in resultData.number"
                                slot-scope="{ row, index }"
                                :slot="'value' + (i + 1)"
                            >
                                <span v-if="tableData[index].checktype === 1">
                                    <RadioGroup
                                        v-model="
                                            tableData[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="tableData[index].checktype === 2"
                                >
                                    <inputNumber
                                        :disabled="
                                            tableData[index].checktype === 2 &&
                                            tableData[index].valuecategory === 2
                                        "
                                        :class="{
                                            active_class: tableData[index][
                                                'value' + (i + 1)
                                            ]
                                                ? tableData[index][
                                                      'value' + (i + 1)
                                                  ] < row.min_value ||
                                                  tableData[index][
                                                      'value' + (i + 1)
                                                  ] > row.max_value
                                                : false,
                                        }"
                                        class="publicinput"
                                        type="text"
                                        v-model="
                                            tableData[index]['value' + (i + 1)]
                                        "
                                        style="width: 100px"
                                    />
                                </span>
                                <span
                                    v-else-if="tableData[index].checktype === 0"
                                >
                                    <input
                                        class="publicinput"
                                        type="text"
                                        v-model="
                                            tableData[index]['value' + (i + 1)]
                                        "
                                        style="width: 100px"
                                    />
                                </span>
                            </template>
                            <template
                                v-for="(item, i) in resultData.number"
                                slot-scope="{ row, index }"
                                :slot="'range' + (i + 1)"
                            >
                                <span
                                    v-show="
                                        tableData[index].checktype === 2 &&
                                        tableData[index].valuecategory === 2
                                    "
                                >
                                    <inputNumber
                                        :disabled="true"
                                        class="publicinput"
                                        type="text"
                                        v-model="
                                            tableData[index]['range' + (i + 1)]
                                        "
                                        :class="{
                                            active_class: tableData[index][
                                                'range' + (i + 1)
                                            ]
                                                ? tableData[index][
                                                      'range' + (i + 1)
                                                  ] > tableData[index]['range']
                                                : false,
                                        }"
                                        style="width: 100px; font-color: black"
                                    />
                                </span>
                            </template>
                        </Table>
                    </template>
                </div>
            </div>
        </div>
        
        <div class="entryItem pr">
            <span class="tip" v-text="message"></span>
            <!--<button class="save" @click="savedata">保存</button>-->
            <Button
                type="primary"
                :loading="loading"
                @click="savedata"
                class="save"
            >
                <span v-if="!loading">{{ $t("900306") }}</span>
                <span v-else></span>
            </Button>
        </div>
        <div>
            <Modal v-model="ngmodal" :styles="{ top: '40px', width: '900px' }">
                <div
                    class="modal_body"
                    style="
                        width: 900px !important;
                        padding: 0 0px;
                        height: 400px !important;
                    "
                >
                    <div class="divboder">
                        <label
                            >{{ $t("1950601")
                            }}<i
                                style="
                                    color: red;
                                    margin-left: 5px !important;
                                    margin-top: -5px !important;
                                "
                                >*</i
                            >:</label
                        >
                        <div
                            style="
                                width: 870px;
                                height: 100%;
                                padding-left: 5px;
                                overflow-y: scroll;
                            "
                        >
                            <Table
                                :columns="ngcolumns"
                                :data="ngtableData"
                            ></Table>
                        </div>
                    </div>
                </div>
                <div slot="footer">
                    <template>
                        <Poptip placement="left" width="300px">
                            <Button type="primary" :loading="loading2">
                                <span v-if="!loading2">{{
                                    $t("1950549")
                                }}</span>
                                <span v-else>{{ $t("1950549") }}</span>
                            </Button>
                            <div class="api" slot="content">
                                <div class="filter">
                                    <label style="width: 120px"
                                        >{{ $t("1950626")
                                        }}<i
                                            style="
                                                color: red;
                                                margin-left: 5px !important;
                                                margin-top: -5px !important;
                                            "
                                            >*</i
                                        >:</label
                                    >
                                    <inputNumber
                                        class="publicinput"
                                        v-model="quantity"
                                        style="width: 100px"
                                    />
                                </div>
                                <Button
                                    type="primary"
                                    :loading="loading2"
                                    @click="saveresult1"
                                >
                                    <span v-if="!loading2">{{
                                        $t("900306")
                                    }}</span>
                                    <span v-else>{{ $t("900306") }}</span>
                                </Button>
                            </div>
                        </Poptip>
                    </template>
                    <Button
                        type="primary"
                        :loading="loading3"
                        @click="saveresult2"
                    >
                        <span v-if="!loading3">{{ "NG" }}</span>
                        <span v-else>{{ "NG" }}</span>
                    </Button>
                </div>
            </Modal>
        </div>
    </div>
</template>

<script>
import axios from "@/libs/api.request";

export default {
    data() {
        return {
            table_scrollx: false,
            lineList: [],
            stationList: [],
            productList: [],
            materialList: [],
            materidArray: [],
            checktypeList: [
                /*{ id: 5, name: this.$t(930033) },
        { id: 2, name: this.$t(930034) },
        { id: 3, name: this.$t(930035) },
        { id: 6, name: this.$t(930036) },
        { id: 1, name: this.$t(950367) },
        { id: 4, name: this.$t(930037) },
        { id: 7, name: this.$t(600233) },*/
            ],
            itemList: [],
            line: {},
            station: {},
            product: {},
            material: {},
            checktype: {},
            item: {},
            number: 0,
            qrcode: "",
            a: null,
            b: 0,
            c: 0,
            d: 0,
            e: 0,
            tableData: [],
            columns: [
                {
                    title: this.$t("1008"),
                    slot: "xuhao",
                    render: (h, params) => {
                        return h("span", params.index + 1);
                    },
                    width: 70,
                    align: "center",
                },
                {
                    title: this.$t("901048"),
                    slot: "item",
                    align: "center",
                },
                {
                    title: '量具信息',
                    slot: "standard",
                    align: "center",
                },
                {
                    title: this.$t("200060"),
                    slot: "min_value",
                    align: "center",
                },
                {
                    title: this.$t("200059"),
                    slot: "max_value",
                    align: "center",
                },
                {
                    title: '极差',
                    slot: "max_value",
                    align: "center",
                },
                {
                    title: this.$t("950408"),
                    slot: "result_value",
                    align: "center",
                },
            ],
            detailshow: true,
            loading: false,
            loading2: false,
            loading3: false,
            resultData: {},
            ngcolumns: [
                {
                    title: this.$t("1008"),
                    key: "xuhao",
                    render: (h, params) => {
                        return h("span", params.index + 1);
                    },
                    width: 70,
                    align: "center",
                },
                {
                    title: this.$t("901048"),
                    key: "item",
                    align: "center",
                },
                {
                    title: this.$t("950245"),
                    key: "standard",
                    align: "center",
                },
                {
                    title: this.$t("200060"),
                    key: "min_value",
                    align: "center",
                },
                {
                    title: this.$t("200059"),
                    key: "max_value",
                    align: "center",
                },
                {
                    title: this.$t("1950619"),
                    key: "range",
                },
                {
                    title: this.$t("800195"),
                    key: "result",
                    align: "center",
                },
                {
                    title: this.$t("8000030"),
                    key: "lowerlimit",
                },
                {
                    title: this.$t("8000031"),
                    key: "upperlimit",
                },
                {
                    title: this.$t("1950610"),
                    key: "value",
                    align: "center",
                },
                {
                    title: this.$t("1950620"),
                    key: "actual_range",
                },
            ],
            ngtableData: [],
            ngmodal: false,
            message: "",
            isNeedFullScreen: false, // 是否要自动打开全屏
            quantity: 1,
            reason: "",
        };
    },
    created() {
        this.initlines();
        this.initchecktype();
    },
    methods: {
        getrange(index, i) {
            var maxValue = this.tableData[index]["max_value" + i];
            var minValue = this.tableData[index]["min_value" + i];
            if (
                maxValue !== "" &&
                maxValue !== null &&
                maxValue !== undefined &&
                minValue !== "" &&
                minValue !== null &&
                minValue !== undefined
            ) {
                this.tableData[index]["range" + i] =
                    Math.round(
                        (this.tableData[index]["max_value" + i] -
                            this.tableData[index]["min_value" + i]) *
                            10000
                    ) / 10000;
                this.tableData[index]["value" + i] =
                    Math.round(
                        ((this.tableData[index]["max_value" + i] +
                            this.tableData[index]["min_value" + i]) /
                            2) *
                            10000
                    ) / 10000;
            } else {
                this.tableData[index]["range" + i] = "";
            }
        },
        nextInput(name, index) {
            var inputs = document.getElementsByClassName(name);
            var data = this.$refs.detailTable.data;
            var total = data.length;
            if (total <= 1) {
                return;
            }
            for (var j = 0; j < total; j++) {
                if (j + 1 === total) {
                    var doc = inputs[0];
                    this.focusNext(doc);
                    break;
                }
                if (index <= j) {
                    var doc = inputs[j + 1];
                    var i = this.focusNext(doc);
                    if (i === 1) {
                        if (j < total - 1 && data[j + 1].checktype === 1) {
                            continue;
                        }
                        break;
                    }
                }
            }
        },
        focusNext(doc) {
            var x = 0;
            var obj = doc.getElementsByTagName("div");
            for (var i = 0; i < obj.length; i++) {
                for (var j = 0; j < obj[i].childNodes.length; j++) {
                    if (obj[i].childNodes[j].tagName == "INPUT") {
                        obj[i].childNodes[j].focus();
                        x = 1;
                        break;
                    }
                }
            }
            return x;
        },
        initlines() {
            axios
                .request({
                    url:
                        "/qms/RepairPostionSetting/GetChanel",
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret == 1) {
                        this.lineList = res.data.data;
                    }
                });
        },
        linechange(i) {
            this.a = i;
            this.line = this.lineList[i];
            this.initstations(this.line.id);
            // option[i].classList.add('active')
        },
        initstations(lineid) {
            this.stationList = [];
            this.station = {};
            this.b = 0;
            if (lineid > 0) {
                let params = {
                line: lineid,
                type: 1,
            };
                axios
                    .request({
                        url:
                            "/acc/SectionProperty/GetSections"
                            ,
                            params,
                        method: "get",
                    })
                    .then((res) => {
                        this.stationList = res.data.data;
                        this.station = this.stationList[0];
                        this.initproduct(this.station.id);
                    });
            }
        },
        initproduct(stationid) {
            this.productList = [];
            this.product = {};
            this.c = 0;
            if (stationid > 0) {
                axios
                    .request({
                        url:
                            "/qms/InspectStandard/GetProductsBySectionId?sectionid=" +
                            stationid,
                        method: "get",
                    })
                    .then((res) => {
                        if (res.data.ret == 1 && res.data.data.length > 0) {
                            this.productList = res.data.data;
                            this.product = this.productList[0];
                            this.initmaterial(this.product.id, stationid);
                            this.inititems();
                        } else {
                            this.productList = [];
                            this.product = [];
                            this.materialList = [];
                            this.tableData = [];
                        }
                    });
            }
        },
        stationchange(i) {
            this.b = i;
            this.station = this.stationList[i];
            this.initproduct(this.station.id);
            this.initSn(this.station.id)
        },
        initSn(sectionid){
            if (sectionid > 0) {
                axios
                    .request({
                        url:
                            "/acc/SectionProperty/GetSn?productId=" + productid + "&sectionId=" + sectionid,
                        method: "get",
                    })
                    .then((res) => {
                        if (res.data.ret === 1) {
                            this.qrcode = res.data.data;
                        }
                    });
            }
        },
        productchange(i) {
            this.c = i;
            this.product = this.productList[i];
            this.initmaterial(this.product.id, this.station.id);
            this.inititems();
        },
        initmaterial(productid, sectionid) {
            this.materialList = [];
            this.material = {};
            this.d = null;
            if (productid > 0) {
                axios
                    .request({
                        url:
                            "/acc/SectionProperty/GetRouteByProduct?productId=" + productid + "&sectionId=" + sectionid,
                        method: "get",
                    })
                    .then((res) => {
                        if (res.data.ret === 1) {
                            this.materialList = res.data.data;
                        }
                    });
            }
        },
        materialchange(i) {
            if (this.materidArray.indexOf(i) > -1) {
                this.materidArray = [];
                this.material = {};
                this.d = -1;
            } else {
                this.materidArray.push(i);
                this.material = this.materialList[i];
                this.d = i;
            }
        },
        initchecktype() {
            axios
                .request({
                    url: "/qms/TypeCount/GetTypeCounts?page=1&pagesize=10000",
                    method: "get",
                })
                .then((res) => {
                    let data = res.data.data;
                    if (
                        res.data.ret === 1 &&
                        Array.isArray(data) &&
                        data.length
                    ) {
                        res.data.data.forEach((ele) => {
                            this.checktypeList.push({
                                id: ele.type_code,
                                name: ele.type_name,
                            });
                        });
                        this.checktype = this.checktypeList[0];
                        this.e = 0;
                    }
                });
        },
        checktypechange(i) {
            this.checktype = this.checktypeList[i];
            this.e = i;
            if (
                this.product.id > 0 &&
                this.station.id > 0 &&
                this.checktype.id > 0
            ) {
                this.inititems();
            }
        },
        inititems() {
            this.quantity = 1;
            this.reason = "";
            this.columns = [
                {
                    type: "index",
                    title: this.$t("1008"),
                    slot: "xuhao",
                    width: 70,
                    fixed: "left",
                },
                {
                    title: this.$t("901048"),
                    slot: "item",
                    minWidth: 200,
                    fixed: "left",
                },
                {
                    title: this.$t("950245"),
                    slot: "standard",
                    minWidth: 200,
                    fixed: "left",
                },
                {
                    title: this.$t("500082"),
                    slot: "min_value",
                    minWidth: 100,
                    fixed: "left",
                },
                {
                    title: this.$t("500081"),
                    slot: "max_value",
                    minWidth: 100,
                    fixed: "left",
                },
                {
                    title: this.$t("8000032"),
                    slot: "range",
                    minWidth: 80,
                    fixed: "left",
                },
            ];
            this.tableData = [];
            let data = {
                productid: this.product.id,
                sectionid: this.station.id,
                checktype: this.checktype.id,
            };
            if (
                data.productid > 0 &&
                data.sectionid > 0 &&
                data.checktype > 0
            ) {
                axios
                    .request({
                        url:
                            "/qms/InspectStandard/GetDetails?productid=" +
                            data.productid +
                            "&sectionid=" +
                            data.sectionid +
                            "&checktype=" +
                            data.checktype,
                        method: "get",
                    })
                    .then((res) => {
                        var tablelist = res.data.data.details;

                        var isMaxMin = false;
                        tablelist.forEach((element) => {
                            if (
                                element.checktype === 2 &&
                                element.valuecategory === 2
                            ) {
                                isMaxMin = true;
                            }
                        });

                        var cloumnLength = res.data.data.quantity;
                        this.resultData.number = cloumnLength;
                        for (var i = 1; i <= cloumnLength; i++) {
                            this.columns.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,
                                          },
                                      ],
                            });
                        }
                        tablelist.forEach((item, i) => {
                            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,
                                    valuecategory: item.valuecategory,
                                    range:
                                        item.checktype === 2 &&
                                        item.valuecategory === 2
                                            ? item.range
                                            : "",
                                };
                                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.tableData.push(data);
                            }
                        });
                        // 处理滚动条样式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);
                    });
            }
            this.detailshow = false;
            this.detailshow = true;
        },
        savedata() {
            this.resultData.details = [];
            this.resultData.productid = this.product.id;
            this.resultData.routeid = this.material.id;
            this.resultData.sectionid = this.station.id;
            this.resultData.sn = this.qrcode;
            this.resultData.checktype = this.checktype.id;
            this.resultData.result = "OK";
            var ngList = [];
            var isMaxMin = false;
            if (
                this.tableData !== undefined &&
                this.tableData !== null &&
                this.tableData !== []
            ) {
                var spcCheck = false;
                var details = this.tableData;
                for (var i = 1; i <= this.resultData.number; 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.lowerlimit = ele["min_value" + i];
                            detail.upperlimit = ele["max_value" + i];
                            detail.result = "";
                            if (ele.valuecategory === 1) {
                                if (
                                    (this.resultData.checktype === 6 ||
                                        this.resultData.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.resultData.checktype === 6 ||
                                        this.resultData.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,
                                        range: ele.range,
                                        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: "",
                                    });
                                }
                            }
                        }
                        this.resultData.details.push(detail);
                    });
                }
                if (spcCheck) {
                    this.message = this.$t(930046) + this.$t(1950628);
                    return;
                }
            }
            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,
                            align: "center",
                        },
                        {
                            title: this.$t("901048"),
                            key: "item",
                            align: "center",
                        },
                        {
                            title: this.$t("950245"),
                            key: "standard",
                            align: "center",
                        },
                        {
                            title: this.$t("200060"),
                            key: "min_value",
                            align: "center",
                        },
                        {
                            title: this.$t("200059"),
                            key: "max_value",
                            align: "center",
                        },
                        {
                            title: this.$t("1950610"),
                            key: "value",
                            align: "center",
                        },
                        {
                            title: this.$t("800195"),
                            key: "result",
                            align: "center",
                        },
                    ];
                } else {
                    this.ngcolumns = [
                        {
                            title: this.$t("1008"),
                            key: "xuhao",
                            render: (h, params) => {
                                return h("span", params.index + 1);
                            },
                            width: 70,
                            align: "center",
                        },
                        {
                            title: this.$t("901048"),
                            key: "item",
                            align: "center",
                        },
                        {
                            title: this.$t("950245"),
                            key: "standard",
                            align: "center",
                        },
                        {
                            title: this.$t("200060"),
                            key: "min_value",
                            align: "center",
                        },
                        {
                            title: this.$t("200059"),
                            key: "max_value",
                            align: "center",
                        },
                        {
                            title: this.$t("1950619"),
                            key: "range",
                        },
                        {
                            title: this.$t("800195"),
                            key: "result",
                            align: "center",
                        },
                        {
                            title: this.$t("8000030"),
                            key: "lowerlimit",
                        },
                        {
                            title: this.$t("8000031"),
                            key: "upperlimit",
                        },
                        {
                            title: this.$t("1950610"),
                            key: "value",
                            align: "center",
                        },
                        {
                            title: this.$t("1950620"),
                            key: "actual_range",
                        },
                    ];
                }
                this.showNg(ngList);
                return;
            }
            this.saveresult();
        },
        saveresult() {
            var data = this.resultData;
            data.quantity = this.quantity;
            data.reason = this.reason;
            this.loading = true;
            this.loading2 = true;
            this.loading3 = true;
            axios
                .request({
                    url: "/qms/ManualCollection/Add",
                    data,
                    method: "post",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        // this.$Message.success(this.$t('800223'))
                        this.number++;
                        this.message = this.$t(930045);
                        this.inititems();
                        this.qrcode = "";
                        this.resultData.qrcode = "";
                        this.detailshow = false;
                        this.detailshow = true;
                        this.ngmodal = false;
                        this.reason = "";
                    } else {
                        this.message = this.$t(930046) + this.$t(res.data.msg);
                    }
                    this.loading = false;
                    this.loading2 = false;
                    this.loading3 = false;
                    if (this.isNeedFullScreen) {
                        this.handleFullScreen();
                    }
                })
                .catch(() => {
                    this.resultData = {};
                    this.loading = false;
                    this.loading2 = false;
                    this.loading3 = false;
                });
        },
        saveresult1() {
            this.resultData.result = "2";
            this.saveresult();
        },
        saveresult2() {
            this.resultData.result = "NG";
            this.saveresult();
        },
        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,
                });
            });
        },
        // 全屏事件
        handleFullScreen() {
            let element = document.getElementById("entry");
            // 判断是否已经是全屏
            // 如果是全屏，退出
            if (this.fullscreen) {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            } else {
                // 否则，进入全屏
                if (element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.webkitRequestFullScreen) {
                    element.webkitRequestFullScreen();
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();
                } else if (element.msRequestFullscreen) {
                    // IE11
                    element.msRequestFullscreen();
                }
            }
            // 改变当前全屏状态
            if (this.fullscreen) {
                this.isNeedFullScreen = false;
            }
            this.fullscreen = !this.fullscreen;
        },
        handleFullScreen1() {
            let element = document.getElementById("entry");
            // 判断是否已经是全屏
            // 如果是全屏，退出
            if (this.fullscreen) {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            } else {
                // 否则，进入全屏
                if (element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.webkitRequestFullScreen) {
                    element.webkitRequestFullScreen();
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();
                } else if (element.msRequestFullscreen) {
                    // IE11
                    element.msRequestFullscreen();
                }
            }
            // 改变当前全屏状态
            this.fullscreen = !this.fullscreen;
        },
        requestFullScreen(element) {
            var requestMethod =
                element.requestFullScreen ||
                element.webkitRequestFullScreen ||
                element.mozRequestFullScreen ||
                element.msRequestFullScreen;
            if (requestMethod) {
                requestMethod.call(element);
            } else if (typeof window.ActiveXObject !== "undefined") {
                var wscript = new ActiveXObject("WScript.Shell");
                if (wscript !== null) {
                    wscript.SendKeys("{F11}");
                }
            }
        },
    },
};
</script>

<style lang="less" scoped>
// th .ivu-table-cell{
//     font-size: 16px!important;
//     color:red
//   }
.row {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
}
.entryWrap {
    position: relative;
    background-color: #f5f7f9;
    overflow-y: auto;
    overflow-x: hidden;
}
.expand {
    position: absolute;
    top: 10px;
    right: 50px;
}
.entryItem {
    background-color: #fff;
    border-radius: 10px;
    margin-bottom: 20px;
    padding: 20px;
    width: 100%;
}
.selectTitle {
    font-size: 18px;
}
.options {
    font-size: 12px;
    padding: 0 10px;
    /* width: 100px; */
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-radius: 5px;
    background-color: #f2f2f2;
    margin: 10px 0;
    margin-right: 50px;
    cursor: pointer;
}
.active {
    background-color: #2d8cf0;
    color: #fff;
}
.number {
    margin: 10px 55px 10px 0;
}
.minus {
    width: 55px;
    height: 42px;
    line-height: 42px;
    font-size: 20px;
    text-align: center;
    color: #fff;
    background-color: #b8741a;
    border-radius: 5px;
    cursor: pointer;
}
.plus {
    width: 55px;
    height: 42px;
    line-height: 42px;
    font-size: 20px;
    text-align: center;
    color: #fff;
    background-color: #4b7902;
    border-radius: 5px;
    cursor: pointer;
}
.digit {
    width: 180px;
    height: 42px;
    line-height: 42px;
    text-align: center;
    font-size: 20px;
    border: 1px solid #000;
    background-color: #d7d7d7;
    margin: 0 5px;
    color: #000;
}
.erweima {
    display: block;
    outline: none;
    width: 100%;
    height: 42px;
    line-height: 42px;
    font-size: 20px;
    color: #000;
    text-align: center;
    border: 1px solid #d8d8d8;
    background-color: #f4f7f9;
    margin: 10px 0;
}

.save {
    width: 95px;
    height: 55px;
    background-color: #347ab8;
    color: #fff;
    /* line-height: 55px; */
    text-align: center;
    font-size: 20px;
    /* cursor: pointer; */
    outline: none;
    border: none;
    border-radius: 10px;
    /* position: absolute;
  right: 20px; */
    /* margin-left: 80%; */
    position: absolute;
    right: 100px;
}
.pr {
    position: relative;
    height: 95px;
}
.tip {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 16px;
    /* border: 1px solid #d2d2d2; */
    border-radius: 5px;
}
.active_class {
    border: red 1px solid;
}
.row1 {
    display: flex;
    flex-direction: row;
}
.inputlabel {
    width: 80px;
    height: 42px;
    line-height: 42px;
    font-size: 20px;
    text-align: center;
    cursor: pointer;
}
</style>

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