微信

index.vue 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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="10" 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>
  47. </div>
  48. <div class="selectCouponLayer" :class="{'show': showSelectCouponLayer}">
  49. <div class="flex-v">
  50. <div>
  51. <i class="iconfont icon-guanbi" @click="showSelectCouponLayer = false"></i>
  52. </div>
  53. <div class="flex-item">
  54. <div class="flex-h">
  55. <div class="flex-item" style="margin: 0 .2rem;">
  56. <ul>
  57. <li v-for="(item,index) in couponList" :key="index" @click="selectCouponItem(item)" :class="{'active':item.select}">
  58. <i class="iconfont icon-gouxuan"></i>
  59. <discounts :data="item"></discounts>
  60. </li>
  61. </ul>
  62. </div>
  63. </div>
  64. </div>
  65. <a @click="sureSelectCoupon">确定</a>
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. import { mapState, createNamespacedHelpers } from 'vuex'
  72. const { mapActions: caseTableActions } = createNamespacedHelpers('placeOrderForCoffee')
  73. import discounts from '../../../components/discounts/discounts'
  74. export default {
  75. name: '',
  76. data () {
  77. var _self = this
  78. return {
  79. showSelectCouponLayer: false,
  80. getCouponOff: false,
  81. couponList: [], // 优惠券列表
  82. postData: {
  83. info: {
  84. CaseId: decodeURI(_self.$route.query.caseid),
  85. AreaId: decodeURI(_self.$route.query.areaid),
  86. AreaName: decodeURI(_self.$route.query.areaname),
  87. TableId: decodeURI(_self.$route.query.tableid),
  88. TableNo: decodeURI(_self.$route.query.tableno),
  89. Amount: 0, // 订单金额
  90. OrdersNum: 0,
  91. Remark: '',
  92. },
  93. detail: [],
  94. customercouponid: ''
  95. },
  96. ticketList: [{
  97. value: '优惠券1',
  98. id: '1',
  99. }, {
  100. value: '优惠券2',
  101. id: '2',
  102. }, {
  103. value: '优惠券3',
  104. id: '3',
  105. }],
  106. orderInfo: JSON.parse(_self.$route.query.info) || []
  107. }
  108. },
  109. components: {
  110. discounts,
  111. },
  112. computed: {
  113. ...mapState({
  114. userInfo: x => x.userCenter.userInfo,
  115. orgId: x => x.app.orgId,
  116. })
  117. },
  118. created () {
  119. console.log(this.$route.query)
  120. this.getCouponList().then((res) => {
  121. // console.log(JSON.stringify(res))
  122. var id = JSON.parse(this.$route.query.info)[0].id, arr = [], nowDate = Date.now()
  123. for (var n = 0; n < res.length; n++) {
  124. if (res[n].Coupon.CouponType === 'goods' && res[n].Status === 1) {
  125. if (res[n].Coupon.IsAll) {
  126. this.couponList.push({
  127. title: res[n].Coupon.CouponName,
  128. desc: res[n].Coupon.Share.UseInstruction,
  129. time: this.toolClass.dateFormat(res[n].EndDate),
  130. useType: '未使用',
  131. tag: '商品',
  132. id: res[n].CustomerCouponId,
  133. select: false,
  134. })
  135. } else {
  136. for (var a = 0; a < res[n].Coupon.Targets.length; a++) {
  137. if (res[n].Coupon.Targets[a].TargetId === id && nowDate >= new Date(res[n].StartDate).getTime() && nowDate < new Date(res[n].EndDate).getTime()) {
  138. this.couponList.push({
  139. title: res[n].Coupon.CouponName,
  140. desc: res[n].Coupon.Share.UseInstruction,
  141. time: this.toolClass.dateFormat(res[n].EndDate),
  142. useType: '未使用',
  143. tag: '商品',
  144. id: res[n].CustomerCouponId,
  145. select: false,
  146. })
  147. }
  148. }
  149. }
  150. }
  151. }
  152. this.getCouponOff = true
  153. // console.log(JSON.stringify(this.couponList))
  154. })
  155. },
  156. methods: {
  157. ...caseTableActions([
  158. 'toPay',
  159. 'getCouponList',
  160. ]),
  161. sureSelectCoupon () {
  162. var bool = false
  163. for (var n = 0; n < this.couponList.length; n++) {
  164. if (this.couponList[n].select) {
  165. bool = true
  166. this.postData.customercouponid = this.couponList[n].id
  167. }
  168. }
  169. if (!bool) {
  170. this.postData.customercouponid = ''
  171. }
  172. this.showSelectCouponLayer = false
  173. },
  174. selectCouponItem (item) { // 选择优惠券
  175. // item.select = !item.select
  176. if (!item.select) {
  177. for (var n = 0; n < this.couponList.length; n++) {
  178. this.couponList[n].select = false
  179. }
  180. item.select = true
  181. } else {
  182. item.select = false
  183. }
  184. },
  185. returnAmount () { // 返回总金额
  186. var amount = 0, num = 0, info = JSON.parse(this.$route.query.info)
  187. for (var n = 0; n < info.length; n++) {
  188. if (info[n].defaultPrice === null) {
  189. amount += info[n].price * info[n].num
  190. num += info[n].num
  191. } else {
  192. amount += info[n].defaultPrice * info[n].defaultNum
  193. num += info[n].defaultNum
  194. }
  195. }
  196. return [amount, num]
  197. },
  198. toPayer () { // 下单
  199. this.postData.info.OrgId = this.orgId
  200. this.postData.info.UserId = this.userInfo.CustomerId
  201. this.postData.info.UserName = this.userInfo.customer.CustomerName
  202. this.postData.info.PayType = this.postData.customercouponid === '' ? 'coupon' : 'vip'
  203. var orderInfo = JSON.parse(this.$route.query.info)
  204. this.postData.detail = []
  205. var amount = 0
  206. var num = 0
  207. for (var n = 0; n < orderInfo.length; n++) {
  208. this.postData.detail.push({
  209. GoodsId: orderInfo[n].id,
  210. GoodsName: orderInfo[n].name,
  211. SpecId: orderInfo[n].spec,
  212. SpecName: orderInfo[n].specname,
  213. Number: orderInfo[n].num - 0,
  214. Price: String(orderInfo[n].price - 0),
  215. })
  216. amount += (orderInfo[n].price - 0) * orderInfo[n].num
  217. num += orderInfo[n].num - 0
  218. }
  219. this.postData.info.Amount = String(amount)
  220. this.postData.info.OrdersNum = num
  221. console.log(JSON.stringify(this.postData))
  222. this.toPay({
  223. info: JSON.stringify(this.postData.info),
  224. detail: JSON.stringify(this.postData.detail),
  225. customercouponid: this.postData.customercouponid
  226. }).then((res) => {
  227. this.$dialog.alert({
  228. message: '下单成功!'
  229. }).then(() => {
  230. window.history.go(-2)
  231. })
  232. })
  233. },
  234. cancel () {
  235. window.history.go(-1)
  236. },
  237. }
  238. }
  239. </script>
  240. <!-- Add "scoped" attribute to limit CSS to this component only -->
  241. <style lang="scss" scoped>
  242. @import 'page.scss';
  243. </style>