payTheBill.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="payTheBill">
  3. <div class="head card">
  4. <div class="p1">{{Merchant.restaurant_name}}</div>
  5. <div class="p2">{{Merchant.restaurant_address}}</div>
  6. </div>
  7. <div class="phone card flex_r flex_jb">
  8. <span>联系方式</span>
  9. <span>{{ userinfo.mobile }}</span>
  10. </div>
  11. <div class="commodity card">
  12. <div class="li tit">
  13. <span class="s1">商品名称</span>
  14. <span class="s2">数量</span>
  15. <span class="s2">原价</span>
  16. </div>
  17. <div class="li li2" v-for="(i,s) in cartList" :key="s">
  18. <span class="s1 ellipsis">{{ i.product_name }}</span>
  19. <span class="s2">{{ i.number }}</span>
  20. <span class="s2">{{ $h.Mul($h.Add(i.product_price, i.spec_price),i.number) }}</span>
  21. </div>
  22. </div>
  23. <div class="money card">
  24. <div class="li flex_r flex_jb">
  25. <span>消费金额</span>
  26. <span>¥{{ cartTotal || 0 }}</span>
  27. </div>
  28. <div class="li flex_r flex_jb">
  29. <span>消费金抵扣<span class="corg">{{Integral}}%</span></span>
  30. <span class="corg">-¥{{ deduction || 0 }}</span>
  31. </div>
  32. <div class="li flex_r flex_jb">
  33. <span>实付金额</span>
  34. <span>¥{{ actuallypaid || 0 }}</span>
  35. </div>
  36. </div>
  37. <div class="money card">
  38. <div class="li flex_r flex_jb">
  39. <span>赠送茶宝</span>
  40. <span>{{ chabao || 0 }}</span>
  41. </div>
  42. </div>
  43. <div class="btnbar">
  44. <div class="btn" @click="payBill">确认支付</div>
  45. </div>
  46. <div class="mag">*核对商品无误后即可付款,然后订单详情页会显示取餐码,将取餐码告知店员即可取餐</div>
  47. </div>
  48. </template>
  49. <script>
  50. import { ToPayOpre } from "@/utils/reqTools.js";
  51. let toPayOpre = new ToPayOpre();
  52. import { post } from "@/request/api.js";
  53. export default {
  54. name: "payTheBill",
  55. props: {},
  56. components: {},
  57. data() {
  58. return {
  59. Merchant: {},
  60. cartList: [],
  61. cartTotal: 0,
  62. userinfo: {},
  63. Integral: 0,
  64. deduction: 0,
  65. actuallypaid: 0,
  66. chabao: 0,
  67. };
  68. },
  69. methods: {
  70. getMerchant(da) {
  71. post("local/getMerchantById", da).then(res => {
  72. if (res.code == 0) {
  73. this.Merchant = res.data;
  74. }
  75. })
  76. },
  77. getIntegral(){
  78. post("local/getIntegral",{type:1}).then(res=>{
  79. if (res.code == 0) {
  80. let i1 = res.data.integral, i2 = res.data.chabao;
  81. this.Integral = this.$h.Mul(i1,100);
  82. this.deduction = this.$h.Mul(this.cartTotal,i1).toFixed(2);
  83. this.actuallypaid = this.$h.Sub(this.cartTotal,this.deduction);
  84. this.chabao = this.$h.Mul(this.actuallypaid,i2).toFixed(2);
  85. }
  86. })
  87. },
  88. getCartList(id) {
  89. post("local/myCart", {
  90. restaurant_id: id,
  91. }).then(res => {
  92. if (res.code == 0) {
  93. let data = res.data;
  94. let totals = 0;
  95. data.forEach(itm => {
  96. totals = this.$h.Add(totals, this.$h.Mul(this.$h.Add(itm.product_price, itm.spec_price), itm.number));
  97. })
  98. this.cartList = data;
  99. this.cartTotal = totals;
  100. this.getIntegral();
  101. }
  102. })
  103. },
  104. async getuserInfo() {
  105. this.userinfo = await uni.userfun();
  106. },
  107. payBill(){
  108. let Arr = []
  109. for (const it of this.cartList) {
  110. let spec = JSON.parse(it.spec)
  111. let product_details = spec.product_details
  112. Arr.push({
  113. product_id: it.product_id,
  114. amount: it.number,
  115. product_details
  116. })
  117. }
  118. let product_detail = JSON.stringify(Arr)
  119. let da = {
  120. brand_id: this.Merchant.brand_id,
  121. restaurant_id: this.Merchant.restaurant_id,
  122. phone: this.userinfo.mobile,
  123. total_amount: this.actuallypaid,
  124. product_detail
  125. }
  126. post("local/merchantOrder", da).then(res => {
  127. if (res.code == 0 && res.data.prepayid) {
  128. toPayOpre.toPay(res.data, (rea) => {
  129. if (!rea) {
  130. // 支付成功
  131. this.goto("/pagesB/orderingfood/orderlist")
  132. } else {
  133. // 支付失败
  134. }
  135. });
  136. }
  137. })
  138. }
  139. },
  140. onReady() {
  141. this.getuserInfo();
  142. },
  143. onLoad(da) {
  144. this.getMerchant(da);
  145. this.getCartList(da.restaurant_id);
  146. },
  147. onShow() {},
  148. mounted() {},
  149. };
  150. </script>
  151. <style scoped lang='scss'>
  152. page {
  153. min-height: 100%;
  154. background-color: #ECECEC;
  155. }
  156. .payTheBill {
  157. padding: 32rpx;
  158. }
  159. .head{
  160. .p2{
  161. font-size: 26rpx;
  162. color: #999;
  163. margin-top: 10rpx;
  164. }
  165. }
  166. .commodity {
  167. .li{
  168. margin-bottom: 8rpx;
  169. &:last-child{
  170. margin-bottom: 0;
  171. }
  172. }
  173. .tit {
  174. font-weight: bold;
  175. margin-bottom: 18rpx;
  176. .s1, .s2 {
  177. font-size: 30rpx;
  178. }
  179. }
  180. .s1, .s2 {
  181. display: inline-block;
  182. font-size: 26rpx;
  183. }
  184. .s1 {
  185. width: calc(100% - 240rpx);
  186. }
  187. .s2 {
  188. width: 120rpx;
  189. text-align: center;
  190. }
  191. }
  192. .money{
  193. .li{
  194. margin-bottom: 16rpx;
  195. &:last-child{
  196. margin-bottom: 0;
  197. }
  198. span{
  199. font-size: 30rpx;
  200. }
  201. }
  202. .corg{
  203. color: #18bb88;
  204. margin-left: 5rpx;
  205. }
  206. }
  207. .btnbar{
  208. padding: 20rpx 0;
  209. .btn{
  210. height: 80rpx;
  211. line-height: 80rpx;
  212. border-radius: 16rpx;
  213. background-color: #18bb88;
  214. text-align: center;
  215. color: #fff;
  216. }
  217. }
  218. .mag{
  219. font-size: 26rpx;
  220. color: #999;
  221. }
  222. .card {
  223. background-color: #fff;
  224. border-radius: 26rpx;
  225. margin-bottom: 30rpx;
  226. padding: 28rpx 30rpx;
  227. font-size: 32rpx;
  228. &:last-child {
  229. margin-bottom: 0;
  230. }
  231. }
  232. </style>