<template>
    <div>
        <lj-win-common :title="title" :show-back="true" :closeWinHandler = "handleCloseWin">
            <template slot="header_right">
                <mu-menu placement="bottom-end" :open.sync="openTitle">
                    <mu-button icon>
                        <i class="iconfont icon-more"></i>
                    </mu-button>
                    <mu-list slot="content">
                        <mu-list-item button @click="handleBomDetail">
                            <mu-list-item-title>用料详情</mu-list-item-title>
                        </mu-list-item>
                        <mu-list-item button @click="handleGotoMtrldef">
                            <mu-list-item-title>物料详情</mu-list-item-title>
                        </mu-list-item>
                    </mu-list>
                </mu-menu>
            </template>
            <div slot="body">
                <div style="display:flex" v-if="ifadd">
                     <lj-searchbar hint="请输入单号或条码号进行查找" 
                                  style="margin-top: 4px;" @search="handleSearchbar" v-model="keyword" />
                    <mu-button icon slot="header_right" @click="handleScan"> <i class="iconfont icon-qrcode-scan"></i></mu-button>
                </div>
                
                <template >
                    <div class="lj-card-item">
                        <mu-row>
                            <mu-col span="3" class="lj-card-secondary-title">质检单号：</mu-col>
                            <mu-col span="7" class="lj-card-secondary-content">{{mainObject.billcode}}</mu-col>
                            <mu-col span="2">
                                <lj-status-badge :value="getStatus(mainObject.flag,mainObject.SecFlag,mainObject.saveflag,mainObject.ifspecial,mainObject.buyerAuditflag)"
                                                 :statusDic="statusDic" v-if="!ifadd"/>
                            </mu-col>
                            <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifadd }">送检号：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">
                                 <mu-auto-complete v-if="ifadd"
                                    v-model="mainObject.relcode"
                                    openOnFocus
                                    solo
                                    full-width
                                    :disabled="!ifadd"
                                >
                                </mu-auto-complete>
                                <span v-else> {{mainObject.relcode}}</span>
                               
                                </mu-col>
                             <mu-col span="3" class="lj-card-secondary-title">指令单号：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">{{mainObject.ordercode}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title">销售订单号：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">{{mainObject.saletaskcode}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title">物料名称：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">{{mainObject.mtrlname}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title">物料编码：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">{{mainObject.mtrlcode}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title">物料规格：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">{{mainObject.mtrlmode}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title">检验日期：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">{{mainObject.checkdate|dateFilter}}
                            </mu-col>
                            <mu-col v-if="ifadd" span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifadd }">质验类型：</mu-col>
                             <mu-col v-if="ifadd" span="9" class="lj-card-secondary-content" :class="{ 'lj-grid-editable-cell' : ifadd }">
                                 <span v-if="mainObject.itemtype || !ifadd" @click="hadleItemTypeClicked">
                                     {{mainObject.itemtype}}
                                 </span>
                                  <a @click="hadleItemTypeClicked" v-else>点击选择</a>
                                 </mu-col>
                            <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifedit && !isAQLCheck }">检验类型：</mu-col>
                            <mu-col span="4" class="lj-card-secondary-content" :class="{ 'lj-grid-editable-cell' : ifedit && !isAQLCheck }">
                                &nbsp;<input type="radio" :disabled="(!ifedit || isAQLCheck)" v-model="mainObject.checktype" value="1" @change="handleChecktypeChange">全检
                                &nbsp;<input type="radio" :disabled="(!ifedit || isAQLCheck || ifAqlCheckAll)" v-model="mainObject.checktype" value="0" @change="handleChecktypeChange">抽检
                            </mu-col>
                            <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifedit }">检验数：</mu-col>
                            <mu-col span="2" class="lj-card-secondary-content">
                                <input type="number" @focus="handleCheckQtyFocus($event)"  :class="{ 'lj-grid-editable-cell' : ifedit }" style="width: 60px;height: 25px;"
                                       :disabled="(ifCheckAll || isAQLCheck)" oninput="value=value.replace(/[^\d]/g,'')"
                                       v-on:input="handleCheckQtyChange" v-model="mainObject.checkqty" />
                            </mu-col>
                            <template v-if="ifadd">
                            <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifedit }" style="margin-top:3px">合格数：</mu-col>
                            <mu-col span="4" class="lj-card-secondary-content">
                                <input type="text" :class="{ 'lj-grid-editable-cell' : ifedit }" style="width: 60px;height: 25px;margin-top:3px"
                                       oninput="value=value.replace(/[^\d]/g,'')"
                                       v-on:input="handleCpcheckGoodQtyChange" v-model="mainObject.goodqty" />
                            </mu-col>
                            
                             <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifedit }" style="margin-top:3px">不合格数：</mu-col>
                            <mu-col span="2" class="lj-card-secondary-content">
                                <input type="text" :class="{ 'lj-grid-editable-cell' : ifedit }" style="width: 60px;height: 25px;margin-top:3px"
                                       oninput="value=value.replace(/[^\d]/g,'')"
                                       v-on:input="handleCpcheckBadQtyChange" v-model="mainObject.badqty" />
                            </mu-col>
                            </template>
                            <mu-col span="3" class="lj-card-secondary-title">批量：</mu-col>
                            <mu-col span="2" class="lj-card-secondary-content">{{mainObject.qty}}</mu-col>
                            <mu-col span="4" class="lj-card-secondary-title">总不合格数：</mu-col>
                            <mu-col span="3" class="lj-card-secondary-content">{{allbadqty}}</mu-col>
                            <mu-col span="4" class="lj-card-secondary-title">当前合格率：</mu-col>
                            <mu-col span="8" class="lj-card-secondary-content">{{goodRate}}%</mu-col>
                            <template v-if="!ifCheckAll">
                                <mu-col span="4" class="lj-card-secondary-title lj-grid-editable-cell">推荐合格率：</mu-col>
                                <mu-col span="8" class="lj-card-secondary-content">90%</mu-col>
                            </template>
                            <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifadd }">备注：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content"> 
                                <mu-auto-complete v-if="ifadd"
                                    v-model="mainObject.dscrp"
                                    openOnFocus
                                    solo
                                    full-width
                                    :disabled="!ifadd"
                                >
                                </mu-auto-complete>

                               <span v-else>{{mainObject.dscrp}}</span> </mu-col>
                            <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifedit }">异常原因：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">
                                <mu-auto-complete
                                    v-model="mainObject.reson"
                                    :placeholder="ifedit ? '请输入异常原因' : ''"
                                    ref="reasonField"
                                    :data="cpCheckMxReasonHistory"
                                    openOnFocus
                                    solo
                                    full-width
                                    @select="reasonSelected"
                                    :disabled="!ifedit"
                                >
                                </mu-auto-complete>
                            </mu-col>
                            <mu-col span="3" class="lj-card-secondary-title" :class="{ 'lj-grid-editable-cell' : ifedit }">处理建议：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">
                                <mu-auto-complete
                                    v-model="mainObject.suggest"
                                    :placeholder="ifedit ? '请输入处理建议' : ''"
                                    ref="suggestField"
                                    :data="cpCheckMxSuggestHistory"
                                    openOnFocus
                                    solo
                                    full-width
                                    @select="suggestSelected"
                                    :disabled="!ifedit"
                                >
                                </mu-auto-complete>
                            </mu-col>
                        </mu-row>
                    </div>

                    <div class="lj-card-item">
                        <mu-row>
                            <mu-col span="3" class="lj-card-secondary-title" v-if="mainObject.status !== ''">{{userInfo.statusname}}：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content" v-if="mainObject.status !== ''">{{mainObject.status}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title" v-if="mainObject.woodcode !== ''">{{userInfo.woodcodename}}：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content" v-if="mainObject.woodcode !== ''">{{mainObject.woodcode}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title" v-if="mainObject.pcode !== ''">{{userInfo.pcodename}}：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content" v-if="mainObject.pcode !== ''">{{mainObject.pcode}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title">客户要求：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content">{{mainObject.dscrpSum}}</mu-col>
                            <mu-col span="3" class="lj-card-secondary-title">特殊要求：</mu-col>
                            <mu-col span="9" class="lj-card-secondary-content" >
                                <a @click="specialDialogOpen=true">点击查看</a>
                            </mu-col>
                        </mu-row>
                    </div>
                </template>
                <template>
                    <div v-if="ifadd">
                        <span>
                            <mu-button flat color="red" @click="handleDelMx">删除明细</mu-button>
                        </span>
                        <span class="taskedit_pzbtn" @click="handleAddMx">
                            添加明细
                        </span>
                    </div>
                    <lj-grid id="cpcheck_grid" ref="cpcheckGrid" :table-data="mxList" :columns="gridColumns" :editing="ifedit"
                            quick-enter-name="cpcheck-mx"
                            quick-enter-property="checkitem_itemname"
                            :row-style="setRowStyle"
                             @content-cell-change="handleBadQtyChange"
                             @cell-click="handleGridCellClick">
                        <template slot="table-footer" slot-scope="{column, data, columnMap}" v-if="isAQLCheck">
                            <tr class="table-footer_tr"
                                v-for="(col, index) in getFooter({columns: column, data:data, columnMap: columnMap})"
                                :key="index"
                            >
                                <template v-for="(itm, idx) in col">
                                    <td v-if="itm"
                                        :key="idx"
                                        :style="itm.cellStyle"
                                        :colspan="itm.colspan"
                                        :class="itm.class"
                                    >
                                        {{ itm.value }}
                                    </td>
                                </template>
                            </tr>
                        </template>
                    </lj-grid>
                </template>
                <template>
                    <div class="lj-card-item">
                        <mu-row>
                            <mu-col span="4" class="lj-card-secondary-title" style="text-align: center;" v-for="(picture, index) in pictureList" ::key="index">
                                <lj-img style="width: 30vw; height: 30vw;" v-bind:src="picture.url" v-bind:md5="picture.filemd5" @click.native="photoBrowser(index)"/><br>
                                {{picture.fileName}}
                            </mu-col>
                        </mu-row>
                    </div>
                </template>
                <template>
                    <lj-list-tree-choose-common :allItem="allItem" :rawList="rawList" name-field="typename" button-field="typename" id-field="typeid" @item-selected="handleItemSelected" ref="checktype" />
                </template>
            </div>
            <template v-if="ifedit" slot="footer">
                <mu-row v-if="!ifadd">
                    <mu-col tag="mu-button" color="primary" @click.native="handleSave(0)">临时保存</mu-col>
                    <template v-if="isAQLCheck || ifCheckAll">
                        <mu-col tag="mu-button" color="primary" @click.native="handleSave(1)" v-if="ifAllPass_aql || ifCheckAll">合格</mu-col>
                        <mu-col tag="mu-button" color="primary" @click.native="handleBadSave">不合格</mu-col>
                    </template>
                    <template v-else>
                        <mu-col v-if="power7288" tag="mu-button" color="primary" @click.native="handleSave(1)">保存并审核</mu-col>
                    </template>
                </mu-row>
                <mu-row v-else>
                     <mu-col tag="mu-button" color="primary" @click.native="handleSaveNew">保存</mu-col>
                </mu-row>
            </template>
        </lj-win-common>
        <mu-dialog :open.sync="mxDialogOpen" title="质检明细标准" scrollable>
            {{currentMxItem.Standard? currentMxItem.Standard:"该质检明细未设置标准"}}
            <mu-button slot="actions" color="primary" flat @click="mxDialogOpen=false">
                关闭
            </mu-button>
        </mu-dialog>
        <mu-dialog :open.sync="specialDialogOpen" width="100%" title="客户产品特殊要求" scrollable>
            {{mainObject.specialcontent}}
            <div class="lj-card-item">
                <mu-row>
                    <mu-col span="4" class="lj-card-secondary-title"
                            style="text-align: center; padding-bottom: 8px;"
                            v-for="(picture, index) in specialFiles" :key="index">
                        <lj-img style="width: 25vw; height: 25vw;" :src="picture.url"
                                :md5="picture.filemd5" @click.native="specialPhotoBrowser(index)"/>
                        <br>
                    </mu-col>
                </mu-row>
            </div>
            <mu-button slot="actions" color="primary" flat @click="specialDialogOpen=false">
                关闭
            </mu-button>
        </mu-dialog>
        <van-action-sheet
            v-model="aqlBadSaveState"
            :actions="aqlBadSaveActions"
            description="质检不合格，请选择"
            cancel-text="取消"
            close-on-click-action
            get-container="body"
            @select="handleSelAQLBadSave"
        >
        </van-action-sheet>
        <van-action-sheet
            v-model="checkItemState"
            :actions="checkItemResultActions"
            description="质检项目预设结果，请选择"
            cancel-text="取消"
            close-on-click-action
            get-container="body"
            @select="handleSelCheckItemResult"
        >
        </van-action-sheet>
    </div>

</template>

<script>
    import ljWinCommon from 'components/lj-win-common'
    import LjStatusBadge from "components/lj-status-badge";
    import LjGrid from "components/lj-grid";
    import LjImg from "components/lj-img";
    import LjSearchbar from "components/lj-searchbar";
    import LjListTreeChooseCommon from "components/lj-list-tree-choose-common";
    export default {
        name: "cpcheck-mx",
        components: {
            ljWinCommon,
            LjStatusBadge,
            LjGrid,
            LjImg,
            LjSearchbar,
            LjListTreeChooseCommon
        },
        created() {
            var pageParm = $lj.getPageParam();
            this.ifadd = pageParm.ifadd == null? false:pageParm.ifadd;
            this.ifmulti = $lj.checkPower('5897');
            
            this.mainObject = pageParm.mainObject;
           
            if(this.mainObject){
                this.allbadqty = this.mainObject.badqty;
                this.mainObject.badinqty = 0;
                if(Number(this.mainObject.checkqty) <= 0) this.mainObject.checkqty = Number(this.mainObject.qty);
                this.goodRate = Math.round((Number(this.mainObject.checkqty) - Number(this.allbadqty))  * 100 / Number(this.mainObject.checkqty));
                if (this.mainObject.flag == 0 && this.mainObject.SecFlag == 0 && $lj.checkPower(5849)) {
                    this.ifedit = true;
                }
            }
            else{
                this.mainObject = {};
            }
            if(this.ifadd)
            {
                this.ifedit = true;
                this.getChecktype();
            }

            this.setGridColumns();

            if (!this.ifedit){
                this.gridColumns[3].editable = false;
                this.gridColumns[4].editable = false;
            }

            this.getReasonHistory();
            this.getSuggestHistory();
            this.userInfo = $lj.getStorage("userInfo");
        },
        mounted() {
            if(!this.ifadd)
            {
                this.ifCheckAll = (!this.ifedit || this.mainObject.checktype == 1) ? true : false;
                var self = this;
                $lj.postLJRequest("GetL1CpcheckMx", {
                    token: $lj.getStorage("token"),
                    billid: this.mainObject.billid
                }, function (rsp) {
                    if (rsp) {
                        for (const cpcheckmx of rsp.cpcheckmxList) {
                            let mx = cpcheckmx;
                            if (cpcheckmx.resultstr !== '') {
                                let resultArr = cpcheckmx.resultstr.split(';');
                                if (resultArr.length > 0) {
                                    for(let i = 0; i < resultArr.length; i++) {
                                        self.$set(mx, 'QcResult' + (i + 1), resultArr[i]);
                                    }
                                }
                            }
                            self.mxList.push(mx)
                            for (const file of cpcheckmx.fileList) {
                                self.pictureList.push(file);
                            }
                        }
                        self.pictureList.sort(self.comparePicutre("relidmx"))
                        self.fnSetQcResult();
                        self.getCustProspecialItem();
                    }
                })
            }
            else{
               // this.hadleItemTypeClicked();
            }
        },
        data() {
            return {
                winmode: 0,
                pictureList: [],
                goodRate: 100,
                ifedit: false,
                ifCheckAll: true,
                mxDialogOpen: false,
                currentMxItem: {},
                allbadqty: 0,
                mainObject: {},
                mxList: [],
                gridColumns: [],
                statusDic: {
                    "待质检": {color: "Warn"},
                    "待初审": {color: "Alert"},
                    "待采购审": {color: "Alert"},
                    "待二审": {color: "Normal"},
                    "已完成": {color: "Pass"}
                },
                specialDialogOpen: false,
                specialFiles: [],
                ifmulti: false,
                cpCheckMxReasonHistory: [],
                capacity: 10,
                draftName: "cpCheckZZMxReasonHistory",
                ifadd:false,
                keyword:'',
                allItem: { TypeID: -1, Typename: "全部", sonflag: 0, parentid: 0 },
                rawList:[],
                userInfo:{},
                power7288: $lj.checkPower(7288),
                openTitle: false,
                suggestDraftName: "cpCheckZZMxSuggestHistory",
                aqlBadSaveState: false,
                aqlBadSaveActions: [
                    {id: 1, name: '全检'},
                    {id: 2, name: '退回', subname: '该物料，全部退回'},
                ],
                ifCheckAll: false,
                ifAllPass_aql: true, // AQL抽检判定，是否全部通过
                isSecaudit: false,
                ifAqlCheckAll: false,
                checkItemState: false,
                checkItemResultActions: [],
                checkItemRow: {}
            }
        },
        methods: {
            saveReason() {
                if(!this.mainObject.reson) return;
                this._cacheSet(this.mainObject.reson);
                // 保存记录
                $lj.setStorage(this.draftName, this.cpCheckMxReasonHistory);
            },
            saveSuggest() {
                if(!this.mainObject.suggest) return;
                this._cacheSet(this.cpCheckMxSuggestHistory,this.mainObject.suggest);
                // 保存记录
                $lj.setStorage(this.suggestDraftName, this.cpCheckMxSuggestHistory);
            },
            // 登录历史
            getReasonHistory() {
                this.cpCheckMxReasonHistory = $lj.getStorage(this.draftName) || [];
                console.log('$lj.this.userHistoryAccount("userHistoryAccount")>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> :>> ', JSON.stringify(this.cpCheckMxReasonHistory));
            },
            // 登录历史
            getSuggestHistory() {
                this.cpCheckMxSuggestHistory = $lj.getStorage(this.suggestDraftName) || [];
                console.log('$lj.this.userHistoryAccount("userHistoryAccount")>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> :>> ', JSON.stringify(this.cpCheckMxSuggestHistory));
            },
            reasonSelected(item, index) {
                // console.log("reasonSelected item",JSON.stringify(item),"index ====>",index);
                // console.log('reasonSelected this.maxUserHistoryAccount :>> ', JSON.stringify(this.maxUserHistoryAccount));
                this.mainObject.reson = this._cacheGet(item);
                this.$refs.reasonField.blur();
            },
            suggestSelected(item, index) {
                // console.log("reasonSelected item",JSON.stringify(item),"index ====>",index);
                // console.log('reasonSelected this.maxUserHistoryAccount :>> ', JSON.stringify(this.maxUserHistoryAccount));
                this.mainObject.suggest = this._cacheGet(this.cpCheckMxSuggestHistory,item);
                this.$refs.suggestField.blur();
            },
            /** LRU */
            _cacheGet(arr,key) {
                let index = arr.findIndex((item) => item === key);
                if (index === -1) {
                    return -1;
                }
                // 删除此元素后插入到数组第一项
                let value = arr[index];
                arr.splice(index, 1);
                arr.unshift(value);
                return value;
            },
            _cacheSet(arr,key) {
                let index = arr.findIndex((item) => item === key);
                // 想要插入的数据已经存在了，那么直接提升它就可以
                if (index > -1) {
                    arr.splice(index, 1);
                } else if (arr.length >= this.capacity) {
                    // 若已经到达最大限制，先淘汰一个最久没有使用的
                    arr.pop();
                }
                arr.unshift(key);
            },
            handleCloseWin(){
                if (this.ifedit){
                    $lj.confirm('提示', '是否放弃保存？', function () {
                        $lj.closeWin();
                    });
                } else {
                    $lj.closeWin();
                }
                this.saveReason();
                this.saveSuggest();
            },
            handelAllCheckCreateDscrp() {
                let dscrp = ""
                for(let mx of this.mxList) {
                    if(mx.aqljudge1_value > 0 || mx.aqljudge2_value > 0 || mx.aqljudge3_value > 0) {
                        dscrp += mx.checkitem_itemname;
                    }
                    if(mx.aqljudge1_value > 0) {
                        dscrp += "严重缺陷数";
                        dscrp += ":";
                        dscrp += mx.aqljudge1_value;
                        dscrp += ";";
                    }
                    if(mx.aqljudge2_value > 0) {
                        dscrp += "主要缺陷数";
                        dscrp += ":";
                        dscrp += mx.aqljudge2_value;
                        dscrp += ";";
                    }
                    if(mx.aqljudge3_value > 0) {
                        dscrp += "轻微缺陷数";
                        dscrp += ":";
                        dscrp += mx.aqljudge3_value;
                        dscrp += ";";
                    }
                }

                return dscrp;
            },
            handleSelAQLBadSave(action, index) {
                if (action.id == 1) {
                    // 全检
                    this.mainObject.dscrp = this.handelAllCheckCreateDscrp();

                    // 重置明细缺陷数
                    for(let mx of this.mxList) {
                        this.$set(mx,"aqljudge1_value",0);
                        this.$set(mx,"aqljudge2_value",0);
                        this.$set(mx,"aqljudge3_value",0);
                    }

                    this.fnSetQcResult();
                    this.fnCountBadqty();

                    this.mainObject.checktype = 1;
                    this.mainObject.checkqty = Number(this.mainObject.qty);

                    this.ifAqlCheckAll = true;

                    this.setGridColumns();
                    // this.fnBadSave()
                } else if (action.id == 2) {
                    // 退回
                    this.mainObject.ifPass = 0;
                    this.mainObject.badqty = this.allbadqty;
                    this.mainObject.goodqty = 0; //入库数都以不合格入库数方式入库
                    this.mainObject.badinqty = 0; //入库数为0

                    //明细数据
                    for (var i in this.mxList) {
                        this.mxList[i].goodqty = 0;
                    }

                    this.isSecaudit = true;

                    this.handleSave(2);
                }
                this.aqlBadSaveState = false;
            },
            handleBadSave() {
                if (this.isAQLCheck) {
                    this.aqlBadSaveState = true
                } else {
                    this.fnBadSave()
                }
            },
            fnBadSave() {
                var allbadqty = 0;
                for (var i in this.mxList) {
                    allbadqty += Number(this.mxList[i].badqty);
                }
                if (allbadqty == 0) {
                    this.$toast.fail("请填写不合格数量");
                    return false;
                }

                this.handleSave(2);
            },
            handleSave(type) {
                var savetype = type;
                this.mainObject.badqty = this.allbadqty;
                if (Number(this.mainObject.qty) < Number(this.mainObject.checkqty)) {
                    alert("检验数数不能大于批量");
                    return;
                }
                if (Number(this.mainObject.checkqty) < Number(this.mainObject.badqty)) {
                    alert("总不合格数不能大于检验数");
                    return;
                }
                if (this.ifCheckAll && type === 2 && Number(this.mainObject.badqty) != Number(this.mainObject.qty)) {
                    alert("不合格全检，总不合格数不等于检验数");
                    return;
                }

                for(let i = 0;i < this.mxList.length;i++) {
                    let mx = this.mxList[i];

                    if(mx.ifcheck == 1 && mx.QcResult == '') {
                        alert(`行${i + 1}必须填写质检结果,请检查!`);
                        return;
                    }
                }

                // 如果开启AQL抽检判定，记录总缺陷数
                if (this.isAQLCheck) {
                    let aqljudge1_value = 0;
                    let aqljudge2_value = 0;
                    let aqljudge3_value = 0;
                    for (const item of this.mxList) {
                        aqljudge1_value = $lj.floatAdd(aqljudge1_value, item.aqljudge1_value);
                        aqljudge2_value = $lj.floatAdd(aqljudge2_value, item.aqljudge2_value);
                        aqljudge3_value = $lj.floatAdd(aqljudge3_value, item.aqljudge3_value);
                    }
                    this.mainObject.aqljudge1_value = aqljudge1_value;
                    this.mainObject.aqljudge2_value = aqljudge2_value;
                    this.mainObject.aqljudge3_value = aqljudge3_value;
                    console.warn(' this.mainObject :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.mainObject));
                }
                
                //主表数据
                if (this.ifCheckAll) {
                    this.mainObject.goodqty = Number(this.mainObject.qty) - Number(this.mainObject.badqty);
                } else {
                    this.mainObject.goodqty = Number(this.mainObject.checkqty) - Number(this.mainObject.badqty);
                }
                let requestBody = {
                    token: $lj.getStorage("token"),
                    savetype: savetype,
                    cpcheck: this.mainObject,
                    cpcheckmxList: this.mxList,
                    cpcheckmxFjList: this.pictureList,
                    ifMultiResult: this.ifmulti ? 1 : 0,
                    isSecaudit: this.ifCheckAll || this.isSecaudit ? 1 : 0
                };
                $lj.postLJRequest("CpcheckzzL1Save", requestBody, function (rsp) {
                    if (rsp) {
                        $lj.toast("保存成功！", 2000);
                        $lj.sendEvent("cpcheck_refresh");
                        $lj.closeWin();
                    }
                })

                this.saveReason();
                this.saveSuggest();
            },
            handleGridCellClick({column, row, index}) {
                if (!column) {
                    return;
                }
                if (column.editable) {
                    return;
                }
                if (column.property === "picHelp") {
                    this.currentMxItem = row;
                    this.mxDialogOpen = true;
                }
                else if(column.property == "picPhoto") {
                    if(!this.ifedit){
                        return;
                    }
                    var self = this;
                    $lj.getPicture(function(ret){
                        if (ret.data){
                            var picture = {
                                url : ret.data,
                                relidmx : row.printid,
                                fileName : row.checkitem_itemname,
                                base64 : ret.base64Data,
                                fileType : "." + ret.data.substring(ret.data.lastIndexOf("\/") + 1, ret.data.length).split(".")[1],
                                ifDBSave : 0
                            };
                            var i = 0;
                            for (const pic of self.pictureList){
                                if (pic.relidmx == picture.relidmx){
                                    if(pic.base64 == picture.base64){
                                        $lj.toast("图片已添加过，不能重复添加", 2000);
                                        return;
                                    }
                                    i++;
                                }
                            }
                            if (i >= 6){
                                alert("检查项目:" + row.checkitem_itemname + "图片数不能超过6张！");
                                return;
                            }
                            self.pictureList.push(picture);
                            self.pictureList.sort(self.comparePicutre("relidmx")); //排序
                        }
                    })
                }
            },
            handleBadQtyChange(event) {
                if (!event) {
                    return;
                }
                let {row, column} = event;
                if (!row || !column) {
                    return;
                }
                if (column.property == 'badqty') {
                    this.fnCountBadqty();
                } else if (column.property.indexOf('aqljudge') > -1) {
                    var rowBadqty = 0;
                    rowBadqty = $lj.floatAdd(rowBadqty, row.aqljudge1_value);
                    rowBadqty = $lj.floatAdd(rowBadqty, row.aqljudge2_value);
                    rowBadqty = $lj.floatAdd(rowBadqty,row.aqljudge3_value);
                    this.$set(row, 'badqty', rowBadqty);

                    this.fnSetQcResult();
                    this.fnCountBadqty();
                }
            },
            fnSetQcResult() {
                if(this.isAQLCheck) {
                    for (let i = 0; i < this.mxList.length; i++) {
                        if (this.mainObject.aqljudge1_goal && Number(this.mxList[i].aqljudge1_value) >= this.mainObject.aqljudge1_goal ||
                            this.mainObject.aqljudge2_goal && Number(this.mxList[i].aqljudge2_value) >= this.mainObject.aqljudge2_goal ||
                            this.mainObject.aqljudge3_goal && Number(this.mxList[i].aqljudge3_value) >= this.mainObject.aqljudge3_goal) {
                            this.$set(this.mxList[i], 'QcResult', '不合格');
                        } else {
                            this.$set(this.mxList[i], 'QcResult', '合格');
                        }
                    }
                }
            },
            fnCountBadqty() {
                var allbadqty = 0;
                for (var i in this.mxList) {
                    this.mxList[i].badqty = Number(this.mxList[i].badqty);
                    allbadqty += this.mxList[i].badqty;
                }
                this.allbadqty = allbadqty;
                this.receiveqty = Number(this.mainObject.qty) - Number(this.allbadqty) + Number(this.mainObject.badinqty);
                this.goodRate = Math.round((Number(this.mainObject.checkqty) - Number(this.allbadqty))  * 100 / Number(this.mainObject.checkqty));
                if (this.allbadqty > this.mainObject.checkqty) {
                    $lj.toast('警告：不合格数不能大于检验数', 2000, 'bottom')
                }
            },
            getStatus(flag,secflag,saveflag,ifspecial,buyerAuditflag){
                if (saveflag == 0 && flag == 0 && secflag == 0){
                    return "待质检";
                }
                if (flag == 0){
                    return "待初审";
                }
                if (secflag == 0){
                    return "待二审";
                }
                return "已完成";
            },
            handleChecktypeChange() {
                console.log("checktype :>>>",this.mainObject.checktype);
                this.ifCheckAll = this.mainObject.checktype == 1 ? true : false;
                console.log("ifCheckAll :>>>",this.ifCheckAll);
                if (this.ifCheckAll) {
                    this.mainObject.checkqty = this.mainObject.qty;
                }
                this.goodRate = Math.round((Number(this.mainObject.checkqty) - Number(this.allbadqty))  * 100 / Number(this.mainObject.checkqty));
            },
            handleCheckQtyChange() {
                this.mainObject.checkqty = Number(this.mainObject.checkqty) > Number(this.mainObject.qty) ? Number(this.mainObject.qty) : Number(this.mainObject.checkqty);
                if(Number(this.mainObject.checkqty) == 0){
                    this.goodRate = 0;
                    return;
                }
                this.goodRate = Math.round((Number(this.mainObject.checkqty) - Number(this.allbadqty))  * 100 / Number(this.mainObject.checkqty));
            },
            handleCpcheckGoodQtyChange(){
                this.mainObject.goodqty = Number(this.mainObject.goodqty) > Number(this.mainObject.qty) ? Number(this.mainObject.qty) : Number(this.mainObject.goodqty);
            },
            handleCpcheckBadQtyChange(){
                 this.mainObject.badqty = Number(this.mainObject.badqty) > Number(this.mainObject.qty) ? Number(this.mainObject.qty) : Number(this.mainObject.badqty);
            },
            comparePicutre(propertyName) {
                return function(object1, object2) {
                    var value1 = object1[propertyName];
                    var value2 = object2[propertyName];
                    if (value2 > value1) {
                        return -1;
                    } else if (value2 < value1) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            },
            photoBrowser(index){
                var images = [];
                for (const picture of this.pictureList) {
                    if(picture.ifDBSave === 0){
                        images.push(picture.url);
                    }else{
                        var url = $lj.constant.cacheDir + "/" + picture.filemd5;
                        images.push(url);
                    }
                }
                $lj.photoBrowser(images, index);
            },
            handleBomDetail() {
                $lj.openWin("mtrl-use-detail", {orderid: this.mainObject.orderid});
                this.openTitle = false;
            },
            /**
             * @description 查看看物料详情
             */
             handleGotoMtrldef() {
                if(!this.mainObject.mtrlid) {
                    $ljWinCommon.toast("请先")
                }
                $lj.openWin("mtrldef-fj", {mainObject: this.mainObject});
                this.openTitle = false;
            },
            getCustProspecialItem() {
                var self = this;
                $lj.postLJRequest("GetCustProspecialItem", {
                    token: $lj.getStorage("token"),
                    cusid: this.mainObject.cusid,
                    mtrlid: this.mainObject.mtrlid
                }, function (ret) {
                    self.specialFiles = ret.specialitem.files
                })
            },
            handleSearchbar(){
                if (!this.keyword) {
                    $lj.toast("请先输入指令单号", 2000);
                    return;
                }
                this.getOrderMlInfo(this.keyword);
            },
            getOrderMlInfo(ordercode){
                let self = this;
                $lj.postLJRequest("GetOrderMsgZZCheck",{
                     token: $lj.getStorage("token"),
                    ordercode:ordercode
                },function(rsp){
                    if(rsp)
                    {
                        if(rsp.cpcheck){
                             self.mainObject = rsp.cpcheck
                             self.$set(self.mainObject,"checktype",1)
                             self.$set(self.mainObject,"goodqty",0)
                             self.$set(self.mainObject,"badqty",0)
                        }
                       else{
                           $lj.toast("该指令单不符合查询条件", 2000);
                       }
                    }
                })
            },
            getChecktype(){
                let self = this;
                 $lj.postLJRequest("GetL1Checktype",{
                     token: $lj.getStorage("token")
                },function(rsp){
                    if(rsp)
                    {
                        self.rawList = rsp.checktypeList
                    }
                })
            },
            hadleItemTypeClicked() {
                this.$refs.checktype.init();
                this.$refs.checktype.open();
            },
            handleItemSelected(item){
                console.log("dsds",JSON.stringify(item));
                if(item.typeid){
                    this.$set(this.mainObject,"itemtypeid",item.typeid)
                    this.$set(this.mainObject,"itemtype",item.typename)
                    this.handleAddMx();
                    // this.mxList = [];
                    // for(let i = 0 ; i<item.checkitemList.length;i++)
                    // {
                    //     var obj = {
                    //         printid : i+1,
                    //         checkitem_itemname:item.checkitemList[i].itemname,
                    //         itemid:item.checkitemList[i].itemid,
                    //         environmen:item.checkitemList[i].environmen,
                    //         method:item.checkitemList[i].method,
                    //         basis:item.checkitemList[i].basis,
                    //         equipment:item.checkitemList[i].equipment,
                    //         standard:item.checkitemList[i].standard,
                    //         goodqty:0,
                    //         badqty:0,
                    //         checkqty:0,
                    //         ch:false,
                    //         checkemp:this.userinfo.username
                    //     }
                    //     this.mxList.push(obj);
                    // }
                    // console.log("mxList",JSON.stringify( this.mxList))
                }
            },
            handleSaveNew(){
                if(!this.mainObject.relid){
                     alert("请输入指令单号");
                     return;
                }
                 if (Number(this.mainObject.qty) < Number(this.mainObject.checkqty)) {
                    alert("检验数数不能大于批量");
                    return;
                }
                if (Number(this.mainObject.checkqty) < Number(this.mainObject.badqty)) {
                    alert("总不合格数不能大于检验数");
                    return;
                }
                if(Number(this.mainObject.goodqty) + Number(this.mainObject.badqty) !== Number(this.mainObject.checkqty)){
                    alert("合格数与不合格数的和必须等于检验数,请检查!");
                    return;
                }

                // 如果开启AQL抽检判定，记录总缺陷数
                if (this.isAQLCheck) {
                    let aqljudge1_value = 0;
                    let aqljudge2_value = 0;
                    let aqljudge3_value = 0;
                    for (const item of this.mxList) {
                        aqljudge1_value = $lj.floatAdd(aqljudge1_value, item.aqljudge1_value);
                        aqljudge2_value = $lj.floatAdd(aqljudge2_value, item.aqljudge2_value);
                        aqljudge3_value = $lj.floatAdd(aqljudge3_value, item.aqljudge3_value);
                    }
                    this.mainObject.aqljudge1_value = aqljudge1_value;
                    this.mainObject.aqljudge2_value = aqljudge2_value;
                    this.mainObject.aqljudge3_value = aqljudge3_value;
                    console.warn(' this.mainObject :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.mainObject));
                }

                let self = this;
                 $lj.postLJRequest("NewCpckeckzzL1Save",{
                     token: $lj.getStorage("token"),
                     cpcheck:self.mainObject,
                     mxList:self.mxList
                },function(rsp){
                    if(rsp)
                    {
                        $lj.toast("保存成功！", 2000);
                        $lj.sendEvent("cpcheck_refresh");
                        $lj.closeWin();
                    }
                })
            },
            handleScan() {
                var self = this;
                $lj.openScanner(function(ret) {
                    var ordercode = ret.content;
                    if (ordercode == "") {
                        alert("请先输入指令单号!");
                        return;
                    }
                   self.getOrderMlInfo(ordercode)
                });
            },
            handleAddMx(){
                if(this.mainObject.itemtypeid > 0){
                    var checktype = this.rawList.find(item => item.typeid === this.mainObject.itemtypeid);
                    if(checktype){
                         this.mxList = [];
                        for(let i = 0 ; i<checktype.checkitemList.length;i++)
                        {
                            var obj = {
                                printid : i+1,
                                checkitem_itemname:checktype.checkitemList[i].itemname,
                                itemid:checktype.checkitemList[i].itemid,
                                environmen:checktype.checkitemList[i].environmen,
                                method:checktype.checkitemList[i].method,
                                basis:checktype.checkitemList[i].basis,
                                equipment:checktype.checkitemList[i].equipment,
                                standard:checktype.checkitemList[i].standard,
                                goodqty:0,
                                badqty:0,
                                checkqty:0,
                                ch:false,
                                checkemp:this.userInfo.username
                            }
                            this.mxList.push(obj);
                        }
                    }
                }
            },
            handleDelMx(){
                let tmpList = []
                let i = 0
                this.mxList.forEach(function (item,index,arr){
                    if(!item.ch){
                        item.printid = i+1;
                        tmpList.push(item);
                    }
                });
                this.mxList = tmpList;
            },
            handleInitAQLMx() {
                if (this.isAQLCheck) {
                    for (let i = 0; i < this.mxList.length; i++) {
                        if (this.mainObject.aqljudge1_goal && Number(this.mxList[i].aqljudge1_value) >= this.mainObject.aqljudge1_goal ||
                            this.mainObject.aqljudge2_goal && Number(this.mxList[i].aqljudge2_value) >= this.mainObject.aqljudge2_goal ||
                            this.mainObject.aqljudge3_goal && Number(this.mxList[i].aqljudge3_value) >= this.mainObject.aqljudge3_goal) {

                            this.$set(this.mxList[i],"QcResult",'不合格');
                        } else {
                            this.$set(this.mxList[i],"QcResult",'合格');
                        }
                    }
                }
            },
            handleCheckQtyFocus(ev) {
                ev.currentTarget && ev.currentTarget.select();
            },
            /** 表尾汇总 */
            getFooter(param) {
                let total = [];
                let result = [];
                const {columns, data, columnMap} = param;
                console.log('getFooter param :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(param));
                if (!columns || columns.length === 0) {
                    return total;
                }
                let colspan = 0;
                columns.forEach((column, index) => {
                    let ljColumn = columnMap.get(column.property);
                    console.log(' ljColumn :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(ljColumn));
                    if (ljColumn) {
                        let obj = {
                            property: ljColumn.property,
                            cellStyle: ljColumn.cellStyle,
                            colspan: 1,
                            class: ''
                        };
                        if (ljColumn.showCounter) {
                            obj.value = data.length
                        } else if (ljColumn.showSummary) {
                            let sum = 0;
                            data.forEach((item) => {
                                sum = $lj.floatAdd(sum, item[ljColumn.property]);
                            });
                            obj.value = sum;
                        } else {
                            obj.value = '';
                        }

                        if (colspan > 0) {
                            colspan--;
                            obj = null;
                        } else if (ljColumn.property == 'printid') {
                            colspan++;
                            obj.value = '小计';
                            obj.colspan = colspan + 1;
                        }
                        if (obj) {
                            total[index] = obj
                        }
                    }
                });
                result = JSON.parse(JSON.stringify(total));
                let ifAllPass = true;
                for (const key in result) {
                    if (result[key] && result[key].property == 'printid') {
                        result[key].value = '质检结果'
                    } else if (result[key] && result[key].property.indexOf('aqljudge') > -1) {
                        let propGoal = result[key].property.replace("_value", "_goal");
                        if (this.mainObject[propGoal] && Number(result[key].value) >= this.mainObject[propGoal]){
                            result[key].value = '不合格'
                            result[key].cellStyle.color = '#FF3B30';
                            ifAllPass = false;
                        } else {
                            result[key].value = '合格'
                            result[key].cellStyle.color = '#000';
                        }
                    } else if (result[key] && result[key].property == 'QcResult') {
                        if (ifAllPass) {
                            result[key].value = '通过';
                            result[key].cellStyle.color = '#219653';
                        } else {
                            result[key].value = '不通过'
                            result[key].cellStyle.color = '#FF3B30';
                        }
                        this.ifAllPass_aql = ifAllPass;
                    }
                }
                for (const ikey in total) {
                    if (total[ikey] && total[ikey].property.indexOf('aqljudge') > -1) {
                        let propGoal = total[ikey].property.replace("_value", "_goal");
                        let value = total[ikey].value;
                        if (this.mainObject[propGoal] && Number(value) >= this.mainObject[propGoal]) {
                            total[ikey].value = '≥' + this.mainObject[propGoal];
                            total[ikey].class = 'red';
                        } else {
                            total[ikey].value = '<' + this.mainObject[propGoal];
                            total[ikey].class = 'gray';
                        }
                    }
                }
                console.log('getFooter [total, result] :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify([total, result]));
                this.$refs.cpcheckGrid && this.$refs.cpcheckGrid.fnScrollX();
                return [total, result];
            },
            setRowStyle(rowIndex, row) {
                if (this.mainObject.aqljudge1_goal && Number(row.aqljudge1_value) >= this.mainObject.aqljudge1_goal ||
                    this.mainObject.aqljudge2_goal && Number(row.aqljudge2_value) >= this.mainObject.aqljudge2_goal ||
                    this.mainObject.aqljudge3_goal && Number(row.aqljudge3_value) >= this.mainObject.aqljudge3_goal) {
                    return {
                        color: '#FF3B30', //red
                        height: '32px'
                    }
                } else {
                    return {
                        height: '32px'
                    }
                }
            },
            setGridColumns(){
                let data = [];
                if(this.isAQLCheck){
                    data = [
                        {label: "序", property: "printid", width: screen.width * 0.1},
                        {label: "检验项目", property: "checkitem_itemname", width: screen.width * 0.2, slot: this.checkItemSlotRender}
                    ];
                    if (this.mainObject.aqljudge1_goal > 0) {
                        let obj = {label: "严重\r\n缺陷数", property: "aqljudge1_value", width: screen.width * 0.15, type: "number", editable: true, showSummary: true};
                        if (!this.ifedit){
                            obj.editable = false;
                        }
                        data.push(obj);
                    }
                    if (this.mainObject.aqljudge2_goal > 0) {
                        let obj = {label: "主要\r\n缺陷数", property: "aqljudge2_value", width: screen.width * 0.15, type: "number", editable: true, showSummary: true};
                        if (!this.ifedit){
                            obj.editable = false;
                        }
                        data.push(obj);
                    }
                    if (this.mainObject.aqljudge3_goal > 0) {
                        let obj = {label: "轻微\r\n缺陷数", property: "aqljudge3_value", width: screen.width * 0.15, type: "number", editable: true, showSummary: true};
                        if (!this.ifedit){
                            obj.editable = false;
                        }
                        data.push(obj);
                    }
                    let data2 = [
                        {label: "单项\r\n结果", property: "QcResult", width: screen.width * 0.15},
                        {label: "", property: "picPhoto", icon: "iconfont icon-camera1", width: screen.width * 0.1 , type: "pic"},
                        {label: "方法", property: "Method", width: screen.width * 0.2},
                    ];
                    this.gridColumns = data.concat(data2);
                } else if(this.ifadd){
                    data = [
                        {label: "选", property: "ch", width: screen.width * 0.1,type:"selection"},
                        {label: "序", property: "printid", width: screen.width * 0.1},
                        {label: "检验项目", property: "checkitem_itemname", width: screen.width * 0.2},
                        {label: "质检结果", property: "QcResult", width: screen.width * 0.3, editable: true,slot: this.checkItemSlotRender},
                        {label: "合格数", property: "goodqty", width: screen.width * 0.2, type: "number", editable: true},
                        {label: "不合格数", property: "badqty", width: screen.width * 0.2, type: "number", editable: true},
                        {label: "检验数", property: "checkqty", width: screen.width * 0.2, type: "number", editable: true},
                        {label: "质检人", property: "checkemp", width: screen.width * 0.2, editable: true},
                        {label: "标准", property: "standard", width: screen.width * 0.2 , editable:true},
                        {label: "环境", property: "environmen", width: screen.width * 0.2 , editable:true},
                        {label: "方法", property: "method", width: screen.width * 0.2 , editable:true},
                        {label: "依据", property: "basis", width: screen.width * 0.2 , editable:true},
                        {label: "设备", property: "equipment", width: screen.width * 0.2 , editable:true},
                        {label:"明细备注",property:"mxdscrp",width:screen.width * 0.3,editable:true}
                    ]

                    this.gridColumns = data;
                } else {
                    if (!this.ifmulti) {
                        data = [
                            {label: "序", property: "printid", width: screen.width * 0.1},
                            {label: "检验项目", property: "checkitem_itemname", width: screen.width * 0.2},
                            {label: "标准", property: "picHelp", icon: "iconfont icon-help1", width: screen.width * 0.1 , type: "pic"},
                            {label: "不合格数", property: "badqty", width: screen.width * 0.2, type: "number", editable: true},
                            {label: "质检结果", property: "QcResult", width: screen.width * 0.3, editable: true,slot: this.checkItemSlotRender},
                            {label: "", property: "picPhoto", icon: "iconfont icon-camera1", width: screen.width * 0.1 , type: "pic"}
                        ]
                    }
                    else {
                        data = [
                            {label: "序", property: "printid", width: screen.width * 0.1},
                            {label: "检验项目", property: "checkitem_itemname", width: screen.width * 0.2},
                            {label: "标准", property: "picHelp", icon: "iconfont icon-help1", width: screen.width * 0.1 , type: "pic"},
                            {label: "不合格数", property: "badqty", width: screen.width * 0.2, type: "number", editable: true},
                            {label: "质检结果", property: "QcResult", width: screen.width * 0.3, editable: true,slot: this.checkItemSlotRender},
                            // {label: "质检结果1", property: "QcResult1", width: screen.width * 0.3, editable: true},
                            // {label: "质检结果2", property: "QcResult2", width: screen.width * 0.3, editable: true},
                            // {label: "质检结果3", property: "QcResult3", width: screen.width * 0.3, editable: true},
                            // {label: "质检结果4", property: "QcResult4", width: screen.width * 0.3, editable: true},
                            // {label: "质检结果5", property: "QcResult5", width: screen.width * 0.3, editable: true},
                            {label: "", property: "picPhoto", icon: "iconfont icon-camera1", width: screen.width * 0.1 , type: "pic"}
                        ]
                    }

                    this.gridColumns = data;
                }
            },
            checkItemSlotRender(h, {row, column, rowIndex}) {
                let self = this;
                if(row.inputway == 1) {
                    // 选择
                    return h('div', {
                        domProps: {
                            innerHTML: `<span>${row[column.property] == "" ? "请选择" : row[column.property]}</span>`
                        },
                        style: {
                            width: "100%",
                            color: "#2196f3"
                        },
                        on: {
                            click: function (event) {
                                self.handleGetCheckItemResult(row);
                            }
                        }
                    });
                } else {
                    // 录入
                    let inputElement;
                    inputElement = h("input", {
                        attrs: {
                            disabled: false,
                            type: "text"
                        },
                        domProps: {
                            value: row[column.property]
                        },
                        style: {
                            textAlign: "right",
                            width: "100%",
                            color: "#2196f3"
                        },
                        on: {
                            input: function (event) {
                                self.$set(row, column.property, event.target.value);
                            },
                            focus: function (event) {
                                inputElement.elm.select();
                            },
                            blur: function (event) {
                                let curValue = row[column.property];
                                self.$set(row, column.property, curValue);
                            }
                        }
                    });
                    return inputElement;
                }
            },
            handleGetCheckItemResult(row) {
                this.checkItemResultActions = [];
                $lj.postLJRequest("CommonDynamicSelect", {
                    token: $lj.getStorage("token"),
                    dsname: "app_checkitem_result_list",
                    queryparams: {
                        itemid: row.itemid
                    }
                }, (ret) => {
                    if(ret) {
                        for(let item of ret.datatable) {
                            this.checkItemResultActions.push({id: item.mxid,name: item.result});
                        }
                        this.checkItemRow = row;
                        this.checkItemState = true;
                    }
                })
            },
            handleSelCheckItemResult(action) {
                this.mxList.forEach(element => {
                    if(element.itemid === this.checkItemRow.itemid) {
                        this.$set(element,"QcResult",action.name);
                    }
                });
                this.checkItemState = false;
            }
        },
        computed: {
            title() {
                if(this.ifedit){
                    if(this.ifadd){
                        return "自制质检单-新建"
                    }
                    else{
                        return "自制质检单-编辑";
                    }
                }else{
                    return "自制质检单-明细";
                }
            },
            isAQLCheck() {
                if (!this.ifCheckAll && this.mainObject.hasOwnProperty('ifaqljudge') && this.mainObject.ifaqljudge == 1) {
                    return true
                }
                return false
            }
        },
        filters: {
            checkTypeFormat(checktype) {
                switch (checktype) {
                    case 0:
                        return "抽检";
                        break;
                    case 1:
                        return "全检";
                        break;
                }
            }
        }
    }
</script>
<style>
.mu-input.is-solo{
    padding: 0;
}
.mu-input {
    font-size: 14px;
    min-height: 1px;
}
.mu-text-field-input {
    height: auto;
    color: #2196F3;
}
</style>
