gold_coin.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <!-- +---------------------------------------------------------------------- -->
  2. <!-- | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -->
  3. <!-- +---------------------------------------------------------------------- -->
  4. <!-- | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -->
  5. <!-- +---------------------------------------------------------------------- -->
  6. <!-- | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -->
  7. <!-- +---------------------------------------------------------------------- -->
  8. <!-- | Author: CRMEB Team <admin@crmeb.com> -->
  9. <!-- +---------------------------------------------------------------------- -->
  10. {extend name="public/container"}
  11. {block name="title"}{$gold_name}充值{/block}
  12. {block name="content"}
  13. <div v-cloak id="app">
  14. <div class="gold-coin">
  15. <div class="header">
  16. <div class="cont">
  17. <div class="text">
  18. 我的{{ gold_name }}
  19. <div class="num">{{ amount }}</div>
  20. </div>
  21. <a class="link" href="{:Url('my/gold_coin')}">明细</a>
  22. </div>
  23. </div>
  24. <div class="main">
  25. <!-- 数量选择 -->
  26. <div class="wrap select">
  27. <div class="head">数量选择</div>
  28. <div class="cont">
  29. <div class="list">
  30. <label v-for="(item, index) in updateOptions" :key="index" class="item">
  31. <input v-model="coinChecked" :value="index" type="radio" name="num">
  32. <div class="item-cont">
  33. <div class="text">
  34. <div :style="{ backgroundImage: 'url(' + gold_image + ')' }" class="num">{{ item.coin }}</div>
  35. {{ item.money }}元
  36. </div>
  37. </div>
  38. </label>
  39. </div>
  40. <label :class="{ checked: coinChecked === options.length }" class="input">
  41. <div class="cell">
  42. <input v-model.number="moneyInput" :class="{ on: !moneyInput }" type="number" @focus="inputFocus" @blur="inputBlur">
  43. </div>
  44. <div :style="{ backgroundImage: 'url(' + gold_image + ')' }" class="cell">{{ moneyToCoin }}</div>
  45. </label>
  46. </div>
  47. </div>
  48. <div class="handle">
  49. <button class="btn" type="button" @click="callPay">立即充值</button>
  50. </div>
  51. <!-- 支付弹窗 -->
  52. <pay-dialog
  53. :open.sync="payDialogOpen"
  54. :money="moneyPay"
  55. :now_money="now_money"
  56. :special_id="moneyPay"
  57. :pay_type_num="payTypeNum"
  58. :is-Wechat="isWechat"
  59. :is-alipay="is_alipay"
  60. :is-balance="is_yue"
  61. :wxpay-h5="wxpayH5"
  62. @change="changeVal"
  63. ></pay-dialog>
  64. <base-login :login-show="loginShow" :site-name="site_name" @login-close="logComplete"></base-login>
  65. </div>
  66. </div>
  67. <quick-menu></quick-menu>
  68. </div>
  69. <script>
  70. require(['vue', 'store', 'components/pay-dialog/index', 'components/base-login/index', 'quick'], function (Vue, store, PayDialog, BaseLogin) {
  71. var from = '{$from}';
  72. var stream_name = '{$stream_name}';
  73. var recharge_price_list = {$recharge_price_list};
  74. var gold_info = {$gold_info};
  75. var is_yue={$is_yue ? 'true' : 'false'};
  76. var now_money={$now_money};
  77. var is_alipay={$is_alipay ? 'true' : 'false'};
  78. var wxpayH5={$is_h5_wechat_payment_switch ? 'true' : 'false'};
  79. var callback_url = '{$callback_url}';
  80. var site_name = '{$Auth_site_name}';
  81. var app = new Vue({
  82. el: '#app',
  83. components: {
  84. 'pay-dialog': PayDialog,
  85. 'base-login': BaseLogin
  86. },
  87. data: {
  88. // 我的金币
  89. gold_name: gold_info.gold_name ? gold_info.gold_name : "金币",
  90. gold_image: gold_info.gold_image,
  91. amount: 0,
  92. // 换算率
  93. rate:gold_info.gold_rate ? gold_info.gold_rate : 10,
  94. // 金币选项
  95. options: recharge_price_list,
  96. // 选中金额
  97. coinChecked: 0,
  98. // 输入金额
  99. moneyInput: 0,
  100. // 支付方式选中项
  101. payChecked: 0,
  102. // 是否显示支付弹窗
  103. payDialogOpen: false,
  104. // 登录弹窗隐藏
  105. loginShow: false,
  106. loginUrl: '',
  107. siteName: '',
  108. payTypeNum:30,//金币充值
  109. is_alipay:is_alipay, //支付宝是否开启
  110. is_yue:is_yue, //余额是否开启
  111. now_money: now_money, //余额
  112. urlStr: '',
  113. from: from,
  114. streamName: stream_name,
  115. wxpayH5: wxpayH5,
  116. site_name: site_name
  117. },
  118. computed: {
  119. updateOptions: function () {
  120. var that = this,
  121. Obj = {},
  122. Arr = [];
  123. that.options.map(function (value) {
  124. Obj.coin = value;
  125. Obj.money = (value / that.rate).toFixed(2);
  126. Arr.push(Obj);
  127. Obj = {};
  128. });
  129. return Arr;
  130. },
  131. // 金额换算金币
  132. moneyToCoin: function () {
  133. return this.moneyInput * this.rate;
  134. },
  135. // 支付金额
  136. moneyPay: function () {
  137. return this.coinChecked == -1 ? this.moneyInput : this.options[this.coinChecked] / this.rate;
  138. },
  139. // 是否微信
  140. isWechat: function () {
  141. var agent = navigator.userAgent.toLowerCase();
  142. return agent.match(/MicroMessenger/i) == 'micromessenger';
  143. }
  144. },
  145. created: function () {
  146. this.my_user_gold_num();
  147. },
  148. methods: {
  149. // 获取我的金币总数
  150. my_user_gold_num: function () {
  151. var vm = this;
  152. store.baseGet($h.U({
  153. c: 'special',
  154. a: 'my_user_gold_num'
  155. }), function (res) {
  156. vm.amount = res.data.data.user_gold_num;
  157. });
  158. },
  159. getUrlStr: function (name) {
  160. var pattern = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'),
  161. array = document.location.search.slice(1).match(pattern);
  162. if (array) {
  163. return decodeURI(array[2]);
  164. }
  165. return null;
  166. },
  167. inputFocus: function () {
  168. this.coinChecked = -1;
  169. if (this.moneyInput) {
  170. this.moneyInput = ''
  171. }
  172. },
  173. inputBlur: function () {
  174. if (!this.moneyInput) {
  175. this.moneyInput = 0;
  176. this.coinChecked = 0;
  177. }
  178. },
  179. // 支付弹窗调起
  180. callPay: function () {
  181. var vm = this;
  182. if (this.coinChecked == -1) {
  183. if (this.moneyInput <= 0) {
  184. $h.pushMsg('请输入正确值');
  185. return;
  186. }
  187. }
  188. store.baseGet($h.U({
  189. c: 'index',
  190. a: 'user_login'
  191. }), function () {
  192. vm.payDialogOpen = true;
  193. }, function () {
  194. vm.loginShow = true;
  195. });
  196. },
  197. closeLogin: function (params) {
  198. if (typeof params !== 'object') {
  199. return;
  200. }
  201. switch (params.action) {
  202. case 'loginClose':
  203. this.loginShow = false;
  204. break;
  205. case 'logComplete':
  206. this.loginShow = false;
  207. this.payDialogOpen = true;
  208. break;
  209. }
  210. },
  211. logComplete: function (data) {
  212. var that = this;
  213. that.loginShow = false;
  214. if (!data) {
  215. return;
  216. }
  217. if (!data.isfollow && is_official_account_switch) {
  218. that.codeUrl = data.url;
  219. that.isfollow = true;
  220. } else {
  221. window.location.reload();
  222. }
  223. },
  224. //所有插件回调处理事件
  225. changeVal:function (opt){
  226. if(typeof opt !='object') opt={};
  227. var action=opt.action || '';
  228. var value=opt.value || '';
  229. this[action] && this[action](value);
  230. },
  231. pay_order: function (data) {
  232. this.orderId = data.data.result.orderId || '';
  233. switch (data.data.status) {
  234. case "PAY_ERROR": case 'ORDER_EXIST': case 'ORDER_ERROR':
  235. this.extendOrder(data.msg);
  236. break;
  237. case 'WECHAT_PAY':
  238. this.wechatPay(data.data.result.jsConfig);
  239. break;
  240. case 'WECHAT_H5_PAY':
  241. this.payDialogOpen=false;
  242. var callbackUrl = callback_url + '?type=4&id=0';
  243. var mwebUrl = data.data.result.jsConfig.mweb_url + '&redirect_url=' + encodeURIComponent(callbackUrl);
  244. window.location.href = mwebUrl;
  245. break;
  246. case 'SUCCESS':
  247. this.successOrder(data.data);
  248. break;
  249. case 'ZHIFUBAO_PAY':
  250. window.location.href = $h.U({m:'wap',c:'alipay', a: 'index', q: { info: data.data.result, params: 'recharge' } });
  251. break;
  252. }
  253. },
  254. wechatPay:function(config){
  255. var that = this;
  256. mapleWx($jssdk(),function(){
  257. this.chooseWXPay(config,function(){
  258. that.successOrder();
  259. },{
  260. fail:that.extendOrder,
  261. cancel:that.extendOrder
  262. });
  263. });
  264. },
  265. successOrder: function (data) {
  266. var that = this, msg, result;
  267. if (data) {
  268. msg = data.msg;
  269. result = data.result;
  270. that.payDialogOpen = false;
  271. $h.showMsg({
  272. title: msg ? msg : '支付成功',
  273. icon: 'success',
  274. success: function () {
  275. if (that.from == 'live') {
  276. window.location.href = $h.U({ c: 'live', a: 'index', q: { stream_name: that.streamName, record_id: that.RecordId } });
  277. } else {
  278. that.my_user_gold_num();
  279. }
  280. }
  281. });
  282. } else {
  283. window.location.reload();
  284. }
  285. },
  286. extendOrder:function(msg){
  287. if (typeof msg === 'object') {
  288. if (msg.errMsg === 'chooseWXPay:cancel') {
  289. msg = '微信支付取消';
  290. } else {
  291. msg = '支付失败';
  292. }
  293. } else {
  294. msg = '支付失败';
  295. }
  296. $h.pushMsg(msg, function () {
  297. window.location=$h.U({c:'special',a:'recharge_index'});
  298. });
  299. }
  300. }
  301. });
  302. });
  303. </script>
  304. {/block}