gold_coin.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. {extend name="public/container"}
  2. {block name="title"}{$gold_name}充值{/block}
  3. {block name="content"}
  4. <div v-cloak id="app">
  5. <div class="gold-coin">
  6. <div class="header">
  7. <div class="cont">
  8. <div class="text">
  9. 我的{{ gold_name }}
  10. <div class="num">{{ amount }}</div>
  11. </div>
  12. <a class="link" href="{:Url('my/gold_coin')}">明细</a>
  13. </div>
  14. </div>
  15. <div class="main">
  16. <!-- 数量选择 -->
  17. <div class="wrap select">
  18. <div class="head">数量选择</div>
  19. <div class="cont">
  20. <div class="list">
  21. <label v-for="(item, index) in updateOptions" :key="index" class="item">
  22. <input v-model="coinChecked" :value="index" type="radio" name="num">
  23. <div class="item-cont">
  24. <div class="text">
  25. <div :style="{ backgroundImage: 'url(' + gold_image + ')' }" class="num">{{ item.coin }}</div>
  26. {{ item.money }}元
  27. </div>
  28. </div>
  29. </label>
  30. </div>
  31. <label :class="{ checked: coinChecked === options.length }" class="input">
  32. <div class="cell">
  33. <input v-model.number="moneyInput" :class="{ on: !moneyInput }" type="number" @focus="inputFocus" @blur="inputBlur">
  34. </div>
  35. <div :style="{ backgroundImage: 'url(' + gold_image + ')' }" class="cell">{{ moneyToCoin }}</div>
  36. </label>
  37. </div>
  38. </div>
  39. <div class="handle">
  40. <button class="btn" type="button" @click="callPay">立即充值</button>
  41. </div>
  42. <payment @change="changeVal" :payment="payHide" :money="moneyPay" :now_money="now_money" :special_id="moneyPay" :pay_type_num="payTypeNum" :isYue="is_yue" :isAlipay="is_alipay" :iswechat="isWechat" @change="closePay"></payment>
  43. <enter :appear="loginHide" :url="loginUrl" :site-name="siteName" @change="closeLogin"></enter>
  44. </div>
  45. </div>
  46. <shortcut></shortcut>
  47. </div>
  48. <script>
  49. var from = '{$from}';
  50. var stream_name = '{$stream_name}';
  51. var recharge_price_list = {$recharge_price_list};
  52. var gold_info = {$gold_info};
  53. var user_gold_num = {$user_gold_num};
  54. var is_yue={$is_yue ? 'true' : 'false'};
  55. var now_money={$now_money};
  56. var is_alipay={$is_alipay ? 'true' : 'false'};
  57. require(['vue', 'store', '{__WAP_PATH}zsff/js/payment.js', '{__WAP_PATH}zsff/js/enter.js', '{__WAP_PATH}zsff/js/shortcut.js'], function (Vue, store) {
  58. var app = new Vue({
  59. el: '#app',
  60. data: {
  61. // 我的金币
  62. gold_name: gold_info.gold_name ? gold_info.gold_name : "金币",
  63. gold_image: gold_info.gold_image,
  64. amount: user_gold_num ? user_gold_num : 0,
  65. // 换算率
  66. rate:gold_info.gold_rate ? gold_info.gold_rate : 10,
  67. // 金币选项
  68. options: recharge_price_list,
  69. // 选中金额
  70. coinChecked: 0,
  71. // 输入金额
  72. moneyInput: 0,
  73. // 支付方式选中项
  74. payChecked: 0,
  75. // 支付弹窗隐藏
  76. payHide: true,
  77. // 登录弹窗隐藏
  78. loginHide: true,
  79. loginUrl: '',
  80. siteName: '',
  81. payTypeNum:30,//金币充值
  82. is_alipay:is_alipay, //支付宝是否开启
  83. is_yue:is_yue, //余额是否开启
  84. now_money: now_money, //余额
  85. urlStr: '',
  86. from: from,
  87. streamName: stream_name
  88. },
  89. computed: {
  90. updateOptions: function () {
  91. var that = this,
  92. Obj = {},
  93. Arr = [];
  94. that.options.map(function (value) {
  95. Obj.coin = value;
  96. Obj.money = (value / that.rate).toFixed(2);
  97. Arr.push(Obj);
  98. Obj = {};
  99. });
  100. return Arr;
  101. },
  102. // 金额换算金币
  103. moneyToCoin: function () {
  104. return this.moneyInput * this.rate;
  105. },
  106. // 支付金额
  107. moneyPay: function () {
  108. return this.coinChecked === this.options.length ? this.moneyInput : this.options[this.coinChecked] / this.rate;
  109. },
  110. // 是否微信
  111. isWechat: function () {
  112. var agent = navigator.userAgent.toLowerCase();
  113. return agent.match(/MicroMessenger/i) == 'micromessenger';
  114. }
  115. },
  116. methods: {
  117. getUrlStr: function (name) {
  118. var pattern = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'),
  119. array = document.location.search.slice(1).match(pattern);
  120. if (array) {
  121. return decodeURI(array[2]);
  122. }
  123. return null;
  124. },
  125. inputFocus: function () {
  126. this.coinChecked = this.options.length;
  127. if (!this.moneyInput) {
  128. this.moneyInput = '';
  129. }
  130. },
  131. inputBlur: function () {
  132. if (!this.moneyInput) {
  133. this.coinChecked = 0;
  134. this.moneyInput = 0;
  135. }
  136. },
  137. // 支付弹窗调起
  138. callPay: function () {
  139. var that = this;
  140. if (this.coinChecked === this.options.length) {
  141. if ((String(this.moneyInput).indexOf('.') + 1) > 0) {
  142. return $h.pushMsgOnce('请输入整数');
  143. }
  144. }
  145. store.baseGet($h.U({ c: 'index', a: 'user_login' }), function () { that.payHide = false; }, function () {
  146. that.loginHide = false;
  147. });
  148. },
  149. //关闭支付
  150. payClose:function(value){
  151. this.payHide=value;
  152. },
  153. closeLogin: function (params) {
  154. if (typeof params !== 'object') {
  155. return;
  156. }
  157. switch (params.action) {
  158. case 'loginClose':
  159. this.loginHide = true;
  160. break;
  161. case 'logComplete':
  162. this.loginHide = true;
  163. this.payHide = false;
  164. break;
  165. }
  166. },
  167. //所有插件回调处理事件
  168. changeVal:function (opt){
  169. if(typeof opt !='object') opt={};
  170. var action=opt.action || '';
  171. var value=opt.value || '';
  172. this[action] && this[action](value);
  173. },
  174. pay_order: function (data) {
  175. this.orderId = data.result.orderId || '';
  176. switch (data.status) {
  177. case "PAY_ERROR": case 'ORDER_EXIST': case 'ORDER_ERROR':
  178. this.extendOrder(data.msg);
  179. break;
  180. case 'WECHAT_PAY':
  181. this.wechatPay(data.result.jsConfig);
  182. break;
  183. case 'SUCCESS':
  184. this.successOrder(data);
  185. break;
  186. case 'ZHIFUBAO_PAY':
  187. window.location.href = $h.U({ c: 'Alipay', a: 'index', q: { info: data.result, params: 'recharge' } });
  188. break;
  189. }
  190. },
  191. wechatPay:function(config){
  192. var that = this;
  193. mapleWx($jssdk(),function(){
  194. this.chooseWXPay(config,function(){
  195. that.successOrder();
  196. },{
  197. fail:that.extendOrder,
  198. cancel:that.extendOrder
  199. });
  200. });
  201. },
  202. successOrder: function (data) {
  203. var that = this,
  204. msg,
  205. result;
  206. if (data) {
  207. msg = data.msg;
  208. result = data.result;
  209. that.payHide = true;
  210. $h.showMsg({
  211. title: msg ? msg : '支付成功',
  212. icon: 'success',
  213. success: function () {
  214. that.amount += result.price * result.rate;
  215. window.location.href = that.from === 'live' ? $h.U({ c: 'live', a: 'index', q: { stream_name: that.streamName, record_id: that.RecordId } }) : $h.U({ c: 'special', a: 'recharge_index' });
  216. }
  217. });
  218. } else {
  219. window.location.reload();
  220. }
  221. },
  222. extendOrder:function(msg){
  223. var that=this;
  224. var msg=msg ? msg :'支付失败';
  225. $h.showMsg({
  226. title:typeof msg=='object' ? '支付失败' :msg,
  227. success:function () {
  228. window.location.href=$h.U({c:'special',a:'recharge_index'});
  229. }
  230. })
  231. },
  232. }
  233. });
  234. });
  235. </script>
  236. {/block}