华西海圻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.

139 lines
4.7 KiB

  1. <template>
  2. <div>
  3. <el-popconfirm confirm-button-text='确认' cancel-button-text='取消' icon="el-icon-info" icon-color="red"
  4. title="确认删除当前数据?" @confirm="deleteRow(rowIndex)">
  5. <el-button v-if="fillType === 'preFill'" slot="reference" type="text" size="small" class="delete-button">
  6. 删除
  7. </el-button>
  8. </el-popconfirm>
  9. <template v-if="fillType === 'actFill'">
  10. <el-button type="text" size="small" @click="onSubPackage">分装</el-button>
  11. <el-button type="text" size="small" @click="onStartConfig">开始配制</el-button>
  12. <el-button type="text" size="small" @click="onConfigComplete">配制完成</el-button>
  13. <el-button type="text" size="small" @click="()=>onPrintTag()">打印标签</el-button>
  14. </template>
  15. </div>
  16. </template>
  17. <script>
  18. import { EventBus } from "@/utils/eventBus";
  19. import { addTj } from "@/utils/calUnitTools";
  20. export default {
  21. name: "TableOpertaion",
  22. props: {
  23. row: {
  24. type: Object,
  25. default: () => { },
  26. },
  27. columns: {
  28. type: Object,
  29. default: () => { },
  30. },
  31. rowIndex: {
  32. type: Number,
  33. default: 0,
  34. },
  35. fillType: {
  36. type: String,
  37. default: "preFill",
  38. },
  39. },
  40. mounted() {
  41. EventBus.$on("dialogSubPackageSubmit", (data) => {
  42. this.onSubPackageSubmit(data)
  43. })
  44. EventBus.$on("subPackageDialogPrintTag", (data) => {
  45. this.onPrintTag(data)
  46. })
  47. },
  48. destroyed() {
  49. EventBus.$off("dialogSubPackageSubmit")
  50. EventBus.$off("subPackageDialogPrintTag")
  51. },
  52. watch: {
  53. row: {
  54. handler(newVal, oldVal) {
  55. this.innerRow = newVal;
  56. },
  57. deep: true,
  58. }
  59. },
  60. data() {
  61. return {
  62. innerRow: this.row,
  63. }
  64. },
  65. methods: {
  66. // 开始配置
  67. onStartConfig() {
  68. this.$emit("startConfig", { rowData: this.innerRow, rowIndex: this.rowIndex, headerSelectFields: this.columns.headerSelectFields })
  69. },
  70. // 配置完成
  71. onConfigComplete() {
  72. this.$emit("configComplete", { rowData: this.innerRow, rowIndex: this.rowIndex, headerSelectFields: this.columns.headerSelectFields })
  73. },
  74. // 打印标签
  75. onPrintTag(data) {
  76. if(data) {
  77. if(data.rowIndex === this.rowIndex){
  78. this.$emit("printTag", { printCode: data.printCode,type:"subPackage",row: this.innerRow })
  79. }
  80. }else{
  81. this.$emit("printTag", { row: this.innerRow,type:"row" })
  82. }
  83. },
  84. // 分装
  85. onSubPackage() {
  86. const { columns, innerRow } = this;
  87. const { headerSelectFields, columnsData } = columns;
  88. const col = columnsData.find((item) => item.myCodeFields);
  89. const { myCodeFields, maxVolumeField, maxVolumeFieldUnit } = col;
  90. const fields = [], cols = [], units = [];
  91. if(!myCodeFields || myCodeFields.length === 0){
  92. console.warn("请先配置myCodeFields字段")
  93. return
  94. }
  95. myCodeFields.forEach((key) => {
  96. fields.push(innerRow[key])
  97. });
  98. maxVolumeField.split(",").forEach((key) => {
  99. cols.push(innerRow[key] || 0)
  100. })
  101. maxVolumeFieldUnit.split(",").forEach((key) => {
  102. units.push(headerSelectFields[key])
  103. })
  104. const {total,unit} = addTj(cols,units)
  105. let defaultData = { mybh: fields.join(""), maxVolume: total, maxVolumeUnit: unit, rowIndex: this.rowIndex }
  106. if (innerRow.fzsj) {
  107. defaultData = innerRow.fzsj
  108. }
  109. EventBus.$emit("showSubPackageDialog", defaultData)
  110. },
  111. onSubPackageSubmit(data) {
  112. if (data.rowIndex === this.rowIndex) {
  113. this.innerRow.fzsj = data;
  114. //通知后端保存数据
  115. const params = {
  116. type: "fieldChanged",
  117. newRecord: null,
  118. resourceList: null,
  119. }
  120. EventBus.$emit('onModifyRecord', params);
  121. this.$emit("subPackageSubmit", { fzsj: data, rowData: this.innerRow, headerSelectFields: this.columns.headerSelectFields });
  122. }
  123. },
  124. // 删除行
  125. deleteRow(index) {
  126. this.$emit("deleteRow", index)
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .delete-button {
  133. color: red;
  134. }
  135. </style>