vip_center.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. mui.ready(function() {
  2. marquee_Show();
  3. getCartNum();
  4. mui.each(document.querySelectorAll('#menu-lease-other .mui-control-item'), function(index, el) {
  5. el.addEventListener('tap', function() {
  6. switch(index) {
  7. case 0:
  8. mui.openWindow({
  9. url: base_path + '/agentWechat/agentNext'
  10. });
  11. break;
  12. case 1:
  13. mui.openWindow({
  14. url: 'after_service_watero.html'
  15. });
  16. break;
  17. case 2:
  18. mui.confirm('服务时间:工作日9:00-18:00', '客服电话:<a>400-8006692</a>', ['取消', '拨打'], function(e) {
  19. if(e.index == 1) {
  20. location.href = 'tel:4008006692'
  21. }
  22. });
  23. break;
  24. case 3:
  25. mui.openWindow({
  26. url: 'faq.html'
  27. });
  28. break;
  29. default:
  30. break
  31. }
  32. }, false)
  33. });
  34. mui.each(document.querySelectorAll('#menu-nav .mui-control-item'), function(index, el) {
  35. var th = this;
  36. el.addEventListener('tap', function() {
  37. mui.openWindow({
  38. url: th.getAttribute("href")
  39. });
  40. }, false)
  41. });
  42. $.ajax(base_path + '/user/member?dates=' + new Date().getTime(), {
  43. dataType: 'json',
  44. type: 'post',
  45. timeout: 15000,
  46. xhrFields: {
  47. withCredentials: true
  48. },
  49. crossDomain: true,
  50. success: function(dt) {
  51. if(dt.isRedirect) {
  52. location.href = dt.redirectURL;
  53. } else {
  54. var data = dt.data;
  55. if(dt.status) {
  56. if(data.userHead != null && typeof(data.userHead) != "undefined" && data.userHead != '') {
  57. var imgObj = $("<img src='" + data.userHead + "?" + new Date().getTime() + "'/>");
  58. $("#headDiv").empty().append(imgObj)
  59. }
  60. if(data.userNickname != null && typeof(data.userNickname) != "undefined" && data.userNickname != '') {
  61. $("#userNickname").html(decodeURI(data.userNickname))
  62. }
  63. var userNickname = $("#userNickname").html();
  64. if(data.shareType != null && typeof(data.shareType) != "undefined" && data.shareType == 2) {
  65. $("#2WM").show();
  66. if(userNickname != "") {
  67. $("#userNickname").html(userNickname + "(会员)")
  68. }
  69. } else {
  70. if(userNickname != "") {
  71. $("#userNickname").html(userNickname + "(用户)")
  72. }
  73. }
  74. $.ajax({
  75. type: 'post',
  76. url: base_path + '/probationOrder/membersProbationOrder',
  77. data: {},
  78. dataType: 'json',
  79. timeout: 15000,
  80. xhrFields: {
  81. withCredentials: true
  82. },
  83. crossDomain: true,
  84. success: function(dts) {
  85. if(dts.isRedirect) {
  86. location.href = dts.redirectURL;
  87. } else {
  88. if(dts.status) {
  89. var str = '';
  90. if(dts.data.probationOrderDtoList.length == 0) {
  91. $("#try_order_list").hide()
  92. }
  93. mui(dts.data.probationOrderDtoList).each(function(index) {
  94. switch(this.probationStatus) {
  95. case 1:
  96. str = "待派送";
  97. break;
  98. case 2:
  99. str = "派送中";
  100. break;
  101. case 3:
  102. str = "待支付";
  103. break;
  104. case 4:
  105. str = "暂停试用";
  106. break;
  107. case 5:
  108. str = "支付完成";
  109. break;
  110. default:
  111. str = "订单关闭";
  112. break
  113. }
  114. var str1 = '',
  115. str2 = '';
  116. if(str == "待支付") {
  117. str1 = '<a data-loading-icon="mui-spinner mui-spinner-custom" data-loading-text="正在支付" class="mui-btn try-btn-pay mui-pull-right" style="margin-right: 12px;" proid="' + this.probationOrderid + '">立即支付</a>';
  118. str2 = '<div>试用剩余时间:<span id="time_out' + (index + 1) + '"></span></div>'
  119. }
  120. $("#try_order_list").append('<li class="mui-table-view-cell mui-media"><a class="go_try_order" proid="' + this.probationOrderid + '" style="margin-left: -20px;"><span class="mui-media-object mui-pull-left wh-80"><img src="' + this.productIntroduceImg + '"></span><div class="mui-media-body center-middle"><div>' + str + '</div><div>订单号:' + this.probationOrderid + '</div>' + str2 + '</div></a><div class="btn-box">' + str1 + '</div></li>');
  121. if(str == "待支付") {
  122. addTimer('time_out' + (index + 1), this.probationRemainingTime / 1000)
  123. }
  124. })
  125. } else {
  126. mui.alert(dts.data.message)
  127. }
  128. }
  129. },
  130. error: function(xhr, type, errorThrown) {
  131. console.log(xhr);
  132. mui.alert("请检查网络或刷新页面重试!")
  133. }
  134. });
  135. document.querySelector('.loading-bg').style.display = 'none'
  136. } else {
  137. var btnArray = ['否', '是'];
  138. mui.confirm(dt.message, '提示', btnArray, function(e) {
  139. if(e.index == 1) {
  140. location.reload(true)
  141. }
  142. })
  143. }
  144. }
  145. },
  146. error: function(xhr, type, errorThrown) {
  147. console.log(xhr)
  148. }
  149. });
  150. if(marquee != '') {
  151. $('body').append('<div class="marquee-show"><div></div></div>')
  152. }
  153. });
  154. mui('body').on('tap', '#rent_wait_deliver', function() {
  155. mui.openWindow({
  156. url: '/watero/view/rent/lease_order_details.html?rentStatus=-1'
  157. })
  158. });
  159. mui('body').on('tap', '#rent_already_deliver', function() {
  160. mui.openWindow({
  161. url: '/watero/view/rent/lease_order_details.html?rentStatus=5'
  162. })
  163. });
  164. mui('body').on('tap', '.icon-shebeiliebiao', function() {
  165. mui.openWindow({
  166. url: '/watero/view/rent/my_equipment.html'
  167. })
  168. });
  169. mui('body').on('tap', '#xieyi-dalog', function() {
  170. mui.openWindow({
  171. url: '/watero/view/rent/try_xieyi.html'
  172. });
  173. });
  174. mui('body').on('tap', '.go_try_order', function() {
  175. mui.openWindow({
  176. url: base_path + '/probation/try_order?orderId=' + this.getAttribute("proid")
  177. })
  178. });
  179. var isPay = true;
  180. mui('body').on('tap', '.try-btn-pay', function() {
  181. var th = this;
  182. if(isPay) {
  183. mui(this).button('loading');
  184. isPay = false;
  185. $.ajax({
  186. type: 'post',
  187. url: base_path + '/probation/pay',
  188. data: {
  189. "orderId": th.getAttribute("proid")
  190. },
  191. dataType: 'json',
  192. timeout: 15000,
  193. xhrFields: {
  194. withCredentials: true
  195. },
  196. crossDomain: true,
  197. success: function(dt) {
  198. if(dt.isRedirect) {
  199. location.href = dt.redirectURL;
  200. } else {
  201. if(dt.status) {
  202. var obj = JSON.parse("{" + dt.data.info + "}");
  203. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  204. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  205. $.ajax({
  206. type: 'post',
  207. url: base_path + '/probation/check_probation_pay_success',
  208. data: {
  209. "orderId": th.getAttribute("proid")
  210. },
  211. dataType: 'json',
  212. timeout: 15000,
  213. xhrFields: {
  214. withCredentials: true
  215. },
  216. crossDomain: true,
  217. success: function(data) {
  218. if(data.isRedirect) {
  219. location.href = data.redirectURL;
  220. } else {
  221. if(data.status) {
  222. if(data.data == 5) {
  223. mui.alert("支付成功", '', function() {
  224. mui.openWindow({
  225. url: base_path + '/probation/try_order?orderId=' + th.getAttribute("proid")
  226. })
  227. })
  228. } else {
  229. mui.alert(data.message, '', function() {
  230. mui(th).button('reset')
  231. })
  232. }
  233. } else {
  234. mui(th).button('reset');
  235. mui.alert(data.message)
  236. }
  237. }
  238. },
  239. error: function(xhr, type, errorThrown) {
  240. isPay = true;
  241. console.log(xhr);
  242. mui(th).button('reset');
  243. mui.alert("请检查网络或刷新页面重试!")
  244. }
  245. })
  246. } else {
  247. isPay = true;
  248. mui(th).button('reset');
  249. mui.alert("对不起,支付失败!请稍后重试!")
  250. }
  251. })
  252. } else {
  253. mui(th).button('reset');
  254. mui.alert(dt.message)
  255. }
  256. }
  257. },
  258. error: function(xhr, type, errorThrown) {
  259. isPay = true;
  260. console.log(xhr);
  261. mui(th).button('reset');
  262. mui.alert("请检查网络或刷新页面重试!")
  263. }
  264. })
  265. } else {
  266. mui.alert("正在请求支付中~~请稍后!");
  267. return
  268. }
  269. });
  270. var addTimer = function() {
  271. var list = [],
  272. interval;
  273. return function(id, time) {
  274. if(!interval) {
  275. interval = setInterval(go, 1000)
  276. }
  277. list.push({
  278. ele: document.getElementById(id),
  279. time: time
  280. })
  281. };
  282. function go() {
  283. for(var i = 0; i < list.length; i += 1) {
  284. list[i].ele.innerHTML = getTimerString(list[i].time ? list[i].time -= 1 : 0);
  285. if(!list[i].time) {
  286. list.splice(i--, 1)
  287. }
  288. }
  289. }
  290. function getTimerString(time) {
  291. d = Math.floor(time / 86400), h = Math.floor((time % 86400) / 3600), m = Math.floor(((time % 86400) % 3600) / 60), s = Math.floor(((time % 86400) % 3600) % 60);
  292. if(time > 0) {
  293. return d + "天" + h + "时" + m + "分" + s + "秒"
  294. } else {
  295. return "试用已结束"
  296. }
  297. }
  298. }();