editPrint.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div class="sys-print-container">
  3. <div class="printDialog">
  4. <el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" fullscreen>
  5. <template #header>
  6. <div style="color: #fff">
  7. <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>
  8. <span> {{ props.title }} </span>
  9. </div>
  10. </template>
  11. <div style="margin: -16px 0px 0px 0px">
  12. <HiprintDesign ref="hiprintDesignRef" />
  13. </div>
  14. <template #footer>
  15. <span class="dialog-footer" style="margin-top: 10px">
  16. <el-button @click="cancel">取 消</el-button>
  17. <el-button type="primary" @click="submit">保存模板</el-button>
  18. </span>
  19. </template>
  20. </el-dialog>
  21. </div>
  22. <el-dialog v-model="state.showDialog2" draggable :close-on-click-modal="false" width="600px">
  23. <template #header>
  24. <div style="color: #fff">
  25. <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>
  26. <span>{{ props.title }}</span>
  27. </div>
  28. </template>
  29. <el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto">
  30. <el-row :gutter="35">
  31. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
  32. <el-form-item label="模板名称" prop="name" :rules="[{ required: true, message: '模板名称不能为空', trigger: 'blur' }]">
  33. <el-input v-model="state.ruleForm.name" placeholder="模板名称" clearable />
  34. </el-form-item>
  35. </el-col>
  36. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  37. <el-form-item label="排序">
  38. <el-input-number v-model="state.ruleForm.orderNo" placeholder="排序" class="w100" />
  39. </el-form-item>
  40. </el-col>
  41. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  42. <el-form-item label="状态">
  43. <el-radio-group v-model="state.ruleForm.status">
  44. <el-radio :value="1">启用</el-radio>
  45. <el-radio :value="2">禁用</el-radio>
  46. </el-radio-group>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
  50. <el-form-item label="备注">
  51. <el-input v-model="state.ruleForm.remark" placeholder="请输入备注内容" clearable type="textarea" />
  52. </el-form-item>
  53. </el-col>
  54. </el-row>
  55. </el-form>
  56. <template #footer>
  57. <span class="dialog-footer">
  58. <el-button @click="templateCancel">取 消</el-button>
  59. <el-button type="primary" @click="templateSubmit">确 定</el-button>
  60. </span>
  61. </template>
  62. </el-dialog>
  63. </div>
  64. </template>
  65. <script lang="ts" setup name="sysEditPrint">
  66. import { onMounted, reactive, ref, nextTick } from 'vue';
  67. import HiprintDesign from '/@/views/system/print/component/hiprint/index.vue';
  68. import { getAPI } from '/@/utils/axios-utils';
  69. import { SysPrintApi } from '/@/api-services/api';
  70. import { UpdatePrintInput } from '/@/api-services/models';
  71. const hiprintDesignRef = ref<InstanceType<typeof HiprintDesign>>();
  72. const props = defineProps({
  73. title: String,
  74. });
  75. const emits = defineEmits(['handleQuery']);
  76. const ruleFormRef = ref();
  77. const state = reactive({
  78. isShowDialog: false,
  79. ruleForm: {} as UpdatePrintInput,
  80. showDialog2: false,
  81. });
  82. onMounted(async () => {});
  83. // 打开弹窗
  84. const openDialog = (row: any) => {
  85. state.ruleForm = JSON.parse(JSON.stringify(row));
  86. state.isShowDialog = true;
  87. ruleFormRef.value?.resetFields();
  88. nextTick(() => {
  89. loadTemplate();
  90. });
  91. };
  92. // 加载模板
  93. const loadTemplate = () => {
  94. hiprintDesignRef.value?.hiprintTemplate.clear();
  95. if (JSON.stringify(state.ruleForm) !== '{}') {
  96. hiprintDesignRef.value?.hiprintTemplate.update(JSON.parse(state.ruleForm.template));
  97. }
  98. };
  99. // 取消
  100. const cancel = () => {
  101. state.isShowDialog = false;
  102. };
  103. // 提交
  104. const submit = async () => {
  105. state.showDialog2 = true;
  106. if (state.ruleForm.orderNo == undefined) state.ruleForm.orderNo = 100;
  107. if (state.ruleForm.status == undefined) state.ruleForm.status = 1;
  108. };
  109. // 模板设置取消
  110. const templateCancel = () => {
  111. state.showDialog2 = false;
  112. };
  113. // 模板设置提交
  114. const templateSubmit = async () => {
  115. state.ruleForm.template = JSON.stringify(hiprintDesignRef.value?.hiprintTemplate.getJson());
  116. if (state.ruleForm.id != undefined && state.ruleForm.id > 0) {
  117. await getAPI(SysPrintApi).apiSysPrintUpdatePost(state.ruleForm);
  118. } else {
  119. await getAPI(SysPrintApi).apiSysPrintAddPost(state.ruleForm);
  120. }
  121. cancel();
  122. templateCancel();
  123. emits('handleQuery');
  124. };
  125. // 导出对象
  126. defineExpose({ openDialog });
  127. </script>
  128. <style lang="scss" scoped>
  129. .printDialog {
  130. :deep(.el-dialog) {
  131. .el-dialog__header {
  132. display: none !important;
  133. }
  134. .el-dialog__body {
  135. max-height: calc(100vh - 80px) !important;
  136. }
  137. }
  138. }
  139. </style>