新媒体-合同签约,CA签约

perfectInfo.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. var qs = parseQueryString(window.location.href),user_id,justIDImg = '',backIDImg = '',userImg = '',admin_id;
  2. var request = '';
  3. $().ready(function(){
  4. if(qs.user_id){
  5. user_id = qs.user_id;
  6. }
  7. if(!getCookie('user_id') || getCookie('user_id') != user_id){
  8. window.location.href="index.html"
  9. }
  10. examineList();
  11. })
  12. function userEdit () {
  13. //提交用户信息
  14. $(".loading").show();
  15. $.ajax({
  16. type: 'post',
  17. url: request + '/api/user/edit',
  18. data:{
  19. 'user_id':user_id,
  20. 'name':$("#name").val(),
  21. 'email':$("#email").val(),
  22. 'id_card_num':$("#ID").val(),
  23. 'address':$("#addr").val(),
  24. 'platform_account':$("#platformID").val(),// 平台账号
  25. 'id_card_facade':justIDImg,
  26. 'id_card_back':backIDImg,
  27. 'admin_id':admin_id
  28. },
  29. dataType:'json',
  30. success: function (res) {
  31. $(".loading").hide();
  32. console.log(res)
  33. if(res.status == 200){
  34. window.location.href='examine.html?type=' + 1 + '&user_id=' + user_id;
  35. }else{
  36. showMsg(res.msg)
  37. }
  38. },
  39. fail: function () {
  40. showMsg('网络错误,请稍后再试~')
  41. $(".loading").hide();
  42. }
  43. })
  44. }
  45. function changeImgID(html) {
  46. console.log(html)
  47. //获取读取我文件的File对象
  48. var selectedFile = '';
  49. if(html == 'justImgInput'){
  50. selectedFile = document.getElementById('justImgInput').files[0];
  51. }
  52. if(html == 'backImgInput'){
  53. selectedFile = document.getElementById('backImgInput').files[0];
  54. }
  55. // if(html == 'userImg'){
  56. // selectedFile = document.getElementById('userImg').files[0];
  57. // }
  58. var reader = new FileReader();
  59. reader.readAsDataURL(selectedFile);
  60. reader.onload = function () {
  61. //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
  62. console.log(this)
  63. //图片压缩
  64. canvasDataURL(this.result,{
  65. quality: 0.01
  66. },function (base64Codes) {
  67. console.log(base64Codes)
  68. if(html == 'justImgInput'){
  69. $(".justID .img img").attr('src',base64Codes);
  70. justIDImg = base64Codes;
  71. }
  72. if(html == 'backImgInput'){
  73. $(".backID .img img").attr('src',base64Codes)
  74. backIDImg = base64Codes;
  75. }
  76. // if(html == 'userImg'){
  77. // $(".uploadID .userImg .img img").attr('src',base64Codes)
  78. // userImg = base64Codes;
  79. // }
  80. })
  81. }
  82. }
  83. function yesButtonEvent () {
  84. //确认提交--弹出弹框提示
  85. if($("#name").val() == ''){
  86. showMsg('请输入用户名');
  87. return;
  88. }
  89. if (!(new RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/).test($("#email").val()))) {
  90. showMsg('请正确输入邮箱')
  91. return;
  92. }
  93. if($("#addr").val().length == 0){
  94. showMsg('请输入家庭住址')
  95. return;
  96. }
  97. if (!(new RegExp(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/).test($("#ID").val()))) {
  98. showMsg('请正确输入身份证号')
  99. return;
  100. }
  101. if($("#platformID").val().length == 0){
  102. showMsg('请输入平台账号ID')
  103. return;
  104. }
  105. if(justIDImg == ''){
  106. showMsg('请上传身份证正面照')
  107. return;
  108. }
  109. if(backIDImg == ''){
  110. showMsg('请上传身份证反面照')
  111. return;
  112. }
  113. // if(userImg == ''){
  114. // showMsg('请上传用户头像')
  115. // return;
  116. // }
  117. //审核客服人
  118. admin_id = $(".customerService .radio li input[name='radio']:checked").val();
  119. if(admin_id == undefined){
  120. showMsg('请选择审核客服人')
  121. return;
  122. }
  123. $('.yesMask').show();
  124. }
  125. function cancelMask () {
  126. //取消弹框
  127. $('.yesMask').hide();
  128. }
  129. function submissionInfo () {
  130. //确认提交
  131. userEdit();
  132. }
  133. function examineList () {
  134. //提交用户信息
  135. $(".loading").show();
  136. $.ajax({
  137. type: 'post',
  138. url: request + '/api/admin/list',
  139. dataType:'json',
  140. success: function (res) {
  141. $(".loading").hide();
  142. if(res.status == 200){
  143. var html = ''
  144. res.data.forEach(function (item,index){
  145. html +='<li><input type="radio" name="radio" value="' + item.id + '" id="' + item.id + item.realname +'"><label for="' + item.id + item.realname + '">' + item.realname + '</label></li>'
  146. })
  147. $(".customerService .radio").html(html)
  148. }else{
  149. showMsg(res.msg)
  150. }
  151. },
  152. fail: function () {
  153. showMsg('网络错误,请稍后再试~')
  154. $(".loading").hide();
  155. }
  156. })
  157. }
  158. //图片压缩
  159. function canvasDataURL(path, obj, callback){
  160. var img = new Image();
  161. img.src = path;
  162. img.onload = function(){
  163. var that = this;
  164. // 默认按比例压缩
  165. var w = that.width,
  166. h = that.height,
  167. scale = w / h;
  168. w = obj.width || w;
  169. h = obj.height || (w / scale);
  170. var quality = 0.2; // 默认图片质量为0.7
  171. //生成canvas
  172. var canvas = document.createElement('canvas');
  173. var ctx = canvas.getContext('2d');
  174. // 创建属性节点
  175. var anw = document.createAttribute("width");
  176. anw.nodeValue = w;
  177. var anh = document.createAttribute("height");
  178. anh.nodeValue = h;
  179. canvas.setAttributeNode(anw);
  180. canvas.setAttributeNode(anh);
  181. ctx.drawImage(that, 0, 0, w, h);
  182. // 图像质量
  183. if(obj.quality && obj.quality <= 1 && obj.quality > 0){
  184. quality = obj.quality;
  185. }
  186. // quality值越小,所绘制出的图像越模糊
  187. var base64 = canvas.toDataURL('image/jpeg', quality);
  188. // 回调函数返回base64的值
  189. callback(base64);
  190. }
  191. }
  192. //获取地址栏参数
  193. function parseQueryString(url) {
  194. var urlObj = {};
  195. var reg = /([^?=&]+)=([^?=&]+)/g;
  196. url.replace(reg, function($0, $1, $2) {
  197. urlObj[$1] = decodeURIComponent($2);
  198. })
  199. return urlObj;
  200. }
  201. // 展示错误提示信息
  202. function showMsg(msg) {
  203. var msgBox = document.getElementsByClassName('alert-info')[0];
  204. msgBox.getElementsByTagName("p")[0].innerHTML=msg;
  205. msgBox.style.display="block";
  206. setTimeout(function() {
  207. msgBox.style.display="none";
  208. }, 2000);
  209. }
  210. //取Cookie的值
  211. function getCookie(name) {
  212. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  213. if (arr = document.cookie.match(reg)){
  214. return arr[2];
  215. }else{
  216. return false
  217. }
  218. }
  219. //写入到Cookie
  220. //name:cookie名称 value:cookie值
  221. function setCookie(name,value){
  222. var exp = new Date();
  223. exp.setTime(exp.getTime() + 12 * 60 * 60000);//过期时间 12小时
  224. // exp.setTime(exp.getTime() + 60 * 10000);//过期时间 10分钟
  225. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  226. }