plm前端
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.

145 lines
4.1 KiB

2 years ago
  1. <template>
  2. <div class="mod-oss">
  3. <el-dialog
  4. v-drag
  5. :title="title"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible"
  8. width="400px"
  9. :append-to-body="true">
  10. <el-form>
  11. <el-form label-position="top">
  12. <el-form-item :label="'标签名称'">
  13. <el-input v-model="userPrint.reportfile" readonly></el-input>
  14. </el-form-item>
  15. <el-form-item :label="'打印机地址'">
  16. <el-input v-model="userPrint.ipaddress" ></el-input>
  17. </el-form-item>
  18. <el-form-item label="打印机名称">
  19. <!-- <el-select placeholder=""-->
  20. <!-- filterable-->
  21. <!-- @blur="selectBlur" style="width:100%" v-model="userPrint.newprintername">-->
  22. <!-- <el-option v-for="(item,index) in printList"-->
  23. <!-- :key="index"-->
  24. <!-- :label="item.label" :value="item.label"></el-option>-->
  25. <!-- </el-select>-->
  26. <el-autocomplete
  27. class="inline-input"
  28. v-model="userPrint.newprintername"
  29. :fetch-suggestions="querySearch"
  30. style="width:100% "
  31. placeholder="请输入内容"
  32. >
  33. <template slot-scope="{ item }">
  34. <span class="addr">{{ item.label }}</span>
  35. </template>
  36. </el-autocomplete>
  37. </el-form-item>
  38. </el-form>
  39. <select v-show="false" ref="printElement">
  40. </select>
  41. </el-form>
  42. <span slot="footer" class="dialog-footer">
  43. <el-button @click="savePrint()" type="primary">{{ buttons.save }}</el-button>
  44. <el-button @click="visible = false" type="primary">{{ buttons.close }}</el-button>
  45. </span>
  46. </el-dialog>
  47. </div>
  48. </template>
  49. <script>
  50. import {saveUserLabelPrint} from '@/api/print/print.js';
  51. export default {
  52. data() {
  53. return {
  54. tableHeight: 365,
  55. title: '用户打印机管理',
  56. visible: false,
  57. userPrint: {
  58. newprintername: '',
  59. userid: this.$store.state.user.name,
  60. ipaddress: '',
  61. reportid: '',
  62. reportFile: '',
  63. },
  64. printList: [],
  65. buttons: {
  66. save: "保存",
  67. close: "关闭"
  68. },
  69. buttonList: []
  70. }
  71. },
  72. components: {},
  73. mounted() {
  74. this.$nextTick(() => {
  75. this.height = (window.innerHeight * 0.82);
  76. })
  77. },
  78. methods: {
  79. querySearch(queryString, cb) {
  80. var restaurants = this.printList;
  81. var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
  82. // 调用 callback 返回建议列表的数据
  83. cb(results);
  84. },
  85. createFilter(queryString) {
  86. return (restaurant) => {
  87. return (restaurant.label.indexOf(queryString) === 0);
  88. };
  89. },
  90. selectBlur(e){
  91. this.userPrint.printername = e.target.value
  92. },
  93. // 初始化
  94. init(val) {
  95. this.visible = true
  96. this.userPrint = val
  97. this.userPrint.ipaddress = val.ipaddress?val.ipaddress: '127.0.0.1'
  98. this.getPrintName()
  99. },
  100. // 获取所有打印机
  101. getPrintName(){
  102. this.$nextTick(() => {
  103. let lodop = this.getLodop()
  104. var elementById = this.$refs.printElement;
  105. lodop.Create_Printer_List(elementById)
  106. setTimeout(()=>{},1000)
  107. var children = elementById.children
  108. let list = []
  109. for (let child of children) {
  110. let option = {
  111. value: child.innerText,
  112. label: child.innerText
  113. }
  114. list.push(option)
  115. }
  116. this.printList = list
  117. })
  118. },
  119. // 保存打印机
  120. savePrint(){
  121. this.userPrint.userid = this.$store.state.user.name
  122. saveUserLabelPrint(this.userPrint).then(({data}) =>{
  123. if (data.code === 0){
  124. this.$message.success(data.msg)
  125. this.visible = false
  126. this.$emit('refreshDataList')
  127. }else {
  128. this.$message.warning(data.msg)
  129. }
  130. })
  131. }
  132. },
  133. created() {
  134. }
  135. }
  136. </script>