payment.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 da = {
  137. type: 2,
  138. count: 1,
  139. phone: this.phone,
  140. product_no: this.selectitem.product_no,
  141. }
  142. post("local/coupon/addOrder", da).then(res => {
  143. if (res.code == 0 && res.data.prepayid) {
  144. toPayOpre.toPay(res.data, (rea) => {
  145. if (!rea) {
  146. // 支付成功
  147. this.goto("/pagesB/orderingfood/orderlist")
  148. } else {
  149. // 支付失败
  150. }
  151. });
  152. }else if (res.code == 0 && res.data == 200) this.goto("/pagesB/orderingfood/orderlist")
  153. })
  154. },
  155. },
  156. onLoad(da) {
  157. this.getIntegral()
  158. let va = uni.getStorageSync("topup_brand");
  159. uni.setNavigationBarTitle({ title: va.name });
  160. this.load(va.name);
  161. this.topupBrand = va;
  162. },
  163. onShow() {},
  164. mounted() {},
  165. };
  166. </script>
  167. <style scoped lang='scss'>
  168. .payment{
  169. padding: 30rpx 30rpx 160rpx;
  170. }
  171. .headbar{
  172. .l,.r_logo{
  173. display: inline-block;
  174. vertical-align: top;
  175. }
  176. .l{
  177. width: calc(100% - 150rpx);
  178. .tit{
  179. font-size: 30rpx;
  180. font-weight: 600;
  181. margin-bottom: 20rpx;
  182. }
  183. .inp{
  184. font-size: 33rpx;
  185. // font-weight: bold;
  186. padding: 8rpx 0;
  187. }
  188. }
  189. .r_logo{
  190. width: 150rpx;
  191. height: 150rpx;
  192. border-radius: 10rpx;
  193. // border: 1px solid #e5e5e5;
  194. box-sizing: border-box;
  195. }
  196. .msg{
  197. border-top: 1px solid #e5e5e5;
  198. margin-top: 12rpx;
  199. padding: 10rpx 0 2rpx;
  200. font-size: 24rpx;
  201. color: #999;
  202. }
  203. }
  204. .tags{
  205. padding: 15rpx 0;
  206. .tab{
  207. // width: 180rpx;
  208. min-width: 100rpx;
  209. text-align: center;
  210. font-size: 30rpx;
  211. font-weight: 600;
  212. color: #999;
  213. padding: 6rpx 0;
  214. &.checked{
  215. color: #333;
  216. position: relative;
  217. border-bottom: 6rpx solid #18bb88;
  218. }
  219. }
  220. }
  221. .product{
  222. margin: 0 -15rpx 30rpx;
  223. .li{
  224. width: calc(50% - 30rpx);
  225. background-color: #fff;
  226. margin: 12rpx 15rpx;
  227. padding: 20rpx 30rpx;
  228. text-align: center;
  229. float: left;
  230. border-radius: 22rpx;
  231. border: 4rpx solid #fff;
  232. &.checked{
  233. border: 4rpx solid #18bb88;
  234. }
  235. }
  236. .p1{
  237. font-size: 28rpx;
  238. margin-bottom: 12rpx;
  239. }
  240. .p{
  241. font-size: 32rpx;
  242. font-weight: bold;
  243. color: #18bb88;
  244. &::before{
  245. content: "¥";
  246. font-size: 25rpx;
  247. }
  248. }
  249. }
  250. .card {
  251. background-color: #fff;
  252. border-radius: 26rpx;
  253. margin-bottom: 30rpx;
  254. padding: 28rpx 30rpx;
  255. font-size: 32rpx;
  256. box-shadow: 4rpx 4rpx 8rpx 4rpx rgba(0, 0, 0, 0.12);
  257. &:last-child {
  258. margin-bottom: 0;
  259. }
  260. }
  261. .money{
  262. .li{
  263. margin-bottom: 16rpx;
  264. &:last-child{
  265. margin-bottom: 0;
  266. }
  267. span{
  268. font-size: 30rpx;
  269. }
  270. }
  271. .corg{
  272. color: #18bb88;
  273. margin-left: 5rpx;
  274. }
  275. }
  276. .msg{
  277. font-size: 26rpx;
  278. margin-top: 50rpx;
  279. }
  280. .footbtn{
  281. width: calc(100% - 60rpx);
  282. height: 80rpx;
  283. background: #17bb87;
  284. border-radius: 45rpx;
  285. position: fixed;
  286. bottom: 50rpx;
  287. left: 30rpx;
  288. color: #fff;
  289. font-size: 36rpx;
  290. text-align: center;
  291. line-height: 80rpx;
  292. }
  293. </style>