/**
|
* 初始化车辆管理详情对话框
|
*/
|
var CarRentalInfo = {
|
tCarInfoData : {},
|
validateFields: {
|
title: {
|
validators: {
|
notEmpty: {
|
message: '标题不能为空'
|
}
|
}
|
},
|
category: {
|
validators: {
|
notEmpty: {
|
message: '类别不能为空'
|
}
|
}
|
},
|
brandId: {
|
validators: {
|
notEmpty: {
|
message: '车牌不能为空'
|
}
|
}
|
},gear: {
|
validators: {
|
notEmpty: {
|
message: '档位不能为空'
|
}
|
}
|
},
|
displacement: {
|
validators: {
|
notEmpty: {
|
message: '排量不能为空'
|
}
|
}
|
},
|
rentMoney: {
|
validators: {
|
notEmpty: {
|
message: '租金不能为空'
|
}
|
}
|
},
|
deposit: {
|
validators: {
|
notEmpty: {
|
message: '押金不能为空'
|
}
|
}
|
},
|
contactsName: {
|
validators: {
|
notEmpty: {
|
message: '联系人不能为空'
|
}
|
}
|
},
|
contactsPhone: {
|
validators: {
|
notEmpty: {
|
message: '联系电话不能为空'
|
}
|
}
|
}
|
}
|
};
|
|
/**
|
* 验证数据是否为空
|
*/
|
CarRentalInfo.validate = function () {
|
$('#carInfoForm').data("bootstrapValidator").resetForm();
|
$('#carInfoForm').bootstrapValidator('validate');
|
return $("#carInfoForm").data('bootstrapValidator').isValid();
|
};
|
|
/**
|
* 清除数据
|
*/
|
CarRentalInfo.clearData = function() {
|
this.tCarInfoData = {};
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
CarRentalInfo.set = function(key, val) {
|
var v = $("#" + key).val();
|
if('' != v){
|
this.tCarInfoData[key] = (typeof val == "undefined") ? v : val;
|
}
|
return this;
|
}
|
|
/**
|
* 设置对话框中的数据
|
*
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
CarRentalInfo.get = function(key) {
|
return $("#" + key).val();
|
}
|
|
/**
|
* 关闭此对话框
|
*/
|
CarRentalInfo.close = function() {
|
parent.layer.close(window.parent.CarRental.layerIndex);
|
}
|
|
/**
|
* 收集数据
|
*/
|
CarRentalInfo.collectData = function() {
|
this
|
.set('id')
|
.set('title')
|
.set('category')
|
.set('brandId')
|
.set('seat')
|
.set('displacement')
|
.set('rentMoney')
|
.set('deposit')
|
.set('pickUpCarCarCertificates')
|
.set('contactsName')
|
.set('contactsPhone')
|
.set('provinceCode')
|
.set('cityCode')
|
.set('gear')
|
.set('describe')
|
.set('addres');
|
}
|
|
/**
|
* 提交添加
|
*/
|
CarRentalInfo.addSubmit = function(status) {
|
this.clearData();
|
this.collectData();
|
if(!this.validate()){
|
return ;
|
}
|
|
let imgUrls = $('#imgUrl img[class="imgUrl"]');
|
if(imgUrls.length == 0){
|
Feng.error("请上传车辆图片");
|
return
|
}
|
let videoUrl = $('#videoUrl video[class="videoUrl"]');
|
if(videoUrl.length == 0){
|
Feng.error("请上传车辆视频");
|
return
|
}
|
let describeImgUrl = $('#describeImgUrl img[class="describeImgUrl"]');
|
let imgs = [];
|
imgUrls.each(function (i, e) {
|
imgs.push($(e).attr('src'));
|
})
|
let videos = [];
|
videoUrl.each(function (i, e) {
|
videos.push($(e).attr('src'));
|
})
|
let describeImgUrls = [];
|
describeImgUrl.each(function (i, e) {
|
describeImgUrls.push($(e).attr('src'));
|
})
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/carRental/addCarRental", function(res){
|
if(res.code == 200){
|
Feng.success("添加成功!");
|
window.parent.CarRental.table.refresh();
|
CarRentalInfo.close();
|
}else{
|
Feng.error(res.msg);
|
}
|
},function(data){
|
Feng.error("添加失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set(this.tCarInfoData);
|
ajax.set('imgUrl', imgs.toString());
|
ajax.set('videoUrl', videos.toString());
|
ajax.set('describeImgUrl', describeImgUrls.toString());
|
ajax.set('status', status);
|
ajax.start();
|
}
|
|
/**
|
* 提交修改
|
*/
|
CarRentalInfo.editSubmit = function(status) {
|
this.clearData();
|
this.collectData();
|
if(!this.validate()){
|
return ;
|
}
|
let imgUrls = $('#imgUrl img[class="imgUrl"]');
|
if(imgUrls.length == 0){
|
Feng.error("请上传车辆图片");
|
return
|
}
|
let videoUrl = $('#videoUrl video[class="videoUrl"]');
|
if(videoUrl.length == 0){
|
Feng.error("请上传车辆视频");
|
return
|
}
|
let describeImgUrl = $('#describeImgUrl img[class="describeImgUrl"]');
|
let imgs = [];
|
imgUrls.each(function (i, e) {
|
imgs.push($(e).attr('src'));
|
})
|
let videos = [];
|
videoUrl.each(function (i, e) {
|
videos.push($(e).attr('src'));
|
})
|
let describeImgUrls = [];
|
describeImgUrl.each(function (i, e) {
|
describeImgUrls.push($(e).attr('src'));
|
})
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/carRental/updateCarRental", function(res){
|
if(res.code == 200){
|
Feng.success("修改成功!");
|
window.parent.CarRental.table.refresh();
|
CarRentalInfo.close();
|
}else{
|
Feng.error(res.msg);
|
}
|
},function(data){
|
Feng.error("修改失败!" + data.responseJSON.message + "!");
|
});
|
ajax.set(this.tCarInfoData);
|
ajax.set('imgUrl', imgs.toString());
|
ajax.set('videoUrl', videos.toString());
|
ajax.set('describeImgUrl', describeImgUrls.toString());
|
ajax.set('status', status);
|
ajax.start();
|
}
|
|
let fileId = "";
|
function uploadImg(idName){
|
if(idName == 'imgUrl'){
|
let files = $('#' + idName).find('img');
|
if(files.length >= 15){
|
Feng.info("只能上传15张图片");
|
return
|
}
|
}else{
|
let files = $('#' + idName).find('video');
|
if(files.length >= 1){
|
Feng.info("只能上传1个视频");
|
return
|
}
|
}
|
fileId = idName;
|
$('#file').click();
|
}
|
|
function delImg(ev, fileId, t){
|
$(ev).parent().remove();
|
if(t == 1){//图片
|
let files = $('#' + fileId).find('img');
|
$($('#' + fileId).parent('div')).siblings('label').text('*车辆图片(' + files.length + '/15):');
|
}
|
if(2 == t){//视频
|
let files = $('#' + fileId).find('video');
|
$($('#' + fileId).parent('div')).siblings('label').text('*车辆视频(' + files.length + '/1):');
|
}
|
}
|
|
|
function initImgSize(){
|
if('' != $('#id').val()){
|
let files = $('#imgUrl').find('img');
|
$($('#imgUrl').parent('div')).siblings('label').text('*车辆图片(' + files.length + '/15):');
|
|
files = $('#videoUrl').find('video');
|
$($('#videoUrl').parent('div')).siblings('label').text('*车辆视频(' + files.length + '/1):');
|
}
|
}
|
|
$(function() {
|
Feng.initValidator("carInfoForm", CarRentalInfo.validateFields);
|
|
initImgSize();
|
|
$('#provinceCode').on('change', function () {
|
let provinceCode = $('#provinceCode').val();
|
var ajax = new $ax(Feng.ctxPath + "/recruit/getRegion", function(res){
|
if(res.code == 200){
|
let data = res.data;
|
let str='';
|
for(let i in data){
|
str += '<option value="' + data[i].code + '">' + data[i].name + '</option>';
|
}
|
$("#cityCode").html(str);
|
}else{
|
Feng.error(res.msg);
|
}
|
});
|
ajax.set("code", provinceCode);
|
ajax.start();
|
})
|
|
$('#file').on('change', function () {
|
let formData = new FormData() //创建一个forData
|
formData.append('file', $('#file')[0].files[0]) //把file添加进去 name命名为img
|
layer.load(); //上传loading
|
$.ajax({
|
url: Feng.ctxPath + '/upload/image1',
|
data: formData,
|
type: "POST",
|
async: true,
|
cache: false,
|
contentType: false,
|
processData: false,
|
success: function(res) {
|
layer.closeAll('loading'); //关闭loading
|
$('#file').val('');
|
if(fileId == 'imgUrl'){
|
$('#' + fileId).append('<div><img src="' + res + '" width="100px" class="imgUrl"><i class="fa fa-close" onclick="delImg(this, \'imgUrl\', 1)" style="color: red;color: red;font-size: 18px;position: absolute;left: 108px;top: -8px;"></i></div> ');
|
let files = $('#' + fileId).find('img');
|
$($('#' + fileId).parent('div')).siblings('label').text('*车辆照片(' + files.length + '/15):');
|
}
|
if(fileId == 'videoUrl'){
|
$('#' + fileId).append('<div><video src="' + res + '" controls style="width: 200px !important;" class="videoUrl"></video><i class="fa fa-close" onclick="delImg(this, \'videoUrl\', 2)" style="color: red;color: red;font-size: 18px;position: absolute;left: 208px;top: -8px;"></i></div> ');
|
let files = $('#' + fileId).find('video');
|
$($('#' + fileId).parent('div')).siblings('label').text('*车辆视频(' + files.length + '/1):');
|
}
|
if(fileId == 'describeImgUrl'){
|
$('#' + fileId).append('<div><img src="' + res + '" width="100px" class="describeImgUrl"/><i class="fa fa-close" onclick="delImg(this, \'describeImgUrl\')" style="color: red;color: red;font-size: 18px;position: absolute;left: 108px;top: -8px;"></i></div> ');
|
}
|
}
|
})
|
})
|
});
|