i_want_to_renew.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>我要续租</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" type="text/css" href="/css/mui.min.css">
  10. <link rel="stylesheet" type="text/css" href="/css/iconfont.css" />
  11. <link rel="stylesheet" type="text/css" href="/css/style.css" />
  12. <style>
  13. .my-bar-nav {top: 0;-webkit-box-shadow: 0 0 0 #ccc;box-shadow: 0 0 0 #ccc;background: #fff;}
  14. .my-bar-nav .mui-btn-link{color: #1cc9f4;font-size: 14px;}
  15. .my-btn-bluetooth{color: #1cc9f4;padding:2px 18px;font-size: 15px;border-color: #1cc9f4;}
  16. .my-table-noline:after,.my-table-noline:before,.my-table-noline li:after,.my-table-noline:before{display: none;}
  17. .mui-btn-link{color: #1cc9f4;}
  18. .my-btn-water-quality{padding:6px 38px;font-size: 15px;}
  19. .my-btn-water-quality.active{border: 1px solid rgba(78,215,249,.5);color: #1cc9f4;}
  20. .year-list{width: 100%;}
  21. .year-list>li{float: left;width: 22%;text-align: center;color: #1cc9f4;}
  22. .year-list>li:first-child{text-align: left;width: 17%;}
  23. .year-list>li:last-child{text-align: right;width: 17%;}
  24. .mui-input-row.mui-input-range{padding-right: 0;}
  25. .my-select {border:0!important;color: #999;background-color: #f5f5f5;margin-bottom: 0;padding: 3px 14px;text-align: center;-webkit-appearance: none;height: 40px;}
  26. .after{padding: 0 11px;position: relative;}
  27. .after:before{content:'';position:absolute;right: 20px;top: 16px;width: 0;height: 0;border-left: 4px solid transparent;border-right: 4px solid transparent;border-top: 7px solid #666;}
  28. .my-view1:after,.my-view1 li:after{display: none;}
  29. .loading{position: fixed;display:none;left: 0;top: 0;right: 0;bottom: 0;width: 100%;height: 100%;background: rgba(0,0,0,.8);color: #fff;text-align: center;padding-top: 50%;font-size: 18px;}
  30. /* 设定WebKit浏览器下range */
  31. /*拖动块的样式*/
  32. .mui-input-range input[type=range]::-webkit-slider-thumb {
  33. -webkit-appearance: none;/*清除系统默认样式*/
  34. height: 26px;/*拖动块高度*/
  35. width: 26px;/*拖动块宽度*/
  36. background: #1cc9f4;/*拖动块背景*/
  37. border-radius: 50%; /*外观设置为圆形*/
  38. border: solid 1px #ddd; /*设置边框*/
  39. }
  40. /*横条样式*/
  41. input[type=range] {
  42. -webkit-appearance: none;/*清除系统默认样式*/
  43. width: 100%;
  44. background: -webkit-linear-gradient(#1cc9f4, #1cc9f4) no-repeat, #ddd;/*设置左边颜色为#61bd12,右边颜色为#ddd*/
  45. background-size: 0% 100%;/*设置左右宽度比例*/
  46. height: 3px;/*横条的高度*/
  47. }
  48. </style>
  49. <script>
  50. // 屏蔽分享
  51. window.hiddenAllWechatMenu = true;
  52. </script>
  53. </head>
  54. <body style="background: #fff;">
  55. <div class="loading-bg">
  56. <div class="mui-loading">
  57. <div class="mui-spinner">
  58. </div>
  59. &nbsp;&nbsp;加载中...
  60. </div>
  61. </div>
  62. <div class="mui-content" style="background: #fff;">
  63. <ul class="mui-table-view mui-text-center my-table-noline">
  64. <li class="mui-table-view-cell">
  65. <span id="machineStopDate" class="mui-h6" ></span>
  66. </li>
  67. <li class="mui-table-view-cell">
  68. <img src="//s.iamberry.com/watero/images/shop/my_equipment.png" width="50%" />
  69. <span id="machineNO" style="position: absolute;color: #fff;left: 50%;top: 70%;-webkit-transform: translateX(-50%);"></span>
  70. </li>
  71. <li class="mui-table-view-cell">
  72. <button type="button" id="machineConnectState" class="my-btn-bluetooth mui-btn-link">
  73. 未连接
  74. </button>
  75. </li>
  76. <li class="mui-table-view-cell" style="padding: 0 35px;">
  77. <div class="mui-input-row mui-input-range">
  78. <input type="range" id='block-range' name="rechargeDuration" value="1" min="1" max="5" >
  79. </div>
  80. <ul class="year-list">
  81. <li>1年</li>
  82. <li>2年</li>
  83. <li>3年</li>
  84. <li>4年</li>
  85. <li>5年</li>
  86. </ul>
  87. </li>
  88. <li class="mui-table-view-cell mui-text-left">
  89. <span class="mui-h5">服务费:</span><span class="cl-red" id="serviceCharge">¥799 元</span><span class="mui-h6 mui-pull-right">到期时间:<span id="rechargeStopDate"></span></span>
  90. </li>
  91. <li class="mui-table-view-cell" style="text-align: left;">
  92. <span class="mui-h6">使用抵扣券</span>
  93. </li>
  94. <li class="after">
  95. <select class="my-select" id="couponSelect" name="couponId">
  96. </select>
  97. </li>
  98. <li class="mui-table-view-cell" style="text-align: left;">
  99. <div><span class="mui-h6">抵扣金额:</span><span id="couponMoney" class="cl-red mui-pull-right">- ¥0 元</span></div>
  100. </li>
  101. <li class="mui-table-view-cell">
  102. 支付金额:<span class="cl-red" id="payCharge">¥799 元</span>
  103. </li>
  104. <li class="mui-table-view-cell">
  105. <button id="sbumitRent" type="button" data-loading-icon="mui-spinner mui-spinner-custom" data-loading-text="支付中,请稍候" class="" disabled>
  106. 确认续租
  107. </button>
  108. </li>
  109. <li class="mui-table-view-cell">
  110. <a id="toRechargeLog" style="text-decoration: underline;font-size: 13px;color: #999;">续租记录</a>
  111. </li>
  112. </ul>
  113. </div>
  114. <div class="loading">
  115. 支付中,请稍候<span class="dian">...</span>
  116. </div>
  117. <script src="/js/mui.min.js"></script>
  118. <script src="/js/jquery-2.1.1.min.js"></script>
  119. <script src="/js/shop/main.js"></script>
  120. <!-- <script src="/js/shop/wechat-utils-1.0.js"></script> -->
  121. <script src="/js/shop/layer.js"></script>
  122. <script src="/js/wechat_iot.js?v=6734343"></script>
  123. <script type="text/javascript">
  124. var machineDeviceId = '',machineId = '',couponId = '',stopDate = '';
  125. var rechargeOrderId = '', payUrl = '';
  126. var payData = {};
  127. var yearNum = 1;//最后要充值的年数
  128. var isPay = true;
  129. //每充一年需要多少钱 最后要充值的费用 优惠金额
  130. var payMoneyOne = 799, payMoney = 799,couponMoney = 0;
  131. mui.ready(function(){
  132. machineId = getParam("machineId");
  133. $('#block-range').val(1);
  134. initMachine(machineId);
  135. //判断机器是否在线
  136. setTimeout("myInterval()",3000);//1000为1秒钟
  137. document.querySelector('.loading-bg').style.display='none';
  138. });
  139. function myInterval(){
  140. sendMsgAndReceiveData(machineDeviceId,"*getData#",function(state,res){
  141. if(200 == state){
  142. //1.去掉遮罩
  143. document.querySelector('.loading-bg').style.display='none';
  144. //2.“确认续租”按钮亮起
  145. $("#sbumitRent").addClass("my-btn-water-quality");
  146. $("#sbumitRent").addClass("active");
  147. $("#sbumitRent").removeAttr("disabled");
  148. }
  149. if(500 == state){
  150. //1.去掉遮罩
  151. document.querySelector('.loading-bg').style.display='none';
  152. //2.弹框该机器不可续费
  153. $("#sbumitRent").prop("disabled","disabled");
  154. $("#machineConnectState").text('未连接');
  155. }
  156. });
  157. }
  158. /**
  159. * 初始化服务费抵扣券下拉框和机器信息
  160. */
  161. function initMachine(machineId){
  162. mui.ajax(base_path + '/machine/get_coupons_machine?dates=' + new Date().getTime(), {
  163. data:{
  164. "machineId":machineId
  165. },
  166. dataType:'json',
  167. type:'post',
  168. timeout:15000,
  169. success: function(dt) {
  170. if(dt.isRedirect) {
  171. location.href = dt.redirectURL;
  172. } else {
  173. if(dt.resultCode == 200 && dt.returnCode == 200){
  174. var couponList = dt.returnMsg.couponList;
  175. var machine = dt.returnMsg.machine;
  176. machineDeviceId = machine.machineDeviceId;
  177. stopDate = machine.machineStopDate;
  178. $("#machineStopDate").text(stopDate + ' 到期');
  179. $("#rechargeStopDate").text(addYears(stopDate,1));
  180. $("#machineNO").text("NO." + (10000 + parseInt(machineId)));
  181. if(machine.machineConnectState == 1){
  182. $("#machineConnectState").text('已连接');
  183. }else{
  184. $("#machineConnectState").text('未连接');
  185. }
  186. var couponSelect = $("#couponSelect");
  187. if(couponList.length == 0){
  188. $("#couponSelect").append('<option value="0">没有可用的抵扣券</option>');
  189. }else{
  190. couponSelect.append('<option serviceMoney="0" value="0">请选择抵扣券</option>');
  191. mui(couponList).each(function(index) {
  192. couponSelect.append('<option value="' + this.serviceId + '" serviceMoney="' + accDiv(this.serviceMoney,100) + '">' + this.serviceName + '</option>');
  193. });
  194. }
  195. }else{
  196. mui.alert("该机器不可以续费!请选择正确的机器!");
  197. }
  198. }
  199. },
  200. error:function(xhr, type, errorThrown){
  201. console.log(xhr);
  202. mui.alert("该机器不可以续费!!");
  203. }
  204. });
  205. }
  206. /**
  207. * 点击年数进度条点击事件
  208. */
  209. document.getElementById('block-range').addEventListener('input',function(){
  210. document.getElementById('block-range').value = this.value;
  211. //修改服务费、到期时间
  212. yearNum = parseInt(this.value);
  213. this.style.backgroundSize= (yearNum - 1) * 25 + "% 100%";
  214. payMoney = yearNum * payMoneyOne;
  215. //year_num = yearNum;
  216. $("#serviceCharge").text('¥' + payMoney + ' 元');
  217. $("#payCharge").text('¥' + (payMoney - couponMoney) + ' 元');
  218. $("#rechargeStopDate").text(addYears(stopDate,yearNum));
  219. });
  220. /**
  221. * 抵扣券下拉框change事件
  222. */
  223. $('#couponSelect').change(function(){
  224. couponMoney = $($('#couponSelect option')[$(this)[0].selectedIndex]).attr("serviceMoney");
  225. $('#couponMoney').text('-¥' + couponMoney + ' 元');
  226. $("#payCharge").text('¥' + (payMoney - couponMoney) + ' 元');
  227. couponId = this.value;
  228. });
  229. /**
  230. * 立即续费
  231. * 校验机器在线、获取预支付id、发起支付
  232. */
  233. mui('body').on('tap', '#sbumitRent', function() {
  234. sendMsgAndReceiveData(machineDeviceId,"*getData#",function(state,res){
  235. if(200 == state){
  236. toPay();
  237. }
  238. if(500 == state){
  239. mui.alert("请保持机器在线!");
  240. }
  241. });
  242. });
  243. function toPay(){
  244. if(rechargeOrderId == ''){
  245. payUrl = base_path + '/machine/machine_pay?dates=';
  246. payData = {
  247. "machineId":machineId,
  248. "year_num":yearNum,
  249. "couponId":couponId
  250. };
  251. }else{
  252. payUrl = base_path + '/machine/recharge_pay?dates=';
  253. payData = {"orderId":rechargeOrderId};
  254. }
  255. if(isPay) {
  256. isPay = false;
  257. layer.open({
  258. type: 2,
  259. shadeClose: false,
  260. content: "正在请求加载订单信息..."
  261. }); // 调用加载弹出层
  262. mui.ajax(payUrl + new Date().getTime(), {
  263. data:payData,
  264. dataType:'json',
  265. type:'post',
  266. timeout:15000,
  267. success: function(dt) {
  268. layer.closeAll();
  269. if(dt.resultCode == 200 && dt.returnCode == 200){
  270. $('#couponSelect').css("display","none");
  271. $("#block-range").prop("disabled","disabled");
  272. var dataObj = dt.returnMsg;
  273. rechargeOrderId = dataObj.returnMsg;
  274. var obj = JSON.parse("{" + dataObj.wechat_pay_id + "}");
  275. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  276. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  277. layer.open({
  278. type: 2,
  279. shadeClose: false,
  280. content: "正在请求加载订单信息..."
  281. }); // 调用加载弹出层
  282. $.ajax({
  283. type: 'post',
  284. url: base_path + '/machine/check_recharge_pay_status',
  285. data: {"rechargeOrderId":rechargeOrderId},
  286. dataType: 'json',
  287. timeout: 15000,
  288. success: function(data) {
  289. //console.log(data);
  290. if(data.status) {
  291. if(data.data.rechargeState == 1){
  292. isPay = true;
  293. //mui.alert("支付成功!跳转到我的设备!");
  294. mui.openWindow({url:'my_equipment.html'});
  295. }else{
  296. mui.alert('如果已支付,请等待同步支付状态!', '', function() {
  297. isPay = true;
  298. });
  299. }
  300. } else {
  301. isPay = true;
  302. mui.alert(data.message);
  303. }
  304. },
  305. error: function(xhr, type, errorThrown) {
  306. //异常处理;
  307. console.log(xhr);
  308. isPay = true;
  309. mui.alert("请检查网络或刷新页面重试!");
  310. }
  311. });
  312. } else {
  313. isPay = true;
  314. mui.alert("对不起,支付失败!请稍后重试!");
  315. }
  316. });
  317. }else{
  318. //console.log(xhr);
  319. isPay = true;
  320. mui.alert("该机器不可以续费!请确保机器已经激活并连接!");
  321. }
  322. },
  323. error:function(xhr, type, errorThrown){
  324. console.log(xhr);
  325. layer.closeAll();
  326. isPay = true;
  327. mui.alert("支付失败!请检查网络或刷新页面重试!");
  328. }
  329. });
  330. } else{
  331. mui.alert("正在请求支付中~~请稍后!");
  332. return;
  333. }
  334. }
  335. mui('body').on('tap', '#toRechargeLog', function() {
  336. window.location.href = 'renew_logs.html?machineId=' + machineId;
  337. });
  338. /**
  339. * 给日期字符串增加年
  340. */
  341. function addYears(dateStr,years){
  342. var date = new Date(Date.parse(stopDate.replace(/-/g, "/")));
  343. var yearStr = date.getFullYear() + years;
  344. var otherStr = dateStr.substring(4,dateStr.length);
  345. return yearStr + otherStr;
  346. }
  347. </script>
  348. </body>
  349. </html>