<template>
    <basic-container style="max-height: 800px; overflow: hidden">
        <avue-crud :search.sync="searchForm" :option="option" :table-loading="loading" :data="data" :page.sync="page"
            ref="crud" v-model="form" :permission="permissionList" :before-open="beforeOpen" :before-close="beforeClose"
            @search-change="searchChange" @search-reset="searchReset" @current-change="currentChange"
            @size-change="sizeChange" @refresh-change="refreshChange" @selection-change="selectSection">
            <template slot-scope="{row}" slot="menu">
                <el-button size="small" v-show="permission.knowledgeView" @click="handleView(row)">查看</el-button>
            </template>
            <template slot-scope="scope" slot="menuLeft">
                <el-button v-show="permission.workApply" type="primary" @click="handleApply">申请</el-button>
            </template>
            <template slot-scope="{ row }" slot="business_type">
                {{ row.business_type == 1 ? '需求工单' : '巡检维修' }}
            </template>
        </avue-crud>
        <el-dialog title="发票申请" :visible.sync="dialogVisible" :append-to-body="true" width="70%" :close-on-click-modal="false">
            <div style="height: 500px; overflow: auto">
                <el-form ref="form" :model="addForm" :rules="addRules" label-width="130px" label-position="left">
                    <el-form-item label="公司税号" prop="taxCode">
                        <el-select v-model="addForm.taxCode" style="width: 98%;" placeholder="公司税号" @change="changeTaxcode">
                            <el-option v-for="item in dutyList" :key="item.id" :label="item.taxCode" :value="item.taxCode"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="公司名称" prop="companyName">
                        <el-input placeholder="请输入公司名称" disabled v-model="addForm.companyName" style="width: 98%;"></el-input>
                    </el-form-item>
                    <el-form-item label="申请明细">
                        <el-table :data="addForm.tableData" border style="width: 98%">
                            <el-table-column width="50" align="center">
                                <template slot-scope="scope">
                                    <div @click="deleteColumn(scope.row, scope.$index)"
                                    style="width:30px;height: 30px;background: #f56c6c;border-radius: 50%;cursor: pointer;display: flex;align-items: center;justify-content: center;">
                                    <i style="color:#fff;font-size: 20px;" class="el-icon-delete"></i>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column label="工单单号" prop="business_code"></el-table-column>
                            <el-table-column label="维修人员" prop="serviceman"></el-table-column>
                            <el-table-column label="工单类型" prop="business_type">
                                <template slot-scope="scope">
                                    {{ scope.row.business_type == 1 ? '需求工单' : '巡检维修' }}
                                </template>
                            </el-table-column>
                            <el-table-column label="工单价格" prop="price"></el-table-column>
                        </el-table>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose">关闭</el-button>
                <el-button  type="primary" @click="handleRepairConfirm">提交</el-button>
            </span>
        </el-dialog>
        <el-dialog title="查看详情" :visible.sync="dialogView" :append-to-body="true" width="70%" :close-on-click-modal="false">
            <div v-show="businessType == 1" style="height:500px;overflow:auto;">
                <el-form ref="form" :model="detailForm" label-width="150px" label-position="left">
                    <div>
                        <div style="
                            color: #101010;
                            font-size: 20px;
                            font-weight: 550;
                            margin-bottom: 20px;
                        ">
                        故障信息
                        </div>
                        <el-form-item label="填报人" prop="informantName" >
                            <el-input placeholder="请输入填报人" disabled v-model="detailForm.informantName" style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="填报人电话" prop="informantPhone" >
                            <el-input placeholder="请输入填报人电话" disabled v-model="detailForm.informantPhone"
                            style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="故障现象描述" prop="faultDescribe">
                            <el-input placeholder="请输入故障现象描述" disabled type="textarea" v-model="detailForm.faultDescribe"
                            style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="故障位置" prop="faultLocation" >
                            <el-input placeholder="请输入故障位置" disabled v-model="detailForm.faultLocation"
                            style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="设备名称" prop="deviceName" >
                            <el-input placeholder="请输入设备名称" v-model="detailForm.deviceName" disabled style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="故障专业类型" prop="faultType" >
                            <el-input placeholder="请输入故障专业类型" v-model="detailForm.faultType" disabled style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="故障视频" v-show="detailForm.errorVideo != ''">
                            <video v-show="detailForm.errorVideo != ''" :src="detailForm.errorVideo"
                                style="width: 148px; height: 148px" controls></video>
                        </el-form-item>
                        <el-form-item label="故障图片"
                        v-show="detailForm.errorImg && detailForm.errorImg.length != 0">
                            <img v-for="item in detailForm.errorImg" :key="item" :src="item.url" alt=""
                            style="width: 148px; height: 148px;margin-right:10px;">
                        </el-form-item>
                        <el-form-item label="提报时间">
                            <el-date-picker v-model="detailForm.fillingTime" type="datetime" style="width:98%;" disabled
                                placeholder="选择日期时间">
                            </el-date-picker>
                        </el-form-item>
                    </div>
                    <div>
                        <div style="
                            color: #101010;
                            font-size: 20px;
                            font-weight: 550;
                            margin-bottom: 20px;
                        ">
                        处理情况
                        </div>
                        <el-form-item label="接单时间">
                        <el-date-picker v-model="detailForm.dispatchTime" type="datetime" disabled style="width:98%;"
                            placeholder="选择日期时间">
                        </el-date-picker>
                        </el-form-item>
                        <el-form-item label="客服意见">
                        <el-input type="textarea" v-model="detailForm.customerOpinion" disabled style="width: 98%;"></el-input>
                        </el-form-item>
                    </div>
                    <div>
                        <div style="
                            color: #101010;
                            font-size: 20px;
                            font-weight: 550;
                            margin-bottom: 20px;
                        ">
                        维修详情
                        </div>
                        <el-form-item label="填报人" prop="repairPersonName">
                        <el-input placeholder="请输入填报人" disabled v-model="detailForm.repairPersonName"
                            style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="设备名称" prop="deviceId">
                        <el-input placeholder="请输入设备名称" v-model="detailForm.deviceName" disabled style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="故障原因" prop="faultCause">
                        <el-input placeholder="请输入故障原因" disabled type="textarea" v-model="detailForm.faultCause"
                            style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="处理方法" prop="processMethod">
                        <el-input placeholder="请输入处理方法" disabled type="textarea" v-model="detailForm.processMethod"
                            style="width: 98%;"></el-input>
                        </el-form-item>
                        <el-form-item label="人工费" prop="laborCost">
                        <el-input placeholder="请输入人工费"
                            disabled v-model="detailForm.laborCost" style="width:98%;"><template slot="append">元</template>
                        </el-input>
                        </el-form-item>
                        <el-form-item label="差旅费" prop="travelExpense">
                        <el-input placeholder="请输入差旅费"
                            disabled v-model="detailForm.travelExpense" style="width:98%;"><template slot="append">元</template></el-input>
                        </el-form-item>
                        <el-form-item label="维修材料" v-show="detailForm.isNeedMaterial == 1">
                        <el-table :data="detailForm.materials" border style="width: 98%">
                            <el-table-column prop="materialName" align="center" label="物料名称">
                            </el-table-column>
                            <el-table-column prop="materialCount" align="center" label="数量">
                            </el-table-column>
                            <el-table-column prop="materialPrice" align="center" label="金额">
                            </el-table-column>
                            <template slot="append">
                            <tr>
                                <td style="padding: 10px;padding-right: 0;font-size: 14px;color: #909399;font-weight: 600;">总计:</td>
                                <td>{{ detailForm.totalPrice }} 元</td>
                                <td style="padding: 10px 0px 10px 100px; font-size: 14px;color: #909399;font-weight: 600;">折扣:</td>
                                <td>
                                <el-input v-model="detailForm.discount" controls-position="right" @input="handleInput"
                                    @change="changeDiscount" disabled>
                                    <template slot="append">折</template>
                                </el-input>
                                </td>
                                <td style="padding: 10px 0px 10px 100px;font-size: 14px;color: #909399;font-weight: 600;">折后金额:</td>
                                <td>{{ detailForm.discountPrice }}<span v-show="discountPrice != ''">元</span></td>
                            </tr>
                            </template>
                        </el-table>
                        </el-form-item>
                    </div>
                </el-form>
            </div>
            <div v-show="businessType == 2" style="height:500px;overflow:auto;">
                <el-form ref="errorForm" :model="errorForm" :rules="addRules" label-width="120px" label-position="left">
                    <div>
                        <div style="
                            color: #101010;
                            font-size: 20px;
                            font-weight: 550;
                            margin-bottom: 20px;
                            ">
                        基本信息
                        </div>
                        <el-form-item label="单位名称" prop="deptName">
                        <el-input placeholder="请输入单位名称" readonly v-model="errorForm.deptName" disabled
                            style="width: 98%;"></el-input>
                        </el-form-item>
                    </div>
                    <div>
                        <div style="
                            color: #101010;
                            font-size: 20px;
                            font-weight: 550;
                            margin-bottom: 20px;
                            ">
                        巡检异常清单
                        </div>
                        <el-form-item label="异常清单">
                        <el-table :span-method="errorSpanMethod" :data="errorForm.tableData" border style="width: 98%"
                            :summary-method="getSummaries" show-summary :row-class-name="tableRowClassName">
                            <el-table-column label="楼层" prop="floorName"></el-table-column>
                            <el-table-column label="房间名称" prop="deptName"></el-table-column>
                            <el-table-column label="专业/设备" prop="deviceName"></el-table-column>
                            <el-table-column label="巡检内容" prop="checkContent"></el-table-column>
                            <el-table-column label="工艺要求" prop="craft"></el-table-column>
                            <el-table-column label="状态" prop="status" v-if="errorForm.repairStatus != 1">
                            <template slot-scope="scope">
                                {{ scope.row.status == 1 ? '异常' : '正常' }}
                            </template>
                            </el-table-column>
                            <!-- <el-table-column label="价格" prop="price" v-if="errorForm.repairStatus != 1"></el-table-column>
                            <el-table-column label="价格" prop="price" v-if="errorForm.repairStatus == 1">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.price"
                                :disabled="viewType == 'view' || viewType == 'evaluate' || viewType == 'confirm'"></el-input>
                            </template>
                            </el-table-column> -->
                            <el-table-column prop="isRepair" align="center" label="是否维修" v-if="errorForm.repairStatus >= 3">
                            <template slot-scope="scope">
                                <el-radio-group v-model="scope.row.isRepair" fill="red">
                                <el-radio :disabled="viewType == 'view' || viewType == 'evaluate'||dataTypes != 1" :label="1">是</el-radio>
                                <el-radio :disabled="viewType == 'view' || viewType == 'evaluate'||dataTypes != 1" class="error_radio"
                                    :label="0">否</el-radio>
                                </el-radio-group>
                            </template>
                            </el-table-column>
                            <el-table-column prop="isNeed" align="center" label="是否需要物料">
                            <template slot-scope="scope">
                                <el-radio-group v-model="scope.row.isNeed" fill="red">
                                <!-- || errorForm.repairStatus != 1 -->
                                <el-radio :disabled="viewType == 'view' || errorForm.repairStatus != 1" :label="'1'">是</el-radio>
                                <el-radio :disabled="viewType == 'view' || errorForm.repairStatus != 1" class="error_radio"
                                    :label="'0'">否</el-radio>
                                </el-radio-group>
                            </template>
                            </el-table-column>
                            <el-table-column align="center" label="物料配置">
                            <template slot-scope="scope">
                                <el-button @click="setMaterial(scope.row)" :disabled="scope.row.isNeed == 0">物料配置</el-button>
                            </template>
                            </el-table-column>
                        </el-table>
                        </el-form-item>
                        <el-form-item label="故障现象">
                        <el-input placeholder="请输入故障现象描述" type="textarea" v-model="errorForm.faultDescribe" style="width:98%;"
                            :disabled="viewType == 'view' || errorForm.repairStatus != 1"></el-input>
                        </el-form-item>
                        <el-form-item label="故障产生原因">
                        <el-input placeholder="请输入故障产生原因" type="textarea" v-model="errorForm.faultCause" style="width:98%;"
                            :disabled="viewType == 'view' || errorForm.repairStatus != 1"></el-input>
                        </el-form-item>
                        <el-form-item label="处理结果">
                        <el-input placeholder="请输入处理结果" type="textarea" v-model="errorForm.processingResult" style="width:98%;"
                            :disabled="viewType == 'view' || errorForm.repairStatus != 1"></el-input>
                        </el-form-item>
                        <el-form-item label="差旅费">
                        <el-input placeholder="请输入差旅费" v-model="errorForm.travelExpense" style="width:98%;"
                            :disabled="viewType == 'view' || errorForm.repairStatus != 1"><template
                            slot="append">元</template></el-input>
                        </el-form-item>
                        <el-form-item label="巡检结论">
                        <el-input placeholder="请输入巡检结论" type="textarea" v-model="errorForm.inspectionConclusion"
                            style="width:98%;" :disabled="viewType == 'view' || errorForm.repairStatus != 1"></el-input>
                        </el-form-item>
                    </div>

                    <div
                        v-show="((errorForm.repairStatus == 2 || errorForm.repairStatus == 102) || ((errorForm.repairStatus == 1 || errorForm.repairStatus == 101) && errorForm.approvePoint == '主管审核维修方案')) && viewType != 'view'">
                        <div style="
                            color: #101010;
                            font-size: 20px;
                            font-weight: 550;
                            margin-bottom: 20px;
                            ">
                        主管审核
                        </div>
                        <el-form-item label="审核结果">
                        <el-select placeholder="请选择审核结果" v-model="errorForm.approveResult" style="width: 98%;"
                            :disabled="(errorForm.repairStatus == 1 || errorForm.repairStatus == 101) && errorForm.approvePoint == '主管审核维修方案'">
                            <el-option label="通过" :value="1"></el-option>
                            <el-option label="驳回" :value="0"></el-option>
                        </el-select>
                        </el-form-item>
                        <el-form-item v-if="errorForm.approveResult === 0" label="驳回意见">
                        <el-input type="textarea" v-model="errorForm.approveRemark" style="width: 98%;"
                            :disabled="(errorForm.repairStatus == 1 || errorForm.repairStatus == 101) && errorForm.approvePoint == '主管审核维修方案'"></el-input>
                        </el-form-item>
                        <el-form-item
                        v-if="(errorForm.repairStatus == 1 || errorForm.repairStatus == 101) && errorForm.approvePoint == '主管审核维修方案'"
                        label="审批时间">
                        <el-input v-model="errorForm.approveTime" style="width: 98%;"
                            :disabled="(errorForm.repairStatus == 1 || errorForm.repairStatus == 101) && errorForm.approvePoint == '主管审核维修方案'"></el-input>
                        </el-form-item>
                    </div>

                    <!-- 维修完成 -->
                    <div v-show="errorForm.repairStatus == 4 || errorForm.repairStatus == 5 || errorForm.repairStatus == 6 || errorForm.repairStatus == 7 || errorForm.repairStatus == 8">
                        <el-form-item label="维修完成图片" prop="signaturePerson" v-if="errorForm.repairStatus == 4">
                        <el-upload action="/api/blade-resource/oss/endpoint/put-file" list-type="picture-card" :headers="headers"
                            accept=".jpeg,.jpg,.png,.pdf" :file-list="completeImgList" :on-success="handleSuccess"
                            :on-remove="handleRemove">
                            <i class="el-icon-plus"></i>
                        </el-upload>
                        </el-form-item>
                        <el-form-item label="维修完成图片" prop="signaturePerson" v-else>
                        <img v-for="item in completeImgList" :key="item" :src="item.url" alt=""
                            style="width: 148px; height: 148px;margin-right:10px;">
                        </el-form-item>
                    </div>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogView = false" type="primary">关 闭</el-button>
            </span>
        </el-dialog>
        <el-dialog :close-on-click-modal="false" title="物料配置" :visible.sync="materialVisible" :append-to-body="true"
        width="70%" :key="Math.random()">
        <el-table :data="materialData" border style="width: 98%">
            <el-table-column width="50" align="center" v-if="viewType == 'submit'">
            <template slot="header" slot-scope="scope">
                <div @click="addColumn()"
                style="width:30px;height: 30px;background: #409eff;border-radius: 50%;cursor: pointer;display: flex;align-items: center;justify-content: center;">
                <i style="color:#fff;font-size: 20px;" class="el-icon-plus"></i>
                </div>
            </template>
            <template slot-scope="scope">
                <div @click="deleteColumn(scope.row, scope.$index)"
                style="width:30px;height: 30px;background: #f56c6c;border-radius: 50%;cursor: pointer;display: flex;align-items: center;justify-content: center;">
                <i style="color:#fff;font-size: 20px;" class="el-icon-delete"></i>
                </div>
            </template>
            </el-table-column>
            <el-table-column prop="productId" align="center" label="物料名称">
            <template slot-scope="scope">
                <el-select @change="((val) => { changeProduct(val, scope.$index) })"
                @blur="((val) => { changeProduct(val, scope.$index) })" v-loadmore="loadmoreProduct"
                v-model="scope.row.productId" filterable remote :remote-method="remoteMethodProduct" placeholder="请选择物品"
                :disabled="viewType != 'submit'">
                <el-option v-for="item in productLists" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </template>
            </el-table-column>
            <el-table-column prop="warehouseId" label="库存ID" align="center">
            <!-- <template slot-scope="scope">
                    <el-input @change="clickInventoryId" placeholder="请输入库存ID" v-model="scope.row.inventoryId"></el-input>
                    </template> -->
            </el-table-column>
            <el-table-column prop="rule" align="center" label="规格" width="80">
            <!-- <template slot-scope="scope">
                    <el-input v-model="scope.row.rule" placeholder="请输入规格" style="width:98%;"></el-input>
                    </template> -->
            </el-table-column>
            <el-table-column prop="xh" align="center" label="型号" width="80">
            <!-- <template slot-scope="scope">
                    <el-input v-model="scope.row.model" placeholder="请输入型号" style="width:98%;"></el-input>
                    </template> -->
            </el-table-column>
            <el-table-column prop="number" align="center" label="数量">
            <template slot-scope="scope">
                <el-input-number style="width: 100%;" @change="((val) => { changeNumber(val, scope.row) })"
                v-model="scope.row.number" placeholder="请输入数量" :min="1"
                :disabled="viewType != 'submit'"></el-input-number>
            </template>
            </el-table-column>
            <el-table-column prop="unit" align="center" label="单位" width="80">
            <!-- <template slot-scope="scope">
                    <el-input v-model="scope.row.unit" placeholder="请输入单位" style="width:98%;"></el-input>
                    </template> -->
            </el-table-column>
            <el-table-column prop="price" align="center" label="价格" width="200">
            <template slot-scope="scope">
                <el-input v-model="scope.row.price" disabled placeholder="请输入价格" style="width:98%;">
                <template slot="append">元</template>
                </el-input>
            </template>
            </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
            <el-button @click="materialVisible = false" type="primary">确 定</el-button>
        </span>
        </el-dialog>
    </basic-container>
</template>

<script>
import {getInvoiceList} from '@/api/system/user'
import { getGoodsList } from '@/api/goodsManagement/goods'
import {getList,saveSubmit,getRepairDetail,getInspectionDetail} from '@/api/invoiceManagement/applyManage'
import { mapGetters } from "vuex";
export default {
    data(){
        return {
            searchForm:{},
            dialogView:false,
            businessType:null,
            option:{
                height: "auto",
                calcHeight: 30,
                tip: false,
                searchShow: true,
                searchMenuSpan: 6,
                border: true,
                index: true,
                dialogType: "dialog",
                dialogClickModal: false,
                addBtn: false,
                viewBtn: false,
                editBtn: false,
                delBtn: false,
                searchShowBtn: false,
                refreshBtn: false,
                columnBtn: false,
                selection: true,
                reserveSelection:true,
                menu:true,
                column: [
                    {
                        label:'工单单号',
                        prop: "business_code",
                    },
                    {
                        label:'工单类型',
                        prop: "business_type",
                        slot:true
                    },
                    // {
                    //     label:'维修人员',
                    //     prop: "serviceman",
                    // },
                    {
                        label:'价格',
                        prop: "price",
                    }
                ]
            },
            addRules:{
                taxCode:{required:true,message:'请选择公司税号',trigger:'change'},
                companyName:{required:true,message:'请输入公司名称',trigger:'change'}
            },
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            data:[],
            selectList:[],
            dialogVisible:false,
            addForm:{},
            dutyList:[],
            detailForm:{},
            errorForm:{},
            materialId:'',
            materialData:'',
            materialVisible:false,
            productLists:[]
        }
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
    },
    mounted(){
        this.onLoad()
    },
    methods:{
        onLoad(){
            getList().then(res =>{
                console.log('res==========>',res)
                this.data = res.data.data.records
            })
        },
        selectSection(selection) {
            this.selectList = selection
        },
        // 切换税号
        changeTaxcode(val){
            this.addForm.companyName = this.dutyList.find(item => item.taxCode == val).companyName
        },
        // 点击申请按钮
        handleApply(){
            if(this.selectList.length == 0){
                this.$message.warning('请至少选择一条数据')
            }else{
                getInvoiceList().then(res =>{
                    this.dutyList = res.data.data
                    if(this.dutyList.length == 0){
                        this.$message.error('发票信息未维护，请前往个人信息页维护发票信息')
                    }else{
                        this.addForm.tableData = this.selectList
                        this.dialogVisible = true
                    }
                })
            }
        },
        handleView(row){
            this.businessType = row.business_type
            if(row.business_type == 1){
                getRepairDetail({id:row.business_id}).then(res =>{
                    console.log('res----------->',res)
                    this.detailForm = res.data.data
                    this.detailForm.errorVideo = res.data.data.videoAttaches.length > 0 ? res.data.data.videoAttaches[0].link : ''
                    this.dialogView = true
                })
            }else{
                getInspectionDetail({id:row.business_id}).then(res =>{
                    this.errorForm = res.data.data
                    this.dialogView = true
                    let data = this.checkDeepData(res.data.data.details)
                    if (this.errorForm.repairStatus > 1) {
                        data.forEach(item => {
                        if (item.detailGoodsList.length > 0) {
                            item.isNeed = '1'
                        } else {
                            item.isNeed = '0'
                        }
                        })
                    }
                    this.errorForm.tableData = []
                    this.errorForm.tableData = data
                    this.errorForm.tableData.map(item => {
                        item.price = item.price == -1 ? '' : item.price
                    })
                    // completeImgList
                    this.completeImgList = this.errorForm.completeImgList!=''?JSON.parse(this.errorForm.completeImgList):[]
                    this.errorForm.approveResult1 = this.errorForm.approveResult
                    this.nameImg = ''
                    this.getSpanArr(this.errorForm.tableData)
                })
            }
        },
        setMaterial(row) {
            this.materialId = row.id
            this.getProductLists()
            this.materialData = row.detailGoodsList
            this.materialVisible = true
        },
        getProductLists(type, val, inventoryId) {
            getGoodsList({ current: 1, size:99999, name: val ? val : null }).then(res => {
                if (type == 'more') {
                this.productLists = this.productLists.concat(res.data.data.records)
                this.productTotals = res.data.data.total
                } else {
                this.productLists = res.data.data.records
                this.productTotals = res.data.data.total
                }
            })
        },
        // 物料总价
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                sums[index] = '合计';
                return;
                }
                const values = data.map(item => {
                let price = null
                if (item.detailGoodsList.length > 0) {
                    price = item.detailGoodsList.reduce((sum, items) => sum + items.price, 0)
                    return price
                }
                });
                if (!values.every(value => isNaN(value))) {
                sums[columns.length - 1] = values.reduce((prev, curr) => {
                    const value = Number(curr);

                    if (!isNaN(value)) {
                    return prev + curr;
                    } else {
                    return prev;
                    }
                }, 0);

                sums[columns.length - 1] = sums[columns.length - 1] > 0 ? sums[columns.length - 1].toFixed(2) : 0
                this.totalPrice = sums[columns.length - 1]
                sums[columns.length - 1] += ' 元';
                }
            });
            return sums;
        },
        //用于回调的函数
        checkData(data, list) {
            data.forEach((item) => {
                if (item.details && item.details.length > 0) {
                this.checkData(item.details, list);
                } else {
                list.push(item);
                }
            });
            return list;
        },
        //调用此函数 返回的就是最底层的数据
        checkDeepData(data) {
            const list = [];
            return this.checkData(data, list);
        },
        getSpanArr(data) {
            for (var i = 0; i < data.length; i++) {
                if (i === 0) {
                this.spanArr.push(1);
                this.pos = 0
                } else {
                // 判断当前元素与上一个元素是否相同
                if (data[i].floorName === data[i - 1].floorName) {
                    this.spanArr[this.pos] += 1;
                    this.spanArr.push(0);
                } else {
                    this.spanArr.push(1);
                    this.pos = i;
                }
                }
            }
        },
        // 申请明细删除
        deleteColumn(row, index) {
            console.log('this.addForm.tableData',this.addForm.tableData)
            if(this.addForm.tableData.length > 1){
                this.addForm.tableData.splice(index, 1);
            }else{
                this.$message.error('至少保留一条申请明细')
            }
        },
        // 点击弹窗关闭按钮
        handleClose(){
            this.dialogVisible = false
            this.addForm = {}
        },
        handleRepairConfirm(){
            this.$refs.form.validate(valid =>{
                if(valid){
                    let data = []
                    this.addForm.tableData.map(item =>{
                        console.log('item------------>',item)
                        data.push({
                            businessId:item.business_id,
                            businessType:item.business_type,
                            businessCode:item.business_code,
                            serviceman:item.serviceman,
                            unitPrice:item.price
                        })
                    })
                    let query = {
                        apply:{
                            taxCode:this.addForm.taxCode,
                            companyName:this.addForm.companyName,
                            applyUser:this.userInfo.user_id,
                            price:this.addForm.tableData.reduce((sum, item) => sum + Number(item.price), 0)
                        },
                        detailList:data
                    }
                    console.log('query',query)
                    saveSubmit(query).then(res =>{
                        if(res.data.code == 200){
                            this.$message.success('申请成功')
                            this.dialogVisible = false
                            this.onLoad()
                        }
                    })
                }
            })
        },
    }
}
</script>

<style>

</style>
