微信

index.vue 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 !== ''">本月已用:{{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.getGoodsTypeList({
  187. caseid: this.caseId,
  188. }).then((res) => {
  189. // console.log(JSON.stringify(res))
  190. this.getGoodsList({
  191. caseid: this.caseId,
  192. }).then((res) => {
  193. // console.log(JSON.stringify(res))
  194. this.mapArr()
  195. })
  196. if (this.userInfo.customer.MapUser !== '') {
  197. this.getCaseTotal({
  198. caseid: this.caseId
  199. })
  200. }
  201. })
  202. },
  203. methods: {
  204. ...caseTableActions([
  205. 'getGoodsTypeList',
  206. 'getGoodsList',
  207. 'toPay',
  208. ]),
  209. ...mapCaseActions([
  210. 'getCaseTotal',
  211. ]),
  212. toPlaceOrder () { // 下单
  213. if (this.selGoods.length) {
  214. if (this.userInfo.customer.MapUser === '') {
  215. 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) } })
  216. } else {
  217. this.showCalcMenu = true
  218. }
  219. } else {
  220. this.$toast('您还没有选择商品哦~')
  221. }
  222. },
  223. mapArr () { // 匹配商品规格
  224. var aArr = (this.goodsTypeList || []), bArr = (this.goodsList || [])
  225. for (var n = 0; n < aArr.length; n++) {
  226. aArr[n].list = []
  227. for (var a = 0; a < bArr.length; a++) {
  228. if (aArr[n].TypeId === bArr[a].TypeId) {
  229. aArr[n].list.push(bArr[a])
  230. }
  231. }
  232. }
  233. this.menuList = []
  234. for (var x = 0; x < aArr.length; x++) {
  235. this.menuList.push({
  236. value: aArr[x].TypeName,
  237. eValue: aArr[x].EnglishName,
  238. id: aArr[x].TypeId,
  239. status: aArr[x].Status,
  240. list: []
  241. })
  242. for (var y = 0; y < aArr[x].list.length; y++) {
  243. this.menuList[x].list.push({
  244. img: aArr[x].list[y].Images,
  245. name: aArr[x].list[y].GoodsName,
  246. id: aArr[x].list[y].GoodsId,
  247. spec: [],
  248. status: aArr[x].list[y].Status,
  249. price: aArr[x].list[y].Price,
  250. num: 0,
  251. })
  252. if (aArr[x].list[y].Specs !== null) {
  253. for (var z = 0; z < aArr[x].list[y].Specs.length; z++) {
  254. this.menuList[x].list[y].spec.push({
  255. value: aArr[x].list[y].Specs[z].SpecName,
  256. id: aArr[x].list[y].Specs[z].SpecId,
  257. num: 0,
  258. status: aArr[x].list[y].Specs[z].Status,
  259. price: aArr[x].list[y].Specs[z].GoodsPrice,
  260. })
  261. }
  262. }
  263. }
  264. }
  265. },
  266. reback () { // 返回桌位选择
  267. this.$dialog.confirm({
  268. message: '返回页面将清空当前选择的商品,确定要返回吗?'
  269. }).then(() => {
  270. // this.$router.push({ name: 'coffeeIndex' })
  271. // window.history.go(-1)
  272. this.$router.go(-1)
  273. })
  274. },
  275. placeOrder (Remark) { // 下单
  276. if (this.ajaxOff) {
  277. this.ajaxOff = false
  278. this.postData.info.OrgId = this.orgId
  279. this.postData.info.UserId = this.userInfo.CustomerId
  280. this.postData.info.UserName = this.userInfo.customer.CustomerName
  281. this.postData.info.PayType = 'sys user'
  282. this.postData.info.Remark = Remark
  283. this.postData.from = sessionStorage.getItem('from') ? sessionStorage.getItem('from') : ''
  284. var orderInfo = this.selGoods
  285. this.postData.detail = []
  286. var amount = 0
  287. var num = 0
  288. for (var n = 0; n < orderInfo.length; n++) {
  289. this.postData.detail.push({
  290. GoodsId: orderInfo[n].id,
  291. GoodsName: orderInfo[n].name,
  292. SpecId: orderInfo[n].spec,
  293. SpecName: orderInfo[n].specname,
  294. Number: orderInfo[n].num - 0,
  295. Price: String(orderInfo[n].price - 0),
  296. })
  297. amount += (orderInfo[n].price - 0) * orderInfo[n].num
  298. num += orderInfo[n].num - 0
  299. }
  300. this.postData.info.Amount = String(amount)
  301. this.postData.info.OrdersNum = num
  302. // console.log(JSON.stringify(this.postData))
  303. this.toPay({
  304. info: JSON.stringify(this.postData.info),
  305. detail: JSON.stringify(this.postData.detail),
  306. customercouponid: JSON.stringify(this.postData.coupon) || '',
  307. from: this.postData.from
  308. }).then((res) => {
  309. this.ajaxOff = true
  310. this.showCalcMenu = false
  311. this.showSuccessPopup = true
  312. // this.$dialog.alert({
  313. // message: '下单成功!',
  314. // confirmButtonText: '返回等待'
  315. // }).then(() => {
  316. // })
  317. })
  318. }
  319. },
  320. popBack () {
  321. this.showSuccessPopup = false
  322. this.$router.push({ name: 'orderList' })
  323. },
  324. closeCalcMenu () { // 关闭已选菜单
  325. this.showCalcMenu = false
  326. },
  327. emptyMenus () { // 清空菜单
  328. this.settlementList = []
  329. },
  330. closePopup () { // 关闭规格弹窗
  331. this.showPopup = false
  332. this.currentSpec = null
  333. },
  334. selectSpec (val) { // 选规格
  335. this.currentSpec = val
  336. this.showPopup = true
  337. },
  338. cutMenu (index) { // 切换菜单
  339. this.MySwiper.slideTo(index, 300)
  340. },
  341. calcMenus (val) { // 计算清单
  342. var ishas = false
  343. const _that = this
  344. this.selGoods.map((goods, inx) => {
  345. if (goods.id === val.id && goods.spec === (val.spec || '')) {
  346. ishas = true
  347. _that.selGoods[inx].num = val.defaultNum
  348. }
  349. })
  350. if (!ishas) {
  351. this.selGoods.push({
  352. id: val.id,
  353. price: val.defaultPrice,
  354. num: val.defaultNum,
  355. name: val.name,
  356. spec: (val.spec || ''),
  357. specname: (val.specname || ''),
  358. })
  359. } else {
  360. if (val.defaultNum === 0) {
  361. this.selGoods.splice(this.selGoods.findIndex(item => item.id === val.id && item.spec === (val.spec || '')), 1)
  362. }
  363. }
  364. },
  365. calcTotalNum () { // 计算总数量、价格
  366. var num = 0, price = 0
  367. if (!this.settlementList.length) {
  368. this.totalNum = 0
  369. this.totalPrice = 0
  370. return
  371. }
  372. for (var n = 0; n < this.settlementList.length; n++) {
  373. if (this.settlementList[n].specId === null) {
  374. num += this.settlementList[n].defaultNum
  375. price += this.settlementList[n].defaultPrice * this.settlementList[n].defaultNum
  376. } else {
  377. num += this.settlementList[n].num
  378. price += this.settlementList[n].price * this.settlementList[n].num
  379. }
  380. }
  381. this.totalNum = num
  382. this.totalPrice = price
  383. },
  384. }
  385. }
  386. </script>
  387. <!-- Add "scoped" attribute to limit CSS to this component only -->
  388. <style lang="scss" scoped>
  389. @import 'page.scss';
  390. </style>
  391. <style>
  392. .van-dialog__message {
  393. text-align: center;
  394. }
  395. </style>