微信

index.vue 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <div class="mainPage flex-v">
  3. <div class="flex-item flex-v">
  4. <div class="banner">
  5. <img :src="banner" class="centerLabel cover" alt="">
  6. <div class="bannerInfo flex-h">
  7. <div class="flex-item">
  8. <div>
  9. <span>项目名称:{{caseName}}</span>
  10. </div>
  11. </div>
  12. <span>{{userInfo.customer.RealName ? userInfo.customer.RealName : userInfo.customer.Name}}您好!</span>
  13. </div>
  14. </div>
  15. <div class="tableInfo flex-h">
  16. <div class="flex-item">
  17. <div>
  18. <span>桌号:{{tableNo}}</span>
  19. <span v-if="userInfo.customer.MapUser !== '' && fromPage === 'sales'">本月已用:{{caseTotal.monthtotal}}杯</span>
  20. </div>
  21. </div>
  22. <a @click="reback">返回选择桌号</a>
  23. </div>
  24. <div class="content flex-item flex-h">
  25. <div class="slideMenus">
  26. <div>
  27. <ul>
  28. <li v-for="(item,index) in menuList" :key="index" :class="{'active': slideMenusActive == index}" @click="cutMenu(index)">
  29. <span>{{item.value}}</span>
  30. <span>{{item.eValue}}</span>
  31. </li>
  32. </ul>
  33. </div>
  34. </div>
  35. <div class="flex-item">
  36. <div>
  37. <swiper :options="swiperOption" ref="mySwiper">
  38. <swiper-slide class="swiper-slide" v-for="(item,index) in menuList" :key="index">
  39. <div class="flex-v">
  40. <h4>{{item.value + ' ' + item.eValue}}</h4>
  41. <div class="flex-item">
  42. <div>
  43. <swiper :options="subSwiperOption" ref="mySubSwiper">
  44. <swiper-slide class="swiper-slide" v-for="(subItem,subIndex) in item.list" :key="subIndex">
  45. <orderItem :data="subItem" @returnData="calcMenus" @selectSpec="selectSpec"></orderItem>
  46. </swiper-slide>
  47. </swiper>
  48. </div>
  49. </div>
  50. </div>
  51. </swiper-slide>
  52. </swiper>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="flex-h">
  58. <div class="flex-item">
  59. <div>
  60. <span>总计</span>
  61. <span>{{sumNum}}</span>
  62. <span>杯</span>
  63. <span>共</span>
  64. <span>{{sumPrice}}</span>
  65. <span>元</span>
  66. <!-- <i class="iconfont" :class="{'icon-jiantou-up': !showCalcMenu,'icon-jiantou-down': showCalcMenu}" @click="showCalcMenu = true"></i> -->
  67. </div>
  68. </div>
  69. <a @click="toPlaceOrder">下单</a>
  70. </div>
  71. <orderPopup :show="showPopup" :data="currentSpec" @closePopup="closePopup" @returnData="calcMenus"></orderPopup>
  72. <calcMenu :show="showCalcMenu" :totalNum="sumNum + caseTotal.total" :data="selGoods" @returnData="calcMenus" @emptyMenus="emptyMenus" @closeCalcMenu="closeCalcMenu" @placeOrder="placeOrder"></calcMenu>
  73. <div class="successPopup" v-if="showSuccessPopup">
  74. <div>
  75. <i class="iconfont icon-gou"></i>
  76. <div class="text">出单成功</div>
  77. <div class="back" @click="popBack">返回等待</div>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import { mapState, createNamespacedHelpers } from 'vuex'
  84. const { mapActions: caseTableActions } = createNamespacedHelpers('placeOrderForCoffee')
  85. const { mapState: mapCaseState, mapActions: mapCaseActions } = createNamespacedHelpers('case')
  86. import orderItem from '../../../components/orderItem/index'
  87. import orderPopup from '../../../components/orderPopup/index'
  88. import calcMenu from '../../../components/calcMenu/index'
  89. import { swiper, swiperSlide } from 'vue-awesome-swiper'
  90. import 'swiper/dist/css/swiper.css'
  91. export default {
  92. name: '',
  93. data () {
  94. const _self = this
  95. return {
  96. ajaxOff: true,
  97. postData: {
  98. info: {
  99. CaseId: decodeURI(_self.$route.query.caseid),
  100. AreaId: decodeURI(_self.$route.query.areaid),
  101. AreaName: decodeURI(_self.$route.query.areaname),
  102. TableId: decodeURI(_self.$route.query.tableid),
  103. TableNo: decodeURI(_self.$route.query.tableno),
  104. Amount: 0, // 订单金额
  105. OrdersNum: 0,
  106. Remark: '',
  107. },
  108. detail: [],
  109. coupon: [],
  110. },
  111. tableNo: decodeURI(this.$route.query.tableno),
  112. tableId: decodeURI(this.$route.query.tableid),
  113. areaId: decodeURI(this.$route.query.areaid),
  114. areaName: decodeURI(this.$route.query.areaname),
  115. caseName: decodeURI(this.$route.query.casename),
  116. caseId: decodeURI(this.$route.query.caseid),
  117. totalCupNum: 0, // 共计使用杯数
  118. showCalcMenu: false, // 显隐已点菜单弹窗
  119. currentSpec: null, // 当前选择规格
  120. showPopup: false, // 显隐选规格弹窗
  121. totalNum: 0, // 总杯数
  122. totalPrice: 0, // 总价格
  123. settlementList: [], // 商品选择清单
  124. slideMenusActive: 0, // 左侧菜单选中索引值
  125. menuList: [],
  126. banner: 'https://jingcheng-h5temp.oss-cn-shanghai.aliyuncs.com/spaceofchengGoodsbanner.png',
  127. swiperOption: {
  128. observer: true,
  129. direction: 'vertical',
  130. on: {
  131. transitionEnd () {
  132. _self.slideMenusActive = this.activeIndex
  133. },
  134. }
  135. },
  136. subSwiperOption: {
  137. observer: true,
  138. direction: 'vertical',
  139. nested: true,
  140. slidesPerView: 'auto',
  141. freeMode: true,
  142. freeModeMomentumVelocityRatio: 2,
  143. },
  144. selGoods: [],
  145. showSuccessPopup: false
  146. }
  147. },
  148. computed: {
  149. ...mapState({
  150. userInfo: x => x.userCenter.userInfo,
  151. goodsTypeList: x => x.placeOrderForCoffee.goodsTypeList,
  152. goodsList: x => x.placeOrderForCoffee.goodsList
  153. }),
  154. ...mapCaseState({
  155. caseTotal: x => x.caseTotal,
  156. }),
  157. MySwiper () {
  158. return this.$refs.mySwiper.swiper
  159. },
  160. MySubSwiper () {
  161. return this.$refs.mySubSwiper.swiper
  162. },
  163. sumNum () {
  164. let num = 0
  165. this.selGoods.map(x => {
  166. num += x.num
  167. })
  168. return num
  169. },
  170. sumPrice () {
  171. let price = 0
  172. this.selGoods.map(x => {
  173. price += x.price * x.num - 0
  174. })
  175. return Math.ceil((price) * 100) / 100
  176. }
  177. },
  178. components: {
  179. swiper,
  180. swiperSlide,
  181. orderItem,
  182. orderPopup,
  183. calcMenu,
  184. },
  185. created () {
  186. this.fromPage = sessionStorage.getItem('from')
  187. this.getGoodsTypeList({
  188. caseid: this.caseId,
  189. }).then((res) => {
  190. // console.log(JSON.stringify(res))
  191. this.getGoodsList({
  192. caseid: this.caseId,
  193. }).then((res) => {
  194. // console.log(JSON.stringify(res))
  195. this.mapArr()
  196. })
  197. if (this.userInfo.customer.MapUser !== '') {
  198. this.getCaseTotal({
  199. caseid: this.caseId
  200. })
  201. }
  202. })
  203. },
  204. methods: {
  205. ...caseTableActions([
  206. 'getGoodsTypeList',
  207. 'getGoodsList',
  208. 'toPayBefore',
  209. 'toPay',
  210. ]),
  211. ...mapCaseActions([
  212. 'getCaseTotal',
  213. ]),
  214. toPlaceOrder () { // 下单
  215. if (this.selGoods.length) {
  216. if (this.userInfo.customer.MapUser === '' || (this.userInfo.customer.MapUser !== '' && sessionStorage.getItem('from') !== 'sales')) {
  217. if (this.ajaxOff) {
  218. this.ajaxOff = false
  219. this.postData.info.OrgId = this.orgId
  220. this.postData.info.UserId = this.userInfo.CustomerId
  221. this.postData.info.UserName = this.userInfo.customer.CustomerName
  222. this.postData.info.PayType = 'sys user'
  223. this.postData.info.Remark = ''
  224. this.postData.from = sessionStorage.getItem('from') ? sessionStorage.getItem('from') : ''
  225. var orderInfo = this.selGoods
  226. this.postData.detail = []
  227. var amount = 0
  228. var num = 0
  229. for (var n = 0; n < orderInfo.length; n++) {
  230. this.postData.detail.push({
  231. GoodsId: orderInfo[n].id,
  232. GoodsName: orderInfo[n].name,
  233. SpecId: orderInfo[n].spec,
  234. SpecName: orderInfo[n].specname,
  235. Number: orderInfo[n].num - 0,
  236. Price: String(orderInfo[n].price - 0),
  237. })
  238. amount += (orderInfo[n].price - 0) * orderInfo[n].num
  239. num += orderInfo[n].num - 0
  240. }
  241. this.postData.info.Amount = String(amount)
  242. this.postData.info.OrdersNum = num
  243. // console.log(JSON.stringify(this.postData))
  244. this.toPayBefore({
  245. info: JSON.stringify(this.postData.info),
  246. detail: JSON.stringify(this.postData.detail),
  247. customercouponid: '',
  248. from: this.postData.from
  249. }).then((res) => {
  250. // console.log(JSON.stringify(res))
  251. this.ajaxOff = true
  252. this.$router.push({ name: 'placeOrderDetail', query: { info: JSON.stringify(this.selGoods), caseid: encodeURI(this.caseId), areaid: encodeURI(this.areaId), areaname: encodeURI(this.areaName), areaid: encodeURI(this.areaId), tableid: encodeURI(this.tableId), tableno: encodeURI(this.tableNo), ordersid: res.OrdersId } })
  253. }).catch(() => {
  254. this.ajaxOff = true
  255. })
  256. }
  257. } else {
  258. this.showCalcMenu = true
  259. }
  260. } else {
  261. this.$toast('您还没有选择商品哦~')
  262. }
  263. },
  264. mapArr () { // 匹配商品规格
  265. var aArr = (this.goodsTypeList || []), bArr = (this.goodsList || [])
  266. for (var n = 0; n < aArr.length; n++) {
  267. aArr[n].list = []
  268. for (var a = 0; a < bArr.length; a++) {
  269. if (aArr[n].TypeId === bArr[a].TypeId) {
  270. aArr[n].list.push(bArr[a])
  271. }
  272. }
  273. }
  274. this.menuList = []
  275. for (var x = 0; x < aArr.length; x++) {
  276. this.menuList.push({
  277. value: aArr[x].TypeName,
  278. eValue: aArr[x].EnglishName,
  279. id: aArr[x].TypeId,
  280. status: aArr[x].Status,
  281. list: []
  282. })
  283. for (var y = 0; y < aArr[x].list.length; y++) {
  284. this.menuList[x].list.push({
  285. img: aArr[x].list[y].Images,
  286. name: aArr[x].list[y].GoodsName,
  287. id: aArr[x].list[y].GoodsId,
  288. spec: [],
  289. status: aArr[x].list[y].Status,
  290. price: aArr[x].list[y].Price,
  291. num: 0,
  292. })
  293. if (aArr[x].list[y].Specs !== null) {
  294. for (var z = 0; z < aArr[x].list[y].Specs.length; z++) {
  295. this.menuList[x].list[y].spec.push({
  296. value: aArr[x].list[y].Specs[z].SpecName,
  297. id: aArr[x].list[y].Specs[z].SpecId,
  298. num: 0,
  299. status: aArr[x].list[y].Specs[z].Status,
  300. price: aArr[x].list[y].Specs[z].GoodsPrice,
  301. })
  302. }
  303. }
  304. }
  305. }
  306. },
  307. reback () { // 返回桌位选择
  308. this.$dialog.confirm({
  309. message: '返回页面将清空当前选择的商品,确定要返回吗?'
  310. }).then(() => {
  311. // this.$router.push({ name: 'coffeeIndex' })
  312. // window.history.go(-1)
  313. this.$router.go(-1)
  314. })
  315. },
  316. placeOrder (Remark) { // 下单
  317. if (this.ajaxOff) {
  318. this.ajaxOff = false
  319. this.postData.info.OrgId = this.orgId
  320. this.postData.info.UserId = this.userInfo.CustomerId
  321. this.postData.info.UserName = this.userInfo.customer.CustomerName
  322. this.postData.info.PayType = 'sys user'
  323. this.postData.info.Remark = Remark
  324. this.postData.from = sessionStorage.getItem('from') ? sessionStorage.getItem('from') : ''
  325. var orderInfo = this.selGoods
  326. this.postData.detail = []
  327. var amount = 0
  328. var num = 0
  329. for (var n = 0; n < orderInfo.length; n++) {
  330. this.postData.detail.push({
  331. GoodsId: orderInfo[n].id,
  332. GoodsName: orderInfo[n].name,
  333. SpecId: orderInfo[n].spec,
  334. SpecName: orderInfo[n].specname,
  335. Number: orderInfo[n].num - 0,
  336. Price: String(orderInfo[n].price - 0),
  337. })
  338. amount += (orderInfo[n].price - 0) * orderInfo[n].num
  339. num += orderInfo[n].num - 0
  340. }
  341. this.postData.info.Amount = String(amount)
  342. this.postData.info.OrdersNum = num
  343. // console.log(JSON.stringify(this.postData))
  344. this.toPay({
  345. info: JSON.stringify(this.postData.info),
  346. detail: JSON.stringify(this.postData.detail),
  347. customercouponid: '',
  348. from: this.postData.from
  349. }).then((res) => {
  350. this.ajaxOff = true
  351. this.showCalcMenu = false
  352. this.showSuccessPopup = true
  353. // this.$dialog.alert({
  354. // message: '下单成功!',
  355. // confirmButtonText: '返回等待'
  356. // }).then(() => {
  357. // })
  358. }).catch(() => {
  359. this.ajaxOff = true
  360. })
  361. }
  362. },
  363. popBack () {
  364. this.showSuccessPopup = false
  365. this.$router.push({ name: 'orderList' })
  366. },
  367. closeCalcMenu () { // 关闭已选菜单
  368. this.showCalcMenu = false
  369. },
  370. emptyMenus () { // 清空菜单
  371. this.settlementList = []
  372. },
  373. closePopup () { // 关闭规格弹窗
  374. this.showPopup = false
  375. this.currentSpec = null
  376. },
  377. selectSpec (val) { // 选规格
  378. this.currentSpec = val
  379. this.showPopup = true
  380. },
  381. cutMenu (index) { // 切换菜单
  382. this.MySwiper.slideTo(index, 300)
  383. },
  384. calcMenus (val) { // 计算清单
  385. var ishas = false
  386. const _that = this
  387. this.selGoods.map((goods, inx) => {
  388. if (goods.id === val.id && goods.spec === (val.spec || '')) {
  389. ishas = true
  390. _that.selGoods[inx].num = val.defaultNum
  391. }
  392. })
  393. if (!ishas) {
  394. this.selGoods.push({
  395. id: val.id,
  396. price: val.defaultPrice,
  397. num: val.defaultNum,
  398. name: val.name,
  399. spec: (val.spec || ''),
  400. specname: (val.specname || ''),
  401. })
  402. } else {
  403. if (val.defaultNum === 0) {
  404. this.selGoods.splice(this.selGoods.findIndex(item => item.id === val.id && item.spec === (val.spec || '')), 1)
  405. }
  406. }
  407. },
  408. calcTotalNum () { // 计算总数量、价格
  409. var num = 0, price = 0
  410. if (!this.settlementList.length) {
  411. this.totalNum = 0
  412. this.totalPrice = 0
  413. return
  414. }
  415. for (var n = 0; n < this.settlementList.length; n++) {
  416. if (this.settlementList[n].specId === null) {
  417. num += this.settlementList[n].defaultNum
  418. price += this.settlementList[n].defaultPrice * this.settlementList[n].defaultNum
  419. } else {
  420. num += this.settlementList[n].num
  421. price += this.settlementList[n].price * this.settlementList[n].num
  422. }
  423. }
  424. this.totalNum = num
  425. this.totalPrice = price
  426. },
  427. }
  428. }
  429. </script>
  430. <!-- Add "scoped" attribute to limit CSS to this component only -->
  431. <style lang="scss" scoped>
  432. @import 'page.scss';
  433. </style>