index.vue 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="subPage">
  3. <div class="system-table-search">
  4. <div class="flex-h">
  5. <div class="flex-item flex-h">
  6. <el-button size="mini" v-if="!businessStatus" type="danger" @click="open">营业</el-button>
  7. <el-button size="mini" v-else type="submit" @click="close">歇业</el-button>
  8. </div>
  9. <ul>
  10. <li>
  11. <el-select v-model="caseid" placeholder="请选择案场">
  12. <el-option
  13. v-for="item in cases"
  14. :key="item.CaseId"
  15. :label="item.CaseName"
  16. :value="item.CaseId">
  17. </el-option>
  18. </el-select>
  19. </li>
  20. </ul>
  21. <el-button
  22. size="mini"
  23. type="primary" @click="init">搜索</el-button>
  24. </div>
  25. <div class="moreFilter"></div>
  26. </div>
  27. <div class="order-list-box">
  28. <div style='position:relative;' v-for="(item,index) in list" :key="index">
  29. <div>
  30. <div style="padding:25px 20px 5px;border-bottom:2px solid #cccccc;">
  31. <i class="iconfont icon-yinchenglogo" style="font-size:70px;color:red;position: relative;bottom: 20px;margin-right:10px;"></i>
  32. <div style="display:inline-block;">
  33. <span style="display:block;font-size:20px;font-weight:700;width:180px;white-space: nowrap;">{{item.AreaName + item.TableNo}}</span>
  34. <span style="display:block;margin-top:10px">下单时间:{{toolClass.dateFormat(item.CreateDate)}}</span>
  35. <span style="display:block;margin-top:10px">已等待:<span style="color:red;font-weight:700;">{{leftTimes[item.OrdersId]}}</span></span>
  36. </div>
  37. </div>
  38. <div style="padding:10px 20px 5px;border-bottom:1px solid #cccccc;" v-for='(item1,index1) in item.Goods' :key='index1'>
  39. <div style="display:flex;justify-content: space-between;align-items: center;padding-right: 10px;"><span>{{item1.GoodsName}}</span><span style="display:inline-block;width:20%;text-align:right" v-if='!item1.SpecName'>× {{item1.Number}}</span></div>
  40. <div style="margin-top:8px;" v-if='item1.SpecName'>
  41. <span style="display:inline-block;width:75%;text-align:left;color:#cccccc">{{item1.SpecName}}</span>
  42. <span style="display:inline-block;width:20%;text-align:right">× {{item1.Number}}</span>
  43. </div>
  44. </div>
  45. <!-- <div style="padding:10px 20px;border-bottom:1px solid #cccccc">备注:{{item.Remark}}</div> -->
  46. <div style="padding:10px 20px;" @click="printPdf(`item${index}`)">下单人:{{item.UserName}}</div>
  47. </div>
  48. <div class="print-area" :class="'item_' + item.OrdersId" style="width:180px;">
  49. <div style="padding:0px 10px 5px;border-bottom:2px solid #cccccc;">
  50. <div style="display:inline-block;">
  51. <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="">
  52. <span style="display:block;font-size:20px;font-weight:700;text-align: center;"> <img width='25px' height="25px" :src='item.AreaIconWhite' alt=""> {{item.AreaName}}</span>
  53. </div>
  54. </div>
  55. <div style="padding:10px 10px 5px;border-bottom:1px solid #cccccc;" v-for='(item1,index1) in item.Goods' :key='index1'>
  56. <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>
  57. <div style="margin-top:8px;" v-if='item1.SpecName'>
  58. <span style="display:inline-block;width:75%;text-align:left;color:#cccccc;font-size:12px;">{{item1.SpecName}}</span>
  59. <span style="display:inline-block;width:20%;text-align:right;font-size:12px;">× {{item1.Number}}</span>
  60. </div>
  61. </div>
  62. <div style="padding:10px 10px 5px;border-bottom:1px solid #cccccc;">
  63. <div style="font-size:12px;">下单人:{{item.UserName}}</div>
  64. <span style="display:block;margin-top:10px;font-size:12px;">下单时间:{{toolClass.dateFormat(item.CreateDate)}}</span>
  65. </div>
  66. <div style="padding:10px 10px;font-size:12px;"></div>
  67. <div style="text-align: right;font-size: 12px;">城的空间.诚咖啡</div>
  68. <div style="height:10px"></div>
  69. </div>
  70. <div class="btns">
  71. <span @click="cancel(item.OrdersId)">取消</span>
  72. <span @click="submit(item.OrdersId)">确定</span>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { createNamespacedHelpers, mapState, mapActions } from 'vuex'
  80. import { getLodop } from '@/util/LodopFuncs'
  81. import { formatTimeBySeconds } from '@/util/util'
  82. const { mapState: mapOrderState, mapActions: mapOrderActions } = createNamespacedHelpers('goodsorder')
  83. var LODOP
  84. export default {
  85. name: '',
  86. data () {
  87. return {
  88. total: 0,
  89. postData: { // 表格搜索条件
  90. phone: '', // 手机号
  91. page: 1, // 当前页码
  92. pagesize: 10, // 请求数据量
  93. },
  94. currentList: [],
  95. leftTimes: {},
  96. business: false,
  97. caseid: '',
  98. interval: () => { }
  99. }
  100. },
  101. computed: {
  102. ...mapOrderState({
  103. list: x => (x.ordersList || {}).list || [],
  104. businessStatus: x => x.businessStatus
  105. }),
  106. ...mapState({
  107. cases: x => x.app.cases.list,
  108. defaultCaseId: x => x.app.cases.default,
  109. userInfo: x => x.app.user
  110. }),
  111. CaseId: {
  112. get () {
  113. return this.caseid || this.defaultCaseId
  114. },
  115. set (val) {
  116. this.caseid = val
  117. }
  118. }
  119. },
  120. created () {
  121. this.updateSystemInfo().then(() => {
  122. if (this.caseid) {
  123. this.init()
  124. }
  125. })
  126. },
  127. methods: {
  128. init () {
  129. if (!this.caseid) {
  130. this.$message({
  131. type: 'info',
  132. message: '请先选择案场'
  133. })
  134. return
  135. }
  136. clearInterval(this.interval)
  137. this.GetOrdersList({ caseid: this.caseid }).then(() => {
  138. this.getBusinessStatus(this.caseid).then(() => {
  139. if (this.businessStatus) {
  140. this.initWebSocket()
  141. }
  142. })
  143. })
  144. this.refreshList()
  145. },
  146. refreshList () {
  147. this.interval = setInterval(() => {
  148. const now = (new Date()).valueOf()
  149. this.leftTimes = this.list.reduce((acc, it) => {
  150. const showDT = now - ((new Date(it.CreateDate)).valueOf())
  151. return { ...acc, [`${it.OrdersId}`]: formatTimeBySeconds(showDT) }
  152. }, {})
  153. }, 1000)
  154. },
  155. timeOut (c) {
  156. let cTime = new Date(c).valueOf()
  157. let time = new Date().valueOf()
  158. let s = parseInt((time - cTime) / 1000)
  159. let m = parseInt(s / 60)
  160. s = s - m * 60
  161. m = m < 10 ? '0' + m : m
  162. s = s < 10 ? '0' + s : s
  163. return `${m} : ${s}`
  164. },
  165. ...mapOrderActions([
  166. 'GetOrdersList',
  167. 'openBusiness',
  168. 'closeBusiness',
  169. 'checkOrder',
  170. 'cancelOrder',
  171. 'getBusinessStatus',
  172. 'updateList'
  173. ]),
  174. ...mapActions([
  175. 'updateSystemInfo'
  176. ]),
  177. submit (id) {
  178. this.$confirm('确定完成此饮品?', '提示', {
  179. confirmButtonText: '确定',
  180. cancelButtonText: '取消',
  181. type: 'warning'
  182. }).then((res) => {
  183. this.checkOrder({ id: id }).then(() => {
  184. this.$message({
  185. type: 'success',
  186. message: '确认订单成功'
  187. })
  188. this.init()
  189. })
  190. }).catch((res) => {
  191. this.$message({
  192. type: 'info',
  193. message: '已取消操作'
  194. })
  195. })
  196. },
  197. cancel (id) {
  198. this.$confirm('确定取消此饮品?', '提示', {
  199. confirmButtonText: '确定',
  200. cancelButtonText: '取消',
  201. type: 'warning'
  202. }).then((res) => {
  203. this.cancelOrder({ id: id }).then(() => {
  204. this.$message({
  205. type: 'success',
  206. message: '取消订单成功'
  207. })
  208. this.init()
  209. })
  210. }).catch((res) => {
  211. this.$message({
  212. type: 'info',
  213. message: '已取消操作'
  214. })
  215. })
  216. },
  217. printPdf (cl) {
  218. this.CreateOneFormPage(cl)
  219. LODOP.PRINT()
  220. // LODOP.PREVIEW()
  221. },
  222. CreateOneFormPage (cl) {
  223. LODOP = getLodop()
  224. LODOP.PRINT_INIT('订单')
  225. LODOP.SET_PRINT_PAGESIZE(3, 480, 40, '')
  226. LODOP.ADD_PRINT_HTM(0, 0, document.getElementsByClassName(cl)[0].offsetWidth, document.getElementsByClassName(cl)[0].offsetHeight, document.getElementsByClassName(cl)[0].innerHTML)
  227. },
  228. initWebSocket () {
  229. console.log(this.user)
  230. let caseid = this.caseid
  231. let id = this.userInfo.UserId
  232. const wsuri = `${window.location.origin.replace('http', 'ws')}/api-v2/common/MQ/websocket/${caseid}/${id}?token=${localStorage.getItem('JWT')}`
  233. // const wsuri = `ws://192.168.0.11/api/guest/MQ/websocket/${caseid}/${id}`
  234. try {
  235. this.websock = new WebSocket(wsuri)
  236. } catch (e) {
  237. console.log(e)
  238. }
  239. this.websock.onopen = console.log
  240. this.websock.onmessage = this.websocketonmessage
  241. this.websock.onclose = console.log
  242. },
  243. websocketonmessage (e) {
  244. const oldList = this.list
  245. const newList = JSON.parse(e.data).data.refreshOnlineGoodsOrders
  246. let newinfo = newList.filter(x => oldList.filter(item => item.OrdersId === x.OrdersId).length === 0)
  247. this.updateList({list: newList}).then(() => {
  248. for (let i = 0; i < newinfo.length; i++) {
  249. this.printPdf(`item_${newinfo[i].OrdersId}`)
  250. }
  251. })
  252. },
  253. open () {
  254. if (!this.caseid) {
  255. this.$message({
  256. type: 'info',
  257. message: '请先选择案场'
  258. })
  259. return
  260. }
  261. this.openBusiness(this.caseid).then(() => {
  262. this.init()
  263. })
  264. },
  265. close () {
  266. if (!this.caseid) {
  267. this.$message({
  268. type: 'info',
  269. message: '请先选择案场'
  270. })
  271. return
  272. }
  273. this.closeBusiness(this.caseid)
  274. }
  275. }
  276. }
  277. </script>
  278. <!-- Add "scoped" attribute to limit CSS to this component only -->
  279. <style lang="scss" scoped>
  280. @import "page.scss";
  281. </style>