bindPrinter.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div class="bind-printer" v-loading="loading" element-loading-text="数据加载中">
  3. <div class="store-list">
  4. <div class="store-list-item" @click="curIdx = index" :class=" index == curIdx ? 'active' : '' " v-for="(item, index) in shopList" :key="index">{{ item.name }}</div>
  5. </div>
  6. <div class="header" v-if="shopList.length">
  7. <div class="left">
  8. <div class="line">
  9. <div class="b_line"></div>
  10. <div class="triangle"></div>
  11. </div>
  12. <div class="label">打印机管理</div>
  13. </div>
  14. <div class="right">
  15. <el-button class="btn" @click.stop="addPrinter(1)">添加打印机</el-button>
  16. </div>
  17. </div>
  18. <template v-if="printerList.length">
  19. <div class="take-out-list" v-for="(v,i) in printerList" :key="i">
  20. <div class="item">
  21. <div class="item-top">
  22. <div class="name">{{v.name}}</div>
  23. </div>
  24. <div class="item-bottom">
  25. <div class="left">
  26. <div class="l-l">
  27. <img :src="v.img" class="l-l-img" />
  28. </div>
  29. <div class="take-out-name">
  30. <div class="take-out-name-bot">
  31. <span :class="['status'+v.onlineStatus,'status']"> 打印机{{v.onlineStatus === 1 ? '在线' : v.onlineStatus === 2 ? '异常' : '离线'}}</span>
  32. </div>
  33. <div>打印机名称:{{v.deviceName}}</div>
  34. <div>打印机编号:{{v.deviceSn}}</div>
  35. <div class="take-out-name-bot">打印机KEY:{{v.deviceSecret}}</div>
  36. <div class="print-num">
  37. <div>客户联:X{{v.printCustomerCount}}</div>
  38. <div>商家联:X{{v.printMerchantCount}}</div>
  39. <div>厨房联:X{{v.printKitchenCount}}</div>
  40. </div>
  41. </div>
  42. </div>
  43. <div class="right">
  44. <el-button @click="addPrinter(2,v)" size="small">编&nbsp;辑</el-button>
  45. <el-button type="danger" @click="deletePrinter(v)" size="small">删&nbsp;除</el-button>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. <el-empty v-else description="暂无绑定打印机!"></el-empty>
  52. <!-- <div class="empty-img" v-else>
  53. <img src="../../../static/image/printer.png" />
  54. </div> -->
  55. <printer-add @shopDeviceList="shopDeviceList(curIdx)" ref="printerAdd" :devices="deviceList"></printer-add>
  56. </div>
  57. </template>
  58. <script>
  59. import printerAdd from "./printerAdd";
  60. import {
  61. getShopList,
  62. shopDeviceList,
  63. deviceDetail,
  64. deviceList,
  65. deviceAdd,
  66. deviceDelete,
  67. deviceStatus,
  68. } from "../../api/shop";
  69. export default {
  70. components: {
  71. printerAdd,
  72. },
  73. data() {
  74. return {
  75. shopList: [],
  76. curIdx: -1,
  77. loading: false,
  78. printerList: [],
  79. showVisible: false,
  80. title: "添加打印机",
  81. deviceList: [],
  82. memberType: this.$store.state.userInfo.memberType
  83. };
  84. },
  85. watch: {
  86. curIdx(newVal, oldVal) {
  87. this.shopDeviceList(newVal);
  88. },
  89. },
  90. created() {
  91. if (this.memberType !== 1) {
  92. this.getShopList();
  93. this.getDeviceList();
  94. }
  95. },
  96. methods: {
  97. deletePrinter(v) {
  98. this.$confirm("此操作将删除打印机, 是否继续?", "提示", {
  99. confirmButtonText: "确定",
  100. cancelButtonText: "取消",
  101. type: "warning",
  102. })
  103. .then(() => {
  104. deviceDelete({ id: v.id }).then((res) => {
  105. if (res.code === 200) {
  106. this.$message({
  107. type: "error",
  108. message: "删除成功!",
  109. });
  110. this.shopDeviceList(this.curIdx);
  111. } else {
  112. this.$message({
  113. type: "error",
  114. message: res.msg,
  115. });
  116. }
  117. });
  118. })
  119. .catch(() => {
  120. this.$message({
  121. type: "info",
  122. message: "已取消删除",
  123. });
  124. });
  125. },
  126. getDeviceList() {
  127. deviceList({ type: 2 }).then((res) => {
  128. if (res.code === 200) {
  129. this.deviceList = res.data;
  130. } else {
  131. this.$message({
  132. type: "error",
  133. message: res.msg,
  134. });
  135. }
  136. });
  137. },
  138. getShopList() {
  139. getShopList().then((res) => {
  140. this.loading = true;
  141. if (res.code === 200) {
  142. this.shopList = res.data;
  143. this.curIdx = 0;
  144. } else {
  145. this.$message({
  146. type: "error",
  147. message: res.msg,
  148. });
  149. }
  150. this.loading = false;
  151. });
  152. },
  153. addPrinter(val, e) {
  154. if (val === 1) {
  155. let shopId = this.shopList[this.curIdx].id;
  156. this.$refs.printerAdd.init("", shopId);
  157. } else {
  158. this.$refs.printerAdd.init(JSON.parse(JSON.stringify(e)));
  159. }
  160. },
  161. shopDeviceList(index) {
  162. shopDeviceList({ deviceType: 2, shopId: this.shopList[index].id }).then(
  163. (res) => {
  164. if (res.code === 200) {
  165. this.printerList = res.data;
  166. } else {
  167. this.$message({
  168. type: "error",
  169. message: res.msg,
  170. });
  171. }
  172. }
  173. );
  174. },
  175. },
  176. };
  177. </script>
  178. <style lang="scss" scoped>
  179. .bind-printer {
  180. min-height: 200px;
  181. .store-list {
  182. display: flex;
  183. flex-wrap: nowrap;
  184. width: 100%;
  185. white-space: nowrap;
  186. overflow-x: auto;
  187. padding-bottom: 10px;
  188. &-item {
  189. padding: 8px 27px;
  190. background-color: #fff;
  191. font-size: 14px;
  192. font-family: PingFang SC;
  193. font-weight: 400;
  194. color: #b1b1b1;
  195. box-sizing: border-box;
  196. border: 1px solid #eee;
  197. border-radius: 17px;
  198. cursor: pointer;
  199. margin-right: 10px;
  200. &.active {
  201. color: #fc7200;
  202. }
  203. }
  204. }
  205. .store-list::-webkit-scrollbar {
  206. height: 6px;
  207. }
  208. .store-list::-webkit-scrollbar-track {
  209. background-color: #eee;
  210. /*border-radius: 5px;
  211. -webkit-border-radius: 5px;
  212. -moz-border-radius: 5px;*/
  213. }
  214. .store-list::-webkit-scrollbar-thumb {
  215. background-color: #999;
  216. border-radius: 6px;
  217. -webkit-border-radius: 6px;
  218. -moz-border-radius: 6px;
  219. }
  220. .take-out-list {
  221. margin-bottom: 10px;
  222. .item {
  223. background-color: #fff;
  224. .item-top {
  225. display: flex;
  226. justify-content: space-between;
  227. box-sizing: border-box;
  228. padding: 20px 18px;
  229. align-items: center;
  230. border-bottom: 1px solid #eee;
  231. .name {
  232. font-size: 16px;
  233. font-family: PingFang SC;
  234. font-weight: bold;
  235. color: #333333;
  236. }
  237. .top-right {
  238. display: flex;
  239. align-items: center;
  240. span {
  241. font-size: 14px;
  242. font-family: PingFang SC;
  243. font-weight: 400;
  244. color: #b1b1b1;
  245. margin-right: 12px;
  246. }
  247. }
  248. }
  249. .item-bottom {
  250. display: flex;
  251. justify-content: space-between;
  252. box-sizing: border-box;
  253. padding: 10px 18px;
  254. align-items: center;
  255. .left {
  256. display: flex;
  257. align-items: center;
  258. .l-l {
  259. width: 155px;
  260. height: 80px;
  261. font-size: 0;
  262. .l-l-img {
  263. width: 100%;
  264. height: 100%;
  265. }
  266. }
  267. .take-out-name {
  268. font-size: 13px;
  269. font-family: PingFang SC;
  270. font-weight: 400;
  271. color: #333333;
  272. line-height: 26px;
  273. margin-left: 30px;
  274. .take-out-name-bot {
  275. // margin-bottom: 10px;
  276. .status {
  277. display: flex;
  278. align-items: center;
  279. &:before {
  280. content: "";
  281. display: block;
  282. width: 8px;
  283. height: 8px;
  284. border-radius: 50%;
  285. margin-right: 5px;
  286. }
  287. }
  288. .status0 {
  289. color: #b1b1b1;
  290. &:before {
  291. background: #b1b1b1;
  292. }
  293. }
  294. .status2 {
  295. color: #f74141;
  296. &:before {
  297. background: #f74141;
  298. }
  299. }
  300. .status1 {
  301. color: #18b71c;
  302. &:before {
  303. background: #18b71c;
  304. }
  305. }
  306. }
  307. .print-num {
  308. display: flex;
  309. div {
  310. margin-right: 20px;
  311. }
  312. }
  313. }
  314. }
  315. .right {
  316. .right-btn {
  317. background-color: #fc7200;
  318. border: none;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. .category_box {
  325. display: flex;
  326. flex-wrap: wrap;
  327. width: 100%;
  328. margin-top: -10px;
  329. .item {
  330. display: flex;
  331. align-items: center;
  332. justify-content: center;
  333. width: 92px;
  334. height: 38px;
  335. margin: 10px 10px 0 0;
  336. background: #f4f4f4;
  337. border-radius: 2px;
  338. cursor: pointer;
  339. &.active {
  340. color: #ffffff;
  341. background: #fc7200;
  342. }
  343. }
  344. }
  345. .header {
  346. display: flex;
  347. align-items: center;
  348. justify-content: space-between;
  349. margin: 10px;
  350. .left {
  351. display: flex;
  352. align-items: center;
  353. .line {
  354. position: relative;
  355. width: 4px;
  356. height: 15px;
  357. background: #fc7200;
  358. border-radius: 4px;
  359. overflow: hidden;
  360. margin-right: 10px;
  361. .b_line {
  362. width: 100px;
  363. height: 6px;
  364. background: #462bf7;
  365. }
  366. .triangle {
  367. width: 0;
  368. height: 0;
  369. border-top: 100px solid #462bf7;
  370. border-left: 100px solid transparent;
  371. }
  372. }
  373. .label {
  374. font-size: 16px;
  375. font-weight: 500;
  376. color: #0d1e40;
  377. }
  378. }
  379. }
  380. .btn {
  381. background: #fc7200;
  382. border-color: #fc7200;
  383. color: #fff;
  384. &.black {
  385. background: #0d1e40;
  386. border-color: #0d1e40;
  387. }
  388. }
  389. }
  390. </style>