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.

314 lines
10 KiB

4 years ago
  1. <template>
  2. <div class="box">
  3. <div class="title">kr-print-designer 打印模板设计器</div>
  4. <section>
  5. <div class="section">模板管理</div>
  6. <el-table :data="tempList" style="width: 100%" size="mini" border>
  7. <el-table-column label="模板名称" prop="title"></el-table-column>
  8. <el-table-column label="模板类型">
  9. <template slot-scope="scope">
  10. <span>{{scope.row.type == 1 ? '出库单' : '入库单'}}</span>
  11. </template>
  12. </el-table-column>
  13. <el-table-column label="模板宽高">
  14. <template slot-scope="scope">
  15. <span>{{scope.row.width + ' * '+ scope.row.height}}</span>
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="纸张大小">
  19. <template slot-scope="scope">
  20. <span>{{scope.row.pageWidth + 'mm * '+ scope.row.pageHeight+'mm'}}</span>
  21. </template>
  22. </el-table-column>
  23. <el-table-column align="right">
  24. <template slot="header">
  25. <el-button size="mini" type="primary" @click="openCreate">创建模板</el-button>
  26. </template>
  27. <template slot-scope="scope">
  28. <el-button type="text" size="mini" @click="handleEdit(scope.$index, scope.row ,scope.row.id)">设计</el-button>
  29. <el-button type="text" size="mini" @click="handlePreview(scope.$index, scope.row)">预览</el-button>
  30. <el-button type="text" size="mini" @click="handleCopy(scope.row)">复制新增</el-button>
  31. <el-button
  32. v-if="!scope.row.default"
  33. type="text"
  34. size="mini"
  35. @click="handleDelete(scope.$index, scope.row)"
  36. >删除</el-button>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <el-dialog title="添加模板" :visible.sync="visible" width="310px">
  41. <el-form ref="form" :model="form" size="small" :rules="rules" label-width="80px">
  42. <el-form-item label="模板名称" prop="title">
  43. <el-input v-model="form.title"></el-input>
  44. </el-form-item>
  45. <el-form-item label="模板类型" prop="type">
  46. <el-select v-model="form.type">
  47. <el-option label="出库单" :value="1"></el-option>
  48. <el-option label="入库单" :value="2"></el-option>
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="模板宽度" prop="width">
  52. <el-input v-model="form.width"></el-input>
  53. </el-form-item>
  54. <el-form-item label="模板高度" prop="height">
  55. <el-input v-model="form.height"></el-input>
  56. </el-form-item>
  57. <el-form-item label="纸张宽度" prop="pageWidth">
  58. <el-input v-model="form.pageWidth"></el-input>
  59. </el-form-item>
  60. <el-form-item label="纸张高度" prop="pageHeight">
  61. <el-input v-model="form.pageHeight"></el-input>
  62. </el-form-item>
  63. </el-form>
  64. <div slot="footer" class="dialog-footer">
  65. <el-button size="mini" @click="visible = false"> </el-button>
  66. <el-button type="primary" size="mini" @click="savaTemp"> </el-button>
  67. </div>
  68. </el-dialog>
  69. </section>
  70. <section>
  71. <div class="section">模板打印测试</div>
  72. <el-form ref="printForm" :model="printForm" size="small" :rules="printRules" :inline="true">
  73. <el-form-item label="打印模板" prop="tempIndex">
  74. <el-select v-model="printForm.tempIndex">
  75. <el-option
  76. v-for="(item,index) in tempList"
  77. :key="index"
  78. :label="item.title"
  79. :value="index"
  80. ></el-option>
  81. </el-select>
  82. </el-form-item>
  83. <el-form-item label="测试数据" prop="data">
  84. <el-input
  85. type="textarea"
  86. style="width:520px"
  87. :rows="6"
  88. v-model="printForm.data"
  89. placeholder="数据模板对应的数据,数据格式为json对象"
  90. ></el-input>
  91. </el-form-item>
  92. <el-form-item>
  93. <div>
  94. <el-button size="mini" type="primary" @click="printPreview(1)">打印预览</el-button>
  95. </div>
  96. <div style="margin-top:10px">
  97. <el-button size="mini" type="success" @click="printPreview(2)">直接打印</el-button>
  98. </div>
  99. </el-form-item>
  100. </el-form>
  101. </section>
  102. <section>
  103. <el-collapse>
  104. <el-collapse-item title="测试数据" name="1">
  105. <el-form ref="testData" :model="testData" size="small" :inline="true">
  106. <el-form-item label="出库数据">
  107. <el-input
  108. type="textarea"
  109. style="width:920px"
  110. :rows="8"
  111. v-model="testData.OutStock"
  112. placeholder="数据模板对应的数据,数据格式为json对象"
  113. ></el-input>
  114. </el-form-item>
  115. <el-form-item label="入库数据">
  116. <el-input
  117. type="textarea"
  118. style="width:920px"
  119. :rows="8"
  120. v-model="testData.InStock"
  121. placeholder="数据模板对应的数据,数据格式为json对象"
  122. ></el-input>
  123. </el-form-item>
  124. </el-form>
  125. </el-collapse-item>
  126. </el-collapse>
  127. </section>
  128. </div>
  129. </template>
  130. <script>
  131. import { Table, TableColumn, Dialog, MessageBox } from 'element-ui'
  132. import Vue from 'vue'
  133. Vue.prototype.$confirm = (...args) => MessageBox.confirm(...args)
  134. const defaultTemp = () => ({
  135. title: '',
  136. type: 1, // 模板类型 1:出库单;2:入库单
  137. width: '',
  138. height: '',
  139. pageWidth: '',
  140. pageHeight: '',
  141. tempItems: [],
  142. })
  143. import { OutStockData, InStockData } from '../data/test'
  144. import {
  145. getTemplateList
  146. ,saveClodopTemplateHeaders
  147. ,saveTemplateHeader
  148. ,deleteClodopTemplate
  149. } from '../api/base.js'
  150. export default {
  151. data() {
  152. return {
  153. site : '',
  154. visible: false,
  155. value: {},
  156. tempList: [],
  157. form: defaultTemp(),
  158. rules: {
  159. title: { required: true, message: '请输入模板名称' },
  160. type: { required: true, message: '请选择模板类型' },
  161. width: { required: true, message: '请输入模板宽度' },
  162. height: { required: true, message: '请输入模板高度' },
  163. pageWidth: { required: true, message: '请输入纸张宽度' },
  164. pageHeight: { required: true, message: '请输入纸张高度' },
  165. },
  166. printForm: {
  167. tempIndex: '',
  168. data: '',
  169. },
  170. printRules: {
  171. tempIndex: { required: true, message: '请选择模板' },
  172. data: { required: true, message: '请输入模板测试数据' },
  173. },
  174. testData: {
  175. OutStock: JSON.stringify(OutStockData),
  176. InStock: JSON.stringify(InStockData),
  177. },
  178. }
  179. },
  180. created() {
  181. Vue.use(Table)
  182. Vue.use(TableColumn)
  183. Vue.use(Dialog)
  184. // this.tempList = JSON.parse(localStorage.getItem('tempList')) || []
  185. this.getTemplateList()
  186. },
  187. methods: {
  188. // 获取数据
  189. getTemplateList(){
  190. let jsonData = {
  191. site : this.site,
  192. }
  193. getTemplateList(jsonData).then(({data}) =>{
  194. this.tempList = data.rows;
  195. })
  196. },
  197. // 预览
  198. handlePreview(index, row) {
  199. this.$lodop.previewTemp(row)
  200. },
  201. // 设计
  202. handleEdit(index, row ,id) {
  203. this.$router.push({
  204. path: '/designer',
  205. query: {
  206. index: index,
  207. id : row.id,
  208. },
  209. })
  210. },
  211. // 删除
  212. handleDelete(index, row) {
  213. this.$confirm('确认删除该条数据吗?', '确认信息')
  214. .then((isPass) => {
  215. if (isPass) {
  216. // this.tempList.splice(index, 1)
  217. // localStorage.setItem('tempList', JSON.stringify(this.tempList))
  218. deleteClodopTemplate(row).then(({data}) =>{
  219. this.getTemplateList()
  220. })
  221. }
  222. })
  223. .catch()
  224. },
  225. handleCopy(row) {
  226. // let copyTemp = JSON.parse(JSON.stringify(row))
  227. // copyTemp.title = copyTemp.title + '_copy'
  228. // copyTemp.default = false
  229. // copyTemp.insertFlag = true
  230. // this.tempList.push(copyTemp)
  231. // localStorage.setItem('tempList', JSON.stringify(this.tempList))
  232. this.saveTemplateInfo(row)
  233. },
  234. //保存复制新增
  235. saveTemplateInfo(row){
  236. let copyTemp = JSON.parse(JSON.stringify(row))
  237. copyTemp.insertFlag = true
  238. copyTemp.title = copyTemp.title + '_copy'
  239. saveClodopTemplateHeaders(copyTemp).then(({data}) =>{
  240. this.getTemplateList()
  241. })
  242. },
  243. // 新增
  244. openCreate() {
  245. this.form = defaultTemp()
  246. this.visible = true
  247. },
  248. // 保存新增
  249. savaTemp() {
  250. this.$refs.form.validate((valid) => {
  251. if (valid) {
  252. // this.tempList.push(this.form)
  253. // localStorage.setItem('tempList', JSON.stringify(this.tempList))
  254. saveTemplateHeader(this.form).then(({data}) =>{
  255. this.getTemplateList()
  256. })
  257. this.visible = false
  258. }
  259. })
  260. },
  261. /**
  262. * 测试打印预览/直接打印
  263. * flag 1:打印预览2直接打印
  264. */
  265. printPreview(flag) {
  266. this.$refs.printForm.validate((valid) => {
  267. if (valid) {
  268. let printData
  269. try {
  270. printData = JSON.parse(this.printForm.data)
  271. } catch (err) {
  272. return this.$message('请输入正确格式的打印数据')
  273. }
  274. if (flag == 1) {
  275. this.$lodop.preview(this.tempList[this.printForm.tempIndex], printData)
  276. } else {
  277. this.$confirm('确认直接打印吗?', '确认信息')
  278. .then((isPass) => {
  279. if (isPass) {
  280. this.$lodop.print(this.tempList[this.printForm.tempIndex], printData)
  281. }
  282. })
  283. .catch((err) => {
  284. console.log(err)
  285. })
  286. }
  287. }
  288. })
  289. },
  290. },
  291. }
  292. </script>
  293. <style scoped>
  294. .box {
  295. width: 1000px;
  296. margin: auto;
  297. padding: 10px 0;
  298. font-family: Arial, Helvetica, sans-serif;
  299. }
  300. .title {
  301. text-align: center;
  302. font-size: 24px;
  303. color: #1890ff;
  304. margin: 20px;
  305. font-weight: bold;
  306. }
  307. .section {
  308. font-size: 18px;
  309. color: #333333;
  310. padding: 10px 0;
  311. }
  312. </style>