index.vue 10 KB

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