微信

index.vue 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 class="layerBg" :class="{'active': !ajaxoff}"></div> -->
  77. </div>
  78. </template>
  79. <script>
  80. import { mapState, createNamespacedHelpers } from 'vuex'
  81. const { mapActions: caseTableActions } = createNamespacedHelpers('placeOrderForCoffee')
  82. import discounts from '../../../components/discounts/discounts'
  83. export default {
  84. name: '',
  85. data () {
  86. var _self = this
  87. return {
  88. ajaxoff: true,
  89. showSelectCouponLayer: false,
  90. getCouponOff: false,
  91. couponList: [], // 优惠券列表
  92. showSuccessPopup: false,
  93. postData: {
  94. info: {
  95. CaseId: decodeURI(_self.$route.query.caseid),
  96. AreaId: decodeURI(_self.$route.query.areaid),
  97. AreaName: decodeURI(_self.$route.query.areaname),
  98. TableId: decodeURI(_self.$route.query.tableid),
  99. TableNo: decodeURI(_self.$route.query.tableno),
  100. Amount: 0, // 订单金额
  101. OrdersNum: 0,
  102. Remark: '',
  103. },
  104. detail: [],
  105. customercouponid: ''
  106. },
  107. ticketList: [{
  108. value: '优惠券1',
  109. id: '1',
  110. }, {
  111. value: '优惠券2',
  112. id: '2',
  113. }, {
  114. value: '优惠券3',
  115. id: '3',
  116. }],
  117. orderInfo: JSON.parse(_self.$route.query.info) || []
  118. }
  119. },
  120. components: {
  121. discounts,
  122. },
  123. computed: {
  124. ...mapState({
  125. userInfo: x => x.userCenter.userInfo,
  126. orgId: x => x.app.orgId,
  127. })
  128. },
  129. created () {
  130. this.getCouponList().then((res) => {
  131. // console.log(JSON.stringify(res))
  132. var id = JSON.parse(this.$route.query.info)[0].id, arr = [], nowDate = Date.now()
  133. res = res || []
  134. for (var n = 0; n < res.length; n++) {
  135. res[n].Coupon.Targets = res[n].Coupon.Targets || []
  136. if (res[n].Coupon.CouponType === 'goods' && res[n].Status === 1) {
  137. 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) {
  138. this.couponList.push({
  139. title: res[n].Coupon.CouponName,
  140. desc: res[n].Coupon.Share.UseRule,
  141. time: this.toolClass.dateFormat(res[n].EndDate),
  142. useType: '未使用',
  143. tag: '商品',
  144. id: res[n].CustomerCouponId,
  145. select: false,
  146. })
  147. } else {
  148. for (var a = 0; a < res[n].Coupon.Targets.length; a++) {
  149. if (res[n].Coupon.Targets[a].TargetId === id && nowDate >= new Date(res[n].StartDate).getTime() && nowDate < new Date(res[n].EndDate).getTime()) {
  150. this.couponList.push({
  151. title: res[n].Coupon.CouponName,
  152. desc: res[n].Coupon.Share.UseInstruction,
  153. time: this.toolClass.dateFormat(res[n].EndDate),
  154. useType: '未使用',
  155. tag: '商品',
  156. id: res[n].CustomerCouponId,
  157. select: false,
  158. })
  159. }
  160. }
  161. }
  162. }
  163. }
  164. this.getCouponOff = true
  165. // console.log(JSON.stringify(this.couponList))
  166. })
  167. },
  168. methods: {
  169. ...caseTableActions([
  170. 'toPay',
  171. 'getCouponList',
  172. ]),
  173. sureSelectCoupon () {
  174. var bool = false
  175. for (var n = 0; n < this.couponList.length; n++) {
  176. if (this.couponList[n].select) {
  177. bool = true
  178. this.postData.customercouponid = this.couponList[n].id
  179. }
  180. }
  181. if (!bool) {
  182. this.postData.customercouponid = ''
  183. }
  184. this.showSelectCouponLayer = false
  185. },
  186. selectCouponItem (item) { // 选择优惠券
  187. // item.select = !item.select
  188. if (!item.select) {
  189. for (var n = 0; n < this.couponList.length; n++) {
  190. this.couponList[n].select = false
  191. }
  192. item.select = true
  193. } else {
  194. item.select = false
  195. }
  196. },
  197. returnAmount () { // 返回总金额
  198. var amount = 0, num = 0, info = JSON.parse(this.$route.query.info)
  199. for (var n = 0; n < info.length; n++) {
  200. if (info[n].defaultPrice === null) {
  201. amount += info[n].price * info[n].num
  202. num += info[n].num
  203. } else {
  204. amount += info[n].defaultPrice * info[n].defaultNum
  205. num += info[n].defaultNum
  206. }
  207. }
  208. return [amount, num]
  209. },
  210. toPayer () { // 下单
  211. if (this.ajaxoff) {
  212. this.ajaxoff = false
  213. this.toPay({
  214. id: this.$route.query.ordersid,
  215. remark: this.postData.info.Remark,
  216. customercouponid: this.postData.customercouponid
  217. }).then((res) => {
  218. this.showSuccessPopup = true
  219. // this.$dialog.alert({
  220. // message: '下单成功!'
  221. // }).then(() => {
  222. // window.history.go(-2)
  223. // })
  224. }).catch(() => {
  225. this.ajaxoff = true
  226. })
  227. }
  228. },
  229. popBack () {
  230. this.showSuccessPopup = false
  231. // window.history.go(-2)
  232. this.$router.push({name: 'coffeeIndex'})
  233. },
  234. cancel () {
  235. // window.history.go(-1)
  236. this.$router.push({name: 'coffeeIndex'})
  237. },
  238. }
  239. }
  240. </script>
  241. <!-- Add "scoped" attribute to limit CSS to this component only -->
  242. <style lang="scss" scoped>
  243. @import 'page.scss';
  244. .layerBg{
  245. width: 100%;
  246. position: absolute;
  247. left: 0;
  248. top: 0;
  249. bottom: 0;
  250. z-index: 100;
  251. display: none;
  252. &.active{
  253. display: block;
  254. }
  255. }
  256. </style>