bindPrinter.vue 9.6 KB

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