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

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