123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- var qs = parseQueryString(window.location.href),user_id,justIDImg = '',backIDImg = '',userImg = '',admin_id;
- var request = '';
- $().ready(function(){
- if(qs.user_id){
- user_id = qs.user_id;
- }
- if(!getCookie('user_id') || getCookie('user_id') != user_id){
- window.location.href="index.html"
- }
- examineList();
- })
- function userEdit () {
- //提交用户信息
- $(".loading").show();
- $.ajax({
- type: 'post',
- url: request + '/api/user/edit',
- data:{
- 'user_id':user_id,
- 'name':$("#name").val(),
- 'email':$("#email").val(),
- 'id_card_num':$("#ID").val(),
- 'address':$("#addr").val(),
- 'platform_account':$("#platformID").val(),// 平台账号
- 'id_card_facade':justIDImg,
- 'id_card_back':backIDImg,
- 'admin_id':admin_id
- },
- dataType:'json',
- success: function (res) {
- $(".loading").hide();
- console.log(res)
- if(res.status == 200){
- window.location.href='examine.html?type=' + 1 + '&user_id=' + user_id;
- }else{
- showMsg(res.msg)
- }
- },
- fail: function () {
- showMsg('网络错误,请稍后再试~')
- $(".loading").hide();
- }
- })
- }
- function changeImgID(html) {
- console.log(html)
- //获取读取我文件的File对象
- var selectedFile = '';
- if(html == 'justImgInput'){
- selectedFile = document.getElementById('justImgInput').files[0];
- }
- if(html == 'backImgInput'){
- selectedFile = document.getElementById('backImgInput').files[0];
- }
- // if(html == 'userImg'){
- // selectedFile = document.getElementById('userImg').files[0];
- // }
- var reader = new FileReader();
- reader.readAsDataURL(selectedFile);
- reader.onload = function () {
- //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
- console.log(this)
- //图片压缩
- canvasDataURL(this.result,{
- quality: 0.01
- },function (base64Codes) {
- console.log(base64Codes)
- if(html == 'justImgInput'){
- $(".justID .img img").attr('src',base64Codes);
- justIDImg = base64Codes;
- }
- if(html == 'backImgInput'){
- $(".backID .img img").attr('src',base64Codes)
- backIDImg = base64Codes;
- }
- // if(html == 'userImg'){
- // $(".uploadID .userImg .img img").attr('src',base64Codes)
- // userImg = base64Codes;
- // }
- })
- }
- }
- function yesButtonEvent () {
-
- //确认提交--弹出弹框提示
- if($("#name").val() == ''){
- showMsg('请输入用户名');
- return;
- }
- 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()))) {
- showMsg('请正确输入邮箱')
- return;
- }
- if($("#addr").val().length == 0){
- showMsg('请输入家庭住址')
- return;
- }
-
- if (!(new RegExp(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/).test($("#ID").val()))) {
- showMsg('请正确输入身份证号')
- return;
- }
- if($("#platformID").val().length == 0){
- showMsg('请输入平台账号ID')
- return;
- }
- if(justIDImg == ''){
- showMsg('请上传身份证正面照')
- return;
- }
- if(backIDImg == ''){
- showMsg('请上传身份证反面照')
- return;
- }
- // if(userImg == ''){
- // showMsg('请上传用户头像')
- // return;
- // }
- //审核客服人
- admin_id = $(".customerService .radio li input[name='radio']:checked").val();
- if(admin_id == undefined){
- showMsg('请选择审核客服人')
- return;
- }
- $('.yesMask').show();
- }
- function cancelMask () {
- //取消弹框
- $('.yesMask').hide();
- }
- function submissionInfo () {
- //确认提交
- userEdit();
- }
- function examineList () {
- //提交用户信息
- $(".loading").show();
- $.ajax({
- type: 'post',
- url: request + '/api/admin/list',
- dataType:'json',
- success: function (res) {
- $(".loading").hide();
- if(res.status == 200){
- var html = ''
- res.data.forEach(function (item,index){
- 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>'
- })
- $(".customerService .radio").html(html)
- }else{
- showMsg(res.msg)
- }
- },
- fail: function () {
- showMsg('网络错误,请稍后再试~')
- $(".loading").hide();
- }
- })
- }
- //图片压缩
- function canvasDataURL(path, obj, callback){
- var img = new Image();
- img.src = path;
- img.onload = function(){
- var that = this;
- // 默认按比例压缩
- var w = that.width,
- h = that.height,
- scale = w / h;
- w = obj.width || w;
- h = obj.height || (w / scale);
- var quality = 0.2; // 默认图片质量为0.7
- //生成canvas
- var canvas = document.createElement('canvas');
- var ctx = canvas.getContext('2d');
- // 创建属性节点
- var anw = document.createAttribute("width");
- anw.nodeValue = w;
- var anh = document.createAttribute("height");
- anh.nodeValue = h;
- canvas.setAttributeNode(anw);
- canvas.setAttributeNode(anh);
- ctx.drawImage(that, 0, 0, w, h);
- // 图像质量
- if(obj.quality && obj.quality <= 1 && obj.quality > 0){
- quality = obj.quality;
- }
- // quality值越小,所绘制出的图像越模糊
- var base64 = canvas.toDataURL('image/jpeg', quality);
- // 回调函数返回base64的值
- callback(base64);
- }
- }
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, function($0, $1, $2) {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- // 展示错误提示信息
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.getElementsByTagName("p")[0].innerHTML=msg;
- msgBox.style.display="block";
- setTimeout(function() {
- msgBox.style.display="none";
- }, 2000);
- }
- //取Cookie的值
- function getCookie(name) {
- var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
- if (arr = document.cookie.match(reg)){
- return arr[2];
- }else{
- return false
- }
- }
- //写入到Cookie
- //name:cookie名称 value:cookie值
- function setCookie(name,value){
- var exp = new Date();
- exp.setTime(exp.getTime() + 12 * 60 * 60000);//过期时间 12小时
- // exp.setTime(exp.getTime() + 60 * 10000);//过期时间 10分钟
- document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
- }
|