<!-- 钻头使用情况 -->
<template>
    <div class="app-container">
        <!-- 搜索区域 -->
        <div class="search-wrapper">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                label-width="68px">
                <!-- <el-form-item label="区块名称" prop="qk">
                    <el-select v-model="queryParams.qk" placeholder="请选择区块名称" clearable filterable>
                        <el-option v-for="item in filteredBlockOptions" :key="item.qk" :label="item.qk"
                            :value="item.qk" />
                    </el-select>
                </el-form-item>
                <el-form-item label="井号" prop="jhs">
                    <el-input v-model="queryParams.jhs" placeholder="请输入井号" clearable
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="完井日期" prop="wjrq">
                    <el-date-picker v-model="queryParams.wjrqks" type="year" value-format="yyyy" placeholder="完井开始年份">
                    </el-date-picker>
                    -
                    <el-date-picker v-model="queryParams.wjrqjs" type="year" value-format="yyyy" placeholder="完井结束年份">
                    </el-date-picker>
                </el-form-item> -->
                <el-form-item>
                    <!-- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
                    <!-- <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['system:jsha:add']">新增</el-button> -->
                    <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                        v-hasPermi="['system:jsha:export']">导出</el-button>
                </el-form-item>
            </el-form>
        </div>

        <!-- 表格容器 -->
        <div class="table-container">
            <!-- 主表格区域 -->
            <div class="main-table-wrapper" :class="{ 'with-detail': selectedRow }">
                <el-table border v-loading="loading" :data="jshaList" @selection-change="handleSelectionChange"
                    @row-click="handleRowClick" height="tableHeight" style="width: 100%">
                    <!-- <el-table-column type="selection" width="55" align="center" /> -->
                    <el-table-column label="序号" align="center" prop="xh" min-width="70" show-overflow-tooltip fixed />
                    <el-table-column label="井号" align="center" prop="jh" min-width="110" show-overflow-tooltip fixed />
                    <el-table-column label="钻头序列号" align="center" prop="ztxlh" min-width="100" show-overflow-tooltip />
                    <el-table-column label="尺寸mm" align="center" prop="cc" min-width="90" show-overflow-tooltip />
                    <el-table-column label="开始井深m" align="center" prop="qsjs" min-width="100" show-overflow-tooltip />
                    <el-table-column label="结束井深m" align="center" prop="zzjs" min-width="100" show-overflow-tooltip />
                    <el-table-column label="进尺m" align="center" prop="jc" min-width="90" show-overflow-tooltip />
                    <el-table-column label="机械钻速m/h" align="center" prop="jxzs" min-width="105" show-overflow-tooltip />
                    <el-table-column label="所钻地层" align="center" prop="szdc" min-width="90" show-overflow-tooltip />
                    <el-table-column label="厂家" align="center" prop="cj" min-width="90" show-overflow-tooltip />
                    <el-table-column label="钻头型号" align="center" prop="ztxh" min-width="90" show-overflow-tooltip />
                    <el-table-column label="IADC号" align="center" prop="iadc" min-width="90" show-overflow-tooltip />
                    <el-table-column label="下井次数" align="center" prop="xjcs" min-width="90" show-overflow-tooltip />
                    <el-table-column label="类型" align="center" prop="lx" min-width="90" show-overflow-tooltip />
                    <el-table-column label="入井新度" align="center" prop="rjxd" min-width="90" show-overflow-tooltip />
                    <el-table-column label="出井新度" align="center" prop="cjxd" min-width="90" show-overflow-tooltip />
                    <el-table-column label="喷嘴直径1号" align="center" prop="pz1" min-width="100" show-overflow-tooltip />
                    <el-table-column label="喷嘴直径2号" align="center" prop="pz2" min-width="100" show-overflow-tooltip />
                    <el-table-column label="喷嘴直径3号" align="center" prop="pz3" min-width="100" show-overflow-tooltip />
                    <!-- <el-table-column label="喷嘴直径4号" align="center" prop="pz4" />
          <el-table-column label="喷嘴直径5号" align="center" prop="pz5" />
          <el-table-column label="喷嘴直径6号" align="center" prop="pz6" />
          <el-table-column label="喷嘴直径7号" align="center" prop="pz7" />
          <el-table-column label="喷嘴直径8号" align="center" prop="pz8" />
          <el-table-column label="喷嘴直径9号" align="center" prop="pz9" />
          <el-table-column label="喷嘴直径10号" align="center" prop="pz10" /> -->
                    <el-table-column label="进尺工作时间合计" align="center" prop="jcsjhj" min-width="150"
                        show-overflow-tooltip />
                    <el-table-column label="进尺工作时间纯钻进" align="center" prop="jcsjczj" min-width="150"
                        show-overflow-tooltip />
                    <el-table-column label="进尺工作时间起下钻" align="center" prop="jcsjqxz" min-width="150"
                        show-overflow-tooltip />
                    <el-table-column label="进尺工作时间扩划眼" align="center" prop="jcsjkhy" min-width="150"
                        show-overflow-tooltip />
                    <el-table-column label="钻压" align="center" prop="zy" min-width="80" show-overflow-tooltip />
                    <el-table-column label="转速" align="center" prop="zs" min-width="80" show-overflow-tooltip />
                    <el-table-column label="缸径" align="center" prop="gj" min-width="80" show-overflow-tooltip />
                    <el-table-column label="泵速" align="center" prop="bs" min-width="80" show-overflow-tooltip />
                    <el-table-column label="排量" align="center" prop="pl" min-width="80" show-overflow-tooltip />
                    <el-table-column label="立管泵压" align="center" prop="lgby" min-width="90" show-overflow-tooltip />
                    <!-- <el-table-column label="钻头压降" align="center" prop="ztyj" /> -->
                    <!-- <el-table-column label="环空压耗" align="center" prop="hkyh" />
          <el-table-column label="冲击力" align="center" prop="cjl" />
          <el-table-column label="喷射速度" align="center" prop="pssd" />
          <el-table-column label="钻头水功率" align="center" prop="ztsgl" />
          <el-table-column label="比水功率" align="center" prop="bsgl" />
          <el-table-column label="上返速度钻杆" align="center" prop="sfsdzg" />
          <el-table-column label="上返速度钻铤" align="center" prop="sfsdzt" />
          <el-table-column label="功率利用率" align="center" prop="gllyl" />
          <el-table-column label="牙齿磨损情况" align="center" prop="ycmsqk" />
          <el-table-column label="轴承磨损情况" align="center" prop="zcmsqk" />
          <el-table-column label="直径磨损情况" align="center" prop="zjmsqk" />
          <el-table-column label="备注" align="center" prop="bz" />
          <el-table-column label="内排齿" align="center" prop="npc" />
          <el-table-column label="外排齿" align="center" prop="wpc" />
          <el-table-column label="磨损特征" align="center" prop="mstz" />
          <el-table-column label="位置" align="center" prop="wz" />
          <el-table-column label="轴承/密封" align="center" prop="zc" />
          <el-table-column label="直径" align="center" prop="zj" />
          <el-table-column label="起钻原因" align="center" prop="qzyy" />
          <el-table-column label="其他特征" align="center" prop="qttz" />
          <el-table-column label="扭矩" align="center" prop="nj" />
          <el-table-column label="钻盘总转数" align="center" prop="zpzzs" />
          <el-table-column label="入井日期" align="center" prop="qsrq" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.qsrq, '{y}-{m}-{d}') }}</span>
            </template>
</el-table-column>
<el-table-column label="起出日期" align="center" prop="zzrq" width="180">
    <template slot-scope="scope">
              <span>{{ parseTime(scope.row.zzrq, '{y}-{m}-{d}') }}</span>
            </template>
</el-table-column>
<el-table-column label="喷嘴类型" align="center" prop="pzlx" />
<el-table-column label="钻头价格" align="center" prop="ztjg" /> -->
                    <!-- <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width"
                        property="operation" fixed="right">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                                v-hasPermi="['system:jsha:edit']">修改</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                                v-hasPermi="['system:jsha:remove']">删除</el-button>
                        </template>
                    </el-table-column> -->
                </el-table>

                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" :page-sizes="[20, 40, 60, 80, 100]" @pagination="getList"
                    style="padding: 10px 0;" />
            </div>

            <!-- 详细数据表格区域 -->
            <transition name="slide-fade">
                <div v-if="selectedRow" class="detail-table-wrapper">
                    <el-table :data="[selectedRow]" border style="width: 100%">
                        <el-table-column label="刀翼总数" prop="tzxl01" align="center" min-width="10%" />
                        <el-table-column label="布齿密度" prop="tzxl02" align="center" min-width="10%" />
                        <el-table-column label="切削齿尺寸mm" prop="tzxl03" align="center" min-width="10%" />
                        <el-table-column label="切削齿后倾角°" prop="tzxl04" align="center" min-width="10%" />
                        <el-table-column label="冠部轮廓" prop="tzxl05" align="center" min-width="10%" />
                        <el-table-column label="保径" prop="tzxl06" align="center" min-width="10%" />
                    </el-table>
                </div>
            </transition>
        </div>

        <!-- 添加或修改钻头数据对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <div v-loading="formLoading">
                    <div class="form-section">
                        <div class="section-title">基础信息</div>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="序号" prop="xh">
                                    <el-input v-model="form.xh" placeholder="请输入序号"
                                        @input="(val) => handleNumberInput(val, 'xh')" maxlength="3"
                                        :disabled="isEdit" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="井号" prop="jh">
                                    <el-input v-model="form.jh" placeholder="请输入井号" :disabled="isEdit" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="尺寸mm" prop="cc">
                                    <el-input v-model="form.cc" placeholder="请输入尺寸"
                                        @input="(val) => handleDecimalInput(val, 'cc')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="开始井深m" prop="qsjs">
                                    <el-input v-model="form.qsjs" placeholder="请输入开始井深m"
                                        @input="(val) => handleDecimalInput(val, 'qsjs')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="结束井深" prop="zzjs">
                                    <el-input v-model="form.zzjs" placeholder="请输入结束井深"
                                        @input="(val) => handleDecimalInput(val, 'zzjs')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="进尺" prop="jc">
                                    <el-input v-model="form.jc" placeholder="请输入进尺"
                                        @input="(val) => handleDecimalInput(val, 'jc')" />
                                </el-form-item>
                            </el-col>

                        </el-row>
                        <el-row>

                            <el-col :span="8">
                                <el-form-item label="机械钻速m/h" prop="jxzs">
                                    <el-input v-model="form.jxzs" placeholder="请输入机械钻速"
                                        @input="(val) => handleDecimalInput(val, 'jxzs')" />
                                </el-form-item>
                            </el-col>

                            <el-col :span="8">
                                <el-form-item label="厂家" prop="cj">
                                    <el-input v-model="form.cj" placeholder="请输入厂家" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="类型" prop="lx">
                                    <el-input v-model="form.lx" placeholder="请输入类型" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="入井新度" prop="rjxd">
                                    <el-input v-model="form.rjxd" placeholder="请输入入井新度"
                                        @input="(val) => handleDecimalInput(val, 'rjxd')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="出井新度" prop="cjxd">
                                    <el-input v-model="form.cjxd" placeholder="请输入出井新度"
                                        @input="(val) => handleDecimalInput(val, 'cjxd')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="喷嘴直径1号" prop="pz1">
                                    <el-input v-model="form.pz1" placeholder="请输入喷嘴直径1号"
                                        @input="(val) => handleDecimalInput(val, 'pz1')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="喷嘴直径2号" prop="pz2">
                                    <el-input v-model="form.pz2" placeholder="请输入喷嘴直径2号"
                                        @input="(val) => handleDecimalInput(val, 'pz2')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="喷嘴直径3号" prop="pz3">
                                    <el-input v-model="form.pz3" placeholder="请输入喷嘴直径3号"
                                        @input="(val) => handleDecimalInput(val, 'pz3')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="钻头序列号" prop="ztxlh">
                                    <el-input v-model="form.ztxlh" placeholder="请输入钻头序列号" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="钻头型号" prop="ztxh">
                                    <el-input v-model="form.ztxh" placeholder="请输入钻头型号" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="所钻地层" prop="szdc">
                                    <el-input v-model="form.szdc" placeholder="请输入所钻地层" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="IADC号" prop="iadc">
                                    <el-input v-model="form.iadc" placeholder="请输入IADC号" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>

                            <el-col :span="8">
                                <el-form-item label="下井次数" prop="xjcs">
                                    <el-input v-model="form.xjcs" placeholder="请输入下井次数"
                                        @input="(val) => handleNumberInput(val, 'xjcs')" maxlength="3" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="工作时间合计" prop="jcsjhj">
                                    <el-input v-model="form.jcsjhj" placeholder="请输入工作时间合计"
                                        @input="(val) => handleDecimalInput(val, 'jcsjhj')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="纯钻进时间" prop="jcsjczj">
                                    <el-input v-model="form.jcsjczj" placeholder="请输入纯钻进时间"
                                        @input="(val) => handleDecimalInput(val, 'jcsjczj')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="起下钻时间" prop="jcsjqxz">
                                    <el-input v-model="form.jcsjqxz" placeholder="请输入起下钻时间"
                                        @input="(val) => handleDecimalInput(val, 'jcsjqxz')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="扩划眼时间" prop="jcsjkhy">
                                    <el-input v-model="form.jcsjkhy" placeholder="请输入扩划眼时间"
                                        @input="(val) => handleDecimalInput(val, 'jcsjkhy')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="钻压" prop="zy">
                                    <el-input v-model="form.zy" placeholder="请输入钻压"
                                        @input="(val) => handleNumberInput(val, 'zy')" maxlength="3" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="转速" prop="zs">
                                    <el-input v-model="form.zs" placeholder="请输入转速"
                                        @input="(val) => handleNumberInput(val, 'zs')" maxlength="3" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="缸径" prop="gj">
                                    <el-input v-model="form.gj" placeholder="请输入缸径" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="泵速" prop="bs">
                                    <el-input v-model="form.bs" placeholder="请输入泵速"
                                        @input="(val) => handleNumberInput(val, 'bs')" maxlength="3" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="排量" prop="pl">
                                    <el-input v-model="form.pl" placeholder="请输入排量" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="立管泵压" prop="lgby">
                                    <el-input v-model="form.lgby" placeholder="请输入立管泵压"
                                        @input="(val) => handleDecimalInput(val, 'lgby')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="钻头压降" prop="ztyj">
                                    <el-input v-model="form.ztyj" placeholder="请输入钻头压降"
                                        @input="(val) => handleDecimalInput(val, 'ztyj')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="环空压耗" prop="hkyh">
                                    <el-input v-model="form.hkyh" placeholder="请输入环空压耗"
                                        @input="(val) => handleDecimalInput(val, 'hkyh')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="冲击力" prop="cjl">
                                    <el-input v-model="form.cjl" placeholder="请输入冲击力"
                                        @input="(val) => handleDecimalInput(val, 'cjl')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="喷射速度" prop="pssd">
                                    <el-input v-model="form.pssd" placeholder="请输入喷射速度"
                                        @input="(val) => handleDecimalInput(val, 'pssd')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="钻头水功率" prop="ztsgl">
                                    <el-input v-model="form.ztsgl" placeholder="请输入钻头水功率"
                                        @input="(val) => handleDecimalInput(val, 'ztsgl')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="比水功率" prop="bsgl">
                                    <el-input v-model="form.bsgl" placeholder="请输入比水功率"
                                        @input="(val) => handleDecimalInput(val, 'bsgl')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="上返速度钻杆" prop="sfsdzg">
                                    <el-input v-model="form.sfsdzg" placeholder="请输入上返速度钻杆"
                                        @input="(val) => handleDecimalInput(val, 'sfsdzg')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="上返速度钻铤" prop="sfsdzt">
                                    <el-input v-model="form.sfsdzt" placeholder="请输入上返速度钻铤"
                                        @input="(val) => handleDecimalInput(val, 'sfsdzt')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="功率利用率" prop="gllyl">
                                    <el-input v-model="form.gllyl" placeholder="请输入功率利用率"
                                        @input="(val) => handleDecimalInput(val, 'gllyl')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="牙齿磨损" prop="ycmsqk">
                                    <el-input v-model="form.ycmsqk" placeholder="请输入牙齿磨损" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="轴承磨损" prop="zcmsqk">
                                    <el-input v-model="form.zcmsqk" placeholder="请输入轴承磨损" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="直径磨损" prop="zjmsqk">
                                    <el-input v-model="form.zjmsqk" placeholder="请输入直径磨损" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="备注" prop="bz">
                                    <el-input v-model="form.bz" placeholder="请输入备注" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="内排齿" prop="npc">
                                    <el-input v-model="form.npc" placeholder="请输入内排齿" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="外排齿" prop="wpc">
                                    <el-input v-model="form.wpc" placeholder="请输入外排齿" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="磨损特征" prop="mstz">
                                    <el-input v-model="form.mstz" placeholder="请输入磨损特征" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="位置" prop="wz">
                                    <el-input v-model="form.wz" placeholder="请输入位置" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="轴承/密封" prop="zc">
                                    <el-input v-model="form.zc" placeholder="请输入轴承/密封" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="直径" prop="zj">
                                    <el-input v-model="form.zj" placeholder="请输入直径" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="起钻原因" prop="qzyy">
                                    <el-input v-model="form.qzyy" placeholder="请输入起钻原因" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="其他特征" prop="qttz">
                                    <el-input v-model="form.qttz" placeholder="请输入其他特征" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="扭矩" prop="nj">
                                    <el-input v-model="form.nj" placeholder="请输入扭矩"
                                        @input="(val) => handleDecimalInput(val, 'nj')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="钻盘总转数" prop="zpzzs">
                                    <el-input v-model="form.zpzzs" placeholder="请输入钻盘总转数"
                                        @input="(val) => handleDecimalInput(val, 'zpzzs')" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="入井日期" prop="qsrq">
                                    <el-date-picker clearable v-model="form.qsrq" type="date" value-format="yyyy-MM-dd"
                                        placeholder="请选择入井日期" style="width: 100%;">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="起出日期" prop="zzrq">
                                    <el-date-picker clearable v-model="form.zzrq" type="date" value-format="yyyy-MM-dd"
                                        placeholder="请选择起出日期" style="width: 100%;">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="喷嘴类型" prop="pzlx">
                                    <el-input v-model="form.pzlx" placeholder="请输入喷嘴类型" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="钻头价格" prop="ztjg">
                                    <el-input v-model="form.ztjg" placeholder="请输入钻头价格"
                                        @input="(val) => handleDecimalInput(val, 'ztjg')" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </div>

                    <div class="form-section">
                        <div class="section-title">特征数据</div>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="刀翼总数" prop="t01">
                                    <el-select v-model="form.t01" placeholder="请选择刀翼总数" clearable style="width: 100%">
                                        <el-option v-for="item in t01Options" :key="item.id" :label="`${item.tzxl}`"
                                            :value="item.id" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="布齿密度" prop="t02">
                                    <el-select v-model="form.t02" placeholder="请选择布齿密度" clearable style="width: 100%">
                                        <el-option v-for="item in t02Options" :key="item.id" :label="`${item.tzxl}`"
                                            :value="item.id" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="切削齿尺寸mm" prop="t03">
                                    <el-select v-model="form.t03" placeholder="请选择切削齿尺寸" clearable style="width: 100%">
                                        <el-option v-for="item in t03Options" :key="item.id" :label="`${item.tzxl}`"
                                            :value="item.id" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="切削齿后倾角°" prop="t04">
                                    <el-select v-model="form.t04" placeholder="请选择切削齿后倾角" clearable style="width: 100%">
                                        <el-option v-for="item in t04Options" :key="item.id" :label="`${item.tzxl}`"
                                            :value="item.id" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="冠部轮廓" prop="t05">
                                    <el-select v-model="form.t05" placeholder="请选择冠部轮廓" clearable style="width: 100%">
                                        <el-option v-for="item in t05Options" :key="item.id" :label="`${item.tzxl}`"
                                            :value="item.id" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="保径" prop="t06">
                                    <el-select v-model="form.t06" placeholder="请选择保径" clearable style="width: 100%">
                                        <el-option v-for="item in t06Options" :key="item.id" :label="`${item.tzxl}`"
                                            :value="item.id" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </div>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { listJsha, getJsha, delJsha, addJsha, updateJsha } from "@/api/system/jsha";
import { getBlockName, getQkxl } from "@/api/system/jsaa";
import { listTzsj } from "@/api/system/jsha";

export default {
    name: "Jsha",
    props: {
        jh: {
            type: String,
            default: ''
        },
        jhs: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            // 区块下拉选项
            blockOptions: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 钻头数据表格数据
            jshaList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 是否为编辑操作
            isEdit: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20, // 修改回默认每页显示20条
                qk: null,
                jh: null,
                jhs: null,
                wjrqks: null,
                wjrqjs: null,
                ztxlh: null,
                ztxh: null,
                iadc: null,
                xjcs: null,
                cc: null,
                lx: null,
                cj: null,
                rjxd: null,
                cjxd: null,
                pz1: null,
                pz2: null,
                pz3: null,
                pz4: null,
                pz5: null,
                pz6: null,
                pz7: null,
                pz8: null,
                pz9: null,
                pz10: null,
                qsjs: null,
                zzjs: null,
                szdc: null,
                jc: null,
                jxzs: null,
                jcsjhj: null,
                jcsjczj: null,
                jcsjqxz: null,
                jcsjkhy: null,
                zy: null,
                zs: null,
                gj: null,
                bs: null,
                pl: null,
                lgby: null,
                ztyj: null,
                hkyh: null,
                cjl: null,
                pssd: null,
                ztsgl: null,
                bsgl: null,
                sfsdzg: null,
                sfsdzt: null,
                gllyl: null,
                ycmsqk: null,
                zcmsqk: null,
                zjmsqk: null,
                bz: null,
                npc: null,
                wpc: null,
                mstz: null,
                wz: null,
                zc: null,
                zj: null,
                qzyy: null,
                qttz: null,
                nj: null,
                zpzzs: null,
                qsrq: null,
                zzrq: null,
                pzlx: null,
                ztjg: null
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                jh: [
                    { required: true, message: "井号不能为空", trigger: "blur" }
                ],
                xh: [
                    { required: true, message: "序号不能为空", trigger: "blur" }
                ],
                cc: [
                    { required: true, message: "尺寸不能为空", trigger: "blur" }
                ],
                qsjs: [
                    { required: true, message: "开始井深不能为空", trigger: "blur" }
                ],
                zzjs: [
                    { required: true, message: "结束井深不能为空", trigger: "blur" }
                ],
                jc: [
                    { required: true, message: "进尺不能为空", trigger: "blur" }
                ],
                jxzs: [
                    { required: true, message: "机械钻速不能为空", trigger: "blur" }
                ]
            },
            selectedRow: null, // 当前选中的行数据
            tableHeight: null,
            // 特征数据选项
            t01Options: [],
            t02Options: [],
            t03Options: [],
            t04Options: [],
            t05Options: [],
            t06Options: [],
            formLoading: false, // 新增表单loading
        };
    },
    computed: {
        filteredBlockOptions() {
            return this.blockOptions.filter(item => item && item.qk);
        }
    },
    watch: {
        jh: {
            handler(newJh) {
                if (newJh) {
                    this.queryParams.jh = newJh;

                }
            },
            immediate: false
        },
        selectedRow: {
            handler(val) {
                this.$nextTick(() => {
                    const containerElement = document.querySelector('.app-container');
                    const searchElement = document.querySelector('.search-wrapper');
                    if (!containerElement || !searchElement) {
                        return;
                    }
                    const containerHeight = containerElement.offsetHeight;
                    const searchHeight = searchElement.offsetHeight;
                    const paginationHeight = 50; // 分页器高度
                    if (val) {
                        // 选中行时，减去详情表格高度
                        this.tableHeight = containerHeight - searchHeight - paginationHeight - 50;
                    } else {
                        // 未选中行时，使用全部可用空间
                        this.tableHeight = containerHeight - searchHeight - paginationHeight;
                    }
                });
            },
            immediate: true
        }
    },
    mounted() {
        // 初始化表格高度
        this.$nextTick(() => {
            const containerElement = document.querySelector('.app-container');
            const searchElement = document.querySelector('.search-wrapper');
            // 检查元素是否存在
            if (!containerElement || !searchElement) {
                return;
            }
            const containerHeight = containerElement.offsetHeight;
            const searchHeight = searchElement.offsetHeight;
            const paginationHeight = 50;
            this.tableHeight = containerHeight - searchHeight - paginationHeight;
        });
        // 添加窗口大小改变事件监听
        window.addEventListener('resize', this.updateTableHeight);
    },
    beforeDestroy() {
        // 移除事件监听
        window.removeEventListener('resize', this.updateTableHeight);
    },
    created() {
        // 如果传入了jh参数，设置到查询参数中
        if (this.jh) {
            this.queryParams.jh = this.jh;
        }
        // 如果传入了jhs参数，设置到查询参数中
        if (this.jhs) {
            this.queryParams.jhs = this.jhs;
        }
        // 只加载选项，不自动加载数据
        // this.getList();
        this.getBlockOptions();
        this.getFeatureOptions();
    },
    methods: {
        /** 获取区块下拉选项 */
        getBlockOptions() {
            getQkxl().then(response => {
                this.blockOptions = response.data || [];
            });
        },
        /** 获取特征数据选项 */
        getFeatureOptions() {
            const featureTypes = [
                { type: "刀翼总数", target: "t01Options" },
                { type: "布齿密度", target: "t02Options" },
                { type: "切削齿尺寸mm", target: "t03Options" },
                { type: "切削齿后倾角°", target: "t04Options" },
                { type: "冠部轮廓", target: "t05Options" },
                { type: "保径", target: "t06Options" }
            ];
            const promises = featureTypes.map(feature =>
                listTzsj({ tzdl: feature.type }).then(response => ({
                    target: feature.target,
                    data: response.rows
                }))
            );

            Promise.all(promises)
                .then(results => {
                    results.forEach(result => {
                        this[result.target] = result.data;
                    });
                })
                .catch(error => {
                    console.error('获取特征数据选项失败:', error);
                    this.$modal.msgError("获取特征数据选项失败");
                });
        },
        /** 查询钻头数据列表 */
        getList() {
            this.loading = true;
            const params = {
                jhs: `${this.jh},${this.jhs}`
            }
            console.log(params, 'params');
            listJsha(params).then(response => {
                this.jshaList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },


        // 取消按钮
        cancel() {
            this.formLoading = false;
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.formLoading = false;
            this.form = {
                jh: null,
                xh: null,
                ztxlh: null,
                ztxh: null,
                iadc: null,
                xjcs: null,
                cc: null,
                lx: null,
                cj: null,
                rjxd: null,
                cjxd: null,
                pz1: null,
                pz2: null,
                pz3: null,
                pz4: null,
                pz5: null,
                pz6: null,
                pz7: null,
                pz8: null,
                pz9: null,
                pz10: null,
                qsjs: null,
                zzjs: null,
                szdc: null,
                jc: null,
                jxzs: null,
                jcsjhj: null,
                jcsjczj: null,
                jcsjqxz: null,
                jcsjkhy: null,
                zy: null,
                zs: null,
                gj: null,
                bs: null,
                pl: null,
                lgby: null,
                ztyj: null,
                hkyh: null,
                cjl: null,
                pssd: null,
                ztsgl: null,
                bsgl: null,
                sfsdzg: null,
                sfsdzt: null,
                gllyl: null,
                ycmsqk: null,
                zcmsqk: null,
                zjmsqk: null,
                bz: null,
                npc: null,
                wpc: null,
                mstz: null,
                wz: null,
                zc: null,
                zj: null,
                qzyy: null,
                qttz: null,
                nj: null,
                zpzzs: null,
                qsrq: null,
                zzrq: null,
                pzlx: null,
                ztjg: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams.wjrqks = '';
            this.queryParams.wjrqjs = '';
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.jh)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.isEdit = false;
            this.open = true;
            this.title = "添加钻头数据";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            this.isEdit = true;
            const query = {
                jh: row.jh,
                xh: row.xh
            }
            getJsha(query).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改钻头数据";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.formLoading = true;
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.isEdit) {
                        updateJsha(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        }).finally(() => {
                            this.formLoading = false;
                        });
                    } else {
                        addJsha(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        }).finally(() => {
                            this.formLoading = false;
                        });
                    }
                } else {
                    this.formLoading = false;
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const query = {
                jh: row.jh,
                xh: row.xh
            };
            this.$modal.confirm('是否确认删除钻头数据编号为"' + row.jh + '"的数据项？').then(function () {
                return delJsha(query);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('system/jshaPdc/export', {
                jhs: `${this.jh},${this.jhs}`
            }, `jsha_${new Date().getTime()}.xlsx`)
        },

        /** 处理行点击 */
        async handleRowClick(row, column) {
            // 如果点击的是操作列，不执行任何操作
            if (column && column.property === 'operation') {
                return;
            }

            try {
                const query = {
                    jh: row.jh,
                    xh: row.xh
                }
                const res = await getJsha(query);
                this.selectedRow = res.data;
            } catch (error) {
                console.error('获取详细数据失败:', error);
                this.selectedRow = null;
            }
        },
        updateTableHeight() {
            this.$nextTick(() => {
                const containerElement = document.querySelector('.app-container');
                const searchElement = document.querySelector('.search-wrapper');

                // 检查元素是否存在
                if (!containerElement || !searchElement) {
                    return;
                }

                const containerHeight = containerElement.offsetHeight;
                const searchHeight = searchElement.offsetHeight;
                const paginationHeight = 50;

                if (this.selectedRow) {
                    this.tableHeight = containerHeight - searchHeight - paginationHeight - 120;
                } else {
                    this.tableHeight = containerHeight - searchHeight - paginationHeight;
                }
            });
        },
        /** 限制只能输入三位数字 */
        handleNumberInput(value, key) {
            // 如果值为空，直接返回
            if (value === '') {
                this.form[key] = '';
                return;
            }
            // 移除非数字字符
            value = value.toString().replace(/[^\d]/g, '');
            // 限制长度为3位
            if (value.length > 3) {
                value = value.slice(0, 3);
            }
            // 更新表单数据
            this.form[key] = value;
        },

        /** 限制只能输入数字且保留两位小数 */
        handleDecimalInput(value, key) {
            // 如果值为空，直接返回
            if (value === '') {
                this.form[key] = '';
                return;
            }
            // 只允许输入数字和小数点
            value = value.toString().replace(/[^\d.]/g, '');
            // 保证只有一个小数点
            const parts = value.split('.');
            if (parts.length > 2) {
                value = parts[0] + '.' + parts.slice(1).join('');
            }
            // 限制小数点后两位
            if (parts.length === 2 && parts[1].length > 2) {
                value = parts[0] + '.' + parts[1].slice(0, 2);
            }
            // 更新表单数据
            this.form[key] = value;
        },
        /**
         * 外部调用：加载数据
         */
        loadData() {
            this.getList();
        }
    }
};
</script>
<style lang="scss" scoped>
.app-container {
    height: calc(100vh - 160px);
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
}

.search-wrapper {
    flex: none;

}

.table-container {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-table-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow: hidden;
}

.detail-table-wrapper {
    height: 75px;
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    background: #fff;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    z-index: 1;
}

.slide-fade-enter-active,
.slide-fade-leave-active {
    transition: all 0.3s ease;
}

.slide-fade-enter,
.slide-fade-leave-to {
    transform: translateY(120px);
    opacity: 0;
}

::v-deep .el-table {
    flex: 1;
}

::v-deep .el-table__body-wrapper {
    overflow-y: auto;
}

::v-deep .el-table__cell>.cell {
    font-weight: normal;
}

::v-deep .el-table--medium .el-table__cell {
    padding: 5px 0 !important;
}

::v-deep.pagination-container {
    padding: 0px !important;
    margin: 0;
}

.form-section {
    margin-bottom: 20px;

    .section-title {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 15px;
        padding-left: 10px;
        border-left: 3px solid #409EFF;
    }
}

::v-deep .el-form-item {
    margin-bottom: 18px;
    padding-right: 20px;
}

::v-deep .el-form-item {
    margin-bottom: 10px !important;
}
</style>
