vue的el-table表格 点击添加要素 出现一个新的div

本文介绍了一种通过界面配置要素属性并实现数据输出的方法。用户可通过下拉菜单选择不同的要素类型,并设置标识符、无效量等参数。支持动态显示特定选项如旋转方向和初相,同时提供了添加和保存功能来构建及导出数据配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 <div class="main" >
          <el-table
            :data="details"
            style="width:100%;">
            <el-table-column
              v-if="false"
              prop="id"
              label="id"
            >
            </el-table-column >
            <el-table-column
              label="要素列表"
              align="center"
              font-size="300"
              width="280" >
              <template slot-scope="scope">
                <el-select v-model="scope.row.selectelemvalue" placeholder="请选择" size="small"  style="width:150px;left: 39px" >
                  <el-option
                    v-for="item in selectelem"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                    v-bind:class="addWind()">
                  </el-option>
                </el-select>
                <div>标识符:
                  <el-input size="mini" placeholder="输入标识符" v-model="scope.row.inputelem1"  clearable  style=" width:150px;left: 8px" > </el-input></div>
                <div>无效量:
                  <el-input size="mini" placeholder="输入无效量" v-model="scope.row.inputelem2" clearable  style=" width:150px;left: 8px" ></el-input></div>
                <div>偏移量:
                  <el-input size="mini" placeholder="输入偏移量" v-model="scope.row.inputelem3" clearable  style=" width:150px;left: 8px" ></el-input></div>
                <div>放大系数:
                  <el-input size="mini" placeholder="输入放大系数量" v-model="scope.row.inputelem4" clearable  style=" width:150px;left: 2px" ></el-input></div>
                <div>点数:
                  <el-select v-model="scope.row.selectpointvalue" placeholder="请选择" size="mini" style=" width:150px;left: 15px">
                    <el-option v-for="item in selectpoint" :key="item.value"  :value="item.value"></el-option>
                  </el-select></div>
                <div v-show="scope.row.isShowDirection" >旋转方向:
                  <el-select  v-model="scope.row.selectdirection" placeholder="请选择" size="mini" style=" width:150px">
                    <el-option v-for="item in selectdir" :key="item.value" :label="item.lable" :value="item.value"
                    ></el-option>
                  </el-select></div>
                <div v-show="scope.row.isShowAngle">初相:
                  <el-select  v-model="scope.row.selectAngle" placeholder="请选择" size="mini" style=" width:150px;left:15px">
                    <el-option v-for="item in selectAng" :key="item.value"  :value="item.value" ></el-option></el-select>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <el-button-group >
            <el-button type="primary" size="mini" @click="handleAdd" round>添加要素</el-button>
            <el-button type="primary" size="mini" @click="handleSave"round>输出数据</el-button>
          </el-button-group>
        <!--</div>-->
      </div>
  handleAdd() {
        this.details.push({
          selectelemvalue:null,
          inputelem1:null,
          inputelem2:null,
          inputelem3:null,
          inputelem4:null,
          selectpointvalue:null,
          selectdirection:null,
          selectAngle: null,

        });
        this.count++;
      },
     handleSave(){
        console.log(this.count)
        var list=[]
        var t=0
        // item:定义的每一条的变量  this.details:要循环的数组
        console.log( this.details)
        for( let item of this.details)
        {
          if(item.selectelemvalue=='海面温度')
          {
            item.selectelemvalue = 'SST'
          }
          var listData= {
            'value':item.selectelemvalue ,
            'lem1':item.inputelem1,
            'lem2':item.inputelem2 ,
            'lem3':item.inputelem3,
            'lem4': item.inputelem4,
            'pointvalue': item.selectpointvalue,
            'direction':item.selectdirection,
            'angle':item.selectAngle
          }
          if(listData.direction == "旋转方向" || listData.angle == "初相" )
          {
            listData.direction = null
            listData.angle = null
          }
          list[t++]=listData
        }
        for(var i=0;i<t;i++) {
          console.log(list[i])
        }
      },

 

data () {
      return {
        details: [{
          selectelemvalue:'海面温度',
          inputelem1:'SST',
          inputelem2:'-32767',
          inputelem3:'0',
          inputelem4:'1e-05',
          selectpointvalue:'10000',
          selectdirection:"旋转方向",
          selectAngle: '初相',
          isShowAngle:false,
          isShowDirection:false
        }],
        
    //其他值就不贴上来了
}
}

点击添加要素之后

<template> <dialog-edit :visible.sync="open" :title="activeTitle" @close="handleDialogClose" @changeTab="handleTabChange" :menuTab="pageMenuTab" :reserve="true" > <!-- 设备台账详情页 --> <template slot="equipmentDetail"> <div class="dialog-content-wrap"> <formlist v-if="dictLoaded" :form="form" :form2="formData" :dictData="dictData" ref="formList" :readonly="true" :width="'120px'" /> </div> </template> <!-- 气量检测页 --> <template slot="GasMeasurement"> <div class="dialog-content-wrap" v-if="GasMeasurementReady"> <gas-detection ref="GasMeasurementRef" :equipment-id="currentEquipmentId" @on-new="handleNewDetection" @on-delete="handleDeleteDetection" /> </div> </template> <template v-slot:footer> <div class="dialog_footer"> <el-button @click="handleCancel">关闭</el-button> </div> </template> </dialog-edit> </template> <script> import { getDictionaries } from "@/utils"; import DialogEdit from '@/components/dialogEdit' import GasMeasurement from "../cmmsGasMeasurement/cmmsGasMeasurement.vue"; // 需要导入API函数 import { getCmmsEquipmentInfo } from "@/api/cmmsEquipmentInfo/cmmsEquipmentInfo.js"; export default { name: "EquipmentDetailDialog", components: { GasMeasurement, DialogEdit, }, data() { return { dictLoaded: false, form: [ { arr: [ { code: "equipmentCode", title: "设备编码", type: 0, readonly: true, verification: true, rule: "0", customTips: "", regular: "", dictionary: "", }, { code: "equipmentCategory", title: "设备大类", type: 1, readonly: true, verification: true, rule: "0", customTips: "请选择设备大类", dictionary: "equipment_category", }, { code: "equipmentSubcategory", title: "设备小类", type: 1, readonly: true, verification: true, rule: "0", customTips: "请选择设备小类", dictionary: "equipment_subcategory", }, { code: "modelDescription", title: "燃气表型号描述", type: 0, readonly: true, verification: true, rule: "0", customTips: "燃气表的具体型号描述", regular: "", }, { code: "specificationModel", title: "规格型号", type: 0, readonly: true, verification: true, rule: "0", customTips: "设备的规格型号", regular: "", }, { code: "accuracyLevel", title: "器具准确度等级", type: 1, readonly: true, verification: true, rule: "0", customTips: "请选择准确度等级", dictionary: "accuracy_level", }, { code: "manufacturer", title: "器具生产单位", type: 0, readonly: true, verification: true, rule: "0", customTips: "设备的生产厂家", regular: "", }, { code: "ownershipType", title: "归属类型", type: 1, readonly: true, verification: true, rule: "0", customTips: "请选择设备归属类型", dictionary: "ownership_type", }, { code: "equipmentOwner", title: "设备归属方", type: 0, readonly: true, verification: true, rule: "0", customTips: "设备的所有者", regular: "", }, { code: "purchaseDate", title: "采购日期", type: 6, readonly: true, verification: true, rule: "0", customTips: "请选择采购日期", dateType: "date", dateFormat: "yyyy-MM-dd", }, { code: "storageLocation", title: "存放位置", type: 0, readonly: true, verification: true, rule: "0", customTips: "设备当前的存放位置", regular: "", }, { code: "overdueYears", title: "超期年限(年)", type: 3, readonly: true, verification: true, rule: "0", customTips: "超出检定有效期的年限", regular: "^[0-9]{1,2}$", min: 0, max: 20, }, { code: "lastVerificationDate", title: "最后检定日期", type: 6, readonly: true, verification: true, rule: "0", customTips: "请选择最后检定日期", dateType: "date", dateFormat: "yyyy-MM-dd", }, { code: "equipmentStatus", title: "设备状态", type: 1, readonly: true, verification: true, rule: "0", customTips: "请选择设备当前状态", dictionary: "equipment_status", }, { code: "storageStatus", title: "仓储状态", type: 1, readonly: true, verification: true, rule: "0", customTips: "请选择仓储状态", dictionary: "storage_status", }, { code: "inspectionStatus", title: "检测状态", type: 1, readonly: true, verification: true, rule: "0", customTips: "请选择检测状态", dictionary: "inspection_status", }, { code: "equipmentPhoto", title: "设备照片", type: 30, readonly: true, verification: true, rule: "0", customTips: "请上传设备照片", multiple: false, fileNum: 1, accept: "image/jpeg,image/png", maxSize: 5, }, { code: "remarks", title: "备注", type: 2, readonly: true, verification: true, rule: "0", customTips: "请填写备注信息", rows: 4, }, ], }, ], formData: {}, open: false, dictData: {}, active: "equipmentDetail", activeTitle: "设备详情", currentEquipmentId: null, GasMeasurementReady: false, pageMenuTab: [ { title: "基础信息", sxTitle: "equipmentDetail", hide: false, icon: "el-icon-document", }, { title: "气量监测", sxTitle: "GasMeasurement", hide: false, icon: "el-icon-data-line", }, ], }; }, methods: { async init(row) { this.open = true; this.active = "equipmentDetail"; this.activeTitle = "基础详情"; this.currentEquipmentId = row.id; try { // 并行加载字典和设备详情 const [dictData, detailData] = await Promise.all([ this.loadDictData().catch((e) => { console.error("字典加载失败:", e); return {}; }), this.loadEquipmentDetail(row.id).catch((e) => { console.error("设备详情加载失败:", e); return this.useRowDataAsFallback(row); }), ]); this.dictData = dictData; this.formData = detailData; this.dictLoaded = true; // 确保表单组件已渲染 this.$nextTick(() => { if (this.$refs.formList) { this.$refs.formList.refreshForm(); } }); } catch (error) { console.error("初始化异常:", error); this.dictLoaded = true; } }, async loadEquipmentDetail(equipmentId) { try { const response = await getCmmsEquipmentInfo(equipmentId); // 增加响应为 undefined 的检查 if (!response) { throw new Error("API返回空响应"); } // 检查响应结构,避免访问 undefined.data if (response.data.code === 0 && response.data.data) { const detailData = response.data.data; return { ...detailData, purchaseDate: detailData.purchaseDate ? this.formatDate(detailData.purchaseDate) : null, lastVerificationDate: detailData.lastVerificationDate ? this.formatDate(detailData.lastVerificationDate) : null, }; } else { throw new Error(response.data.msg || "设备详情数据格式错误"); } } catch (error) { throw new Error(`加载设备详情失败: ${error.message}`); } }, async loadDictData() { const dictKeys = [ "equipment_category", "equipment_subcategory", "accuracy_level", "ownership_type", "equipment_status", "storage_status", "inspection_status", ]; try { const data = await getDictionaries(dictKeys); this.dictData = Object.fromEntries( dictKeys.map((key) => [key, data[key] || []]) ); } catch (error) { console.error("加载字典数据失败:", error); this.dictData = Object.fromEntries(dictKeys.map((key) => [key, []])); } }, formatDate(dateString) { return dateString ? new Date(dateString).toISOString().split("T")[0] : null; }, // 添加这个方法 handleDialogClose() { this.handleCancel(); this.$emit("close"); // 确保触发close事件 }, useRowDataAsFallback(row) { return { ...row, purchaseDate: row.purchaseDate ? this.formatDate(row.purchaseDate) : null, lastVerificationDate: row.lastVerificationDate ? this.formatDate(row.lastVerificationDate) : null, }; }, handleCancel() { this.open = false; this.GasMeasurementReady = false; this.$emit("closed"); }, handleTabChange(activeTab) { this.active = activeTab; const activeItem = this.pageMenuTab.find( (item) => item.sxTitle === activeTab ); if (activeItem) { this.activeTitle = activeItem.title; } if (activeTab === "GasMeasurement") { // 确保设备ID已设置后再渲染组件 this.GasMeasurementReady = !!this.currentEquipmentId; this.$nextTick(() => { if (this.$refs.GasMeasurementRef) { this.$refs.GasMeasurementRef.refreshData(); } }); } }, }, mounted() { // 确保组件正常挂载 this.$nextTick(() => { console.log("formList组件实例:", this.$refs.formList); }); }, }; </script> <style scoped> .dialog-content-wrap { padding: 15px; height: 100%; overflow: auto; } </style> 气量监测的地方是个分页查询,怎么修改这个文件 这个是分页的vue /** * 气量监测页面 * * @author gucw * @date 2025-06-10 */ <template> <div class="mod-config padding"> <el-form :inline="true" :model="dataForm" ref="form" @keyup.enter.native="getDataList()" > <el-form-item label="读数录入时间"> <el-date-picker v-model="readingTimeList" type="daterange" range-separator="-" value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder=" 结束日期" ></el-date-picker> </el-form-item> <el-form-item label="类型(空跑/检测/计费)" prop="measurementType"> <el-select v-model="dataForm.measurementType" :placeholder="'请选择类型(空跑/检测/计费)'" > <el-option v-for="(item, index) in measurement_type" :key="item.cId" :label="item.entryname" :value="item.entrycode" ></el-option> </el-select> </el-form-item> <el-form-item> <el-button v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:list')" @click="getDataList()" type="primary" >查询</el-button > <el-button v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:list')" @click="resetForm('form')" >重置</el-button > <el-button v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:add')" type="primary" @click="addOrUpdateHandle()" >新增</el-button > <el-button v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:remove')" type="danger" @click="deleteHandle()" >批量删除</el-button > </el-form-item> </el-form> <EproTable class="m-t-10" :tableData="dataList" :titleData="titleForm" :optionData="optionData" :disselected="false" @tableSelect="getTableSelect" v-loading="tableLoading" > <el-table-column slot="action" fixed="right" label="操作" align="center" width="110" > <template slot-scope="scope"> <el-tooltip content="编辑" placement="top" v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:edit')" > <div class="iconfont icon-edit click iconStyle pifu" @click.stop="addOrUpdateHandle(scope.row)" ></div> </el-tooltip> <el-tooltip content="删除" placement="top" v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:remove')" > <div class="iconfont icon-delete click iconStyle pifu" @click.stop="deleteHandle(scope.row.id)" ></div> </el-tooltip> </template> </el-table-column> </EproTable> <el-pagination background @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalCount" layout="total, sizes, prev, pager, next, jumper" > </el-pagination> <!-- 弹窗, 新增 / 修改 --> <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" ></add-or-update> </div> </template> <script> import AddOrUpdate from "./cmmsGasMeasurementAddAndUpdate"; import { listCmmsGasMeasurement, delCmmsGasMeasurement, } from "@/api/cmmsGasMeasurement/cmmsGasMeasurement.js"; import EproTable from "@/components/epro-table/epro-table"; import { getDictionaries } from "@/utils"; export default { data() { return { dataList: [], pageIndex: 1, pageSize: 10, totalCount: 0, tableLoading: false, dataListSelections: [], addOrUpdateVisible: false, readingTimeList: [], measurement_stage: [], measurement_type: [], optionData: { readingValue: { width: "150px" }, readingTime: { width: "150px" }, stageDict: { width: "150px" }, measurementTypeDict: { width: "150px" }, gasVolume: { width: "150px" }, }, titleForm: { readingValue: "读数", readingTime: "读数录入时间", stageDict: "阶段(出库/检测后/检测前/入库/拆表后)", measurementTypeDict: "类型(空跑/检测/计费)", gasVolume: "气量", }, dataForm: { readingTime: null, measurementType: null, }, }; }, components: { AddOrUpdate, EproTable, }, activated() { this.getDataList(); this.getDictionaries(); }, methods: { // 获取table数据 getTableSelect(val) { this.dataListSelections = val; }, // 获取数据列表 getDataList() { this.$set(this.dataForm, "page", this.pageIndex); this.$set(this.dataForm, "limit", this.pageSize); this.$set(this.dataForm, "beginreadingTime", this.readingTimeList[0]); this.$set(this.dataForm, "endreadingTime", this.readingTimeList[1]); this.tableLoading = true; listCmmsGasMeasurement(this.dataForm).then(({ data }) => { this.dataList = data.page.list; this.totalCount = data.page.totalCount; this.tableLoading = false; }); }, // 获取字典 getDictionaries() { return new Promise((resolve) => { let arr = ["measurement_stage", "measurement_type"]; getDictionaries(arr).then((data) => { this.measurement_stage = data["measurement_stage"]; this.measurement_type = data["measurement_type"]; resolve(); }); }); }, // 每页数 sizeChangeHandle(val) { this.pageSize = val; this.pageIndex = 1; this.getDataList(); }, // 当前页 currentChangeHandle(val) { this.pageIndex = val; this.getDataList(); }, //重置表格 resetForm(formName) { this.$refs[formName].resetFields(); this.readingTimeList = []; this.getDataList(); }, // 新增 / 修改 addOrUpdateHandle(data) { this.addOrUpdateVisible = true; this.$nextTick(() => { this.$refs.addOrUpdate.init(data); }); }, // 删除 deleteHandle(id) { if (this.dataListSelections.length === 0 && !id) { this.$message({ message: "请选择数据", type: "warning", }); return; } var ids = id ? [id] : this.dataListSelections.map((item) => { return item.id; }); this.$confirm( `确定对[id=${ids.join(",")}]进行[${ ids.length == 1 ? "删除" : "批量删除" }]操作?`, "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", } ).then(() => { delCmmsGasMeasurement(ids).then(({ data }) => { if (data.code === 0) { this.getDataList(); this.$message.success("删除成功"); } else { this.$message.error(data.msg); } }); }); }, }, }; </script>
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值