张诺
4 天以前 d8fead89b61acd2b1462559c2fa634b05f73c5d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!-- 使用示例 -->
<template>
  <div>
    <!-- 基本使用 -->
    <ProductionDetailsTable v-model="tableData" />
    
    <!-- 自定义配置 -->
    <ProductionDetailsTable 
      v-model="tableData" 
      :border="true"
      :show-operations="false"
      :auto-calculate="false"
      @input-change="handleChange"
      @delete-row="handleDelete"
    />
    
    <!-- 操作按钮 -->
    <el-row :gutter="10" style="margin-top: 20px;">
      <el-col :span="4">
        <el-button type="primary" @click="addRow">新增行</el-button>
      </el-col>
      <el-col :span="4">
        <el-button type="danger" @click="clearData">清空数据</el-button>
      </el-col>
      <el-col :span="4">
        <el-button type="success" @click="submitData">提交数据</el-button>
      </el-col>
    </el-row>
  </div>
</template>
 
<script setup>
import { ref } from 'vue'
import ProductionDetailsTable from './ProductionDetailsTable.vue'
 
// 表格数据
const tableData = ref([
  {
    coalType: '动力煤',
    calorificValue: '5000',
    productionQuantity: '100',
    laborCost: '1000',
    energyCost: '800',
    equipmentDepreciation: '500',
    purchasePrice: '2000',
    totalCost: '4300'
  }
])
 
// 获取组件实例引用
const tableRef = ref(null)
 
// 事件处理
const handleChange = (data) => {
  console.log('数据变化:', data)
}
 
const handleDelete = (index) => {
  console.log('删除行:', index)
}
 
// 操作方法
const addRow = () => {
  if (tableRef.value) {
    tableRef.value.addRow({
      coalType: '新煤种',
      calorificValue: '0',
      productionQuantity: '0',
      laborCost: '0',
      energyCost: '0',
      equipmentDepreciation: '0',
      purchasePrice: '0',
      totalCost: '0'
    })
  }
}
 
const clearData = () => {
  if (tableRef.value) {
    tableRef.value.clearData()
  }
}
 
const submitData = () => {
  console.log('提交的数据:', tableData.value)
  // 这里可以调用API提交数据
}
</script>