print.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <view class="print-page">
  3. <view class="print-list">
  4. <view class="item" v-for="item in prints" :key="item.printerId">
  5. <view class="row">
  6. <view class="name">
  7. <view class="text">{{ item.printerName }}</view>
  8. <view class="default" v-if="item.moren">默认</view>
  9. <view class="offline" v-if="item.status == 1">设备已离线</view>
  10. <view class="online" v-if="item.status == 2">在线</view>
  11. <view class="danger" v-if="item.status == 3">异常</view>
  12. <view class="reload" @click="reload(item.printerId)">刷新</view>
  13. </view>
  14. <u-icon name="trash" size="26" color="#6c6c6c" @click="handItemRemove(item)"></u-icon>
  15. </view>
  16. <view class="row">
  17. <view class="no">打印机编号: {{ item.sn }}</view>
  18. <u-icon name="edit-pen" size="26" color="#6c6c6c" @click="handItemEdit(item)"></u-icon>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="add-print" @click="addPrint">
  23. 添加小票打印机
  24. </view>
  25. <u-modal
  26. :show="deleteVisible"
  27. :title="modalTitle"
  28. closeOnClickOverlay
  29. showCancelButton
  30. confirmColor="#d64d3b"
  31. @confirm="handDelete"
  32. @cancel="deleteVisible = false"
  33. @close="deleteVisible = false">
  34. </u-modal>
  35. <u-modal
  36. :show="formVisible"
  37. :title="modalTitle"
  38. closeOnClickOverlay
  39. showCancelButton
  40. @confirm="handAdd"
  41. @cancel="cancelForm"
  42. @close="cancelForm">
  43. <view class="container">
  44. <view class="item">
  45. <view class="label">名称</view>
  46. <view class="value">
  47. <u-input type="text" placeholder="请输入打印机名称" v-model="formItem.printerName"></u-input>
  48. </view>
  49. </view>
  50. <view class="item">
  51. <view class="label">编号</view>
  52. <view class="value">
  53. <u-input type="text" placeholder="请输入打印机编号" :disabled="flag" v-model="formItem.sn"></u-input>
  54. </view>
  55. </view>
  56. <view class="item">
  57. <view class="label">密钥</view>
  58. <view class="value">
  59. <u-input type="text" placeholder="请输入打印机密钥" :disabled="flag" v-model="formItem.printerKey"></u-input>
  60. </view>
  61. </view>
  62. <view class="item">
  63. <view class="label">打印联数</view>
  64. <view class="value">
  65. <u-input type="text" placeholder="请输入打印机联数" v-model="formItem.times"></u-input>
  66. </view>
  67. </view>
  68. <view class="item">
  69. <view class="label">是否默认</view>
  70. <view class="value">
  71. <!-- <u-switch v-model="formItem.moren" size="18"></u-switch> -->
  72. <!-- <switch :checked="formItem.moren" size="22" class="switch" style="transform:scale(0.7)"></switch> -->
  73. <checkBox :isOpen="formItem.moren" @toggle="changMoren"></checkBox>
  74. </view>
  75. </view>
  76. <view class="desc">
  77. 当有多台小票机时, 新订单只会在默认小票机上出票
  78. </view>
  79. </view>
  80. </u-modal>
  81. </view>
  82. </template>
  83. <script>
  84. import {mapState} from 'vuex';
  85. import {checkBox} from '../components/p-checkbox.vue'
  86. export default {
  87. components: {
  88. checkBox
  89. },
  90. data () {
  91. return {
  92. printerUrl: '/storePrintApi/getPrinterList',
  93. reloadUrl: '/storePrintApi/reloadPrinter',
  94. printerByIdUrl: '/storePrintApi/getPrinterById',
  95. deleteUrl: '/storePrintApi/delete',
  96. saveUrl: '/storePrintApi/updatePrinter',
  97. modalTitle: '',
  98. deleteVisible: false,
  99. delItem: null,
  100. formItem: {
  101. printerId: '',
  102. storeId: '',
  103. moren: false,
  104. sn: '',
  105. printerKey: '',
  106. printerName: '',
  107. times: ''
  108. },
  109. formVisible: '',
  110. prints: [],
  111. flag: true
  112. }
  113. },
  114. computed: {
  115. ...mapState(['storeInfo'])
  116. },
  117. methods: {
  118. loadData () {
  119. uni.showLoading({
  120. title: '加载中'
  121. });
  122. var dateStr = (new Date()).getTime();
  123. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  124. this.requst({
  125. url: this.printerUrl,
  126. data: {
  127. timestamp: dateStr,
  128. sign: sign,
  129. storeId: this.storeInfo.storeId,
  130. storeUserId: this.storeInfo.storeUserId
  131. },
  132. success: res => {
  133. if (res.data.rtnBean.rtnCode == 0) {
  134. this.prints = res.data.list
  135. }
  136. uni.stopPullDownRefresh();
  137. uni.hideLoading();
  138. },
  139. fail: (e) => {
  140. console.log("接口调用失败:" + JSON.stringify(e));
  141. uni.stopPullDownRefresh()
  142. uni.hideLoading();
  143. },
  144. })
  145. },
  146. getPrinter (id) {
  147. uni.showLoading({
  148. title: '加载中'
  149. });
  150. var dateStr = (new Date()).getTime();
  151. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  152. this.requst({
  153. url: this.printerByIdUrl,
  154. data: {
  155. timestamp: dateStr,
  156. sign: sign,
  157. storeId: this.storeInfo.storeId,
  158. storeUserId: this.storeInfo.storeUserId,
  159. id: id
  160. },
  161. success: res => {
  162. if (res.data.rtnBean.rtnCode == 0) {
  163. this.formItem = res.data.obj
  164. }
  165. uni.hideLoading();
  166. },
  167. fail: (e) => {
  168. console.log("接口调用失败:" + JSON.stringify(e));
  169. uni.hideLoading();
  170. },
  171. })
  172. },
  173. reload (printerId) {
  174. uni.showLoading({
  175. title: '加载中'
  176. });
  177. var dateStr = (new Date()).getTime();
  178. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  179. this.requst({
  180. url: this.reloadUrl,
  181. data: {
  182. timestamp: dateStr,
  183. sign: sign,
  184. storeId: this.storeInfo.storeId,
  185. storeUserId: this.storeInfo.storeUserId,
  186. printerId: printerId
  187. },
  188. success: res => {
  189. if (res.data.rtnBean.rtnCode == 0) {
  190. this.prints = res.data.list
  191. }
  192. uni.hideLoading();
  193. },
  194. fail: (e) => {
  195. console.log("接口调用失败:" + JSON.stringify(e));
  196. uni.hideLoading();
  197. },
  198. })
  199. },
  200. close () {
  201. this.deleteVisible = false
  202. },
  203. cancelForm () {
  204. this.formVisible = false
  205. this.formItem = {
  206. printerId: '',
  207. storeId: '',
  208. moren: false,
  209. sn: '',
  210. printerKey: '',
  211. printerName: '',
  212. times: ''
  213. }
  214. },
  215. handItemRemove (item) {
  216. this.modalTitle = `确定要删除 [${item.printerName}] 打印机吗?`
  217. this.delItem = item
  218. this.deleteVisible = true
  219. },
  220. handDelete () {
  221. console.log('这里写删除接口: ', this.delItem);
  222. uni.showLoading({
  223. title: '删除中'
  224. });
  225. var dateStr = (new Date()).getTime();
  226. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  227. this.requst({
  228. url: this.deleteUrl,
  229. data: {
  230. timestamp: dateStr,
  231. sign: sign,
  232. storeId: this.storeInfo.storeId,
  233. storeUserId: this.storeInfo.storeUserId,
  234. id: this.delItem.printerId,
  235. sn: this.delItem.sn
  236. },
  237. success: res => {
  238. if (res.data.rtnBean.rtnCode == 0) {
  239. uni.hideLoading();
  240. uni.showToast({
  241. title: '删除成功',
  242. icon: 'none'
  243. })
  244. this.deleteVisible = false
  245. this.delItem = {}
  246. this.loadData()
  247. } else {
  248. uni.hideLoading();
  249. this.$api.msg(res.data.rtnBean.rtnMsg);
  250. }
  251. },
  252. fail: (e) => {
  253. console.log("接口调用失败:" + JSON.stringify(e));
  254. uni.hideLoading();
  255. }
  256. })
  257. this.delItem = null
  258. this.modalTitle = ''
  259. this.deleteVisible = false
  260. },
  261. handItemEdit (item) {
  262. console.log('item :>> ', item);
  263. this.getPrinter(item.printerId)
  264. this.modalTitle = '添加/编辑打印机'
  265. this.formVisible = true
  266. this.flag = true
  267. },
  268. addPrint () {
  269. this.modalTitle = '添加/编辑打印机'
  270. this.formVisible = true
  271. this.flag = false
  272. },
  273. handAdd () {
  274. console.log('这里写保存接口: ', this.formItem);
  275. if (!this.formItem.printerName) {
  276. uni.showToast({
  277. title: '请输入打印机名称',
  278. icon: 'none'
  279. })
  280. return
  281. }
  282. if (!this.formItem.sn) {
  283. uni.showToast({
  284. title: '请输入打印机编号',
  285. icon: 'none'
  286. })
  287. return
  288. }
  289. if (!this.formItem.printerKey) {
  290. uni.showToast({
  291. title: '请输入打印机秘钥',
  292. icon: 'none'
  293. })
  294. return
  295. }
  296. if (!this.formItem.times) {
  297. uni.showToast({
  298. title: '请输入打印机打印份数',
  299. icon: 'none'
  300. })
  301. return
  302. }
  303. uni.showLoading({
  304. title: '保存中'
  305. });
  306. var dateStr = (new Date()).getTime();
  307. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  308. this.requst({
  309. url: this.saveUrl,
  310. data: {
  311. timestamp: dateStr,
  312. sign: sign,
  313. storeId: this.storeInfo.storeId,
  314. storeUserId: this.storeInfo.storeUserId,
  315. printerId: this.formItem.printerId,
  316. moren: this.formItem.moren ? 1 : 0,
  317. sn: this.formItem.sn,
  318. printerKey: this.formItem.printerKey,
  319. printerName: this.formItem.printerName,
  320. times: this.formItem.times,
  321. },
  322. success: res => {
  323. if (res.data.rtnBean.rtnCode == 0) {
  324. uni.hideLoading();
  325. uni.showToast({
  326. title: '添加成功',
  327. icon: 'none'
  328. })
  329. this.formVisible = false
  330. this.formItem = {
  331. printerId: '',
  332. storeId: '',
  333. moren: false,
  334. sn: '',
  335. printerKey: '',
  336. printerName: '',
  337. times: ''
  338. }
  339. this.loadData()
  340. } else {
  341. uni.hideLoading();
  342. this.$api.msg(res.data.rtnBean.rtnMsg);
  343. }
  344. },
  345. fail: (e) => {
  346. console.log("接口调用失败:" + JSON.stringify(e));
  347. uni.hideLoading();
  348. }
  349. })
  350. },
  351. changMoren (e) {
  352. console.log('e :>> ', e);
  353. this.formItem.moren = !this.formItem.moren
  354. }
  355. },
  356. onPullDownRefresh() {
  357. this.loadData();
  358. },
  359. onLoad () {
  360. this.loadData()
  361. }
  362. }
  363. </script>
  364. <style lang="scss" scoped>
  365. .print-page {
  366. width: 100vw;
  367. height: 100vh;
  368. background-color: #fff;
  369. }
  370. .print-list {
  371. height: calc(100vh - env(safe-area-inset-bottom) - 120rpx);
  372. height: calc(100vh - constant(safe-area-inset-bottom) - 120rpx);
  373. background-color: #f5f5f5;
  374. padding: 20rpx;
  375. box-sizing: border-box;
  376. .item {
  377. background-color: #fff;
  378. margin-bottom: 20rpx;
  379. border-radius: 10rpx;
  380. padding: 20rpx;
  381. display: flex;
  382. flex-direction: column;
  383. .row {
  384. @include between;
  385. color: $text-color;
  386. }
  387. .row:first-child {
  388. margin-bottom: 20rpx;
  389. }
  390. .name {
  391. font-size: 36rpx;
  392. @include flexStart;
  393. }
  394. .no {
  395. font-size: $font-base;
  396. }
  397. .default, .offline, .online, .dange, .reload {
  398. font-size: $font-sm;
  399. padding: 4rpx 20rpx;
  400. border-radius: 10rpx;
  401. margin-left: 20rpx;
  402. }
  403. .default {
  404. background-color: $theme-color;
  405. color: #fff;
  406. }
  407. .offline {
  408. border: 2rpx solid $uni-color-button;
  409. color: $uni-color-button;
  410. }
  411. .online {
  412. border: 2rpx solid $uni-color-success;
  413. color: $uni-color-success;
  414. }
  415. .dange {
  416. border: 2rpx solid $uni-color-button;
  417. color: $uni-color-button;
  418. }
  419. .reload {
  420. border: 2rpx solid $uni-color-primary;
  421. color: $uni-color-primary;
  422. }
  423. }
  424. }
  425. .add-print {
  426. position: fixed;
  427. left: 10vw;
  428. width: 80vw;
  429. height: 80rpx;
  430. border-radius: 40rpx;
  431. @include flexCenter;
  432. color: #fff;
  433. background-color: $light-color;
  434. bottom: calc(20rpx + env(safe-area-inset-bottom));
  435. bottom: calc(20rpx + constant(safe-area-inset-bottom));
  436. }
  437. /deep/ .u-modal__content {
  438. padding: 20rpx !important;
  439. box-sizing: border-box !important;
  440. }
  441. .container {
  442. width: 100%;
  443. .name {
  444. margin: 40rpx 0;
  445. }
  446. .item {
  447. @include between;
  448. margin-bottom: 20rpx;
  449. .label {
  450. width: 160rpx;
  451. }
  452. .value {
  453. width: calc(100% - 160rpx);
  454. }
  455. }
  456. .desc {
  457. color: $uni-color-button;
  458. font-size: $font-sm;
  459. }
  460. }
  461. </style>