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

182 lines
6.3 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. import {getuuid} from "@/utils/index"
  21. export default {
  22. name: "TableOpertaion",
  23. props: {
  24. row: {
  25. type: Object,
  26. default: () => { },
  27. },
  28. columns: {
  29. type: Object,
  30. default: () => { },
  31. },
  32. rowIndex: {
  33. type: Number,
  34. default: 0,
  35. },
  36. fillType: {
  37. type: String,
  38. default: "preFill",
  39. },
  40. },
  41. mounted() {
  42. EventBus.$on("dialogSubPackageSubmit", (data) => {
  43. this.onSubPackageSubmit(data)
  44. })
  45. EventBus.$on("subPackageDialogPrintTag", (data) => {
  46. this.onPrintTag(data)
  47. })
  48. },
  49. destroyed() {
  50. EventBus.$off("dialogSubPackageSubmit")
  51. EventBus.$off("subPackageDialogPrintTag")
  52. },
  53. watch: {
  54. row: {
  55. handler(newVal, oldVal) {
  56. this.innerRow = newVal;
  57. },
  58. deep: true,
  59. }
  60. },
  61. data() {
  62. return {
  63. innerRow: this.row,
  64. uuid:getuuid(),
  65. }
  66. },
  67. methods: {
  68. //获取实际填报的config
  69. getColumnConfig(){
  70. const { columns } = this;
  71. const { columnsData } = columns;
  72. let o = {};
  73. columnsData.forEach((item) => {
  74. if(item.bodyFillType === "actFill"){
  75. o[item.prop] = "";
  76. }else if(item.bodySubFillType === "actFill"){
  77. o[item.bodySubKey] = "";
  78. }
  79. });
  80. return o;
  81. },
  82. // 开始配置
  83. onStartConfig() {
  84. this.$emit("startConfig", { rowData: this.innerRow, rowIndex: this.rowIndex, headerSelectFields: this.columns.headerSelectFields })
  85. },
  86. // 配置完成
  87. onConfigComplete() {
  88. const actConfig = this.getColumnConfig();
  89. const cloneRow = JSON.parse(JSON.stringify(this.innerRow));
  90. const isComplete = Object.values({...actConfig,...cloneRow}).every((val)=>{
  91. // 0 算有值
  92. if (val === 0) return true;
  93. if (val === "0") return true;
  94. // 其他情况:非 null、非 undefined、非空字符串
  95. return val != null && val != undefined && val != "";
  96. });
  97. if(!isComplete){
  98. this.$message.error("表单内容未填完,请填写完成后才能配制完成")
  99. return
  100. }
  101. this.$emit("configComplete", { rowData: this.innerRow, rowIndex: this.rowIndex, headerSelectFields: this.columns.headerSelectFields })
  102. },
  103. // 打印标签
  104. onPrintTag(data) {
  105. if(data) {
  106. if(data.rowIndex === this.rowIndex){
  107. this.$emit("printTag", { printCode: data.printCode,type:"subPackage",row: this.innerRow })
  108. }
  109. }else{
  110. this.$emit("printTag", { row: this.innerRow,type:"row" })
  111. }
  112. },
  113. // 分装
  114. onSubPackage() {
  115. const { columns, innerRow } = this;
  116. console.log(columns,innerRow,"inner")
  117. const { headerSelectFields, columnsData } = columns;
  118. const col = columnsData.find((item) => item.myCodeFields);
  119. const { myCodeFields, maxVolumeField, maxVolumeFieldUnit } = col;
  120. const fields = [], cols = [], units = [];
  121. if(!myCodeFields || myCodeFields.length === 0){
  122. console.warn("请先配置myCodeFields字段")
  123. return
  124. }
  125. myCodeFields.forEach((key) => {
  126. fields.push(innerRow[key])
  127. });
  128. maxVolumeField.split(",").forEach((key) => {
  129. cols.push(innerRow[key] || 0)
  130. })
  131. maxVolumeFieldUnit.split(",").forEach((key) => {
  132. units.push(headerSelectFields[key])
  133. })
  134. const {total,unit} = addTj(cols,units)
  135. let defaultData = { mybh: fields.join(""), maxVolume: total, maxVolumeUnit: unit, rowIndex: this.rowIndex }
  136. if (innerRow.fzsj) {
  137. defaultData = {...innerRow.fzsj,...defaultData}
  138. }
  139. EventBus.$emit("showSubPackageDialog", {...defaultData,uuid:this.uuid})
  140. },
  141. onSubPackageSubmit(data) {
  142. console.log(data,"submit")
  143. if (data.uuid === this.uuid) {
  144. console.log(data,"inner submit")
  145. this.innerRow.fzsj = data;
  146. //通知后端保存数据
  147. const params = {
  148. type: "fieldChanged",
  149. newRecord: null,
  150. resourceList: null,
  151. }
  152. EventBus.$emit('onModifyRecord', params);
  153. this.$emit("subPackageSubmit", { fzsj: data, rowData: this.innerRow, headerSelectFields: this.columns.headerSelectFields });
  154. }
  155. },
  156. // 删除行
  157. deleteRow(index) {
  158. this.$emit("deleteRow", index);
  159. setTimeout(() => {
  160. const params = {
  161. type: "fieldChanged",
  162. newRecord: null,
  163. resourceList: null,
  164. }
  165. EventBus.$emit('onModifyRecord', params,)
  166. }, 30);
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .delete-button {
  173. color: red;
  174. }
  175. </style>