微信

index.vue 13KB

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