|
@@ -25,7 +25,7 @@
|
25
|
25
|
<div class="moreFilter"></div>
|
26
|
26
|
</div>
|
27
|
27
|
<div class="order-list-box">
|
28
|
|
- <div style='position:relative;' v-for="(item,index) in list" :key="index">
|
|
28
|
+ <div style='position:relative;' v-for="(item,index) in ordersList" :key="index">
|
29
|
29
|
<div>
|
30
|
30
|
<div style="padding:25px 20px 5px;border-bottom:2px solid #cccccc;display:flex;align-items: center;">
|
31
|
31
|
<!-- <i class="iconfont icon-yinchenglogo" style="font-size:70px;color:red;position: relative;bottom: 20px;margin-right:10px;"></i> -->
|
|
@@ -46,28 +46,7 @@
|
46
|
46
|
<div style="padding:10px 20px;border-bottom:1px solid #cccccc;white-space: normal;">备注:{{item.Remark}}</div>
|
47
|
47
|
<div style="padding:10px 20px;">下单人:{{item.UserName}}</div>
|
48
|
48
|
</div>
|
49
|
|
- <div class="print-area" :class="'item_' + item.OrdersId" style="width:180px;">
|
50
|
|
- <div style="padding:0px 10px 5px;border-bottom:2px solid #cccccc;">
|
51
|
|
- <div style="display:inline-block;">
|
52
|
|
- <img class="topIcon" style="display:block;width:60%;margin:0 0 20px 0px;" src="http://jingcheng-resourceplat.oss-cn-shanghai.aliyuncs.com/upload/111101940020.png" alt="">
|
53
|
|
- <span style="display:block;font-size:20px;font-weight:700;text-align: center;"> <img width='30px' :src='item.AreaIconWhite' alt=""> {{item.AreaName + item.TableNo}}</span>
|
54
|
|
- </div>
|
55
|
|
- </div>
|
56
|
|
- <div style="padding:10px 10px 5px;border-bottom:1px solid #cccccc;" v-for='(item1,index1) in item.Goods' :key='index1'>
|
57
|
|
- <div style="font-size:12px;"><span style="display:inline-block;width:75%;text-align:left;">{{item1.GoodsName}}</span><span style="display:inline-block;width:22%;text-align:right;font-size:12px;" v-if='!item1.SpecName'>× {{item1.Number}}</span></div>
|
58
|
|
- <div style="margin-top:8px;" v-if='item1.SpecName'>
|
59
|
|
- <span style="display:inline-block;width:75%;text-align:left;color:#cccccc;font-size:12px;">{{item1.SpecName}}</span>
|
60
|
|
- <span style="display:inline-block;width:20%;text-align:right;font-size:12px;">× {{item1.Number}}</span>
|
61
|
|
- </div>
|
62
|
|
- </div>
|
63
|
|
- <div style="padding:10px 10px 5px;border-bottom:1px solid #cccccc;">
|
64
|
|
- <div style="font-size:12px;">下单人:{{item.UserName}}</div>
|
65
|
|
- <span style="display:block;margin-top:10px;font-size:12px;">下单时间:{{toolClass.dateFormat(item.CreateDate)}}</span>
|
66
|
|
- </div>
|
67
|
|
- <div style="padding:10px 10px;font-size:12px;">备注:{{item.Remark}}</div>
|
68
|
|
- <div style="text-align: right;font-size: 12px;">城的空间.城咖啡</div>
|
69
|
|
- <div style="height:10px"></div>
|
70
|
|
- </div>
|
|
49
|
+ <print-list :print-list="printList" :lodop="lodop" @printed="clearPrintList" />
|
71
|
50
|
<div class="btns">
|
72
|
51
|
<span @click="cancel(item.OrdersId,index)">取消</span>
|
73
|
52
|
<span @click="submit(item.OrdersId,index)">确定</span>
|
|
@@ -82,22 +61,29 @@ import { createNamespacedHelpers, mapState, mapActions } from 'vuex'
|
82
|
61
|
import { getLodop } from '@/util/LodopFuncs'
|
83
|
62
|
import { formatTimeBySeconds } from '@/util/util'
|
84
|
63
|
import { replaceURLParams } from '@/util/ajax'
|
|
64
|
+import XWebSocket from '@/util/websocket'
|
85
|
65
|
|
86
|
66
|
// const WebSocket = require('ws')
|
87
|
67
|
const { mapState: mapOrderState, mapActions: mapOrderActions } = createNamespacedHelpers('goodsorder')
|
88
|
68
|
|
89
|
|
-var LODOP
|
90
|
69
|
export default {
|
91
|
70
|
name: '',
|
|
71
|
+ components: {
|
|
72
|
+ 'print-list': () => import('./print'),
|
|
73
|
+ },
|
92
|
74
|
data () {
|
93
|
75
|
return {
|
|
76
|
+ lodop: null,
|
|
77
|
+ ws: null,
|
|
78
|
+ wsID: '',
|
|
79
|
+ printList: [],
|
|
80
|
+
|
94
|
81
|
total: 0,
|
95
|
82
|
postData: { // 表格搜索条件
|
96
|
83
|
phone: '', // 手机号
|
97
|
84
|
page: 1, // 当前页码
|
98
|
85
|
pagesize: 10, // 请求数据量
|
99
|
86
|
},
|
100
|
|
- currentList: [],
|
101
|
87
|
leftTimes: {},
|
102
|
88
|
business: false,
|
103
|
89
|
caseid: '',
|
|
@@ -108,8 +94,23 @@ export default {
|
108
|
94
|
},
|
109
|
95
|
computed: {
|
110
|
96
|
...mapOrderState({
|
111
|
|
- list: x => (x.ordersList || {}).list || [],
|
112
|
|
- businessStatus: x => x.businessStatus
|
|
97
|
+ ordersList: x => x.ordersList,
|
|
98
|
+ }),
|
|
99
|
+ ...mapOrderState({
|
|
100
|
+ businessStatus (state) {
|
|
101
|
+ if (!state.businessStatus) {
|
|
102
|
+ this.ws.close()
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ if (state.businessStatus && (this.wsID !== this.CaseId) && this.CaseId) {
|
|
106
|
+ this.ws.close()
|
|
107
|
+ this.initWebSocket()
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ this.wsID = this.CaseId
|
|
111
|
+
|
|
112
|
+ return state.businessStatus
|
|
113
|
+ }
|
113
|
114
|
}),
|
114
|
115
|
...mapState({
|
115
|
116
|
cases: x => x.app.cases.list,
|
|
@@ -123,90 +124,69 @@ export default {
|
123
|
124
|
set (val) {
|
124
|
125
|
this.caseid = val
|
125
|
126
|
}
|
126
|
|
- }
|
|
127
|
+ },
|
127
|
128
|
},
|
128
|
129
|
created () {
|
|
130
|
+ this.lodop = getLodop()
|
|
131
|
+ this.lodop.PRINT_INIT('城咖啡订单')
|
|
132
|
+ this.lodop.SET_PRINT_PAGESIZE(3, 480, 40, '')
|
|
133
|
+
|
129
|
134
|
this.updateSystemInfo().then(() => {
|
130
|
135
|
console.log(this.CaseId)
|
131
|
136
|
if (this.CaseId) {
|
132
|
137
|
this.init()
|
133
|
138
|
}
|
134
|
139
|
})
|
135
|
|
- },
|
136
|
|
- mounted () {
|
137
|
|
- // setTimeout(window.location.reload, 600 * 1000)
|
138
|
|
- },
|
139
|
|
- beforeRouteLeave (to, from, next) {
|
140
|
|
- // 导航离开该组件的对应路由时调用
|
141
|
|
- // 可以访问组件实例 `this`
|
142
|
|
- // console.log(this.websockets)
|
143
|
|
- this.needReload = false
|
144
|
|
- Object.keys(this.websockets).forEach((key) => {
|
145
|
|
- this.destroyWebsocket(this.websockets[key])
|
|
140
|
+
|
|
141
|
+ this.ws = new XWebSocket({
|
|
142
|
+ message: this.receviedNewOrders.bind(this),
|
|
143
|
+ delay: 10,
|
|
144
|
+ autoConnect: true,
|
146
|
145
|
})
|
147
|
|
- this.websockets = {}
|
148
|
|
- next()
|
|
146
|
+ },
|
|
147
|
+ beforeDestroyed () {
|
|
148
|
+ this.ws.close()
|
149
|
149
|
},
|
150
|
150
|
methods: {
|
151
|
151
|
init () {
|
152
|
|
- if (this.needReload) {
|
153
|
|
- this.needReload = false
|
154
|
|
- Object.keys(this.websockets).forEach((key) => {
|
155
|
|
- // console.log(key, this.websockets[key])
|
156
|
|
- this.destroyWebsocket(this.websockets[key])
|
|
152
|
+ // 必须选案场
|
|
153
|
+ if (!this.CaseId) {
|
|
154
|
+ this.$message({
|
|
155
|
+ type: 'info',
|
|
156
|
+ message: '请先选择案场'
|
157
|
157
|
})
|
158
|
|
- this.websockets = {}
|
159
|
|
- // console.log('init')
|
160
|
|
- var param = []
|
161
|
|
- if (!this.CaseId) {
|
162
|
|
- this.$message({
|
163
|
|
- type: 'info',
|
164
|
|
- message: '请先选择案场'
|
165
|
|
- })
|
166
|
|
- return
|
|
158
|
+ return
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ // 获取新单
|
|
162
|
+ this.GetOrdersList({ caseid: this.CaseId }).then(list => {
|
|
163
|
+ // 打印新单
|
|
164
|
+ if (list) {
|
|
165
|
+ this.printList = list.map(x => x.IsIntimidate === 0)
|
167
|
166
|
}
|
168
|
|
- clearInterval(this.interval)
|
169
|
|
- // console.log(this.CaseId)
|
170
|
|
- this.GetOrdersList({ caseid: this.CaseId }).then((res) => {
|
171
|
|
- for (var n = 0; n < (res.list || []).length; n++) {
|
172
|
|
- if (res.list[n].IsIntimidate === 0) {
|
173
|
|
- param.push(res.list[n].OrdersId)
|
174
|
|
- }
|
175
|
|
- }
|
176
|
|
- var bool = true
|
177
|
|
- var timer = setInterval(() => {
|
178
|
|
- if (param.length && bool) {
|
179
|
|
- bool = false
|
180
|
|
- this.printPdf(`item_${param[0]}`)
|
181
|
|
- this.putPrintGoodsOrder({
|
182
|
|
- id: param[0]
|
183
|
|
- }).then(() => {
|
184
|
|
- param.splice(0, 1)
|
185
|
|
- bool = true
|
186
|
|
- })
|
187
|
|
- } else {
|
188
|
|
- this.needReload = true
|
189
|
|
- clearInterval(timer)
|
190
|
|
- }
|
191
|
|
- }, 300)
|
192
|
|
- this.getBusinessStatus(this.CaseId).then(() => {
|
193
|
|
- if (this.businessStatus) {
|
194
|
|
- this.initWebSocket()
|
195
|
|
- }
|
196
|
|
- })
|
|
167
|
+
|
|
168
|
+ // 开张, 则实时监控新单
|
|
169
|
+ this.getBusinessStatus(this.CaseId).then(() => {
|
|
170
|
+
|
197
|
171
|
})
|
|
172
|
+
|
|
173
|
+ // 页面倒计时
|
|
174
|
+ clearInterval(this.interval)
|
198
|
175
|
this.refreshList()
|
199
|
|
- }
|
|
176
|
+ })
|
200
|
177
|
},
|
201
|
178
|
refreshList () {
|
202
|
179
|
this.interval = setInterval(() => {
|
203
|
180
|
const now = (new Date()).valueOf()
|
204
|
|
- this.leftTimes = this.list.reduce((acc, it) => {
|
|
181
|
+ this.leftTimes = (this.ordersList || []).reduce((acc, it) => {
|
205
|
182
|
const showDT = now - ((new Date(it.CreateDate)).valueOf())
|
206
|
183
|
return { ...acc, [`${it.OrdersId}`]: formatTimeBySeconds(showDT) }
|
207
|
184
|
}, {})
|
208
|
185
|
}, 1000)
|
209
|
186
|
},
|
|
187
|
+ clearPrintList () {
|
|
188
|
+ this.printList = []
|
|
189
|
+ },
|
210
|
190
|
timeOut (c) {
|
211
|
191
|
let cTime = new Date(c).valueOf()
|
212
|
192
|
let time = new Date().valueOf()
|
|
@@ -241,8 +221,8 @@ export default {
|
241
|
221
|
type: 'success',
|
242
|
222
|
message: '确认订单成功'
|
243
|
223
|
})
|
244
|
|
- this.list.splice(index, 1)
|
245
|
|
- this.updateList({ list: this.list })
|
|
224
|
+
|
|
225
|
+ this.updateList({ list: this.ordersList.filter(x => x.OrdersId !== id) })
|
246
|
226
|
})
|
247
|
227
|
}).catch((res) => {
|
248
|
228
|
this.$message({
|
|
@@ -262,8 +242,8 @@ export default {
|
262
|
242
|
type: 'success',
|
263
|
243
|
message: '取消订单成功'
|
264
|
244
|
})
|
265
|
|
- this.list.splice(index, 1)
|
266
|
|
- this.updateList({ list: this.list })
|
|
245
|
+
|
|
246
|
+ this.updateList({ list: this.ordersList.filter(x => x.OrdersId !== id) })
|
267
|
247
|
})
|
268
|
248
|
}).catch((res) => {
|
269
|
249
|
this.$message({
|
|
@@ -272,82 +252,37 @@ export default {
|
272
|
252
|
})
|
273
|
253
|
})
|
274
|
254
|
},
|
275
|
|
- printPdf (cl) {
|
276
|
|
- this.CreateOneFormPage(cl)
|
277
|
|
- LODOP.PRINT()
|
278
|
|
- },
|
279
|
|
- CreateOneFormPage (cl) {
|
280
|
|
- LODOP = getLodop()
|
281
|
|
- LODOP.PRINT_INIT('订单')
|
282
|
|
- LODOP.SET_PRINT_PAGESIZE(3, 480, 40, '')
|
283
|
|
- LODOP.ADD_PRINT_HTM(0, 0, document.getElementsByClassName(cl)[0].offsetWidth, document.getElementsByClassName(cl)[0].offsetHeight, document.getElementsByClassName(cl)[0].innerHTML)
|
284
|
|
- },
|
285
|
255
|
initWebSocket () {
|
286
|
256
|
console.log('initWebSocket')
|
287
|
|
- // console.log(this.user)
|
288
|
257
|
let caseid = this.CaseId
|
289
|
258
|
let id = this.userInfo.UserId
|
290
|
259
|
const wsPath = this.$api.system.notify.newGoodsOrders.url
|
291
|
260
|
const wsRealPath = replaceURLParams(wsPath, { grps: caseid, id })
|
292
|
|
- this.newWebsocket(wsRealPath)
|
|
261
|
+ const wsURL = `${window.location.origin.replace('http', 'ws')}${wsRealPath}?token=${localStorage.getItem('JWT')}`
|
|
262
|
+ this.ws.connect(wsURL)
|
293
|
263
|
},
|
294
|
|
- websocketonmessage (e) {
|
295
|
|
- // let oldList = this.list
|
296
|
|
- let newList = JSON.parse(e.data).data.refreshOnlineGoodsOrders
|
297
|
|
- // let newinfo = newList.filter(x => this.list.filter(item => item.OrdersId === x.OrdersId).length === 0)
|
298
|
|
- this.updateList({ list: this.list.concat(newList) }).then(() => {
|
299
|
|
- newList.forEach((it) => {
|
300
|
|
- // console.log(it)
|
301
|
|
- if (!it.IsIntimidate) {
|
302
|
|
- // console.log('print')
|
303
|
|
- this.putPrintGoodsOrder({
|
304
|
|
- id: it.OrdersId
|
305
|
|
- }).then(() => {
|
306
|
|
- this.printPdf(`item_${it.OrdersId}`)
|
|
264
|
+ receviedNewOrders (e) {
|
|
265
|
+ const newOrders = JSON.parse(e.data).data.refreshOnlineGoodsOrders
|
|
266
|
+ if (!newOrders || !newOrders.length) return
|
|
267
|
+
|
|
268
|
+ // 放入待制作队列
|
|
269
|
+ this.updateList({ list: this.list.concat(newOrders) })
|
|
270
|
+
|
|
271
|
+ // 放入待打队列
|
|
272
|
+ const ps = newOrders.filter(x => x.IsIntimidate === 0).map((orders) => {
|
|
273
|
+ return new Promise((resolve, reject) => {
|
|
274
|
+ if (orders.IsIntimidate === 0) {
|
|
275
|
+ // 先远程更新掉打单状态字段
|
|
276
|
+ this.putPrintGoodsOrder({id: orders.OrdersId}).then(() => {
|
|
277
|
+ resolve(orders)
|
307
|
278
|
})
|
|
279
|
+ } else {
|
|
280
|
+ resolve()
|
308
|
281
|
}
|
309
|
282
|
})
|
310
|
283
|
})
|
311
|
|
- },
|
312
|
|
- newWebsocket (wsRealPath) {
|
313
|
|
- const ws = this.websockets[wsRealPath]
|
314
|
|
- // console.log('newWebsocket', ws)
|
315
|
|
- if (!ws) {
|
316
|
|
- const url = `${window.location.origin.replace('http', 'ws')}${wsRealPath}?token=${localStorage.getItem('JWT')}`
|
317
|
|
- this.websockets[wsRealPath] = new WebSocket(url)
|
318
|
|
- this.websockets[wsRealPath].onopen = console.log
|
319
|
|
- this.websockets[wsRealPath].onmessage = this.websocketonmessage
|
320
|
|
- this.websockets[wsRealPath].onclose = ((ws) => {
|
321
|
|
- return e => this.reloadWebSocket(e, ws)
|
322
|
|
- })(this.websockets[wsRealPath])
|
323
|
|
- this.websockets[wsRealPath].interval = setInterval(() => {
|
324
|
|
- try { this.websockets[wsRealPath].send(10) } catch (err) { console.log(err) }
|
325
|
|
- }, 120000)
|
326
|
|
- }
|
327
|
|
- },
|
328
|
|
- reloadWebSocket (e, ws) {
|
329
|
|
- if (e.target.readyState >= 2) {
|
330
|
|
- // console.log(e.currentTarget.url)
|
331
|
|
- Object.keys(this.websockets).forEach((key) => {
|
332
|
|
- // this.websockets[key].close()
|
333
|
|
- clearInterval(this.websockets[key].interval)
|
334
|
|
- })
|
335
|
|
- ws = null
|
336
|
|
- setTimeout(() => {
|
337
|
|
- if (this.needReload) { // 此变量判断是否需要重连
|
338
|
|
- this.websockets = {}
|
339
|
|
- this.initWebSocket()
|
340
|
|
- }
|
341
|
|
- }, 5000)
|
342
|
|
- }
|
343
|
|
- },
|
344
|
|
- destroyWebsocket (ws) {
|
345
|
|
- ws.onclose = ((ws) => {
|
346
|
|
- // console.log('close')
|
347
|
|
- })(ws)
|
348
|
|
- ws.close()
|
349
|
|
- clearInterval(ws.interval)
|
350
|
|
- ws = null
|
|
284
|
+
|
|
285
|
+ Promise.all(ps).then((its = []) => this.printList.concat(its.filter(x => x)))
|
351
|
286
|
},
|
352
|
287
|
open () {
|
353
|
288
|
if (!this.CaseId) {
|
|
@@ -369,6 +304,7 @@ export default {
|
369
|
304
|
})
|
370
|
305
|
return
|
371
|
306
|
}
|
|
307
|
+ this.ws.close()
|
372
|
308
|
this.closeBusiness(this.CaseId)
|
373
|
309
|
}
|
374
|
310
|
}
|