function.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. //个人信息初始化
  2. function load(){
  3. layer.load(3);
  4. $.ajax({
  5. url: "/personal/getPresonalMessage",
  6. type: "get",
  7. data: {},
  8. headers: {"token": localStorage.getItem("token")},
  9. dataType: "json",
  10. success: (data) => {
  11. if(data.msg == "200"){
  12. $(".name_div_val").find("div").html(data.data.name);
  13. $(".buy_account").html("充值人:    " + data.data.name);
  14. $(".phoen_left").find(".phone_val").html(data.data.phone );
  15. $(".account_div .blance_content").find("p").html(data.data.balanceOf);
  16. $(".permissions_div .blance_content").find("p").html(data.data.offerNum);
  17. $(".headpir_img").attr("src", data.data.headpir);
  18. //首页报价单权限余额 账户信息业务无用
  19. $(".offer_num_div .balance_of_fount").find("p").html(data.data.offerNum);
  20. //收支明细
  21. $(".bottom_content div").remove();
  22. $.each(data.payments.data, (index, item) => {
  23. var totalFee = item.total_fee;//付款金额
  24. var refundFee = item.refund_fee == undefined ? 0 : item.refund_fee;//退款金额
  25. var percentageFee = data.system.percentage_fee;
  26. //平台手续费,付款金额 - 退款金额 - (付款金额 * 平台手续费) = 实际收入
  27. var income = (totalFee - refundFee) == 0 ? (totalFee - refundFee) : (totalFee - refundFee - (totalFee * percentageFee))
  28. $(".bottom_content").append("<div class=\"content_div_font\" uuid=\""+ item.uuid +"\">\n" +
  29. " <div class=\"date_detail\">"+ item.jdrq +"</div>\n" +
  30. " <div class=\"content_detail\">"+ item.offer_name +"</div>\n" +
  31. " <div class=\"amount_detail\">¥"+ income.toFixed(2) +"</div>\n" +
  32. " </div>");
  33. });
  34. }
  35. layer.closeAll("loading");
  36. },
  37. error: () => {
  38. layer.closeAll("loading");
  39. layer.alert("网络错误 请联系管理员");
  40. }
  41. });
  42. }
  43. //充值弹框
  44. function topUp(){
  45. topUpNum();//次数渲染 余额渲染
  46. layer.open({
  47. type: 1,
  48. title: false,
  49. shadeClose: true,
  50. anim: 1,
  51. closeBtn: 0,
  52. area: ['auto', '700px'],
  53. content: $(".top_up_div"),
  54. end: () => {
  55. clearInterval(runInterval);
  56. $("#qrcode").find("img").remove();
  57. $("input[name=totalFee]").val("");
  58. runInterval = null;
  59. },
  60. cancel: () => {
  61. clearInterval(runInterval);
  62. $("#qrcode").find("img").remove();
  63. $("input[name=totalFee]").val("");
  64. runInterval = null;
  65. }
  66. });
  67. }
  68. //权限购买弹框
  69. function buyPermissions(){
  70. getByNumber();
  71. layer.open({
  72. type: 1,
  73. title: false,
  74. shadeClose: true,
  75. anim: 1,
  76. closeBtn: 0,
  77. area: ['auto', '700px'],
  78. content: $(".quotation_number"),
  79. end: () => {
  80. clearInterval(offerNumPayRunInterval);
  81. offerNumPayRunInterval = null;
  82. getByNumber();
  83. gysTopUpNum();
  84. },
  85. cancel: () => {
  86. clearInterval(offerNumPayRunInterval);
  87. offerNumPayRunInterval = null;
  88. getByNumber();
  89. gysTopUpNum();
  90. }
  91. });
  92. }
  93. //充值自定义切换
  94. function selectAmout(obj){
  95. if($(obj).hasClass("select_amount_val_click")){
  96. $(obj).removeClass("select_amount_val_click");
  97. } else {
  98. $(".select_amount_val").removeClass("select_amount_val_click");
  99. $(obj).addClass("select_amount_val_click");
  100. }
  101. }
  102. //选择支付方式
  103. function selectPay(obj){
  104. $(".pay_div_mode").removeClass("select_pay_click");
  105. $(".pay_div_mode").find("div").html(" ");
  106. $(obj).addClass("select_pay_click");
  107. $(".select_pay_click").find("div").html("<i class=\"layui-icon\">&#xe605;</i>")
  108. }
  109. //支付宝余额充值
  110. function zfbSupplierBalance(){
  111. layer.load(3);
  112. var totalFee = 0;
  113. //判断是否选择给定的金额
  114. if(typeof($(".top_up_div .select_amount_val_click").attr("value")) != "undefined"){
  115. totalFee = $(".top_up_div .select_amount_val_click").attr("value");
  116. }
  117. //获取输入的自定义金额
  118. if($("input[name=totalFee]").val() != null && $("input[name=totalFee]").val() != ""){
  119. totalFee = $("input[name=totalFee]").val();
  120. }
  121. //判断金额不能小于1
  122. if(totalFee < 1){
  123. layer.msg("金额不能小于1", {icon: 2});
  124. layer.closeAll("loading");
  125. return false;
  126. }
  127. //非空验证
  128. if(totalFee == 0){
  129. layer.msg("请填写或选择金额", {icon: 2});
  130. layer.closeAll("loading");
  131. return false;
  132. }
  133. $.ajax({
  134. url: "https://www.tuyatrip.com/api/pay/zfbpaySupplierBalance",
  135. type: "get",
  136. data: {
  137. "price": totalFee
  138. },
  139. dataType: "text",
  140. headers: {"token": localStorage.getItem("token")},
  141. success: (data) => {
  142. layer.confirm("是否已完成支付?",{
  143. btn: ['确认', '取消'],
  144. title: "昵称修改",
  145. skin: 'layclass'
  146. }, function () {
  147. layer.load(3);
  148. load();
  149. layer.closeAll()
  150. }, function(){
  151. load();
  152. layer.closeAll()
  153. });
  154. const div = document.createElement('divform');
  155. div.innerHTML = data; // data就是接口返回的form 表单字符串
  156. document.body.appendChild(div);
  157. let len = document.forms.length - 1;
  158. document.forms[len].setAttribute('target', '_blank'); // 新开窗口跳转
  159. document.forms[len].submit();
  160. layer.closeAll("loading");
  161. },
  162. error: () => {
  163. layer.alert("服务器异常,请联系管理员", {icon: 2});
  164. layer.closeAll("loading");
  165. }
  166. });
  167. }
  168. //生成二维码
  169. function onblurEle(){
  170. layer.load(3);
  171. let name = $(".top_up_div .select_pay_click span").text();
  172. if(name == "支付宝"){
  173. zfbSupplierBalance();
  174. return false;
  175. }
  176. var totalFee = 0;
  177. //判断是否选择给定的金额
  178. if(typeof($(".top_up_div .select_amount_val_click").attr("value")) != "undefined"){
  179. totalFee = $(".top_up_div .select_amount_val_click").attr("value");
  180. }
  181. //获取输入的自定义金额
  182. if($("input[name=totalFee]").val() != null && $("input[name=totalFee]").val() != ""){
  183. totalFee = $("input[name=totalFee]").val();
  184. }
  185. //判断金额不能小于1
  186. if(totalFee < 1){
  187. layer.msg("金额不能小于1", {icon: 2});
  188. layer.closeAll("loading");
  189. return false;
  190. }
  191. //非空验证
  192. if(totalFee == 0){
  193. layer.msg("请填写或选择金额", {icon: 2});
  194. layer.closeAll("loading");
  195. return false;
  196. }
  197. $("#qrcode").find("img").remove();
  198. clearInterval(runInterval);
  199. runInterval = null;
  200. $.ajax({
  201. url: "/wxpay/wxpaySupplierBalance",
  202. type: "get",
  203. data: {
  204. "price": totalFee
  205. },
  206. headers: {"token": localStorage.getItem("token")},
  207. dataType: "json",
  208. success: (data) => {
  209. var qrcode = new QRCode(document.getElementById("qrcode"), { // 显示二维码的元素或该元素的 ID
  210. text: data.code_url, // 内容可以是文字,链接,邮箱
  211. width: 120, //设置宽度
  212. height: 120, // 设置高度
  213. colorDark : "#000", // 设置前景色
  214. colorLight : "#fff", // 设置背景色
  215. // correctLevel : QRCode.CorrectLevel.L // 设置容错级别,上面有介绍
  216. });
  217. rotationTrainingStatus(data.out_trade_no);
  218. layer.closeAll("loading");
  219. },
  220. error: () => {
  221. layer.alert("服务器异常,请联系管理员", {icon: 2});
  222. layer.closeAll("loading");
  223. }
  224. });
  225. }
  226. //生成二维码
  227. function qrCode(){
  228. layer.load(3);
  229. }
  230. //轮训查询状态
  231. var runInterval; //定时任务
  232. function rotationTrainingStatus(uuid){
  233. runInterval = setInterval(function (){
  234. $.ajax({
  235. url: "/wxpay/getTopUp",
  236. type: "get",
  237. data: {
  238. "uuid": uuid
  239. },
  240. headers: {"token": localStorage.getItem("token")},
  241. dataType: "json",
  242. success: (data) => {
  243. if(data.data == 1){
  244. clearInterval(runInterval);
  245. layer.closeAll();
  246. parent.layer.msg("充值成功", {icon: 1});
  247. load();
  248. }
  249. },
  250. error: () => {
  251. layer.alert("服务器异常,请联系管理员", {icon: 2});
  252. layer.closeAll("loading");
  253. }
  254. });
  255. }, 1000)
  256. }
  257. //查询报价单单价
  258. function getByNumber(){
  259. layer.load(3);
  260. $.ajax({
  261. url: "/personal/getByNumber",
  262. type: "get",
  263. data: {},
  264. headers: {"token": localStorage.getItem("token")},
  265. dataType: "json",
  266. success: (data) => {
  267. $(".price_calculate").html(data.data.power_unit);
  268. unitPrice = data.data.power_unit;
  269. topUpNum();//次数渲染 余额渲染
  270. eachNumberAmout(); //次数余额
  271. layer.closeAll("loading");
  272. },
  273. error: () => {
  274. layer.alert("服务器异常,请联系管理员", {icon: 2});
  275. layer.closeAll("loading");
  276. }
  277. });
  278. }
  279. //监听输入框
  280. function getValue(obj){
  281. var num = $(obj).val();
  282. $("#qrcode_ok").find("img").remove();
  283. $(".price_calculate").html((Number(num * unitPrice).toFixed(2)));
  284. }
  285. //支付方式
  286. function payType(obj){
  287. var offerNum = $("input[name=offerNum]").val();//次数
  288. var offerNumSelect = $(".quotation_number .select_amount_val_click").attr("value");//次数
  289. if(offerNum == "" && typeof(offerNumSelect) == "undefined"){
  290. layer.msg("次数不能为空,请输入或者选择购买次数");
  291. return false;
  292. }
  293. $(".quotation_number .pay_div_mode").removeClass("select_pay_click");
  294. $(".quotation_number .pay_div_mode").find("div").html(" ");
  295. $(obj).addClass("select_pay_click");
  296. $(".select_pay_click").find("div").html("<i class=\"layui-icon\">&#xe605;</i>");
  297. var name = $(obj).find("span").text();
  298. if(name == "余额支付"){
  299. $(".blance_button").show();
  300. $("#qrcode_ok").find("img").remove();
  301. clearInterval(offerNumPayRunInterval);
  302. } else if(name == "微信支付"){
  303. $(".blance_button").hide();
  304. offerNumPay();
  305. } else if(name == "支付宝"){
  306. $("#qrcode_ok").find("img").remove();
  307. clearInterval(offerNumPayRunInterval);
  308. }
  309. }
  310. //支付宝购买次数
  311. function zfbOfferNumPay(){
  312. layer.load(3);
  313. var offerNum = $("input[name=offerNum]").val();//次数
  314. var offerNumSelect = $(".select_amount_val_click").attr("value");//次数
  315. var numOffer = 0;
  316. if(typeof(offerNumSelect) != "undefined"){
  317. numOffer = offerNumSelect;
  318. }
  319. if(offerNum != "" && offerNum != null){
  320. numOffer = offerNum;
  321. }
  322. $.ajax({
  323. url: "https://www.tuyatrip.com/api/pay/zfbpaySupplierOfferNum",
  324. type: "get",
  325. data: {
  326. "offerNum": numOffer
  327. },
  328. headers: {"token": localStorage.getItem("token")},
  329. dataType: "text",
  330. success: (data) => {
  331. layer.confirm("是否已完成支付?",{
  332. btn: ['确认', '取消'],
  333. title: false,
  334. skin: 'layclass'
  335. }, function () {
  336. layer.load(3);
  337. load();
  338. layer.closeAll();
  339. }, function(){
  340. load();
  341. layer.closeAll()
  342. });
  343. const div = document.createElement('divform');
  344. div.innerHTML = data; // data就是接口返回的form 表单字符串
  345. document.body.appendChild(div);
  346. let len = document.forms.length - 1;
  347. document.forms[len].setAttribute('target', '_blank'); // 新开窗口跳转
  348. document.forms[len].submit();
  349. layer.closeAll("loading");
  350. },
  351. error: () => {
  352. layer.alert("服务器异常,请联系管理员", {icon: 2});
  353. layer.closeAll("loading");
  354. }
  355. });
  356. }
  357. //购买次数生成二维码
  358. var offerNumPayRunInterval = null;
  359. function offerNumPay(){
  360. layer.load(3);
  361. clearInterval(offerNumPayRunInterval);
  362. offerNumPayRunInterval = null;
  363. //如果存在二维码则不执行下面信息
  364. if($("#qrcode_ok").html().indexOf("<img") != -1){
  365. return false;
  366. }
  367. var offerNum = $("input[name=offerNum]").val();//次数
  368. var offerNumSelect = $(".select_amount_val_click").attr("value");//次数
  369. var numOffer = 0;
  370. if(typeof(offerNumSelect) != "undefined"){
  371. numOffer = offerNumSelect;
  372. }
  373. if(offerNum != "" && offerNum != null){
  374. numOffer = offerNum;
  375. }
  376. $.ajax({
  377. url: "/wxpay/wxpaySupplierOfferNum",
  378. type: "get",
  379. data: {
  380. "offerNum": numOffer
  381. },
  382. headers: {"token": localStorage.getItem("token")},
  383. dataType: "json",
  384. success: (data) => {
  385. var qrcode = new QRCode(document.getElementById("qrcode_ok"), { // 显示二维码的元素或该元素的 ID
  386. text: data.code_url, // 内容可以是文字,链接,邮箱
  387. width: 120, //设置宽度
  388. height: 120, // 设置高度
  389. colorDark : "#000", // 设置前景色
  390. colorLight : "#fff", // 设置背景色
  391. // correctLevel : QRCode.CorrectLevel.L // 设置容错级别,上面有介绍
  392. });
  393. rotationTrainingOfferNum(data.out_trade_no);
  394. layer.closeAll("loading");
  395. },
  396. error: () => {
  397. layer.alert("服务器异常,请联系管理员", {icon: 2});
  398. layer.closeAll("loading");
  399. }
  400. });
  401. }
  402. //供应商充值次数回调
  403. function rotationTrainingOfferNum(uuid){
  404. offerNumPayRunInterval = setInterval(function (){
  405. $.ajax({
  406. url: "/wxpay/getOfferNum",
  407. type: "get",
  408. data: {
  409. "uuid": uuid
  410. },
  411. headers: {"token": localStorage.getItem("token")},
  412. dataType: "json",
  413. success: (data) => {
  414. if(data.data == 1){
  415. clearInterval(offerNumPayRunInterval);
  416. gysTopUpNum();
  417. layer.closeAll();
  418. layer.msg("充值成功", {icon: 1});
  419. load();
  420. }
  421. },
  422. error: () => {
  423. layer.alert("服务器异常,请联系管理员", {icon: 2});
  424. layer.closeAll("loading");
  425. }
  426. });
  427. }, 1000)
  428. }
  429. //余额确认
  430. function balanceOfOk(){
  431. var name = $(".quotation_number .select_pay_click span").text();
  432. if(name == "支付宝"){
  433. zfbOfferNumPay();
  434. return false;
  435. }
  436. var offerNum = $("input[name=offerNum]").val();//次数
  437. var offerNumSelect = $(".select_amount_val_click").attr("value");//次数
  438. if(offerNum == "" && typeof(offerNumSelect) == "undefined"){
  439. layer.msg("次数不能为空,请输入或者选择购买次数");
  440. return false;
  441. }
  442. var numOffer;
  443. if(typeof(offerNumSelect) != "undefined"){
  444. numOffer = offerNumSelect;
  445. }
  446. if(offerNum != "" && offerNum != null){
  447. numOffer = offerNum;
  448. }
  449. layer.load(3);
  450. $.ajax({
  451. url: "/personal/payBlance",
  452. type: "get",
  453. data: {"offerNum": numOffer},
  454. headers: {"token": localStorage.getItem("token")},
  455. dataType: "json",
  456. success: (data) => {
  457. if(data.msg == "200"){
  458. parent.layer.msg("购买成功", {icon: 1});
  459. gysTopUpNum();
  460. layer.closeAll();
  461. load();
  462. } else if(data.msg == "500"){
  463. layer.msg(data.errMsg, {icon: 2});
  464. }
  465. layer.closeAll("loading");
  466. },
  467. error: () => {
  468. layer.alert("服务器异常,请联系管理员", {icon: 2});
  469. layer.closeAll("loading");
  470. }
  471. });
  472. }
  473. //将base64转换为blob
  474. function dataURLtoBlob (dataurl) {
  475. var arr = dataurl.split(','),
  476. mime = arr[0].match(/:(.*?);/)[1],
  477. bstr = atob(arr[1]),
  478. n = bstr.length,
  479. u8arr = new Uint8Array(n);
  480. while (n--) {
  481. u8arr[n] = bstr.charCodeAt(n);
  482. }
  483. return new Blob([u8arr], { type: mime });
  484. }
  485. //将blob转换为file
  486. function blobToFile(theBlob, fileName){
  487. let file = new window.File([theBlob], fileName, {type: theBlob.type});
  488. return file;
  489. }
  490. //上传到oos图片 修改头像
  491. function cutOos(formData){
  492. layer.load(2);
  493. $.ajax({
  494. url: "https://www.tuyatrip.com/api/upload/uploadFile",
  495. type: "post",
  496. data: formData,
  497. headers: {"token": localStorage.getItem("token")},
  498. processData: false,
  499. contentType: false,
  500. dataType: "json",
  501. success: (data) => {
  502. if(data.msg == "200"){
  503. $.ajax({
  504. url: "/personal/updateName",
  505. type: "put",
  506. data: {
  507. "headpir": data.data
  508. },
  509. // contentType: "application/json",
  510. headers: {"token": localStorage.getItem("token")},
  511. dataType: "json",
  512. success: (dataVal) => {
  513. if(dataVal.msg == "200"){
  514. layer.closeAll();
  515. parent.layer.msg("上传头像成功", {icon: 1});
  516. console.log(data.data)
  517. parent.$(".head_portrait").attr("src", data.data);
  518. parent.conn.updateOwnUserInfo({avatarurl: data.data});
  519. load();
  520. } else if(dataVal.msg == "300"){
  521. layer.closeAll("loading");
  522. layer.msg(dataVal.errMsg, {icon: 2});
  523. }
  524. },
  525. error: () => {
  526. layer.closeAll("loading");
  527. layer.alert("网络错误 请联系管理员");
  528. }
  529. });
  530. }
  531. },
  532. error: () => {
  533. layer.closeAll("loading");
  534. layer.alert("网络错误 请联系管理员");
  535. }
  536. });
  537. }
  538. //查询充值次数
  539. function topUpNum(){
  540. $.ajax({
  541. url: "/personal/topUpNum",
  542. type: "get",
  543. data: {},
  544. headers: {"token": localStorage.getItem("token")},
  545. dataType: "json",
  546. success: (data) => {
  547. if(data.msg == "200"){
  548. $(".balance_of_val").html(data.data.balance_of);//余额
  549. $(".cumulative_num").html(paramReturn("累计充值", parent.type)+ (typeof data.data.topUp == "undefined" ? "0" : data.data.topUp) + paramReturn("次", parent.type));//充值次数
  550. $(".quotation_num").html(paramReturn("报价单单价", parent.type) + ":" + unitPrice);//充值次数
  551. }
  552. layer.closeAll("loading");
  553. },
  554. error: () => {
  555. layer.closeAll("loading");
  556. layer.alert("网络错误 请联系管理员");
  557. }
  558. });
  559. }
  560. //循环计算次数金额
  561. function eachNumberAmout(){
  562. $.each($(".select_number_val"), (index, item) => {
  563. var num = $(item).attr("value");
  564. $(item).find(".amount_number_val").html("¥" + (Number(num * unitPrice).toFixed(2)));
  565. });
  566. }
  567. //供应商充值次数成功后元素恢复初始化
  568. function gysTopUpNum(){
  569. $("input[name=offerNum]").val("")
  570. $("#qrcode_ok").find("img").remove();
  571. if(!$($(".select_number_val")[0]).hasClass("select_amount_val_click")){
  572. $($(".select_number_val")[0]).click();
  573. }
  574. $(".quotation_number .pay_div_mode").removeClass("select_pay_click");
  575. $(".quotation_number .pay_div_mode").find("div").html(" ");
  576. $($(".quotation_number .pay_div_mode")[0]).addClass("select_pay_click");
  577. $(".quotation_number .select_pay_click").find("div").html("<i class=\"layui-icon\">&#xe605;</i>");
  578. $(".blance_button").show();
  579. }
  580. //支付宝提现
  581. function withdrawal(){
  582. let str = "<div class='phoneBox'>"
  583. +"<div class='phoneSmBox'>支付宝账号 <input type='text' name='identity' autocomplete='off' class='layui-input'></div>"
  584. +"<div class='phoneSmBox'>支付宝真实姓名 <input type='text' name='name' autocomplete='off' class='layui-input'></div>"
  585. +"<div class='phoneSmBox'>提现金额 <input type='text' name='money' autocomplete='off' class='layui-input'></div>"
  586. +"</div>";
  587. layer.confirm(str,{
  588. btn: ['确认', '取消'],
  589. title: false,
  590. skin: 'layclass'
  591. }, function () {
  592. layer.load(3);
  593. //修改
  594. $.ajax({
  595. url: "https://www.tuyatrip.com/api/zfbWithdrawal/zfbCash",
  596. type: "put",
  597. data: {
  598. "name": $("input[name=name]").val(),
  599. "identity": $("input[name=identity]").val(),
  600. "money": $("input[name=money]").val()
  601. },
  602. // contentType: "application/json",
  603. headers: {"token": localStorage.getItem("token")},
  604. dataType: "text",
  605. success: (data) => {
  606. if(data.msg =="500"){
  607. layer.closeAll();
  608. parent.layer.msg(data.errMsg, {icon: 3});
  609. } else {
  610. layer.closeAll();
  611. parent.layer.msg(data, {icon: 1});
  612. load();
  613. }
  614. },
  615. error: () => {
  616. layer.closeAll("loading");
  617. layer.alert("网络错误 请联系管理员");
  618. }
  619. });
  620. }, function(){
  621. layer.closeAll()
  622. });
  623. }