payTheBill.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. brand_id: ""
  68. };
  69. },
  70. methods: {
  71. getMerchant(da) {
  72. post("local/getMerchantById", da).then(res => {
  73. if (res.code == 0) {
  74. this.Merchant = res.data;
  75. }
  76. })
  77. },
  78. getIntegral(){
  79. post("local/getIntegral",{type:1,brand_id: this.brand_id}).then(res=>{
  80. if (res.code == 0) {
  81. let i1 = res.data.integral, i2 = res.data.chabao;
  82. this.Integral = this.$h.Mul(i1,100);
  83. this.deduction = this.$h.Mul(this.cartTotal,i1).toFixed(2);
  84. this.actuallypaid = this.$h.Sub(this.cartTotal,this.deduction);
  85. this.chabao = this.$h.Mul(this.actuallypaid,i2).toFixed(2);
  86. }
  87. })
  88. },
  89. getCartList(id) {
  90. post("local/myCart", {
  91. restaurant_id: id,
  92. }).then(res => {
  93. if (res.code == 0) {
  94. let data = res.data;
  95. let totals = 0;
  96. data.forEach(itm => {
  97. totals = this.$h.Add(totals, this.$h.Mul(this.$h.Add(itm.product_price, itm.spec_price), itm.number));
  98. })
  99. this.cartList = data;
  100. this.cartTotal = totals;
  101. this.getIntegral();
  102. }
  103. })
  104. },
  105. async getuserInfo() {
  106. this.userinfo = await uni.userfun();
  107. },
  108. payBill(){
  109. if (!this.userinfo.mobile) {
  110. // #ifdef  MP-WEIXIN
  111. uni.showModal({
  112. title: "温馨提示",
  113. content: "您还未登录",
  114. showCancel: true,
  115. confirmText: "前往登录",
  116. confirmColor: "#f02f2f",
  117. success(res) {
  118. if (res.confirm) {
  119. uni.navigateTo({url:"/pages/my/wxLogin"})
  120. }
  121. },
  122. });
  123. // #endif
  124. return
  125. }
  126. let that = this
  127. let localInfo = uni.getStorageSync("localInfo");
  128. let um = localInfo.property;
  129. let str = um > this.actuallypaid ? "将优先使用茶币抵扣" : "将使用茶币抵扣部分支付"
  130. if(um > 0){
  131. uni.showModal({
  132. title: "温馨提示",
  133. content: `您的可用茶币为 ${um},` + str,
  134. showCancel: true,
  135. confirmText: "确认",
  136. confirmColor: "#f02f2f",
  137. success(res) {
  138. if (res.confirm) {
  139. that.payok();
  140. }
  141. },
  142. });
  143. }else this.payok();
  144. },
  145. payok(){
  146. let Arr = []
  147. for (const it of this.cartList) {
  148. let spec = JSON.parse(it.spec)
  149. let product_details = spec.product_details
  150. Arr.push({
  151. product_id: it.product_id,
  152. amount: it.number,
  153. product_details
  154. })
  155. }
  156. let type = "";
  157. // #ifdef H5
  158. type = "H5";
  159. // #endif
  160. // #ifdef APP
  161. type = "app";
  162. // #endif
  163. // #ifdef MP-WEIXIN
  164. type = "jsapi";
  165. // #endif
  166. let product_detail = JSON.stringify(Arr)
  167. let da = {
  168. brand_id: this.Merchant.brand_id,
  169. restaurant_id: this.Merchant.restaurant_id,
  170. phone: this.userinfo.mobile,
  171. total_amount: this.actuallypaid,
  172. product_detail,
  173. trade_type: type,
  174. }
  175. post("local/merchantOrder", da).then(res => {
  176. if(res.data && res.data != 200){
  177. let data = JSON.parse(res.data)
  178. data.prepayid = data.package?data.package.split('prepay_id=')[1]:''
  179. if (res.code == 0 && data.prepayid) {
  180. toPayOpre.toPay(data, (rea) => {
  181. if (!rea) {
  182. // 支付成功
  183. this.goto("/pagesB/orderingfood/orderlist")
  184. } else {
  185. // 支付失败
  186. }
  187. });
  188. }
  189. }else if (res.code == 0 && res.data == 200) this.goto("/pagesB/orderingfood/orderlist")
  190. })
  191. }
  192. },
  193. onReady() {
  194. this.getuserInfo();
  195. },
  196. onLoad(da) {
  197. this.brand_id = da.brand_id;
  198. this.getMerchant(da);
  199. this.getCartList(da.restaurant_id);
  200. },
  201. onShow() {},
  202. mounted() {},
  203. };
  204. </script>
  205. <style scoped lang='scss'>
  206. page {
  207. min-height: 100%;
  208. background-color: #ECECEC;
  209. }
  210. .payTheBill {
  211. padding: 32rpx;
  212. }
  213. .head{
  214. .p2{
  215. font-size: 26rpx;
  216. color: #999;
  217. margin-top: 10rpx;
  218. }
  219. }
  220. .commodity {
  221. .li{
  222. margin-bottom: 8rpx;
  223. &:last-child{
  224. margin-bottom: 0;
  225. }
  226. }
  227. .tit {
  228. font-weight: bold;
  229. margin-bottom: 18rpx;
  230. .s1, .s2 {
  231. font-size: 30rpx;
  232. }
  233. }
  234. .s1, .s2 {
  235. display: inline-block;
  236. font-size: 26rpx;
  237. }
  238. .s1 {
  239. width: calc(100% - 240rpx);
  240. }
  241. .s2 {
  242. width: 120rpx;
  243. text-align: center;
  244. }
  245. }
  246. .money{
  247. .li{
  248. margin-bottom: 16rpx;
  249. &:last-child{
  250. margin-bottom: 0;
  251. }
  252. span{
  253. font-size: 30rpx;
  254. }
  255. }
  256. .corg{
  257. color: #18bb88;
  258. margin-left: 5rpx;
  259. }
  260. }
  261. .btnbar{
  262. padding: 20rpx 0;
  263. .btn{
  264. height: 80rpx;
  265. line-height: 80rpx;
  266. border-radius: 16rpx;
  267. background-color: #18bb88;
  268. text-align: center;
  269. color: #fff;
  270. }
  271. }
  272. .mag{
  273. font-size: 26rpx;
  274. color: #999;
  275. }
  276. .card {
  277. background-color: #fff;
  278. border-radius: 26rpx;
  279. margin-bottom: 30rpx;
  280. padding: 28rpx 30rpx;
  281. font-size: 32rpx;
  282. &:last-child {
  283. margin-bottom: 0;
  284. }
  285. }
  286. </style>