Ei kuvausta

identity.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. var params=parseQueryString(window.location.href);
  2. var hasError=params.hasError?params.hasError:''
  3. var getTypeId=""//接口获取到的typeId
  4. var obj={}//信用状况
  5. // var hasSet=false;
  6. $().ready(function(){
  7. clickRecord("openLink","链接打开")//链接打开
  8. getInfo();
  9. getType();
  10. if(params.hasCode==1) {
  11. $(".button").hide();
  12. }
  13. })
  14. $(".top img").on("click",function(){
  15. if(params.typeId) {
  16. window.location.href="second.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+hasError+"&code="+params.code+"&hasCode="+params.hasCode+"&typeId="+params.typeId
  17. }else {
  18. window.location.href="second.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+hasError+"&code="+params.code+"&hasCode="+params.hasCode
  19. }
  20. })
  21. function init(index){
  22. var identityPicker = new mui.PopPicker();
  23. identityPicker.setData(credit_record_status,"贷款记录");
  24. // 设置选中的下拉项
  25. identityPicker.pickers[0].setSelectedIndex(index,2000)
  26. var identityDom = document.getElementById("credit_record_status");
  27. if(index>-1) {
  28. jQuery("#credit_record_status").text(credit_record_status[index].text)
  29. jQuery("#credit_record_status").addClass("hasValue")
  30. }
  31. identityDom.addEventListener('tap', function(event) {
  32. identityPicker.show(function(items) {
  33. $("#credit_record_status").text(items[0].text)
  34. jQuery("#credit_record_status").addClass("hasValue")
  35. obj.credit_record_status=items[0].value;
  36. });
  37. }, false);
  38. }
  39. function getType() {
  40. $.ajax({
  41. type:"post",
  42. url:"/user/typeList",
  43. success:function(res) {
  44. console.log(res)
  45. if(res&&res.errno==200) {
  46. var typeList=res.rst.type_list
  47. // 根据typeId来判断
  48. for(var i in typeList) {
  49. // 社保
  50. if(params.typeId==1&&typeList[i].type_name=="社保公积金") {
  51. getType=typeList[i].id
  52. // 公积金
  53. }else if(params.typeId==2&&typeList[i].type_name=="社保公积金"){
  54. getType=typeList[i].id
  55. // 流水
  56. }else if(params.typeId==3&&typeList[i].type_name=="流水"){
  57. getType=typeList[i].id
  58. // 车贷
  59. }else if(params.typeId==4&&typeList[i].type_name=="房车贷"){
  60. getType=typeList[i].id
  61. // 房贷
  62. }else if(params.typeId==5&&typeList[i].type_name=="房车贷"){
  63. getType=typeList[i].id
  64. }else if(!params.typeId&&typeList[i].type_name=="优质单") {
  65. getType=typeList[i].id
  66. }else if(params.typeId==0&&typeList[i].type_name=="优质单") {
  67. getType=typeList[i].id
  68. }
  69. }
  70. }else {
  71. showMsg(res.err)
  72. }
  73. },
  74. error:function(){
  75. showMsg("网络错误,请稍后再试");
  76. }
  77. })
  78. }
  79. $(".button").on("tap",function(){
  80. if(!$("#name").val()) {
  81. showMsg("请填写姓名")
  82. return false;
  83. }else if(!$("#id_no").val()) {
  84. showMsg("请填写身份证号")
  85. return false;
  86. }else if(!obj.credit_record_status||obj.credit_record_status<0){
  87. showMsg("请选择信用记录");
  88. return false;
  89. }else {
  90. setInfo();
  91. }
  92. })
  93. $(".button1").on("tap",function(){
  94. if(params.typeId) {
  95. window.location.href="status.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+1+"&code="+params.code+"&status=1"+"&typeId="+params.typeId
  96. }else {
  97. window.location.href="status.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+1+"&code="+params.code+"&status=1"
  98. }
  99. })
  100. // 展示错误提示信息
  101. function showMsg(msg) {
  102. $(".alert-info").show();
  103. $(".alert-info p").text(msg)
  104. setTimeout(function() {
  105. $(".alert-info").hide();
  106. }, 1000);
  107. }
  108. function getInfo(){
  109. $.ajax({
  110. url:"/user/getUser",
  111. type:"post",
  112. dataType:"json",
  113. data:{
  114. phone:params.phone,
  115. token:params.token,
  116. uid:params.uid,
  117. channel_id:params.source
  118. },
  119. success:function(res) {
  120. if(res&&res.errno==0) {
  121. var data=res.rst.data
  122. init(data.credit_record_status-1)
  123. if(data.name) {
  124. $("#name").attr("value",data.name)
  125. $("#name").addClass("hasValue")
  126. }
  127. if(data.id_no) {
  128. $("#id_no").attr("value",data.id_no)
  129. $("id_no").addClass("hasValue")
  130. }
  131. if(data.credit_record_status>0) {
  132. $("#credit_record_status").text(credit_record_status[data.credit_record_status-1].text)
  133. $("#credit_record_status").addClass("hasValue")
  134. }
  135. // obj.credit_record_status=data.credit_record_status-1
  136. obj.credit_record_status=data.credit_record_status
  137. }else {
  138. showMsg(res.rst.msg)
  139. }
  140. },
  141. error:function(err) {
  142. showMsg("网络错误,请稍后再试")
  143. }
  144. })
  145. }
  146. function setInfo(){
  147. // if(!hasSet) {
  148. $.ajax({
  149. url:"/user/setUser",
  150. type:"post",
  151. dataType:"json",
  152. data:{
  153. phone:params.phone,
  154. token:params.token,
  155. uid:params.uid,
  156. id_no:$("#id_no").val(),
  157. name:$("#name").val(),
  158. credit_record_status:obj.credit_record_status,
  159. channel_id:params.source,
  160. type_id:getType
  161. },
  162. success:function(res) {
  163. hasSet=true
  164. if(res&&res.errno==0) {
  165. clickRecord("submitApplyClick","提交申请按钮点击")//链接打开
  166. if(params.hasError==1) {
  167. reapply()
  168. }else {
  169. if(params.typeId) {
  170. window.location.href="status.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+1+"&code="+params.code+"&status=1"+"&typeId="+params.typeId
  171. }else {
  172. window.location.href="status.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+1+"&code="+params.code+"&status=1"
  173. }
  174. }
  175. }else {
  176. showMsg(res.rst.msg)
  177. }
  178. },
  179. error:function(err) {
  180. showMsg("网络错误,请稍后再试")
  181. }
  182. })
  183. // }
  184. }
  185. // 重新审核
  186. function reapply() {
  187. $.ajax({
  188. url:"/user/reapply",
  189. type:"post",
  190. dataType:"json",
  191. data:{
  192. phone:params.phone,
  193. token:params.token,
  194. channel_id:params.source,
  195. uid:params.uid
  196. },
  197. success:function(res) {
  198. if(res&&res.errno==0) {
  199. if(params.typeId) {
  200. window.location.href="status.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+1+"&code="+params.code+"&status=1"+"&typeId="+params.typeId
  201. }else {
  202. window.location.href="status.html?source="+params.source+"&phone="+params.phone+"&uid="+params.uid+"&token="+params.token+"&hasError="+1+"&code="+params.code+"&status=1"
  203. }
  204. }else {
  205. showMsg(res.rst.msg)
  206. }
  207. },
  208. error:function(err) {
  209. showMsg("网络错误,请稍后再试")
  210. }
  211. })
  212. }
  213. //获取地址栏参数
  214. function parseQueryString(url) {
  215. var urlObj = {};
  216. var reg = /([^?=&]+)=([^?=&]+)/g;
  217. url.replace(reg, function($0, $1, $2) {
  218. urlObj[$1] = decodeURIComponent($2);
  219. })
  220. return urlObj;
  221. }
  222. // 埋点
  223. function clickRecord(eventId,eventName){
  224. $.ajax({
  225. url:"/user/clickRecord",
  226. type:"post",
  227. dataType:"json",
  228. data:{
  229. event_id:eventId,
  230. event_name:eventName,
  231. channel_id:params.source
  232. },
  233. success:function(res) {
  234. }
  235. })
  236. }