index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <!-- index.wxml -->
  3. <view class="wrap">
  4. <view class="wrap_nr">
  5. <view class="wrap_t" :style="'background-image: url(' + topBg + ')'">
  6. <view class="wrap_t_name">卡内余额</view>
  7. <view class="total_price">
  8. <text class="unit">¥</text>
  9. {{ money }}
  10. </view>
  11. </view>
  12. <view class="wrap_b">
  13. <view class="card_top">
  14. <view class="wrap_b_t">
  15. <view class="wrap_b_t_l">
  16. <image class="item_icon" mode="heightFix" src="/static/statics/img/icon_dengji.png"></image>
  17. <view class="item_name">请选择充值方案</view>
  18. </view>
  19. <view class="wrap_b_t_r" @tap="goCashLog">充值记录</view>
  20. </view>
  21. <image class="line_tu" src="/static/statics/img/line_tu.png"></image>
  22. </view>
  23. <view class="card_list">
  24. <view class="card_item_w" @tap="clickCard" :data-id="item.id" v-for="(item, index) in cardList" :key="index">
  25. <view :class="item.checked ? 'card_item active' : 'card_item'">
  26. <view v-if="item.type == 2">
  27. <!-- 年卡 -->
  28. <view class="card_item_col">
  29. <view class="card_text">{{ item.price }}元购{{ item.title }}</view>
  30. <view class="card_send">得</view>
  31. <view class="card_text">会员</view>
  32. </view>
  33. </view>
  34. <view v-else>
  35. <!-- 充值卡 -->
  36. <view class="card_item_col">
  37. <view class="card_text">充值{{ item.price }}元</view>
  38. <view class="card_send">得</view>
  39. <view class="card_text">{{ item.priceAddCoupons }}元</view>
  40. </view>
  41. <view class="card_item_col desc" v-if="item.coupon_rule">
  42. <text class="">{{ item.price }}元卡金</text>
  43. <text class="">+ {{ item.coupon_rule.coupon.price }}元x{{ item.coupon_rule.num }}张券</text>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- loading -->
  53. <!-- <van-overlay show="{{ loading }}" z-index="100">
  54. <van-loading custom-class="custom_loading" />
  55. </van-overlay> -->
  56. </template>
  57. <script>
  58. // index.js
  59. let myPro = require('../../../utils/wxRequest.js');
  60. let util = require('../../../utils/util.js');
  61. export default {
  62. data() {
  63. return {
  64. money: '',
  65. topBg: '/static/statics/img/cash_bg.png',
  66. // 全局loading
  67. loading: false,
  68. store: '',
  69. cardList: ''
  70. };
  71. },
  72. onLoad: function (options) {
  73. // Do some initialize when page load.
  74. let that = this;
  75. that.setData({
  76. topBg: 'data:image/png;base64,' + uni.getFileSystemManager().readFileSync(that.topBg, 'base64')
  77. });
  78. },
  79. onShow: function () {
  80. // Do something when page show.
  81. let that = this; // 店铺
  82. uni.getStorage({
  83. key: 'store',
  84. success: function (res) {
  85. that.setData({
  86. store: JSON.parse(res.data)
  87. });
  88. }
  89. });
  90. that.getUserInfo();
  91. that.getRechargeCard();
  92. },
  93. onReady: function () {
  94. // Do something when page ready.
  95. },
  96. onHide: function () {
  97. // Do something when page hide.
  98. },
  99. onUnload: function () {
  100. // Do something when page close.
  101. },
  102. onPullDownRefresh: function () {
  103. // Do something when pull down.
  104. },
  105. onReachBottom: function () {
  106. // Do something when page reach bottom.
  107. },
  108. onPageScroll: function () {
  109. // Do something when page scroll
  110. },
  111. onResize: function () {
  112. // Do something when page resize
  113. },
  114. methods: {
  115. // 用户信息
  116. getUserInfo() {
  117. let that = this;
  118. myPro
  119. .wxRequest('user/v2/userinfo', 'GET', {})
  120. .then((res) => {
  121. that.setData({
  122. money: res.result.money
  123. }); // 同步会员信息 is_member
  124. getApp().globalData.is_member = res.result.is_member;
  125. })
  126. .catch((err) => {
  127. console.log('报错信息', err);
  128. uni.showToast({
  129. title: err,
  130. icon: 'none'
  131. });
  132. });
  133. },
  134. // 获取充值卡
  135. getRechargeCard() {
  136. let that = this;
  137. let params = {
  138. type: 2,
  139. card_type: 1 // 1普通 2年卡(会员卡)
  140. };
  141. myPro
  142. .wxRequest('user/v2/rechargecardlist', 'GET', params)
  143. .then((res) => {
  144. let list = res.result;
  145. for (let i in list) {
  146. list[i].checked = false; // 卡+券的总金额 (都按代金券走,折扣券不考虑)
  147. if (list[i].coupon_rule) {
  148. list[i].priceAddCoupons = (list[i].coupon_rule.coupon.price * list[i].coupon_rule.num + parseFloat(list[i].price)).toFixed(2);
  149. } else {
  150. list[i].priceAddCoupons = list[i].price;
  151. }
  152. }
  153. that.setData({
  154. cardList: list
  155. });
  156. })
  157. .catch((err) => {
  158. console.log('报错信息', err);
  159. uni.showToast({
  160. title: err,
  161. icon: 'none'
  162. });
  163. });
  164. },
  165. // 选择充值卡
  166. clickCard(event) {
  167. let that = this;
  168. let id = event.currentTarget.dataset.id;
  169. let list = that.cardList;
  170. for (let i in list) {
  171. if (list[i].id == id) {
  172. list[i].checked = !list[i].checked;
  173. if (list[i].checked) {
  174. that.nextFun(list[i].id);
  175. }
  176. } else {
  177. list[i].checked = false;
  178. }
  179. }
  180. that.setData({
  181. cardList: list
  182. });
  183. },
  184. // 充值
  185. nextFun(id) {
  186. let that = this;
  187. let params = {
  188. recharge_card_id: id,
  189. store_id: that.store ? that.store.id : 1 // 门店id
  190. };
  191. myPro
  192. .wxRequest('user/recharge', 'POST', params)
  193. .then((res) => {
  194. let config = res.result.config;
  195. that.wxPayCard(JSON.parse(config));
  196. })
  197. .catch((err) => {
  198. console.log('报错信息', err);
  199. uni.showToast({
  200. title: err,
  201. icon: 'none'
  202. });
  203. });
  204. },
  205. // 微信付款
  206. wxPayCard: function (result) {
  207. let that = this;
  208. uni.requestPayment({
  209. timeStamp: result.timeStamp,
  210. nonceStr: result.nonceStr,
  211. package: result.package,
  212. signType: result.signType,
  213. paySign: result.paySign,
  214. success(res) {
  215. uni.showToast({
  216. title: '充值成功',
  217. icon: 'none'
  218. }); // 拉取余额和会员角色
  219. that.getUserInfo();
  220. },
  221. fail(res) {
  222. uni.showToast({
  223. title: '充值失败',
  224. icon: 'none'
  225. });
  226. console.log('报错信息', res);
  227. }
  228. });
  229. },
  230. // 充值记录
  231. goCashLog() {
  232. let that = this;
  233. uni.navigateTo({
  234. url: '/pages/user/cashlog/index'
  235. });
  236. }
  237. }
  238. };
  239. </script>
  240. <style>
  241. /**index.wxss**/
  242. .wrap {
  243. width: 750rpx;
  244. min-height: 100vh;
  245. background: #f6f6f6;
  246. }
  247. .wrap_nr {
  248. padding: 14rpx 30rpx 0;
  249. }
  250. .wrap_t {
  251. width: 690rpx;
  252. height: 225rpx;
  253. font-size: 30rpx;
  254. color: #000000;
  255. /* padding-left: 60rpx; */
  256. background-repeat: no-repeat;
  257. background-size: 690rpx 225rpx;
  258. display: flex;
  259. /* flex-direction: column; */
  260. align-items: center;
  261. justify-content: center;
  262. }
  263. .wrap_t .total_price {
  264. /* margin-top: 30rpx; */
  265. font-size: 48rpx;
  266. font-weight: 500;
  267. margin-left: 30rpx;
  268. }
  269. .wrap_t .total_price .unit {
  270. font-size: 30rpx;
  271. }
  272. .wrap_b {
  273. /* background: #FFFFFF; */
  274. margin-top: 24rpx;
  275. border-radius: 5rpx;
  276. }
  277. .card_top {
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. }
  282. .card_top .line_tu {
  283. width: 690rpx;
  284. height: 30rpx;
  285. }
  286. .wrap_b_t {
  287. width: 100%;
  288. padding: 30rpx 30rpx 10rpx;
  289. background: #ffffff;
  290. display: flex;
  291. align-items: center;
  292. justify-content: space-between;
  293. }
  294. .wrap_b_t .wrap_b_t_l {
  295. display: flex;
  296. align-items: center;
  297. }
  298. .wrap_b_t .item_icon {
  299. width: 48rpx;
  300. height: 36rpx;
  301. }
  302. .wrap_b_t .item_name {
  303. font-size: 30rpx;
  304. color: #000000;
  305. padding-left: 20rpx;
  306. }
  307. .wrap_b_t .wrap_b_t_r {
  308. font-size: 24rpx;
  309. color: rgba(0, 0, 0, 0.87);
  310. }
  311. .card_list {
  312. background: #ffffff;
  313. padding: 0 30rpx 10rpx;
  314. }
  315. .btn_wrap {
  316. margin-top: 90rpx;
  317. }
  318. .btn_wrap .btn {
  319. width: 405rpx;
  320. height: 98rpx;
  321. margin: 0 auto;
  322. background: #d54c43;
  323. border-radius: 10rpx;
  324. font-size: 28rpx;
  325. color: #fffefe;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. }
  330. </style>