微信

index.vue 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div class="mainPage">
  3. <div class="content">
  4. <h2>确认下单信息</h2>
  5. <div class="list flex-h">
  6. <div class="flex-item">
  7. <ul>
  8. <li class="flex-h" v-for="(item,index) in orderInfo" :key="index">
  9. <div class="flex-item">
  10. <div><span>{{item.name}}</span></div>
  11. </div>
  12. <div class="flex-item">
  13. <div><span>{{item.specname}}</span></div>
  14. </div>
  15. <div class="flex-item">
  16. <div><span>x{{item.num}}</span></div>
  17. </div>
  18. <div class="flex-item">
  19. <div><span>{{item.price * item.num}}</span></div>
  20. </div>
  21. </li>
  22. <li class="flex-h">
  23. <div class="flex-item">
  24. <div><span>选择商品券</span></div>
  25. </div>
  26. <a class="active" v-if="getCouponOff && couponList.length" @click="showSelectCouponLayer = true">
  27. <span>{{postData.customercouponid === '' ? '有' + couponList.length + '张优惠券可选' : '已选择优惠券'}}</span>
  28. <i class="iconfont icon-jiantou-right"></i>
  29. </a>
  30. </li>
  31. </ul>
  32. </div>
  33. </div>
  34. <h6>添加备注</h6>
  35. <div class="remark flex-h">
  36. <div class="flex-item flex-h">
  37. <div class="flex-h">
  38. <textarea class="flex-item" cols="30" rows="6" v-model="postData.info.Remark"></textarea>
  39. </div>
  40. </div>
  41. </div>
  42. <span>下单人:{{userInfo.customer.CustomerName}} {{userInfo.customer.Phone}}</span>
  43. <div class="bottom">
  44. <a @click="cancel">取消</a>
  45. <a @click="toPayer">确定</a>
  46. <div style="width: 100%;position: absolute;left: 0;bottom: 0;top: 0;" v-if="!ajaxoff"></div>
  47. </div>
  48. </div>
  49. <div class="selectCouponLayer" :class="{'show': showSelectCouponLayer}">
  50. <div class="flex-v">
  51. <div>
  52. <i class="iconfont icon-guanbi" @click="showSelectCouponLayer = false"></i>
  53. </div>
  54. <div class="flex-item">
  55. <div class="flex-h">
  56. <div class="flex-item" style="margin: 0 .2rem;">
  57. <ul>
  58. <li v-for="(item,index) in couponList" :key="index" @click="selectCouponItem(item)" :class="{'active':item.select}">
  59. <i class="iconfont icon-gouxuan"></i>
  60. <discounts :data="item"></discounts>
  61. </li>
  62. </ul>
  63. </div>
  64. </div>
  65. </div>
  66. <a @click="sureSelectCoupon">确定</a>
  67. </div>
  68. </div>
  69. <div class="successPopup" v-if="showSuccessPopup">
  70. <div>
  71. <i class="iconfont icon-gou"></i>
  72. <div class="text">出单成功</div>
  73. <div class="back" @click="popBack">返回等待</div>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { mapState, createNamespacedHelpers } from 'vuex'
  80. const { mapActions: caseTableActions } = createNamespacedHelpers('placeOrderForCoffee')
  81. import discounts from '../../../components/discounts/discounts'
  82. export default {
  83. name: '',
  84. data () {
  85. var _self = this
  86. return {
  87. ajaxoff: true,
  88. showSelectCouponLayer: false,
  89. getCouponOff: false,
  90. couponList: [], // 优惠券列表
  91. showSuccessPopup: false,
  92. postData: {
  93. info: {
  94. CaseId: decodeURI(_self.$route.query.caseid),
  95. AreaId: decodeURI(_self.$route.query.areaid),
  96. AreaName: decodeURI(_self.$route.query.areaname),
  97. TableId: decodeURI(_self.$route.query.tableid),
  98. TableNo: decodeURI(_self.$route.query.tableno),
  99. Amount: 0, // 订单金额
  100. OrdersNum: 0,
  101. Remark: '',
  102. },
  103. detail: [],
  104. customercouponid: ''
  105. },
  106. ticketList: [{
  107. value: '优惠券1',
  108. id: '1',
  109. }, {
  110. value: '优惠券2',
  111. id: '2',
  112. }, {
  113. value: '优惠券3',
  114. id: '3',
  115. }],
  116. orderInfo: JSON.parse(_self.$route.query.info) || []
  117. }
  118. },
  119. components: {
  120. discounts,
  121. },
  122. computed: {
  123. ...mapState({
  124. userInfo: x => x.userCenter.userInfo,
  125. orgId: x => x.app.orgId,
  126. })
  127. },
  128. created () {
  129. this.getCouponList().then((res) => {
  130. // console.log(JSON.stringify(res))
  131. var id = JSON.parse(this.$route.query.info)[0].id, arr = [], nowDate = Date.now()
  132. for (var n = 0; n < res.length; n++) {
  133. res[n].Coupon.Targets = res[n].Coupon.Targets || []
  134. if (res[n].Coupon.CouponType === 'goods' && res[n].Status === 1) {
  135. if (res[n].Coupon.IsAll && nowDate >= new Date(res[n].StartDate).getTime() && nowDate < new Date(res[n].EndDate).getTime() && res[n].CaseId === this.$route.query.caseid) {
  136. this.couponList.push({
  137. title: res[n].Coupon.CouponName,
  138. desc: res[n].Coupon.Share.UseRule,
  139. time: this.toolClass.dateFormat(res[n].EndDate),
  140. useType: '未使用',
  141. tag: '商品',
  142. id: res[n].CustomerCouponId,
  143. select: false,
  144. })
  145. } else {
  146. for (var a = 0; a < res[n].Coupon.Targets.length; a++) {
  147. if (res[n].Coupon.Targets[a].TargetId === id && nowDate >= new Date(res[n].StartDate).getTime() && nowDate < new Date(res[n].EndDate).getTime()) {
  148. this.couponList.push({
  149. title: res[n].Coupon.CouponName,
  150. desc: res[n].Coupon.Share.UseInstruction,
  151. time: this.toolClass.dateFormat(res[n].EndDate),
  152. useType: '未使用',
  153. tag: '商品',
  154. id: res[n].CustomerCouponId,
  155. select: false,
  156. })
  157. }
  158. }
  159. }
  160. }
  161. }
  162. this.getCouponOff = true
  163. // console.log(JSON.stringify(this.couponList))
  164. })
  165. },
  166. methods: {
  167. ...caseTableActions([
  168. 'toPay',
  169. 'getCouponList',
  170. ]),
  171. sureSelectCoupon () {
  172. var bool = false
  173. for (var n = 0; n < this.couponList.length; n++) {
  174. if (this.couponList[n].select) {
  175. bool = true
  176. this.postData.customercouponid = this.couponList[n].id
  177. }
  178. }
  179. if (!bool) {
  180. this.postData.customercouponid = ''
  181. }
  182. this.showSelectCouponLayer = false
  183. },
  184. selectCouponItem (item) { // 选择优惠券
  185. // item.select = !item.select
  186. if (!item.select) {
  187. for (var n = 0; n < this.couponList.length; n++) {
  188. this.couponList[n].select = false
  189. }
  190. item.select = true
  191. } else {
  192. item.select = false
  193. }
  194. },
  195. returnAmount () { // 返回总金额
  196. var amount = 0, num = 0, info = JSON.parse(this.$route.query.info)
  197. for (var n = 0; n < info.length; n++) {
  198. if (info[n].defaultPrice === null) {
  199. amount += info[n].price * info[n].num
  200. num += info[n].num
  201. } else {
  202. amount += info[n].defaultPrice * info[n].defaultNum
  203. num += info[n].defaultNum
  204. }
  205. }
  206. return [amount, num]
  207. },
  208. toPayer () { // 下单
  209. if (this.ajaxoff) {
  210. this.ajaxoff = false
  211. this.postData.info.OrgId = this.orgId
  212. this.postData.info.UserId = this.userInfo.CustomerId
  213. this.postData.info.UserName = this.userInfo.customer.CustomerName
  214. this.postData.info.PayType = this.postData.customercouponid === '' ? 'coupon' : 'vip'
  215. var orderInfo = JSON.parse(this.$route.query.info)
  216. this.postData.detail = []
  217. var amount = 0
  218. var num = 0
  219. for (var n = 0; n < orderInfo.length; n++) {
  220. this.postData.detail.push({
  221. GoodsId: orderInfo[n].id,
  222. GoodsName: orderInfo[n].name,
  223. SpecId: orderInfo[n].spec,
  224. SpecName: orderInfo[n].specname,
  225. Number: orderInfo[n].num - 0,
  226. Price: String(orderInfo[n].price - 0),
  227. })
  228. amount += (orderInfo[n].price - 0) * orderInfo[n].num
  229. num += orderInfo[n].num - 0
  230. }
  231. this.postData.info.Amount = String(amount)
  232. this.postData.info.OrdersNum = num
  233. console.log(JSON.stringify(this.postData))
  234. this.toPay({
  235. info: JSON.stringify(this.postData.info),
  236. detail: JSON.stringify(this.postData.detail),
  237. customercouponid: this.postData.customercouponid
  238. }).then((res) => {
  239. this.showSuccessPopup = true
  240. // this.$dialog.alert({
  241. // message: '下单成功!'
  242. // }).then(() => {
  243. // window.history.go(-2)
  244. // })
  245. }).catch(() => {
  246. this.ajaxoff = true
  247. })
  248. }
  249. },
  250. popBack () {
  251. this.showSuccessPopup = false
  252. // window.history.go(-2)
  253. this.$router.push({name: 'coffeeIndex'})
  254. },
  255. cancel () {
  256. // window.history.go(-1)
  257. this.$router.push({name: 'coffeeIndex'})
  258. },
  259. }
  260. }
  261. </script>
  262. <!-- Add "scoped" attribute to limit CSS to this component only -->
  263. <style lang="scss" scoped>
  264. @import 'page.scss';
  265. </style>