printerList.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div class="printer-list">
  3. <div class="model">
  4. <div class="title">
  5. <div class="name">云打印</div>
  6. <div class="status-list">
  7. <div class="status">
  8. <div class="bg1"></div>
  9. <div class="con">在线{{pinter.onlineNum}}</div>
  10. </div>
  11. <div class="status">
  12. <div class="bg1 bg2"></div>
  13. <div class="con">离线{{pinter.offlineNum}}</div>
  14. </div>
  15. <div class="status">
  16. <div class="bg1 bg3"></div>
  17. <div class="con">异常{{pinter.abnormalNum}}</div>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="printer-list">
  22. <div class="item" v-for="(v,i) in printerList" :key="i">
  23. <img class="img" :src="require(`../../../../static/image/printer-online-${v.onlineStatus}.png`)" alt="">
  24. <div class="name">{{v.name}}</div>
  25. <div class="shop-name">{{v.shopName}}</div>
  26. <div class="btns">
  27. <img @click.stop="printTest(v)" src="../../../../static/image/print-icon.png" alt="">
  28. <img @click.stop="addPrinter(v)" src="../../../../static/image/edit-icon.png" alt="">
  29. <img @click.stop="deletePrinter(v)" src="../../../../static/image/delete-icon.png" alt="">
  30. </div>
  31. </div>
  32. <div class="item" @click.stop="addPrinter('')">
  33. <img class="img" src="../../../../static/image/icon-add.png" alt="">
  34. <div class="name">添加打印机</div>
  35. <div class="shop-name"> </div>
  36. </div>
  37. </div>
  38. </div>
  39. <printer-add :shopList="shopList" @shopDeviceList="refreshData" ref="printerAdd" :devices="deviceList"></printer-add>
  40. </div>
  41. </template>
  42. <script>
  43. import printerAdd from "./printerAdd";
  44. import {
  45. getShopList,
  46. shopDeviceList,
  47. deviceDetail,
  48. deviceList,
  49. deviceAdd,
  50. deviceDelete,
  51. deviceStatus,
  52. printTest,
  53. shopListNew,
  54. } from "../../../api/shop";
  55. export default {
  56. name: "printerList",
  57. components: {
  58. printerAdd,
  59. },
  60. data() {
  61. return {
  62. pinter: {},
  63. printerList: [],
  64. deviceList: [],
  65. shopList: [],
  66. };
  67. },
  68. // 监听属性 类似于data概念
  69. computed: {},
  70. // 监控data中的数据变化
  71. watch: {},
  72. // 方法集合
  73. methods: {
  74. printTest(v) {
  75. printTest({ deviceSn: v.deviceSn }).then((res) => {
  76. if (res.code === 200) {
  77. this.$message({
  78. type: "success",
  79. message: "操作成功!",
  80. });
  81. } else {
  82. this.$message({
  83. type: "error",
  84. message: res.msg,
  85. });
  86. }
  87. });
  88. },
  89. deletePrinter(v) {
  90. this.$confirm("此操作将删除打印机, 是否继续?", "提示", {
  91. confirmButtonText: "确定",
  92. cancelButtonText: "取消",
  93. type: "warning",
  94. center: true,
  95. })
  96. .then(() => {
  97. deviceDelete({ id: v.id }).then((res) => {
  98. if (res.code === 200) {
  99. this.$message({
  100. type: "error",
  101. message: "删除成功!",
  102. });
  103. this.refreshData();
  104. } else {
  105. this.$message({
  106. type: "error",
  107. message: res.msg,
  108. });
  109. }
  110. });
  111. })
  112. .catch(() => {
  113. this.$message({
  114. type: "info",
  115. message: "已取消删除",
  116. });
  117. });
  118. },
  119. refreshData() {
  120. this.getPrinterNum();
  121. this.getPrinterList();
  122. },
  123. addPrinter(e) {
  124. console.log(e);
  125. if (!e) {
  126. this.$refs.printerAdd.init();
  127. } else {
  128. this.$refs.printerAdd.init(JSON.parse(JSON.stringify(e)));
  129. }
  130. },
  131. getPrinterList() {
  132. shopDeviceList({ deviceType: 2 }).then((res) => {
  133. if (res.code === 200) {
  134. this.printerList = res.data;
  135. } else {
  136. this.$message({
  137. type: "error",
  138. message: res.msg,
  139. });
  140. }
  141. });
  142. },
  143. getPrinterNum() {
  144. deviceStatus().then((res) => {
  145. if (res.code === 200) {
  146. this.pinter = res.data;
  147. } else {
  148. this.$message({
  149. type: "error",
  150. message: res.msg,
  151. });
  152. }
  153. });
  154. },
  155. getDeviceList() {
  156. deviceList({ type: 2 }).then((res) => {
  157. if (res.code === 200) {
  158. this.deviceList = res.data;
  159. } else {
  160. this.$message({
  161. type: "error",
  162. message: res.msg,
  163. });
  164. }
  165. });
  166. },
  167. getShopList() {
  168. shopListNew().then((res) => {
  169. if (res.code === 200) {
  170. this.shopList = res.data;
  171. } else {
  172. this.$message({
  173. type: "error",
  174. message: res.msg,
  175. });
  176. }
  177. });
  178. },
  179. },
  180. // 生命周期 - 创建完成(可以访问当前this实例)
  181. created() {
  182. this.getPrinterNum();
  183. this.getPrinterList();
  184. this.getDeviceList();
  185. this.getShopList();
  186. },
  187. // 生命周期 - 挂载完成(可以访问DOM元素)
  188. mounted() {},
  189. // 生命周期 - 创建之前
  190. beforeCreate() {},
  191. // 生命周期 - 挂载之前
  192. beforeMount() {},
  193. // 生命周期 - 更新之前
  194. beforeUpdate() {},
  195. // 生命周期 - 更新之后
  196. updated() {},
  197. // 生命周期 - 销毁之前
  198. beforeDestroy() {},
  199. // 生命周期 - 销毁完成
  200. destroyed() {},
  201. // 如果页面有keep-alive缓存功能,这个函数会触发
  202. activated() {},
  203. };
  204. </script>
  205. <style lang="scss" scoped type="text/css">
  206. .model {
  207. .title {
  208. position: relative;
  209. display: flex;
  210. align-items: center;
  211. font-size: 16px;
  212. font-weight: bold;
  213. line-height: 22px;
  214. color: #333333;
  215. padding-left: 10px;
  216. margin-top: 24px;
  217. .status-list {
  218. display: flex;
  219. align-items: center;
  220. font-size: 14px;
  221. font-weight: 400;
  222. line-height: 22px;
  223. color: #999999;
  224. .status {
  225. display: flex;
  226. align-items: center;
  227. margin-left: 30px;
  228. .con {
  229. margin-left: 5px;
  230. }
  231. .bg1 {
  232. width: 40px;
  233. height: 10px;
  234. border-radius: 2px;
  235. background: linear-gradient(180deg, #64c47c 0%, #1aaa3d 100%);
  236. }
  237. .bg2 {
  238. background: rgba(204, 204, 204, 0.39);
  239. }
  240. .bg3 {
  241. background: linear-gradient(180deg, #ff8a8a 0%, #e60000 100%);
  242. }
  243. }
  244. }
  245. }
  246. .title::before {
  247. width: 3px;
  248. height: 16px;
  249. background: rgba(252, 114, 0, 0.39);
  250. border-radius: 2px;
  251. content: "";
  252. position: absolute;
  253. top: 2px;
  254. left: 0;
  255. }
  256. .printer-list {
  257. display: flex;
  258. flex-wrap: wrap;
  259. .item {
  260. position: relative;
  261. display: flex;
  262. flex-direction: column;
  263. align-items: center;
  264. justify-content: center;
  265. width: 320px;
  266. height: 182px;
  267. background: #ffffff;
  268. border-radius: 8px;
  269. margin: 10px 20px 0 0;
  270. cursor: pointer;
  271. .img {
  272. width: 80px;
  273. height: 80px;
  274. }
  275. .name {
  276. font-size: 14px;
  277. font-weight: 500;
  278. line-height: 20px;
  279. color: #333333;
  280. }
  281. .shop-name {
  282. font-size: 12px;
  283. font-weight: 400;
  284. line-height: 20px;
  285. color: #999999;
  286. }
  287. .btns {
  288. position: absolute;
  289. top: 10px;
  290. right: 0;
  291. img {
  292. width: 20px;
  293. height: 20px;
  294. margin-right: 10px;
  295. }
  296. }
  297. }
  298. }
  299. }
  300. </style>