pay_wx.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <!DOCTYPE html>
  2. <html class="bg-white">
  3. <head>
  4. <meta charset="utf-8">
  5. <!--此行代码为禁止苹果手机自动识别电话号码-->
  6. <meta name="format-detection" content="telephone=no">
  7. <meta name="viewport"
  8. content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
  9. <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  10. <title>{{$shop_info['shop_name']}}支付</title>
  11. <link rel="stylesheet" type="text/css" href="{{asset('wap/css/weui.min.css')}}"/>
  12. <link rel="stylesheet" type="text/css" href="{{asset('wap/two/common.css')}}?t=121221"/>
  13. <link rel="stylesheet" type="text/css" href="{{asset('wap/two/pay-page.css')}}?t=43645645654654fdgfd"/>
  14. <link rel="stylesheet" type="text/css" href="{{asset('wap/two/keyboard.css')}}?t=4334543"/>
  15. <link rel="stylesheet" type="text/css" href="{{asset('wap/two/font/iconfont.css')}}"/>
  16. <script src="{{asset('wap/js/jquery-2.1.4.js')}}"></script>
  17. <script src="{{asset('wap/js/vue.js')}}?a=1"></script>
  18. <script src="{{asset('wap/js/jweixin-1.6.0.js')}}?a=1"></script>
  19. <script src="{{asset('wap/js/common.js')}}?a=1"></script>
  20. </head>
  21. <body>
  22. <div id="app">
  23. <!-- 导航栏 -->
  24. <div class="layout">
  25. <!-- 导航栏 -->
  26. <div class="nav-bar">
  27. <!-- <div>
  28. <img src="./images//组 49@2x.png" class="nav-img">
  29. </div> -->
  30. <div class="nav-title">{{$shop_info['shop_name']}}</div>
  31. <!-- <div>
  32. <img src="./images/组 117@2x.png" class="nav-img">
  33. </div> -->
  34. </div>
  35. <!-- 支付详情 -->
  36. <form id="zfb_pay" method="post" action="{{route('pay.zfb_pay')}}">
  37. <div class="pay-detail">
  38. <div class="pay-layout">
  39. <div class="spend-total">消费总额</div>
  40. <div class="input-money">
  41. <span>¥</span>
  42. <input type="text" disabled="disabled" v-model="pay_money" mix="0.01" ref="textarea" >
  43. <input type="hidden" name="shop_id" value="{{$shop_info['id']}}"></input>
  44. </div>
  45. <div class="prompt">可询问工作人员应缴费用总额</div>
  46. </div>
  47. </div>
  48. </form>
  49. <!-- button -->
  50. <div class="button-layout" @click="creatWxPay">
  51. <div class="button">
  52. <span>支付</span>
  53. </div>
  54. </div>
  55. <div class="block"></div>
  56. <div class="keyboard">
  57. <div class="one-row row">
  58. <div class="key" @click="pressKey('1')">1</div>
  59. <div class="key" @click="pressKey('2')">2</div>
  60. <div class="key" @click="pressKey('3')">3</div>
  61. </div>
  62. <div class="two-row row">
  63. <div class="key" @click="pressKey('4')">4</div>
  64. <div class="key" @click="pressKey('5')">5</div>
  65. <div class="key" @click="pressKey('6')">6</div>
  66. </div>
  67. <div class="three-row row">
  68. <div class="key" @click="pressKey('7')">7</div>
  69. <div class="key" @click="pressKey('8')">8</div>
  70. <div class="key" @click="pressKey('9')">9</div>
  71. </div>
  72. <div class="four-row row">
  73. <div class="key key-dot" @click="pressKey('.')"><div class="dot"></div></div>
  74. <div class="key" @click="pressKey('0')">0</div>
  75. <div class="key key-dot" @click="pressKey('x')" @touchstart="gtouchstart()" @touchmove="gtouchmove()" @touchend="gtouchend()"> <span class="iconfont icon-24gl-delete"></span></div>
  76. </div>
  77. </div>
  78. </div>
  79. <!--BEGIN toast-->
  80. <div id="toast" style="display: none;">
  81. <div class="weui-mask_transparent"></div>
  82. <div class="weui-toast">
  83. <i class="weui-icon-success-no-circle weui-icon_toast"></i>
  84. <p class="weui-toast__content">@{{success_msg}}</p>
  85. </div>
  86. </div>
  87. <!--BEGIN toast-->
  88. <div id="textMoreToast" v-show="error_show">
  89. <div class="weui-mask_transparent"></div>
  90. <div class="weui-toast weui-toast_text-more">
  91. <i class="weui-icon-warn weui-icon_toast"></i>
  92. <p class="weui-toast__content">@{{error_msg}}</p>
  93. </div>
  94. </div>
  95. </div>
  96. <script>
  97. $(function () {
  98. var vm = new Vue({
  99. el: '#app',
  100. data: {
  101. pay_money: '',
  102. payStr: '',
  103. success_msg: '',
  104. error_msg: '',
  105. error_show: false,
  106. success_show: false,
  107. is_pay: false,
  108. is_ajax: false,
  109. wx_config: {
  110. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  111. appId: "{{$wx_js['appid']}}", // 必填,公众号的唯一标识
  112. timestamp: {{$wx_js['timestamp']}}, // 必填,生成签名的时间戳
  113. nonceStr: "{{$wx_js['noncestr']}}", // 必填,生成签名的随机串
  114. signature: "{{$wx_js['signature']}}",// 必填,签名
  115. jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
  116. },
  117. defaultHeight: '0', //默认屏幕高度
  118. nowHeight: '0', //实时屏幕高度
  119. timeOutEvent: null,
  120. intervalEvent: null,
  121. },
  122. mounted() {
  123. //获取默认高度
  124. },
  125. methods: {
  126. 'gtouchstart': function () {
  127. this.timeOutEvent = setTimeout(function () {
  128. vm.longStatus = true;
  129. vm.intervalEvent = setInterval(function () {
  130. console.log('定时任务执行了')
  131. let ret= vm.pressKey('x')
  132. if(!ret){
  133. clearInterval(vm.intervalEvent);
  134. }
  135. console.log(ret)
  136. }, 100)
  137. }, 500);//这里设置定时器,定义长按500毫秒触发长按事件,时间可以自己改,个人感觉500毫秒非常合适
  138. return false;
  139. },
  140. //手释放,如果在500毫秒内就释放,则取消长按事件,此时可以执行onclick应该执行的事件
  141. 'gtouchend': function () {
  142. if(this.intervalEvent) clearInterval(this.intervalEvent);
  143. if(this.timeOutEvent) clearTimeout(this.timeOutEvent);//清除定时器
  144. return false;
  145. },
  146. //如果手指有移动,则取消所有事件,此时说明用户只是要移动而不是长按
  147. 'gtouchmove': function () {
  148. if(this.intervalEvent) clearInterval(this.intervalEvent);
  149. if(this.timeOutEvent) clearTimeout(this.timeOutEvent);//清除定时器
  150. return false;
  151. },
  152. 'pressKey': function (key) {
  153. if (key === 'x') {
  154. if (this.payStr.length <= 0) {
  155. return false;
  156. }
  157. this.payStr = this.payStr.substr(0, this.payStr.length - 1);
  158. }else {
  159. let dNum=this.payStr.indexOf(".");
  160. if(dNum>=0){
  161. if(this.payStr.length-dNum>=3){
  162. return false;
  163. }
  164. }
  165. if (key === '.') {
  166. if (dNum >= 0) {
  167. return false;
  168. }
  169. } else if(key==='0'){
  170. if(this.payStr.length===1 && this.payStr==='0'){
  171. return false;
  172. }
  173. }
  174. this.payStr = this.payStr + key;
  175. }
  176. this.pay_money= this.payStr;
  177. console.log(this.payStr)
  178. return true;
  179. },
  180. 'errorMgs': function (error_msg) {
  181. this.error_msg = error_msg;
  182. this.error_show = true;
  183. setTimeout(function () {
  184. vm.error_show = false;
  185. }, 2000)
  186. },
  187. 'successMsg': function (success_msg) {
  188. this.success_msg = success_msg;
  189. this.success_show = true;
  190. setTimeout(function () {
  191. vm.success_show = false;
  192. }, 2000)
  193. },
  194. 'startWx': function () {
  195. wx.config(this.wx_config);
  196. wx.error(function (res) {
  197. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  198. console.log(res);
  199. });
  200. },
  201. 'creatWxPay': function () {
  202. if (isNaN(this.pay_money) || this.pay_money * 1 < 0) {
  203. this.pay_money = '';
  204. this.errorMgs('支付金额不合法');
  205. return false;
  206. }
  207. if (this.pay_money * 1 < 0.01) {
  208. this.errorMgs('最低支付金额0.01元');
  209. return false;
  210. }
  211. if (this.is_ajax) {
  212. return false;
  213. }
  214. // this.is_ajax = true;
  215. let _that = this;
  216. sendAjax('{{route('pay.wx_pay')}}', {
  217. 'pay_money': this.pay_money,
  218. 'shop_id': '{{$shop_info['id']}}'
  219. }, function (data) {
  220. if (data.code * 1 == 1) {
  221. // return false;
  222. wx.chooseWXPay({
  223. timestamp: data.data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  224. nonceStr: data.data.nonceStr, // 支付签名随机串,不长于 32 位
  225. package: data.data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  226. signType: data.data.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
  227. paySign: data.data.paySign, // 支付签名
  228. success: function (res) {
  229. // 支付成功后的回调函数
  230. _that.successMsg('支付成功');
  231. setTimeout(function () {
  232. window.location.href = '{{route('pay.pay_end')}}?pay_id=' + data.data.order_id;
  233. }, 1500);
  234. }
  235. });
  236. } else {
  237. vm.is_ajax = false;
  238. vm.errorMgs(data.msg);
  239. }
  240. })
  241. }
  242. },
  243. watch: {
  244. 'pay_money': function () {
  245. if (this.pay_money * 1 == 0) {
  246. this.is_pay = false;
  247. return false;
  248. }
  249. if (this.pay_money != '') {
  250. }
  251. this.is_pay = true;
  252. }
  253. },
  254. created: function () {
  255. console.log('------------------')
  256. this.startWx();
  257. }
  258. });
  259. })
  260. </script>
  261. <script>
  262. (function (doc, win) {
  263. var docEl = win.document.documentElement;
  264. var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  265. var refreshRem = function () {
  266. var clientWidth = win.innerWidth ||
  267. doc.documentElement.clientWidth ||
  268. doc.body.clientWidth;
  269. console.log(clientWidth)
  270. if (!clientWidth) return;
  271. var fz;
  272. var width = clientWidth;
  273. fz = 16 * width / 375;
  274. docEl.style.fontSize = fz + 'px';
  275. };
  276. if (!doc.addEventListener) return;
  277. win.addEventListener(resizeEvt, refreshRem, false);
  278. doc.addEventListener('DOMContentLoaded', refreshRem, false);
  279. refreshRem();
  280. })(document, window)
  281. </script>
  282. </body>
  283. </html>