payment.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <div class="payment">
  3. <div class="headbar card">
  4. <div class="l">
  5. <div class="tit">充值账号</div>
  6. <input class="inp" v-model="phone" :placeholder="`请输入${topupBrand.name}账号`" />
  7. </div>
  8. <img class="r_logo" :src="topupBrand.img" alt="">
  9. <div class="msg">* 请确保充值账号无误,充值成功后不支持退换</div>
  10. </div>
  11. <div class="tags flex_r flex_jse">
  12. <div :class="['tab',checked==i?'checked':'']" v-for="(i,s) in tags" :key="s" @click="checked = i">{{ i }}</div>
  13. </div>
  14. <div class="product clearfix">
  15. <div :class="{li:true,checked:i.checked}" v-for="(i,s) in products" :key="s" @click="ontag(s)" v-show="showfun(i)">
  16. <div class="p1">{{ i.product_name.replace(checked,"") }}</div>
  17. <div class="p" v-if="i.custom_price>0">{{ $h.Div(i.custom_price, 100) }}</div>
  18. <div class="p" v-else>{{ $h.Div(i.official_price, 100) }}</div>
  19. </div>
  20. </div>
  21. <template v-if="cartTotal>0">
  22. <div class="money card">
  23. <div class="li flex_r flex_jb">
  24. <span>消费金额</span>
  25. <span>¥{{ cartTotal || 0 }}</span>
  26. </div>
  27. <div class="li flex_r flex_jb">
  28. <span>消费券抵扣<span class="corg" v-if="selectitem.custom_price==0">{{Integral}}%</span></span>
  29. <span class="corg">-¥{{ deduction || 0 }}</span>
  30. </div>
  31. <div class="li flex_r flex_jb">
  32. <span>实付金额</span>
  33. <span>¥{{ actuallypaid || 0 }}</span>
  34. </div>
  35. </div>
  36. <div class="money card">
  37. <div class="li flex_r flex_jb">
  38. <span>赠送茶宝</span>
  39. <span>{{ chabao || 0 }}</span>
  40. </div>
  41. </div>
  42. </template>
  43. <div class="msg" v-html="selectitem.use_explain"></div>
  44. <div class="footbtn" @click="pay">立即充值</div>
  45. </div>
  46. </template>
  47. <script>
  48. import { ToPayOpre } from "@/utils/reqTools.js";
  49. let toPayOpre = new ToPayOpre();
  50. import { post } from "@/request/api.js";
  51. import { Asc } from "@/utils/myfun.js";
  52. export default {
  53. name: "payment",
  54. props: {},
  55. components: {},
  56. data() {
  57. return {
  58. phone: "",
  59. products: [],
  60. tags: [],
  61. checked: "",
  62. selectitem: {},
  63. egral: {},
  64. cartTotal: 0,
  65. Integral: 0,
  66. deduction: 0,
  67. actuallypaid: 0,
  68. chabao: 0,
  69. topupBrand: {},
  70. };
  71. },
  72. methods: {
  73. showfun(da){
  74. return this.checked ? this.checked == da.next_name : true
  75. },
  76. getIntegral(){
  77. post("local/getIntegral",{type:3}).then(res=>{
  78. if (res.code == 0) {
  79. this.egral = res.data;
  80. }
  81. })
  82. },
  83. load(va){
  84. post("local/coupon/productList",{type_name:va,type:1}).then(res=>{
  85. if (res.code == 0) {
  86. let a = res.data.next_name, b = res.data.product_list;
  87. Asc(b,"official_price"); //原价升序
  88. if(a.length) this.checked = a[0];
  89. this.tags = a;
  90. this.products = b;
  91. }
  92. })
  93. },
  94. ontag(key) {
  95. let da = this.products;
  96. da.forEach(value => this.$set(value, 'checked', false));
  97. da[key].checked = true;
  98. this.selectitem = da[key];
  99. this.egralfun()
  100. },
  101. egralfun(){
  102. let i1 = this.egral.integral, i2 = this.egral.chabao;
  103. this.Integral = this.$h.Mul(i1,100);
  104. if(this.selectitem.custom_price > 0){
  105. this.cartTotal = this.$h.Div(this.selectitem.custom_price, 100);
  106. this.deduction = this.$h.Mul(this.selectitem.custom_integral, 1);
  107. }
  108. else {
  109. this.cartTotal = this.$h.Div(this.selectitem.official_price, 100)
  110. this.deduction = this.$h.Mul(this.cartTotal,i1).toFixed(2);
  111. }
  112. this.actuallypaid = this.$h.Sub(this.cartTotal,this.deduction);
  113. this.chabao = this.$h.Mul(this.actuallypaid,i2).toFixed(2);
  114. },
  115. pay() {
  116. let that = this
  117. let localInfo = uni.getStorageSync("localInfo");
  118. let um = localInfo.property;
  119. let str = um > this.actuallypaid ? "将优先使用付宝抵扣" : "将使用付宝抵扣部分支付"
  120. if(um > 0){
  121. uni.showModal({
  122. title: "温馨提示",
  123. content: `您的可用付宝为 ${um},` + str,
  124. showCancel: true,
  125. confirmText: "确认",
  126. confirmColor: "#f02f2f",
  127. success(res) {
  128. if (res.confirm) {
  129. that.payok();
  130. }
  131. },
  132. });
  133. }else this.payok();
  134. },
  135. payok(){
  136. let type = "";
  137. // #ifdef H5
  138. type = "H5";
  139. // #endif
  140. // #ifdef APP
  141. type = "app";
  142. // #endif
  143. // #ifdef MP-WEIXIN
  144. type = "jsapi";
  145. // #endif
  146. let da = {
  147. type: 2,
  148. count: 1,
  149. phone: this.phone,
  150. product_no: this.selectitem.product_no,
  151. trade_type: type,
  152. }
  153. post("local/coupon/addOrder", da).then(res => {
  154. if(res.data && res.data != 200){
  155. let data = JSON.parse(res.data)
  156. data.prepayid = data.package?data.package.split('prepay_id=')[1]:''
  157. if (res.code == 0 && data.prepayid) {
  158. toPayOpre.toPay(data, (rea) => {
  159. if (!rea) {
  160. // 支付成功
  161. this.goto("/pagesB/orderingfood/orderlist")
  162. } else {
  163. // 支付失败
  164. }
  165. });
  166. }
  167. }else if (res.code == 0 && res.data == 200) this.goto("/pagesB/orderingfood/orderlist")
  168. })
  169. },
  170. },
  171. onLoad(da) {
  172. this.getIntegral()
  173. let va = uni.getStorageSync("topup_brand");
  174. uni.setNavigationBarTitle({ title: va.name });
  175. this.load(va.name);
  176. this.topupBrand = va;
  177. },
  178. onShow() {},
  179. mounted() {},
  180. };
  181. </script>
  182. <style scoped lang='scss'>
  183. .payment{
  184. padding: 30rpx 30rpx 160rpx;
  185. }
  186. .headbar{
  187. .l,.r_logo{
  188. display: inline-block;
  189. vertical-align: top;
  190. }
  191. .l{
  192. width: calc(100% - 150rpx);
  193. .tit{
  194. font-size: 30rpx;
  195. font-weight: 600;
  196. margin-bottom: 20rpx;
  197. }
  198. .inp{
  199. font-size: 33rpx;
  200. // font-weight: bold;
  201. padding: 8rpx 0;
  202. }
  203. }
  204. .r_logo{
  205. width: 150rpx;
  206. height: 150rpx;
  207. border-radius: 10rpx;
  208. // border: 1px solid #e5e5e5;
  209. box-sizing: border-box;
  210. }
  211. .msg{
  212. border-top: 1px solid #e5e5e5;
  213. margin-top: 12rpx;
  214. padding: 10rpx 0 2rpx;
  215. font-size: 24rpx;
  216. color: #999;
  217. }
  218. }
  219. .tags{
  220. padding: 15rpx 0;
  221. .tab{
  222. // width: 180rpx;
  223. min-width: 100rpx;
  224. text-align: center;
  225. font-size: 30rpx;
  226. font-weight: 600;
  227. color: #999;
  228. padding: 6rpx 0;
  229. &.checked{
  230. color: #333;
  231. position: relative;
  232. border-bottom: 6rpx solid #18bb88;
  233. }
  234. }
  235. }
  236. .product{
  237. margin: 0 -15rpx 30rpx;
  238. .li{
  239. width: calc(50% - 30rpx);
  240. background-color: #fff;
  241. margin: 12rpx 15rpx;
  242. padding: 20rpx 30rpx;
  243. text-align: center;
  244. float: left;
  245. border-radius: 22rpx;
  246. border: 4rpx solid #fff;
  247. &.checked{
  248. border: 4rpx solid #18bb88;
  249. }
  250. }
  251. .p1{
  252. font-size: 28rpx;
  253. margin-bottom: 12rpx;
  254. }
  255. .p{
  256. font-size: 32rpx;
  257. font-weight: bold;
  258. color: #18bb88;
  259. &::before{
  260. content: "¥";
  261. font-size: 25rpx;
  262. }
  263. }
  264. }
  265. .card {
  266. background-color: #fff;
  267. border-radius: 26rpx;
  268. margin-bottom: 30rpx;
  269. padding: 28rpx 30rpx;
  270. font-size: 32rpx;
  271. box-shadow: 4rpx 4rpx 8rpx 4rpx rgba(0, 0, 0, 0.12);
  272. &:last-child {
  273. margin-bottom: 0;
  274. }
  275. }
  276. .money{
  277. .li{
  278. margin-bottom: 16rpx;
  279. &:last-child{
  280. margin-bottom: 0;
  281. }
  282. span{
  283. font-size: 30rpx;
  284. }
  285. }
  286. .corg{
  287. color: #18bb88;
  288. margin-left: 5rpx;
  289. }
  290. }
  291. .msg{
  292. font-size: 26rpx;
  293. margin-top: 50rpx;
  294. }
  295. .footbtn{
  296. width: calc(100% - 60rpx);
  297. height: 80rpx;
  298. background: #17bb87;
  299. border-radius: 45rpx;
  300. position: fixed;
  301. bottom: 50rpx;
  302. left: 30rpx;
  303. color: #fff;
  304. font-size: 36rpx;
  305. text-align: center;
  306. line-height: 80rpx;
  307. }
  308. </style>