华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.1 KiB

  1. <template>
  2. <div class="jcb-table-container">
  3. <CustomTable :ref="`tableRef`" :columns="jcbColumns" :formData="formData" :prefixKey="prefixKey"
  4. class="jcb-table" operationWidth="120px" @clickButton="handleClickButton" @blur="commonHandleUpdate"
  5. @onAddRow="onAddRow"
  6. @onRegentSubmit="commonHandleUpdate"
  7. fieldItemLabel="template.common.operationSteps" :showOperation="templateFillType === 'preFill'">
  8. <template slot="operation" slot-scope="{ row, rowIndex, columns }">
  9. <TableOpertaionDelete :row="row" :rowIndex="rowIndex" :columns="columns" @deleteRow="deleteRow">
  10. </TableOpertaionDelete>
  11. </template>
  12. </CustomTable>
  13. </div>
  14. </template>
  15. <script>
  16. import CustomTable from '../CustomTable.vue';
  17. import TableOpertaionDelete from "@/components/Template/operation/TableOpertaionDelete.vue";
  18. import { getuuid } from "@/utils/index.js";
  19. import moment from "moment"
  20. export default {
  21. inject: ['templateFillType'],
  22. components: {
  23. CustomTable,
  24. TableOpertaionDelete,
  25. },
  26. name: 'JcbComp',
  27. props: {
  28. formData: {
  29. type: Object,
  30. default: () => { },
  31. },
  32. prefixKey: {
  33. type: String,
  34. default: '',
  35. },
  36. item:{
  37. type: Object,
  38. default: () => { },
  39. },
  40. type:{
  41. type: String,
  42. default: 'qb',
  43. }
  44. },
  45. data() {
  46. return {
  47. };
  48. },
  49. mounted() {
  50. console.log(this.prefixKey,"prefixKey")
  51. },
  52. computed: {
  53. jcbColumns() {
  54. const { buttonName = "取出" } = this.item;
  55. return [
  56. {
  57. label: '处理批',
  58. prop: 'mc',
  59. width: '200px',
  60. bodyType: "jcb",
  61. bodyKey: "clpClick",
  62. bodyFillType: "preFill",
  63. bodySubType: 'span',
  64. bodySubKey: 'bh',
  65. },
  66. {
  67. label: '时间',
  68. prop: 'time',
  69. width: '200px',
  70. bodyType: "input",
  71. bodyDisabled: true,
  72. bodyFillType: "actFill",
  73. bodySubType: "button",
  74. bodySubButtonName: buttonName,
  75. bodySubKey: "timeClick",
  76. bodySubFillType: "actFill",
  77. },
  78. ]
  79. },
  80. },
  81. methods: {
  82. // 添加表格行
  83. onAddRow(data) {
  84. const { dataSource = [] } = data;
  85. const tableRef = this.$refs['tableRef'];
  86. if (tableRef) {
  87. tableRef.addRow({ mc: '', time: '' ,id:getuuid(),rowIndex:dataSource.length});
  88. // 添加行后触发数据变化
  89. this.onDataChange();
  90. }
  91. },
  92. // 删除表格行
  93. deleteRow(rowIndex) {
  94. const tableRef = this.$refs['tableRef'];
  95. if (tableRef) {
  96. tableRef.deleteRow(rowIndex);
  97. // 删除行后触发数据变化
  98. this.onDataChange();
  99. }
  100. },
  101. // 实现validateFormData方法,用于表单验证
  102. validateFormData() {
  103. // 调用CustomTable的同步验证方法
  104. const validateResult = this.$refs.tableRef.validateFormData();
  105. // 如果验证通过,还需要检查是否有数据行
  106. if (validateResult.valid) {
  107. const filledData = this.$refs.tableRef.getFilledFormData();
  108. const { stepTableFormData = [] } = filledData;
  109. if (stepTableFormData.length === 0) {
  110. return { valid: false, error: '请添加取板数据' };
  111. }
  112. }
  113. console.log("validateResult",validateResult);
  114. return validateResult;
  115. },
  116. // 点击按钮事件
  117. handleClickButton(key, rowIndex,colIndex,e,data) {
  118. if (key === 'timeClick') {
  119. this.$refs['tableRef'].updateDataSourceByRowIndex(rowIndex, { time: moment().format("YYYY-MM-DD HH:mm:ss") },{signData:data,updateFields:['time']})
  120. this.onDataChange();
  121. }
  122. },
  123. // 数据变化处理方法
  124. onDataChange() {
  125. // 获取表格数据
  126. let tableData = [];
  127. if (this.$refs.tableRef) {
  128. const filledData = this.$refs.tableRef.getFilledFormData();
  129. tableData = filledData.stepTableFormData || [];
  130. }
  131. // 触发自定义事件,将数据变化传递给父组件
  132. this.$emit('update', {
  133. jcbInfo: {
  134. stepTableFormData: tableData,
  135. }
  136. });
  137. },
  138. // 处理表格blur事件
  139. commonHandleUpdate() {
  140. // 表格数据变化时触发数据变化通知
  141. this.onDataChange();
  142. },
  143. }
  144. }
  145. </script>
  146. <style lang="scss">
  147. .jcb-table-container {
  148. width: 600px;
  149. }
  150. .jcb-table {
  151. .custom-table-wrapper {
  152. margin-top: 0;
  153. }
  154. }
  155. </style>