1 avBody = avalon.define("avBody", function (vm) { 2 3 vm.Address = "";//地址 4 vm.BrandModel = "";//品牌型号 5 vm.CarProprietor = "";//车辆所有人 6 vm.CarType = "";//车辆类型 7 vm.EngineNubmer = "";//发动机号 8 vm.IdentifyNumber = "";//识别号 9 vm.InsuranceExpiresTime = "";//保险到期 10 vm.YearTestExpiresTime = "";//年检到期 11 vm.PlateNumber = "";//车牌号 12 vm.GetCarManageInfo = []; 13 vm.CoachId = ""; 14 vm.ID = ""; 15 vm.CheckCarType = function (value, obj) { 16 if (value == "C2") { 17 $("#radC2").attr("style", "background-color:#4caf5e;margin-left:50px;"); 18 $("#radC1").attr("style", "background-color:#888;margin-left:0px;"); 19 } else { 20 $("#radC1").attr("style", "background-color:#4caf5e;margin-left:0px;"); 21 $("#radC2").attr("style", "background-color:#888;margin-left:50px;"); 22 value = "C1"; 23 } 24 avBody.CarType = value; 25 } 26 vm.LicenseExpriesTime = ""; 27 vm.GetLocalTime = function (nS) { 28 return new Date(parseInt(nS.replace("/Date(", "").replace(")/", "")));//.toLocaleString().replace(/:\d{1,2}$/, ' ') 29 }; 30 vm.GetLocalTimeNull = function (nS) { 31 if (nS != null && nS != "") { 32 var date = avBody.GetLocalTime(nS); 33 34 var d = date.getFullYear() + "-" + (date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1)) + '-' + (date.getDate() >= 10 ? date.getDate() : "0" + date.getDate()); 35 return d; 36 } else { 37 return ''; 38 } 39 40 }; 41 //加载教练信息 42 vm.LoadData = function () { 43 44 $.postToken(appPath + "CostManage/GetCTCarInfo", { CoachId: avBody.QueryString("CoachId") }, function (data) { 45 if (data.IsSuccess) { 46 avBody.GetCarManageInfo = data.Data; 47 //隐藏lodaing 48 $(".loadinghouse").hide(); 49 //显示列表 50 $("#div_GetCTCarinfo").show(); 51 52 } else { 53 alert("获取车辆失败!!"); 54 } 55 }); 56 57 58 }; 59 vm.GetCTCarInfoByID = function (el) { 60 avBody.ID = el.ID; 61 avBody.showcardeatail(); 62 $.postToken(appPath + "CostManage/GetCTCarInfo", {ID:el.ID,CoachId:avBody.QueryString("CoachId")}, function (data) { 63 if (data.IsSuccess) { 64 var entity = data.Data[0]; 65 avBody.Address = entity["Address"];//地址 66 avBody.BrandModel = entity["BrandModel"];//品牌型号 67 avBody.CarProprietor = entity["CarProprietor"];//车辆所有人 68 avBody.CarType = entity["CarType"];//车辆类型 69 avBody.EngineNubmer = entity["EngineNubmer"];//发动机号 70 avBody.IdentifyNumber = entity["IdentifyNumber"];//识别号 71 avBody.InsuranceExpiresTime = avBody.GetLocalTimeNull(entity["InsuranceExpiresTime"]);//保险到期 72 avBody.YearTestExpiresTime = avBody.GetLocalTimeNull(entity["YearTestExpiresTime"]);//年检到期 73 avBody.LicenseExpriesTime = avBody.GetLocalTimeNull(entity["LicenseExpriesTime"]);//年检到期 74 $("#txtInsuranceExpiresTime").val(avBody.InsuranceExpiresTime); 75 $("#txtYearTestExpiresTime").val(avBody.YearTestExpiresTime); 76 $("#txtLicenseExpriesTime").val(avBody.LicenseExpriesTime); 77 avBody.PlateNumber = entity["PlateNumber"];//车牌号 78 // $("#txtInsuranceExpiresTime").val(entity["InsuranceExpiresTime"]); 79 $("#SelCarType").val(entity["CarType"]); 80 avBody.CheckCarType(avBody.CarType); 81 82 } else { 83 alert("获取车辆失败!!"); 84 } 85 }); 86 87 88 }; 89 vm.SubmitBtn = function (obj) { 90 if (avBody.ID != "") { 91 avBody.UptCostManageInfo(avBody.ID,obj); 92 } else { 93 avBody.AddCTCarInfo(obj); 94 } 95 }; 96 97 vm.AddCTCarInfo = function (obj) { 98 99 avBody.InsuranceExpiresTime = $("#txtInsuranceExpiresTime").val();100 avBody.YearTestExpiresTime = $("#txtYearTestExpiresTime").val();101 avBody.LicenseExpriesTime = $("#txtLicenseExpriesTime").val();102 103 var parm = {104 105 Address: avBody.Address,//地址106 BrandModel: avBody.BrandModel ,//品牌型号107 CarProprietor: avBody.CarProprietor ,//车辆所有人108 CarType: avBody.CarType,//车辆类型109 EngineNubmer: avBody.EngineNubmer,//发动机号110 IdentifyNumber:avBody.IdentifyNumber ,//识别号111 InsuranceExpiresTime:avBody.InsuranceExpiresTime,//保险到期112 YearTestExpiresTime: avBody.YearTestExpiresTime,//年检到期113 PlateNumber: avBody.PlateNumber, //车牌号 ,114 CoachId: avBody.QueryString("CoachId"),115 LicenseExpriesTime: avBody.LicenseExpriesTime//营运证有效期116 };117 var thisObj = $(obj);118 var oldVal = thisObj.val();119 $(obj).attr("disabled", true).val("提交中...");120 $.postToken(appPath + "CostManage/AddCTCarInfo", parm, function (data) {121 if (data.IsSuccess) {122 alert123 alert("添加成功!");124 avBody.Address = "";//地址125 avBody.BrandModel = "";//品牌型号126 avBody.CarProprietor = "";//车辆所有人127 avBody.CarType = "";//车辆类型128 avBody.EngineNubmer = "";//发动机号129 avBody.IdentifyNumber = "";//识别号130 avBody.InsuranceExpiresTime = "";//保险到期131 avBody.YearTestExpiresTime = "";//年检到期132 avBody.PlateNumber = "";//车牌号 133 $("#SelCarType").val("");134 avBody.LoadData();135 } else {136 137 alert("添加失败!" + data.Message);138 }139 140 thisObj.attr("disabled", false).val(oldVal);141 });142 143 144 145 };146 147 vm.UptCostManageInfo = function (Id, obj) {148 149 avBody.InsuranceExpiresTime = $("#txtInsuranceExpiresTime").val();150 avBody.YearTestExpiresTime = $("#txtYearTestExpiresTime").val();151 avBody.LicenseExpriesTime=$("#txtLicenseExpriesTime").val();152 153 var parm = {154 ID: Id, 155 Address: avBody.Address,//地址156 BrandModel: avBody.BrandModel ,//品牌型号157 CarProprietor: avBody.CarProprietor ,//车辆所有人158 CarType: avBody.CarType,//车辆类型159 EngineNubmer: avBody.EngineNubmer,//发动机号160 IdentifyNumber:avBody.IdentifyNumber ,//识别号161 InsuranceExpiresTime:avBody.InsuranceExpiresTime,//保险到期162 YearTestExpiresTime: avBody.YearTestExpiresTime,//年检到期163 PlateNumber: avBody.PlateNumber ,//车牌号 ,164 CoachId: avBody.QueryString("CoachId"),165 LicenseExpriesTime: avBody.LicenseExpriesTime//营运证有效期166 };167 var thisObj = $(obj);168 var oldVal = thisObj.val();169 $(obj).attr("disabled", true).val("提交中...");170 $.postToken(appPath + "CostManage/UptCTCarInfo", parm, function (data) {171 if (data.IsSuccess) {172 alert("修改成功!");173 avBody.LoadData();174 175 } else {176 177 alert("修改失败!" + data.Message);178 }179 180 thisObj.attr("disabled", false).val(oldVal);181 }); 182 };183 vm.DelCTCarInfo = function (Id,obj) { 184 185 var parm = {186 ID: Id,187 CoachId: avBody.QueryString("CoachId")188 };189 190 if (confirm("确认要删除该车辆吗?")) {191 var thisObj = $(obj);192 var oldVal = thisObj.val();193 $(obj).attr("disabled", true).val("提交中...");194 $.postToken(appPath + "CostManage/DelCTCarInfo", parm, function (data) {195 if (data.IsSuccess) {196 197 avBody.backcar();198 } else {199 200 alert("删除失败!" + data.Message);201 }202 203 thisObj.attr("disabled", false).val(oldVal);204 });205 } else {206 return false; 207 }208 };209 vm.showcardeatail = function () {210 211 if (avBody.ID != null && avBody.ID != "") {212 $("#Delbtn").show();213 } else {214 $("#Delbtn").hide();215 }216 $(".cardetaile").slideDown();217 $(".carcontent").slideUp();218 219 avBody.Address = "";//地址220 avBody.BrandModel = "";//品牌型号221 avBody.CarProprietor = "";//车辆所有人222 avBody.CarType = "";//车辆类型223 avBody.EngineNubmer = "";//发动机号224 avBody.IdentifyNumber = "";//识别号225 avBody.InsuranceExpiresTime = "";//保险到期226 avBody.YearTestExpiresTime = "";//年检到期227 $("#txtInsuranceExpiresTime").val("");228 $("#txtYearTestExpiresTime").val("");229 avBody.PlateNumber = "";//车牌号 230 avBody.CheckCarType("");231 };232 vm.backcar = function () {233 $(".cardetaile").slideUp();234 $(".carcontent").slideDown();235 $("#SelCarType").val("");//车辆类型236 avBody.ID = "";237 avBody.Address = "";//地址238 avBody.BrandModel = "";//品牌型号239 avBody.CarProprietor = "";//车辆所有人240 avBody.CarType = "";//车辆类型241 avBody.EngineNubmer = "";//发动机号242 avBody.IdentifyNumber = "";//识别号243 avBody.InsuranceExpiresTime = "";//保险到期244 $("#txtInsuranceExpiresTime").val("");245 $("#txtYearTestExpiresTime").val("");246 avBody.YearTestExpiresTime = "";//年检到期247 248 avBody.PlateNumber = "";//车牌号 249 avBody.LoadData();250 251 };252 //End253 vm.QueryString = function (name) {254 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");255 var r = window.location.search.substr(1).match(reg);256 if (r != null) return r[2];257 return null;258 };259 });260 261 $(function () {262 //if (avBody.QueryString("CoachId") == "" || avBody.QueryString("CoachId") == null) { 263 // alert("参数错误!!");264 // return false;265 //}266 avBody.CoachId = avBody.QueryString("CoachId");267 avBody.LoadData();268 });