coupon.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div class="discountCoupon">
  3. <div class="products">
  4. <scroll-view class="productList" scroll-x="true">
  5. <div class="item" v-for="(i,s) in products" :key="s" @click="ontag(s)" :class="{active:i.checked}">
  6. <image :src="i.cover_url" class="p_img" mode="aspectFill" />
  7. <div class="p_con">
  8. <div class="t">{{ i.product_name }}</div>
  9. <div class="p">{{ egralfun(i.official_price) }}</div>
  10. <div class="fp">官方价¥{{ $h.Div(i.official_price, 100) }}</div>
  11. <span v-if="i.checked" class="colg iconfont">&#xe62c;</span>
  12. </div>
  13. </div>
  14. </scroll-view>
  15. </div>
  16. <div class="product_con">
  17. <div class="card">
  18. <div class="li flex_r flex_jb">
  19. <span>购买数量</span>
  20. <numbox v-model="count" :min="1" @change="countchange" />
  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="msg" v-html="selectitem.use_explain"></div>
  44. </div>
  45. <div class="footbtn" @click="pay">立即购买</div>
  46. </div>
  47. </template>
  48. <script>
  49. import numbox from "@/pagesB/components/number-box/number-box.vue"
  50. import { post } from "@/request/api.js";
  51. import { ToPayOpre } from "@/utils/reqTools.js";
  52. let toPayOpre = new ToPayOpre();
  53. export default {
  54. name: "discountCoupon",
  55. props: {},
  56. components: { numbox },
  57. data() {
  58. return {
  59. count: 1,
  60. topupBrand: {},
  61. products: [],
  62. egral: {},
  63. selectitem: {},
  64. cartTotal: 0,
  65. Integral: 0,
  66. deduction: 0,
  67. actuallypaid: 0,
  68. chabao: 0,
  69. };
  70. },
  71. methods: {
  72. getIntegral() {
  73. post("local/getIntegral", { type: 3 }).then(res => {
  74. if (res.code == 0) {
  75. this.egral = res.data;
  76. }
  77. })
  78. },
  79. egralfun(va) {
  80. let i1 = this.egral.integral;
  81. let cartTotal = this.$h.Div(va, 100)
  82. let deduction = this.$h.Mul(cartTotal, i1).toFixed(2);
  83. return this.$h.Sub(cartTotal, deduction);
  84. },
  85. load(va) {
  86. post("local/coupon/productList", { type_name: va, type: 0 }).then(res => {
  87. if (res.code == 0) {
  88. this.products = res.data;
  89. this.ontag(0);
  90. }
  91. })
  92. },
  93. ontag(key) {
  94. let da = this.products;
  95. da.forEach(value => this.$set(value, 'checked', false));
  96. da[key].checked = true;
  97. this.selectitem = da[key];
  98. this.egralf();
  99. },
  100. egralf() {
  101. let i1 = this.egral.integral,
  102. i2 = this.egral.chabao;
  103. this.Integral = this.$h.Mul(i1, 100);
  104. this.cartTotal = this.$h.Mul(this.$h.Div(this.selectitem.official_price, 100), this.count)
  105. this.deduction = this.$h.Mul(this.cartTotal, i1);
  106. this.actuallypaid = this.$h.Sub(this.cartTotal, this.deduction);
  107. this.chabao = this.$h.Mul(this.actuallypaid, i2);
  108. },
  109. countchange(va) {
  110. this.count = va
  111. this.egralf();
  112. },
  113. pay() {
  114. let da = {
  115. type: 3,
  116. count: this.count,
  117. phone: uni.getStorageSync("userinfo").mobile,
  118. product_no: this.selectitem.product_no,
  119. }
  120. post("local/coupon/addOrder", da).then(res => {
  121. if (res.code == 0 && res.data.prepayid) {
  122. toPayOpre.toPay(res.data, (rea) => {
  123. if (!rea) {
  124. // 支付成功
  125. this.goto("/pagesB/orderingfood/orderlist")
  126. } else {
  127. // 支付失败
  128. }
  129. });
  130. }
  131. })
  132. },
  133. },
  134. created() {
  135. this.getIntegral();
  136. },
  137. onLoad(da) {
  138. let va = uni.getStorageSync("topup_brand");
  139. uni.setNavigationBarTitle({ title: va.name });
  140. this.topupBrand = va;
  141. this.load(va.name);
  142. },
  143. onShow() {},
  144. mounted() {},
  145. };
  146. </script>
  147. <style scoped lang='scss'>
  148. .products {
  149. background-color: #fff;
  150. padding: 0 30rpx 28rpx;
  151. box-shadow: 4rpx 4rpx 26rpx 2rpx rgba(17, 18, 29, 0.1);
  152. }
  153. .productList {
  154. box-sizing: border-box;
  155. white-space: nowrap;
  156. background-color: rgba($color: #000, $alpha: 0.05);
  157. padding: 0 15rpx;
  158. border-radius: 16rpx;
  159. }
  160. .item {
  161. width: 380rpx;
  162. display: inline-block;
  163. background-color: #fff;
  164. border-radius: 15rpx;
  165. margin: 16rpx 15rpx;
  166. box-shadow: 4rpx 4rpx 26rpx 2rpx rgba(0, 0, 0, 0.15);
  167. vertical-align: middle;
  168. .p_img {
  169. width: 100%;
  170. height: 235rpx;
  171. border-radius: 15rpx 15rpx 0 0;
  172. }
  173. .p_con {
  174. padding: 8rpx 20rpx;
  175. position: relative;
  176. .t {
  177. font-size: 32rpx;
  178. white-space: pre-wrap;
  179. min-height: 82rpx;
  180. line-height: 36rpx;
  181. }
  182. .p {
  183. font-size: 35rpx;
  184. font-weight: bold;
  185. &:before {
  186. content: "¥";
  187. font-size: 20rpx;
  188. }
  189. }
  190. .fp {
  191. font-weight: 400;
  192. color: #999;
  193. font-size: 28rpx;
  194. text-decoration: line-through;
  195. }
  196. .colg {
  197. color: #18bb88;
  198. position: absolute;
  199. right: 28rpx;
  200. bottom: 20rpx;
  201. }
  202. }
  203. &.active {
  204. border: 4rpx solid #18bb88;
  205. box-shadow: 4rpx 4rpx 26rpx 2rpx rgba($color: #18bb88, $alpha: 0.3);
  206. .p_con {
  207. .p {
  208. color: #18bb88;
  209. }
  210. }
  211. }
  212. }
  213. .card {
  214. background-color: #fff;
  215. border-radius: 20rpx;
  216. margin-bottom: 30rpx;
  217. padding: 28rpx 30rpx;
  218. font-size: 32rpx;
  219. box-shadow: 4rpx 4rpx 26rpx 2rpx rgba(17, 18, 29, 0.1);
  220. &:last-child {
  221. margin-bottom: 0;
  222. }
  223. }
  224. .product_con {
  225. padding: 28rpx 30rpx;
  226. }
  227. .money {
  228. .li {
  229. margin-bottom: 16rpx;
  230. &:last-child {
  231. margin-bottom: 0;
  232. }
  233. span {
  234. font-size: 30rpx;
  235. }
  236. }
  237. .corg {
  238. color: #18bb88;
  239. margin-left: 5rpx;
  240. }
  241. }
  242. .msg {
  243. font-size: 26rpx;
  244. margin-top: 50rpx;
  245. }
  246. .footbtn {
  247. width: calc(100% - 60rpx);
  248. height: 80rpx;
  249. background: #17bb87;
  250. border-radius: 45rpx;
  251. position: fixed;
  252. bottom: 50rpx;
  253. left: 30rpx;
  254. color: #fff;
  255. font-size: 36rpx;
  256. text-align: center;
  257. line-height: 80rpx;
  258. }
  259. </style>