let  laypage,table,form,upload,fileList = new Array();
layui.use(['layer', 'form', 'element','laypage','upload'], function(){
		//getToken();
		//test2();
		//test3();
		var layer = layui.layer; //弹层
		 laypage = layui.laypage; //分页
		 table = layui.table; //表格
		 form=layui.form;
		 upload=layui.upload;
		 let uploadObj = upload.render({
		    elem: '#test2',
		    multiple: true,
		    dataType: "json",
		    exts: 'jpg|png|jpeg',
		    acceptMime: 'image/jpg,image/png,image/jpeg',
		    // number: 3, //最大上传数量
		    size: 1024 * 100, //最大文件大小，单位k
		    auto: false, //是否自动上传 ，默认为true
		    bindAction: '#hideUpload', //绑定的按钮
		    choose: function (obj) {
		        uploadObj.config.elem.next()[0].value = '';
		        obj.preview(function (index, file, result) {
		            $('#uploader-list').append(
		                '<div id="" class="file-iteme">' +
		                '<div class="handle"><p>x</p></div>' +
		                '<img class="img" style="width: 130px;height: 100px;" data-index=' + index + ' data-name=' + file.name + ' src=' + result + '>' +
		                '</div>'
		            );
		            let map = new Map();//将选择的图片索引和图片写成对象存入集合
		            map.index = index;
		            map.file = file;
		            fileList.push(map);
		        });
		    }
		});
		 
	form.on('submit(demo1)', function(data){
				console.log(data.field);
					
				console.log(fileList[0].file);
			console.log(encryptCBC(fileList[0].file))	;
				 let formData = new FormData();
				for (let i = 0; i < fileList.length; i++) {
				    formData.append("file[]", fileList[i].file)
				}
				formData.append("param",JSON.stringify(data.field))
				for (let [key, value] of formData.entries()) {
				    console.log(key, value);
				}
				 return false;

		})
	
	
	
	})
	
	
	
	
	
	
	
	
	
	
	
//初始化表格
function initTable() {
	 table.render({
	        elem: '#cityTable',
	        url: PATH_URL+'/system/sys/sysLog/getSystemLogsTest', // 表单数据的接口
	        height: 470,
	        page: true,
	        cols: [[
	          {field:'cid',title: 'ID'},
	          {field:'ip',  title: 'ip'},
	          {field:'failureReason',  title: '名称'},
	          {field:'createDate',title: '名称'},
	          {field:'deposit', title: '名称'},
	          {toolbar: '#optionBar',  title: '操作'}
	        ]]
	      });
}



//POST body 传参
function getToken(){
	$.ajax({
		url: PATH_URL+'/auth/login',
		data: JSON.stringify({
			"username":"guest",
			"password":"Bonus@admin123",
			"type":'1'
		}),
		type: 'POST',
		dataType:"json",
		contentType: "application/json",
		async: false,
		success: function (result) {
			localStorage.setItem("token",result.data.access_token)
		}, error: function () {
		}
	});
}



//POST 请求 formdata 
//www-传参 自动加解密
function test2(){
	$.ajax({
		url: PATH_URL+'/auth/login2',
		data:{
			"username":"guest",
			"password":"Bonus@admin123"
		},
		type: 'POST',
		async: false,
		success: function (result) {
				console.log(result)
		}, error: function () {
		}
	});
}
//get 请求
function test3(){
	$.ajax({
		url: PATH_URL+'zhgd/auth/login3',
		data:{
			"username":"guest",
			"password":"Bonus@admin123"
		},
		contentType: "application/json",
		type: 'GET',
		async: false,
		success: function (result) {
				console.log(result)
		}, error: function () {
		}
	});
}