Vue点击本条添加加class样式,移除其他条class样式

<!DOCTYPE html>
<html>
<head>
	<title>Vue如何加class</title>
	 <meta charset="utf-8"/>
	 <style type="text/css">
	 	.classred{
	 		color:red;
	 	}
	 </style>
</head>
<body>
<div id="app">	
	<ul class="list">
        <li v-for="(item,index) in liList" v-on:click="addClass(index)" v-bind:class="{ classred:index==current}">{{item.title}}</li>
    </ul>
</div>
<script src="./vue.min.js"></script>
<script type="text/javascript">
	var vm = new Vue({
		el: '#app',
		data: {
		  	name:'叶落森',
		  	current:0,
                        liList:[
                             {title:'叶落森1'},
                             {title:'叶落森2'},
                             {title:'叶落森3'},
                             {title:'叶落森4'}
                        ]
		},
		methods:{			
			addClass:function(index){					
                            this.current=index;
                        }
		},	   
	        mounted: function() {}         	
	})
</script>
</body>
</html>

--------------------- 
作者:叶落森 
来源:优快云 
原文:https://blog.youkuaiyun.com/xiasohuai/article/details/80749931 

<script setup> import {computed, ref, nextTick, watch} from 'vue' import { useI18n } from 'vue-i18n' import * as XLSX from 'xlsx/xlsx.mjs' import { useAppStore } from '@/stores/app.js' import { useThemeStore } from '@/stores/theme.js' import { useWellStore } from '@/stores/well.js' import Card from '@/components/layout/Card.vue' import WellTrajectory from '@/components/BoetWidgets/3d/WellTrajectory.vue' import ImportDialog from './import-dialog/ImportDialog.vue' import InterpolateDialog from './interpolate-dialog/InterpolateDialog.vue' import TrackPrediction from './track-prediction/TrackPrediction.vue' import WaitDrillTrackDesignDialog from './wait-drill-track-design-dialog/WaitDrillTrackDesignDialog.vue' import HitTargetPredictionDialog from './hit-target-prediction-dialog/HitTargetPredictionDialog.vue' import EditDialog from './edit-dialog/EditDialog.vue' import {deepClone, exportExcel, formatTimeString, formatDecimal} from '@/common/util.js' import BaseFrame from '@/components/layout/BaseFrame.vue' import {Plus, Check, Close, Delete, Download, DataLine, Aim, EditPen, Share, Upload} from '@element-plus/icons-vue' import {ElLoading, ElMessage} from 'element-plus' import {getDrilledTracks, deleteDrilledTrack, getDrilledTrackDatas, saveDrilledTrackData, deleteDrilledTrackData} from '@/api/modules/drilled-track.js' const { t } = useI18n() const appStore = useAppStore() const themeStore = useThemeStore() const wellStore = useWellStore() const well = computed(()=>{ return wellStore.getWell() }) const rowIndex = ref(null) // 表格行 const selectRow = ref(null) // 选中的行 const importDialogVisible = ref(false) const interpolateDialogVisible = ref(false) const waitDrillTrackDesignDialogVisible = ref(false) const hitTargetPredictionDialogVisible = ref(false) const isAdd = ref(true) const editDialogVisible = ref(false) const tableRef = ref(null) const drilledTracks = ref([]) const importSource = ref('file') // 新增:默认是文件导入 // 实钻轨迹 const handleGetDrilledTracks = ()=>{ const params = { wellId: well.value.wellId, wellBoreId: well.value.wellBoreId } getDrilledTracks(params).then(res=>{ if (res) { drilledTracks.value = res // 使用 nextTick 确保表格已经渲染 nextTick(()=>{ // 确保表格引用存在且有数据 if (tableRef.value && drilledTracks.value.length) { const firstRow = drilledTracks.value[0] // 默认选中第一行 tableRef.value.setCurrentRow(firstRow) } }) } }) } // 点击行时,设置当前行 const currentRow = ref(null) const handleCurrentChange = (val)=>{ currentRow.value = val handleGetDrilledTrackDatas() } const drilledTrackDatas = ref([]) const drilledTrackGraphTempDatas = ref([]) // 实钻轨迹数据 const handleGetDrilledTrackDatas = ()=>{ const params = { wellId: well.value.wellId, wellBoreId: well.value.wellBoreId, drilledTrackId: currentRow.value.id } getDrilledTrackDatas(params).then(res=>{ drilledTrackDatas.value = res drilledTrackGraphTempDatas.value = res }) } // 删除待钻轨迹 const handleDeleteDrilledTrack = (idx, row)=>{ const params = { wellId: row.wellId, drilledTrackId: row.id } deleteDrilledTrack(params).then(()=>{ drilledTracks.value.splice(idx, 1) if (drilledTracks.value.length) { const firstRow = drilledTracks.value[0] // 默认选中第一行 tableRef.value.setCurrentRow(firstRow) } else { drilledTrackDatas.value = [] } }) } // 新增 const handleAdd = (idx)=>{ // rowIndex.value = idx + 1 // drilledTrackDatas.value.splice(idx + 1, 0, {md: null, inc: null, azi: null}) const newIndex = idx + 1 drilledTrackDatas.value.splice(newIndex, 0, {md: null, inc: null, azi: null}) // 设置新行编辑状态 editingRows.value.push(newIndex) selectRows.value[newIndex] = deepClone(drilledTrackDatas.value[newIndex]) } // 编辑 const handleUpdate = (idx)=>{ if (!editingRows.value.includes(idx)) { editingRows.value.push(idx) selectRows.value[idx] = deepClone(drilledTrackDatas.value[idx]) } } // 取消编辑 const handleCancel = (idx, row)=>{ if (!row.id) { // 新增行取消 drilledTrackDatas.value.splice(idx, 1) } // 从编辑状态中移除 const indexInEditing = editingRows.value.indexOf(idx) if (indexInEditing !== -1) { editingRows.value.splice(indexInEditing, 1) delete selectRows.value[idx] } } // 保存数据 const handleComplete = async(idx)=>{ const row = drilledTrackDatas.value[idx] // 获取相邻行的值(考虑编辑状态) const prevRow = idx > 0 ? drilledTrackDatas.value[idx - 1] : null const nextRow = idx < drilledTrackDatas.value.length - 1 ? drilledTrackDatas.value[idx + 1] : null // 两个深度之间的间隔不能小于这个值 const eps = 1e-8 // 验证测深值必须大于上一行 if (prevRow && prevRow.md !== null && row.md - prevRow.md <= eps) { ElMessage.warning('测深必须大于上一个值') return false } // 验证测深值必须小于下一行 if (nextRow && nextRow.md !== null && row.md - nextRow.md >= eps) { ElMessage.warning('测深必须小于下一个值') return false } const nonEmptyNewRows = drilledTrackDatas.value .slice(idx + 1) // 获取当前行之后的行 .filter(r=>!r.id && // 新增行(没有ID) editingRows.value.includes(drilledTrackDatas.value.indexOf(r)) && // 处于编辑状态 (r.md !== null || r.inc !== null || r.azi !== null) // 至少有一个字段非空 ) .map(r=>({ ...r })) // 深拷贝 // console.log(nonEmptyNewRows) const postData = { id: row.id, wellId: well.value.wellId, wellBoreId: well.value.wellBoreId, drilledTrackId: currentRow.value.id, md: row.md, inc: row.inc, azi: row.azi } try { await saveDrilledTrackData(postData) // 从编辑状态中移除 const indexInEditing = editingRows.value.indexOf(idx) // console.log(indexInEditing) if (indexInEditing !== -1) { editingRows.value.splice(indexInEditing, 1) delete selectRows.value[idx] } // 重新载数据 await handleGetDrilledTrackDatas() // +++ 新增:重新添加非空的新行并恢复编辑状态 +++ nonEmptyNewRows.forEach(newRow=>{ console.log(nonEmptyNewRows) const newIndex = drilledTrackDatas.value.length - 1 console.log(newIndex) console.log(drilledTrackDatas) drilledTrackDatas.value.push(newRow) console.log(newRow) editingRows.value.push(newIndex) console.log(editingRows.value.push(newIndex)) selectRows.value[newIndex] = deepClone(newRow) console.log(selectRows) }) } catch (error) { console.error('保存失败:', error) ElMessage.error('保存失败') } } // 删除轨迹数据 const handleDeleteDrilledTrackData = (row)=>{ const params = { wellId: well.value.wellId, drilledTrackDataId: row.id } deleteDrilledTrackData(params).then(()=>{ handleGetDrilledTrackDatas() }) } // 3D轨迹配置 const drilledTrackGraphConfig = ref({ skin: { blackTheme: themeStore.isDark}, showLegend: false, showScaleSelector: false, showTubeSizeSlider: true, tubeSize: 0 }) // 图形数据 const drilledTrackGraphDatas = computed(()=>{ if (!drilledTrackGraphTempDatas.value) { return null } // 过滤新录入的数据 const filterData = drilledTrackGraphTempDatas.value.filter(t=>t.id) const data = filterData.map(({ ns: x, ew: y, ...rest })=>({ x, y, ...rest })) return [ { 'code': 0, 'isDrilled': true, 'data': data, 'name': '实钻轨迹', 'isShow': true } ] }) const excelData = ref([]) const excelFile = ref(null) const loading = ref(null) // 导入轨迹数据 const handleImportDrilledTrackData = (ev)=>{ // 获取文件后缀 const ext = ev.name.substring(ev.name.lastIndexOf('.')) if (ext !== '.xls' && ext !== '.xlsx') { ElMessage.warning('请选择EXCEL文件') return false } excelData.value = [] excelFile.value = ev.raw if (!excelFile.value) { ElMessage.warning('文件打开失败') return false } else { loading.value = ElLoading.service({ lock: true, text: '文件解析中,请稍候...', background: 'rgba(0, 0, 0, 0.7)' }) // 读取文件 setTimeout(readExcelFile, 100) } } // 文件读取并解析 const readExcelFile = ()=>{ const reader = new FileReader() reader.readAsBinaryString(excelFile.value)// 以二进制的方式读取 reader.onload = ev=>{ const fileData = ev.target.result const workBook = XLSX.read(fileData, {type: 'binary'})// 解析二进制格式数据 workBook.SheetNames.forEach((sheetName, index)=>{ const item = { sheetName: sheetName } const workSheet = workBook.Sheets[workBook.SheetNames[index]]// 获取第一个Sheet item.rows = XLSX.utils.sheet_to_json(workSheet, {range: -1, defval: null})// 指定-1行为列头,空单元格赋值 null // 获取json数据key if (item.rows && item.rows.length > 0) { item.keys = [] const keys = Object.keys(item.rows[0]) keys.forEach((key, index)=>{ item.keys.push({ idx: index, key: key, label: '' }) }) } excelData.value.push(item) }) importDialogVisible.value = true loading.value.close() } } const handleImport = (source)=>{ if (source === 'file') { // 模拟点击隐藏的 input 或 el-upload 打开系统文件夹 document.querySelector('#hiddenFileInput').click() } else if (source === 'clipboard') { importSource.value = 'clipboard' importDialogVisible.value = true } } const handleImportReload = ()=>{ handleGetDrilledTrackDatas() importDialogVisible.value = false } // 导出轨迹数据 const handleExportDrilledTrackData = ()=>{ // 过滤数据,只取一部分属性的数据 const partData = drilledTrackDatas.value.map(({md, inc, azi, tvd, nsOffset, ewOffset, horiOffset, projOffset, dogleg})=>({ md, inc, azi, tvd, nsOffset, ewOffset, horiOffset, projOffset, dogleg })) // 值数组 const valueArray = partData.map(obj=>Object.values(obj)) const headerArray = ['测深', '井斜', '方位', '垂深', '南北位移', '东西位移', '水平位移', '投影位移', '狗腿度'] const sheetName = '实钻轨迹' const fileName = '实钻轨迹.xlsx' exportExcel(sheetName, headerArray, formatDecimal(valueArray), fileName, 15) } // 监听well变化 watch(()=>well, (newVal)=>{ if (Object.keys(newVal.value).length !== 0) { handleGetDrilledTracks() } }, {deep: true, immediate: true}) const editingRows = ref([]) const selectRows = ref({}) // 修改:处理测深输入事件 const handleMdInput = (index)=>{ const row = drilledTrackDatas.value[index] // 检查件:当前是最后一行、正在编辑、测深有值、是新增行(无ID) if ( index === drilledTrackDatas.value.length - 1 && editingRows.value.includes(index) && row.md !== null && row.md !== '' && !row.id ) { // 在下方添加新行 drilledTrackDatas.value.push({md: null, inc: null, azi: null}) const newIndex = drilledTrackDatas.value.length - 1 // 设置新行进入编辑状态 editingRows.value.push(newIndex) selectRows.value[newIndex] = deepClone(drilledTrackDatas.value[newIndex]) } } </script> <template> <BaseFrame> <!-- 左侧内容区 --> <div class="col-span-8 flex flex-1 flex-col gap-2"> <!-- 轨迹列表 --> <Card> <template #header> <div class="flex justify-between pl-0 pr-0"> <div class="flex items-center gap-2"> <span class="text-slate-600 dark:text-slate-50 text-[14px]"><strong>【{{ well.wellId ? `${well.wellCode} | ${well.wellBoreName}` : '暂未选井' }}】</strong></span> </div> <div class="flex items-center"> <el-button :icon="Plus" size="small" class="mr-3" @click="editDialogVisible=true;isAdd=true;">{{ t('add') }}</el-button> <el-dropdown @command="importSource=>handleImport(importSource)"> <el-button :icon="Download" size="small">{{ t('import') }}</el-button> <template #dropdown> <el-dropdown-menu> <el-dropdown-item command="file">导入文件</el-dropdown-item> <el-dropdown-item command="clipboard">从剪切板导入</el-dropdown-item> </el-dropdown-menu> </template> </el-dropdown> <input id="hiddenFileInput" type="file" accept=".xlsx,.xls" style="display:none" @change="handleImportDrilledTrackData" > <el-button :icon="Upload" size="small" class="ml-3" :disabled="!currentRow" @click="handleExportDrilledTrackData"> {{ t('export') }} </el-button> <el-button :icon="EditPen" size="small" :disabled="!currentRow" @click="interpolateDialogVisible=true"> {{ t('interpolate') }} </el-button> <el-button :icon="Share" size="small" :disabled="!currentRow" @click="appStore.toggleTrackPredictionDrawer()"> {{ t('plan') }} </el-button> <el-button :icon="Share" size="small" :disabled="!currentRow" @click="waitDrillTrackDesignDialogVisible=true"> 待钻设计 </el-button> <el-button :icon="Aim" size="small" :disabled="!currentRow" @click="hitTargetPredictionDialogVisible=true"> {{ t('targetEntry') }} </el-button> <el-button :icon="DataLine" size="small"> {{ t('trend') }} </el-button> </div> </div> </template> <template #default> <div class="h-[14vh]"> <el-table ref="tableRef" :data="drilledTracks" highlight-current-row height="100%" size="small" border stripe style="width: 100%;" @current-change="handleCurrentChange"> <el-table-column type="index" :label="t('order')" width="50" align="center" fixed /> <el-table-column prop="name" :label="t('name')" min-width="80" header-align="center" /> <el-table-column prop="createTime" align="center" :label="t('date')" width="120"> <template #default="{ row }"> <span>{{ formatTimeString(row.createTime, 'YYYY-MM-DD') }}</span> </template> </el-table-column> <el-table-column fixed="right" align="center" :label="t('operate')" width="100"> <template #default="{$index,row}"> <el-button link type="success" size="small" @click.stop="editDialogVisible=true;isAdd=false;"> {{ t('revise') }} </el-button> <el-popconfirm width="200" class="box-item" :title="`确认删除实钻轨迹?`" placement="bottom" confirm-button-text="确认" cancel-button-text="取消" @confirm="handleDeleteDrilledTrack($index,row)" > <template #reference> <el-button link type="danger" size="small" @click.stop> {{ t('delete') }} </el-button> </template> </el-popconfirm> </template> </el-table-column> </el-table> </div> </template> </Card> <!--/ 轨迹列表 --> <!-- 详细数据 --> <Card class="px-2" style="height:calc(100vh - 14rem)"> <div class="h-[98%] overflow-y-auto mt-2"> <el-table size="small" border stripe :data="formatDecimal(drilledTrackDatas)" height="100%" style="width: 100%" > <el-table-column :label="t('operate')" width="90" align="center" fixed="left"> <template #default="{$index,row}"> <template v-if="editingRows.includes($index)"> <div class="flex gap-1 *:!ml-0"> <el-button size="small" type="warning" plain :icon="Close" @click="handleCancel($index, row)" /> <el-button size="small" plain type="success" :icon="Check" @click="handleComplete($index)" /> </div> </template> <template v-else> <div class="flex gap-1 *:!ml-0"> <el-button size="small" class="ml-1" plain :icon="Plus" @click="handleAdd($index)" /> <el-popconfirm width="200" class="box-item" :title="`确认删除本条轨迹数据?`" placement="bottom" confirm-button-text="确认" cancel-button-text="取消" @confirm="handleDeleteDrilledTrackData(row)" > <template #reference> <el-button plain size="small" :icon="Delete" @click.stop /> </template> </el-popconfirm> </div> </template> </template> </el-table-column> <el-table-column label="测深" prop="depth" header-align="center" min-width="80" fixed="left"> <template #header> <div>{{ t('Md') }}</div> <div class="unit-size">(m)</div> </template> <template #default="{$index,row}"> <template v-if="editingRows.includes($index)"> <el-input ref="input" v-model="drilledTrackDatas[$index].md" v-format-input size="small" placeholder="请输入测深" @input="handleMdInput($index)" /> </template> <span v-else @dblclick="handleUpdate($index)">{{ row.md }}</span> </template> </el-table-column> <el-table-column label="井斜" prop="inc" header-align="center" min-width="80" fixed="left"> <template #header> <div>{{ t('inclination') }}</div> <div class="unit-size">(°)</div> </template> <template #default="{$index,row}"> <template v-if="editingRows.includes($index)"> <el-input v-model="drilledTrackDatas[$index].inc" v-format-input size="small" placeholder="请输入井斜" /> </template> <span v-else @dblclick="handleUpdate($index)">{{ row.inc }}</span> </template> </el-table-column> <el-table-column label="方位" prop="azi" header-align="center" min-width="80" fixed="left"> <template #header> <div>{{ t('azimuth') }}</div> <div class="unit-size">(°)</div> </template> <template #default="{$index,row}"> <template v-if="editingRows.includes($index)"> <el-input v-model="drilledTrackDatas[$index].azi" v-format-input size="small" placeholder="请输入方位" /> </template> <span v-else @dblclick="handleUpdate($index)">{{ row.azi }}</span> </template> </el-table-column> <el-table-column label="垂深" prop="tvd" header-align="center" min-width="80" > <template #header> <div>{{ t('Tvd') }}</div> <div class="unit-size">(m)</div> </template> </el-table-column> <el-table-column label="段长" prop="sectionLength" header-align="center" min-width="80" > <template #header> <div>{{ t('courseLength') }}</div> <div class="unit-size">(m)</div> </template> </el-table-column> <el-table-column label="南北位移" prop="nsOffset" header-align="center" min-width="80" > <template #header> <div>{{ t('NsOffset') }}</div> <div class="unit-size">(m)</div> </template> </el-table-column> <el-table-column label="东西位移" prop="ewOffset" header-align="center" min-width="80" > <template #header> <div>{{ t('EwOffset') }}</div> <div class="unit-size">(m)</div> </template> </el-table-column> <el-table-column label="水平位移" prop="horiOffset" header-align="center" min-width="80" > <template #header> <div>{{ t('closure') }}</div> <div class="unit-size">(m)</div> </template> </el-table-column> <el-table-column label="投影位移" prop="projOffset" header-align="center" min-width="80" > <template #header> <div>{{ t('Verticaldistance') }}</div> <div class="unit-size">(m)</div> </template> </el-table-column> <el-table-column label="闭合方位" prop="closeAzi" header-align="center" min-width="80" > <template #header> <div>{{ t('closureAz') }}</div> <div class="unit-size">(°)</div> </template> </el-table-column> <el-table-column label="狗腿度" prop="dogleg" header-align="center" min-width="80" > <template #header> <div>{{ t('dogleg') }}</div> <div class="unit-size">(°/30m)</div> </template> </el-table-column> <el-table-column label="工具面" prop="toolface" header-align="center" min-width="80" > <template #header> <div>{{ t('toolface') }}</div> <div class="unit-size">(°)</div> </template> </el-table-column> <el-table-column label="井斜变化率" prop="incChangeRate" header-align="center" min-width="80" > <template #header> <div>{{ t('incChangeRate') }}</div> <div class="unit-size">(°/30m)</div> </template> </el-table-column> <el-table-column label="方位变化率" prop="aziChangeRate" header-align="center" min-width="80" > <template #header> <div>{{ t('aziChangeRate') }}</div> <div class="unit-size">(°/30m)</div> </template> </el-table-column> </el-table> </div> </Card> <!--/ 详细数据 --> </div> <!-- 右侧2D/3D区域 --> <div class="col-span-4 flex flex-col"> <Card class="flex-1"> <WellTrajectory v-if="drilledTrackGraphDatas" id="divTubeElement" v-model:config="drilledTrackGraphConfig" :show-well-name="false" :show-full-screen-btn="true" :show-animation="false" is-auto-play.sync="true" :data="drilledTrackGraphDatas" /> </Card> </div> <!-- 新增/修改 对话框 --> <edit-dialog v-if="editDialogVisible" :row-data="isAdd?null:currentRow" @reload="handleImportReload" @close="editDialogVisible=false" /> <!-- 导入数据 --> <import-dialog v-if="importDialogVisible" v-model:import-source="importSource" :drilled-track-id="currentRow.id" :excel-data="excelData" @reload="handleGetDrilledTrackDatas" @close="importDialogVisible=false" /> <!-- 插值计算 --> <interpolate-dialog v-if="interpolateDialogVisible" :drilled-track-id="currentRow.id" @close="interpolateDialogVisible=false" /> <!-- 轨迹预测抽屉 --> <el-drawer v-model="appStore.trackPredictionDrawerVisible" title="轨迹预测" :with-header="true" size="100%" direction="ltr" :close-on-click-modal="false" :close-on-press-escape="false" :destroy-on-close="true" > <track-prediction :last-drilled-track-data="drilledTrackDatas[drilledTrackDatas.length-1]" /> </el-drawer> <!-- 待钻设计 --> <wait-drill-track-design-dialog v-if="waitDrillTrackDesignDialogVisible" :last-drilled-track-data="drilledTrackDatas[drilledTrackDatas.length-1]" @close="waitDrillTrackDesignDialogVisible=false" /> <!-- 中靶预测 --> <hit-target-prediction-dialog v-if="hitTargetPredictionDialogVisible" :drilled-track-id="currentRow.id" @close="hitTargetPredictionDialogVisible=false" /> </BaseFrame> </template> <style lang="scss" scoped> .tab-content { @apply p-2 absolute left-0 top-0 w-full h-full overflow-auto; } .border-card { :deep(.el-tabs__nav-scroll) { @apply flex; .el-tabs__nav { @apply flex-1; .el-tabs__item { @apply flex-1; } } } &.no-border { @apply border-none; } } :deep(.el-drawer) { .el-drawer__header { @apply mb-1 } } </style> 修改本代码,要求保存上一行时,自动新增行内有内容时应该保留当前行并保留编辑状态
07-17
<template> <a-card :bordered="false" :class="{isShowStyle: indirectFlag}"> <!-- 查询区域 --> <div class="table-page-search-wrapper" v-if="!indirectFlag"> <a-form layout="inline" @keyup.enter.native="searchQuery"> <a-row :gutter='24'> <a-col :span='8'> <a-form-item label='主机厂'> <a-input v-model.trim='queryParam.oems' placeholder='请输入主机厂名称'></a-input> </a-form-item> </a-col> <a-col :span='8'> <a-form-item label='客户名称'> <a-input v-model.trim='queryParam.endUser' placeholder='请输入客户名称'></a-input> </a-form-item> </a-col> <a-col :span='8'> <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'> <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button> <a-button type='primary' @click='reset' icon='reload' style='margin-left: 8px'>重置</a-button> </span> </a-col> </a-row> </a-form> </div> <!-- 查询区域-END --> <!-- 操作按钮区域 --> <div class="table-operator"> <!-- <a-button @click="handleAdd" type="primary" icon="plus" v-if="indirectModal" :disabled="hiddenFlag">新增--> <!-- </a-button>--> <a-upload v-if="!hiddenFlag" name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel"> <a-button type="primary" icon="import" :disabled="hiddenFlag">导入</a-button> </a-upload> <!-- <a-button icon='link' type='primary' @click='outmb' v-if="indirectModal" :disabled="hiddenFlag">--> <!-- 导入模板--> <!-- </a-button>--> <a-button icon='link' type='primary' @click='outmb1' :disabled="hiddenFlag"> 导入模板 </a-button> <a-button type="primary" @click="bacthSave" v-if="indirectModal" :disabled="hiddenFlag">保存</a-button> <a-button type="primary" @click="subStatus" v-if="indirectModal" :disabled="hiddenFlag">提交</a-button> <a-dropdown v-if='selectedRowKeys.length > 0'> <a-menu slot='overlay'> <a-menu-item key='1' @click='batchDelete'> <a-icon type='delete' /> 删除 </a-menu-item> </a-menu> <a-button style='margin-left: 8px'> 批量操作 <a-icon type='down' /> </a-button> </a-dropdown> </div> <!-- table区域-begin --> <div> <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">--> <!-- <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a--> <!-- style="font-weight: 600">{{ selectedRowKeys.length }}</a>项--> <!-- <a style="margin-left: 24px" @click="onClearSelected">清空</a>--> <!-- </div>--> <j-editable-table v-if="indirectModal" ref="editableTable" size="middle" bordered rowKey="id" :columns="dynamicColumns" :dataSource="dataSource" :rowNumber="true" :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" class="j-table-force-nowrap" :actionButton="true" :disabledRows="{ status:1}" @change="handleTableChange"> <template v-slot:oemsSlot="props"> <a-input v-model='props.text' placeholder='请输入主机厂' :disabled="isDisabled(props)" @input="oemsInput(props)"> <a-icon slot='prefix' type='cluster' @click.stop='handleOemsClick(props)'/> </a-input> </template> <template v-slot:productSearchSlot="props"> <a-select v-model="props.text" show-search placeholder="请选择产品名称" :default-active-first-option="false" :show-arrow="false" :filter-option="false" :not-found-content="null" style="width: 100%" @search="handleProductSearch" @change="handleProductChange(props)" > <a-select-option v-for="item in productList" :key="item.value" :value="item.value"> {{ item.text }} </a-select-option> </a-select> </template> <template v-slot:productSlot="props"> <j-search-select-tag v-model="props.text" placeholder="请选择产品名称" dict="bs_inventory GROUP BY cInvName, cInvName, cInvName" /> </template> <template v-slot:publishSlot="props"> <div> <a-input-search v-model="props.text" placeholder="请先选择用户" readOnly unselectable="on" @search="onSearchDepUser(props)"> <a-button slot="enterButton" :disabled="false">选择用户</a-button> </a-input-search> <j-select-user-by-dep-modal ref="selectModal" modal-width="80%" :multi="false" @ok="selectOK" :user-ids="props.value" @initComp="initComp"/> </div> </template> <span slot='titleSlot' slot-scope='text'> <j-ellipsis :value='text' :length='40'/> </span> </j-editable-table> <a-table v-else ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" class="j-table-force-nowrap" @change="handleTableChange"> <span slot='titleSlot' slot-scope='text'> <j-ellipsis :value='text' :length='40'/> </span> <span slot="action" slot-scope="text, record"> <a @click="handleEdit(record)" :disabled="!record.editBtn">编辑</a> <a-divider type="vertical"/> <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)"> <a :disabled="!record.editBtn">删除</a> </a-popconfirm> </span> </a-table> </div> <indirectBusinessProducts-modal ref="modalForm" :indirectModal="indirectModal" @ok="modalFormOk"></indirectBusinessProducts-modal> <indirectBusinessProducts-item-modal ref="modalItemForm" @ok="modalFormOk"></indirectBusinessProducts-item-modal> <a-modal title='客户名称(主机厂)' :width='1000' :visible='cusVisible' @ok='handleCusSubmit' @cancel='closeCusModal' cancelText='关闭'> <cus-component ref='cusComponent'></cus-component> </a-modal> </a-card> </template> <script> import '@/assets/less/TableExpand.less' import {mixinDevice} from '@/utils/mixin' import {JeecgListMixin} from '@/mixins/JeecgListMixin' import IndirectBusinessProductsModal from './modules/IndirectBusinessProductsModal' import JEllipsis from "../../../components/jeecg/JEllipsis.vue"; import IndirectBusinessProductsItemModal from "./modules/IndirectBusinessProductsItemModal.vue"; import {deleteAction, downFile, getAction, postAction, putAction} from "../../../api/manage"; import {filterDictText, initDictOptions} from '@/components/dict/JDictSelectUtil' import {FormTypes} from '@/utils/JEditableTableUtil' import JEditableTable from "@comp/jeecg/JEditableTable.vue"; import CusComponent from "@views/modules/eoa/plan/components/CusComponent.vue"; import JSelectUserByDep from "@comp/jeecgbiz/JSelectUserByDep.vue"; import JSelectUserByDepModal from "@comp/jeecgbiz/modal/JSelectUserByDepModal.vue"; import JSearchSelectTag from "@comp/dict/JSearchSelectTag.vue"; export default { name: "IndirectBusinessProductsList", mixins: [JeecgListMixin, mixinDevice], components: { JSearchSelectTag, JSelectUserByDepModal, JSelectUserByDep, CusComponent, JEditableTable, IndirectBusinessProductsItemModal, JEllipsis, IndirectBusinessProductsModal }, props: { indirectFlag: { type: Boolean, default: false }, indirectModal: { type: Object, default: () => { } }, hiddenFlag: { type: Boolean, default: false }, }, data() { return { usernames: null, value: null, userIds: null, description: 'indirect_business_products管理页面', statusDictOptions: [], busType: 'my', cusVisible: false, // 表头 columns: [ { title: '#', dataIndex: '', key: 'rowIndex', width: 60, align: "center", customRender: function (t, r, index) { return parseInt(index) + 1; } }, // { // title: '客户名称(主机厂)', // align: "center", // dataIndex: 'oems' // }, { title: '客户名称', align: "center", dataIndex: 'endUser' }, { title: '终端用户', align: "center", dataIndex: 'oems', scopedSlots: {customRender: 'titleSlot'}, width: 100 }, { title: '车型(米)', align: "center", dataIndex: 'carType', customRender: (text, record, index) => { //字典值替换通用方法 return filterDictText(this.vehicleModelOptions, text); } }, { title: '产品明细', align: "center", scopedSlots: {customRender: 'titleSlot'}, dataIndex: 'productDetails' }, { title: '发布数量', align: "center", dataIndex: 'number' }, { title: '预测金额', align: "center", dataIndex: 'redictedAmount' }, { title: '发布人', align: "center", dataIndex: 'publishName' }, { title: '发布时间', align: "center", dataIndex: 'publishTime', customRender: function (text) { return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text) } }, { title: '产品类型', align: "center", dataIndex: 'productType', customRender: (text, record, index) => { //字典值替换通用方法 return filterDictText(this.productTypeOptions, text); } }, // { // title: '产品大类', // align: "center", // dataIndex: 'productCategories' // }, { title: '提交状态', align: "center", dataIndex: 'status', customRender: (text, record, index) => { //字典值替换通用方法 return filterDictText(this.statusDictOptions, text); } }, { title: '操作', dataIndex: 'action', align: "center", // fixed:"right", width: 147, scopedSlots: {customRender: 'action'} } ], url: { list: "/indirect_business/products/list", delete: "/indirect_business/products/delete", deleteBatch: "/indirect_business/products/deleteBatch", setStatus: "/indirect_business/products/setStatus", batchAdd: "/indirect_business/products/batchAdd", teamExcelTemplate: "indirect_business/indirectBusiness/teamExcelTemplate", teamExcelTemplateProduct: "indirect_business/indirectBusiness/teamExcelTemplateProduct", importExcelUrl: "indirect_business/products/importExcel", }, dictOptions: {}, queryParam:{ status:'1' }, productList: [],//储存产品信息列表 currentClickRowId: null, // 存储当前点击的行ID } }, computed: { importExcelUrl: function () { if (!this.indirectModal) { return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`; } else { return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}?busId=${this.indirectModal.busId}&endUser=${this.indirectModal.endCustomer}`; } }, getLoginUsername() { return this.$store.getters.userInfo.username; }, loginPermissions() { return this.indirectModal.helpPerson.includes(this.$store.getters.userInfo.username); }, rowSelection() { return { onChange: (selectedRowKeys, selectedRows) => { this.onSelectChange(selectedRowKeys, selectedRows); }, getCheckboxProps: record => ({ props: { disabled: record.status === 1 || record.status === null }, }), }; }, dynamicColumns() { const baseColumns = [ { title: "busId", align: "center", key: "busId", type: FormTypes.hidden, defaultValue: this.indirectModal.busId }, // 动态客户名称列 { title: this.indirectModal.category === '1' ? '客户名称' : '终端客户名称', align: "center", key: 'endUser', type: FormTypes.input, placeholder: '请输入客户名称', disabled: true, defaultValue: this.indirectModal.endCustomer, width: '220px' } ]; if (this.indirectModal.category === '2'){ baseColumns.push({ title: '主机厂', align: "center", key: 'oems', placeholder: "请选择主机厂", type: FormTypes.slot, slotName: 'oemsSlot', validateRules: this.indirectModal.category === '2' ? [ { required: true, message: '主机厂不能为空' }, { validator: (rule, value, callback) => { if (value === '' || value === null || value === undefined) { callback(new Error('请选择主机厂')); // 配合 required 使用 } } } ] : [], width: '220px', }); } baseColumns.push({ title: '车型(米)', align: "center", key: 'carType', type: FormTypes.select, dictCode: 'vehicle_model', placeholder: '请选择车型', customRender: (text, record, index) => { //字典值替换通用方法 return filterDictText(this.vehicleModelOptions, text); }, width: '150px' }) baseColumns.push({ title: '产品名称', align: "center", key: 'productDetails', placeholder: "请选择产品名称", type: FormTypes.slot, slotName: 'productSearchSlot', width: '240px' }) baseColumns.push({ title: '发布数量', align: "center", key: 'number', type: FormTypes.input, inputType: 'number', placeholder: "请输入发布数量", validateRules: [ { pattern: /^[1-9]\d*$/, // 正整数正则 message: '发布数量必须是正整数' } ], width: '150px' }) baseColumns.push({ title: '预测金额', align: "center", key: 'redictedAmount', type: FormTypes.input, inputType: 'number', placeholder: "请输入预测金额", // 动态校验规则(category == '2' 时必填且必须为正数) validateRules: this.indirectModal.category === '2' ? [ { required: true, message: '预测金额不能为空', trigger: ['blur', 'change'] // 触发校验的时机 }, { pattern: /^(0|[1-9]\d*)(\.\d+)?$/, // 正整数正则 message: '发布数量必须是正数' } ] : [], width: '150px' }) if (this.indirectModal.category === '2'){ baseColumns.push({ title: '主机厂负责人', align: "center", key: 'oemResponsiblePerson', type: FormTypes.hidden, }); } // if (this.indirectModal.category === '2'){ // baseColumns.push({ // title: '主机厂负责人', // align: "center", // key: 'oemResponsiblePersonName', // type: FormTypes.input, // disabled: true, // width: '200px' // }); // } baseColumns.push({ title: '发布人', align: "center", key: 'publishBy', type: FormTypes.hidden, defaultValue: this.$store.getters.userInfo.username, placeholder: "请选择发布人", width: '240px' }) baseColumns.push({ title: '发布人', align: "center", key: 'publishName', type: FormTypes.slot, slotName: 'publishSlot', defaultValue: this.$store.getters.userInfo.realname, placeholder: "请选择发布人", width: '240px' }) baseColumns.push({ title: '发布时间', align: "center", key: 'publishTime', type: FormTypes.date, customRender: function (text) { return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text) }, defaultValue: this.formatDate(new Date()), width: '170px' }) baseColumns.push({ title: '产品类型', align: "center", key: 'productType', placeholder: "请选择产品类型", type: FormTypes.select, dictCode: 'product_type', customRender: (text, record, index) => { //字典值替换通用方法 return filterDictText(this.productTypeOptions, text); }, defaultValue: '0', width: '130px' }) baseColumns.push({ title: '提交状态', align: "center", key: 'status', type: FormTypes.select, dictCode: 'public_status', customRender: (text, record, index) => { //字典值替换通用方法 return filterDictText(this.statusDictOptions, text); }, defaultValue: '0', disabled: true, width: '130px' }) return baseColumns; }, }, methods: { initDictConfig() { getAction('/base/bsInventory/distinctAllList',null).then((res) => { if (res.success) { this.productList = res.result.map(item => ({ text: item.cinvname, value: item.cinvname })) } }) //判断查询件 if (!this.indirectModal){ this.queryParam.status = 1 this.loadData(1) }else{ this.queryParam.busId = this.indirectModal.busId this.queryParam.status = '' this.loadData(1) } console.log('this.queryParam.status',this.queryParam.status) initDictOptions('public_status').then((res) => { if (res.success) { this.statusDictOptions = res.result } }) initDictOptions('vehicle_model').then((res) => { if (res.success) { this.vehicleModelOptions = res.result } }) initDictOptions('product_type').then((res) => { if (res.success) { this.productTypeOptions = res.result } }) }, // 产品名称远程搜索 handleProductSearch(value) { if (!value) return; // 空输入不查询 // 调用接口查询匹配的产品 getAction('/base/bsInventory/distinctAllList', { 'cinvname': value }).then(res => { if (res.success) { this.productList = res.result.map(item => ({ text: item.cinvname, value: item.cinvname })); } }); }, handleProductChange(props) { // 存储当前点击的行记录和ID this.currentClickRowId = props.rowId; this.$refs.editableTable.setValues([{ rowKey: this.currentClickRowId, values: { 'productDetails': props.text } }]); }, outmb() { downFile(this.url.teamExcelTemplate, '').then((res) => { if (!res) { this.$message.warning('文件下载失败') return } let blob = new Blob([res], {type: 'application/vnd.ms-excel'}) let downloadElement = document.createElement('a') let href = window.URL.createObjectURL(blob) // 创建下载的链接 downloadElement.href = href downloadElement.download = '间接销售登记表导入模板.xls' // 下载后文件名 document.body.appendChild(downloadElement) downloadElement.click() // 点击下载 document.body.removeChild(downloadElement) // 下载完成移除元素 window.URL.revokeObjectURL(href) // 释放掉blob对象 }) }, outmb1() { downFile(this.url.teamExcelTemplateProduct, '').then((res) => { if (!res) { this.$message.warning('文件下载失败') return } let blob = new Blob([res], {type: 'application/vnd.ms-excel'}) let downloadElement = document.createElement('a') let href = window.URL.createObjectURL(blob) // 创建下载的链接 downloadElement.href = href downloadElement.download = '间接销售登记导入模板.xlsx' // 下载后文件名 document.body.appendChild(downloadElement) downloadElement.click() // 点击下载 document.body.removeChild(downloadElement) // 下载完成移除元素 window.URL.revokeObjectURL(href) // 释放掉blob对象 }) }, subStatus(){ const ids = this.$refs.editableTable.getSelection() if (ids.length==0){ this.$message.warn("请选择一记录") return; } const selectedRow = this.$refs.editableTable.getValuesSync({rowIds: ids}).values selectedRow.forEach(item => { if (item.status == "1"){ this.$message.warn("请选择未提交的数据") return; } }) let that = this that.$confirm({ title: '提示', content: '确认提交吗?', onOk: function() { putAction(that.url.setStatus, selectedRow).then((res) => { if (res.success) { that.$message.success(res.message); that.loadData(); that.onClearSelected(); } else { that.$message.warning(res.message); that.loadData(); } }) } }) }, bacthSave() { this.$refs.editableTable.getValues(error => { if (error === 0) { let that = this postAction(that.url.batchAdd, this.$refs.editableTable.getValuesSync().values).then((res) => { if (res.success) { that.$message.success(res.message); that.loadData(); } else { that.$message.warning(res.message); that.loadData(); } }) } else { this.$message.error('验证未通过') } }) }, reset(){ this.queryParam = {status:'1'} this.loadData() }, batchDelete: function () { if(!this.url.deleteBatch){ this.$message.error("请设置url.deleteBatch属性!") return } if (this.selectedRowKeys.length <= 0) { this.$message.warning('请选择一记录!'); return; } else if (this.selectionRows.some(item => item.status != 0)) { this.$message.warning('请选择未提交记录!') return; } else { var ids = ""; for (var a = 0; a < this.selectedRowKeys.length; a++) { ids += this.selectedRowKeys[a] + ","; } var that = this; this.$confirm({ title: "确认删除", content: "是否删除选中数据?", onOk: function () { that.loading = true; deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => { if (res.success) { that.$message.success(res.message); that.loadData(); that.onClearSelected(); } else { that.$message.warning(res.message); } }).finally(() => { that.loading = false; }); } }); } }, handleCusSubmit() { if (!this.$refs.cusComponent.selectionRows || this.$refs.cusComponent.selectionRows.length === 0) { this.$message.warning('请选择一记录') return false } var customerNames = ""; var oemResponsiblePerson = ""; var oemResponsiblePersonName = ""; for (var a = 0; a < this.$refs.cusComponent.selectedRowRecords.length; a++) { customerNames += this.$refs.cusComponent.selectedRowRecords[a].customerName + ","; if (this.$refs.cusComponent.selectedRowRecords[a].responsiblePerson !== null) { oemResponsiblePerson += this.$refs.cusComponent.selectedRowRecords[a].responsiblePerson + ","; } if (this.$refs.cusComponent.selectedRowRecords[a].responsiblePersonName!==null){ oemResponsiblePersonName += this.$refs.cusComponent.selectedRowRecords[a].responsiblePersonName + ","; } } const oems = customerNames.substr(0,customerNames.length-1) const oemResponsiblePersons = oemResponsiblePerson.substr(0,oemResponsiblePerson.length-1) const oemResponsiblePersonNames = oemResponsiblePersonName.substr(0,oemResponsiblePersonName.length-1) // 找到当前点击的行并更新数据 this.$refs.editableTable.setValues( [{ rowKey: this.currentClickRowId, values: { 'oems': oems, 'oemResponsiblePerson': oemResponsiblePersons, 'oemResponsiblePersonName': oemResponsiblePersonNames, } }] ) this.closeCusModal() }, oemsInput(props) { // 存储当前点击的行记录和ID this.currentClickRowId = props.rowId; // 找到当前点击的行并更新数据 this.$refs.editableTable.setValues( [{ rowKey: this.currentClickRowId, values: { 'oems': props.text } }] ) }, handleOemsClick(props) { console.log("主机厂",this.$refs.editableTable.getValues({rowIds: props.rowId})) // 存储当前点击的行记录和ID this.currentClickRowId = props.rowId; this.openCusModal(); // 直接打开弹窗 }, openCusModal() { this.cusVisible = true }, closeCusModal() { this.$refs.cusComponent.selectionRows = [] this.$refs.cusComponent.selectedRowKeys = [] this.$refs.cusComponent.queryParam = {} this.cusVisible = false }, formatDate(date) { const year = date.getFullYear() const month = (date.getMonth() + 1).toString().padStart(2, '0') const day = date.getDate().toString().padStart(2, '0') return `${year}-${month}-${day}` }, initComp(userNames) { this.userNames = userNames }, onSearchDepUser(props) { this.currentClickRowId = props.rowId if (this.isSelectUser) this.$refs.selectModal.queryParam.username = this.value; this.$refs.selectModal.showModal() this.$refs.selectModal.queryParam.username = ""; }, selectOK(rows, idstr) { if (!rows) { this.userNames = '' this.userIds = '' } else { let temp = '' for (let item of rows) { temp += ',' + item.realname } this.userNames = temp.substring(1) this.userIds = idstr // 找到当前点击的行并更新数据 this.$refs.editableTable.setValues( [{ rowKey: this.currentClickRowId, values: { 'publishBy': this.userIds, 'publishName': this.userNames, } }] ) } }, // 判断是否禁用 isDisabled(props){ const item = this.$refs.editableTable.getValuesSync({rowIds: [props.rowId]}) return item.values[0].status === '1' } } } </script> <style scoped> @import '~@assets/less/common.less'; .isShowStyle /deep/ .ant-card-body { padding: unset; } </style>中<template v-slot:oemsSlot="props"> <a-input v-model='props.text' placeholder='请输入主机厂' :disabled="isDisabled(props)" @input="oemsInput(props)"> <a-icon slot='prefix' type='cluster' @click.stop='handleOemsClick(props)'/> </a-input> </template>插槽的:disabled怎么使用,我想根据本条记录的status判断是否禁用
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值