editPrint.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="sys-print-container">
  3. <div class="printDialog">
  4. <el-dialog v-model="state.isShowDialog" draggable overflow destroy-on-close 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: 0px 0px 0px 0px">
  12. <HiprintDesign :mode-index="mode" 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 overflow destroy-on-close 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="10">
  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="12" :md="12" :lg="12" :xl="12" class="mb20">
  50. <el-form-item label="打印类型">
  51. <g-sys-dict v-model="state.ruleForm.printType" code="PrintTypeEnum" render-as="radio" />
  52. </el-form-item>
  53. </el-col>
  54. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
  55. <el-form-item label="客户端服务地址">
  56. <el-input v-model="state.ruleForm.clientServiceAddress" placeholder="客户端服务地址" clearable />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
  60. <el-form-item label="打印参数">
  61. <el-input v-model="state.ruleForm.printParam" placeholder="请输入打印参数" clearable type="textarea" />
  62. </el-form-item>
  63. </el-col>
  64. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
  65. <el-form-item label="备注">
  66. <el-input v-model="state.ruleForm.remark" placeholder="请输入备注内容" clearable type="textarea" />
  67. </el-form-item>
  68. </el-col>
  69. </el-row>
  70. </el-form>
  71. <template #footer>
  72. <span class="dialog-footer">
  73. <el-button @click="templateCancel">取 消</el-button>
  74. <el-button type="primary" @click="templateSubmit">确 定</el-button>
  75. </span>
  76. </template>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script lang="ts" setup name="sysEditPrint">
  81. import { onMounted, reactive, ref, nextTick } from 'vue';
  82. import HiprintDesign from '/@/views/system/print/component/hiprint/index.vue';
  83. import { getAPI } from '/@/utils/axios-utils';
  84. import { SysPrintApi } from '/@/api-services/api';
  85. import { UpdatePrintInput } from '/@/api-services/models';
  86. const hiprintDesignRef = ref<InstanceType<typeof HiprintDesign>>();
  87. const mode = ref(0);
  88. const props = defineProps({
  89. title: String,
  90. });
  91. const emits = defineEmits(['handleQuery']);
  92. const ruleFormRef = ref();
  93. const state = reactive({
  94. isShowDialog: false,
  95. ruleForm: {} as UpdatePrintInput,
  96. showDialog2: false,
  97. });
  98. // 页面初始化
  99. onMounted(async () => {});
  100. // 打开弹窗
  101. const openDialog = (row: any) => {
  102. state.ruleForm = JSON.parse(JSON.stringify(row));
  103. if (state.ruleForm?.template) {
  104. let templateJson = JSON.parse(state.ruleForm.template);
  105. mode.value = templateJson.panels[0].index;
  106. }
  107. state.isShowDialog = true;
  108. ruleFormRef.value?.resetFields();
  109. nextTick(() => {
  110. loadTemplate();
  111. });
  112. };
  113. // 加载模板
  114. const loadTemplate = () => {
  115. hiprintDesignRef.value?.hiprintTemplate.clear();
  116. hiprintDesignRef.value?.setPrintDataDemo(state.ruleForm.printDataDemo);
  117. if (JSON.stringify(state.ruleForm) !== '{}') {
  118. hiprintDesignRef.value?.hiprintTemplate.update(JSON.parse(state.ruleForm.template || '{}'));
  119. hiprintDesignRef.value?.initPaper();
  120. }
  121. };
  122. // 取消
  123. const cancel = () => {
  124. state.isShowDialog = false;
  125. };
  126. // 提交
  127. const submit = async () => {
  128. state.showDialog2 = true;
  129. if (state.ruleForm.orderNo == undefined) state.ruleForm.orderNo = 100;
  130. if (state.ruleForm.status == undefined) state.ruleForm.status = 1;
  131. if (state.ruleForm.printType == undefined) state.ruleForm.printType = 1;
  132. };
  133. // 模板设置取消
  134. const templateCancel = () => {
  135. state.showDialog2 = false;
  136. };
  137. // 模板设置提交
  138. const templateSubmit = async () => {
  139. let templateJson = hiprintDesignRef.value?.hiprintTemplate.getJson();
  140. templateJson.panels[0].index = hiprintDesignRef.value?.mode;
  141. state.ruleForm.template = JSON.stringify(templateJson);
  142. const printDataDemo = hiprintDesignRef.value?.printDataDemo;
  143. state.ruleForm.printDataDemo = printDataDemo;
  144. if (state.ruleForm.id != undefined && state.ruleForm.id > 0) {
  145. await getAPI(SysPrintApi).apiSysPrintUpdatePost(state.ruleForm);
  146. } else {
  147. await getAPI(SysPrintApi).apiSysPrintAddPost(state.ruleForm);
  148. }
  149. cancel();
  150. templateCancel();
  151. emits('handleQuery');
  152. };
  153. // 导出对象
  154. defineExpose({ openDialog });
  155. </script>
  156. <style lang="scss" scoped>
  157. .printDialog {
  158. :deep(.el-dialog) {
  159. .el-dialog__header {
  160. display: none !important;
  161. }
  162. .el-dialog__body {
  163. max-height: calc(100vh - 80px) !important;
  164. height: calc(100vh - 80px) !important;
  165. }
  166. }
  167. }
  168. </style>