common.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. (function (w) {
  2. var Common = function(){
  3. }
  4. // 定时刷新列表时间
  5. Common.prototype.setIntervalTimes = 3 * 60 * 1000;
  6. /**
  7. * 加载层
  8. */
  9. Common.prototype.loading = function(){
  10. $("#loading-tips").addClass("showPrompt");
  11. }
  12. /**
  13. * 去除加载层
  14. */
  15. Common.prototype.closeload = function(){
  16. $("#loading-tips").removeClass("showPrompt");
  17. }
  18. /**
  19. * 初始化表格事件
  20. */
  21. Common.prototype.initTabEvent = function(tabId){
  22. // dataTable 默认错误提示是alert,这里做处理
  23. $.fn.dataTable.ext.errMode = function( settings, tn, msg){
  24. //打印msg,和tn来判断,进了这个方法都是ajax走了error才会到这里来
  25. console.log(msg);
  26. }
  27. var $tab = $("#"+tabId);
  28. // 当Ajax请求完成时触发
  29. $tab.on('xhr.dt', function ( e, settings, json, xhr ){
  30. // json 为空 可能是登陆超时,刷新页面
  31. if(json == null){
  32. console.error("请求错误");
  33. // window.location.reload (true);
  34. }
  35. } );
  36. var dom;// 一个节点对象
  37. // 选中行保存行节点对象
  38. $tab.find("tbody").on( 'click', 'tr', function () {
  39. if(dom){
  40. //上一次选中行颜色恢复
  41. $(dom).css("background-color", "");
  42. }
  43. //选中行变色
  44. $( this ).css("background-color", "#B0BED9");
  45. dom = this;
  46. });
  47. var $tablebody = $('#'+tabId+' tbody');
  48. //单击选择该数据返回ID
  49. $tablebody.on( 'click', 'tr', function () {
  50. if(!$(this)[0].hasAttribute("clicheckedid")){
  51. $tablebody.find("[clicheckedid]").removeAttr("clicheckedid");
  52. var data = $tab.DataTable().row(this).data();
  53. var id = "";
  54. if(data) id = data.id;
  55. $(this).attr("clicheckedid", id);
  56. }
  57. } );
  58. }
  59. /**
  60. * 获取表格选中行的id
  61. */
  62. Common.prototype.getTabCheckedTrId = function(tabId){
  63. var $tab = $("#"+tabId);
  64. var dom = $('#'+tabId+' tbody').find("[clicheckedid]");
  65. var id = "";
  66. if(dom) id = dom.attr("clicheckedid");
  67. return id;
  68. }
  69. /**
  70. * 表格刷新
  71. */
  72. Common.prototype.tabRefresh = function(tabId){
  73. var $tab = $("#"+tabId);
  74. $tab.dataTable().api().ajax.reload( null, false ); // 刷新表格数据,分页信息不会重置
  75. }
  76. /**
  77. * 加载委托方下拉框控件数据
  78. */
  79. Common.prototype.initWtfdata = function(id){
  80. $.ajax({
  81. url: "ht/findWtfAll",
  82. type: "post",
  83. contentType:"application/json;charset=utf-8",
  84. // async: false,// 同步请求 防止编辑时延迟
  85. data: JSON.stringify({}),
  86. success: function(data){
  87. if (data.success) {
  88. var list = data.data;
  89. if(list && list.length>0){
  90. var html="<option value=''>请选择委托方</option>";
  91. $.each(list,function (i,obj) {
  92. if(obj.name != ""){
  93. html+="<option value='"+obj.id+"'";
  94. html+=">"+obj.yjwtf+"</option>";
  95. }
  96. })
  97. $(id).html(html);
  98. }
  99. }
  100. }
  101. });
  102. }
  103. /**
  104. * 加载分公司下拉控件数据
  105. */
  106. Common.prototype.initFgsdata = function(id, qxzShow, isasyncs){
  107. if(isasyncs === undefined || isasyncs) isasyncs = true;
  108. $.ajax({
  109. url: "grab/findFgsAll",
  110. type: "post",
  111. contentType:"application/json;charset=utf-8",
  112. async: isasyncs,// 同步请求 防止编辑时延迟
  113. data: JSON.stringify({}),
  114. success: function(data){
  115. if (data.success) {
  116. var list = data.data;
  117. if(list && list.length>0){
  118. var html = "";
  119. if(qxzShow === undefined || qxzShow) {
  120. html+= "<option value=''>请选择分公司</option>";
  121. }
  122. $.each(list,function (i,obj) {
  123. if(obj.name != ""){
  124. html+="<option value='"+obj.id+"'";
  125. html+=">"+obj.fgsMc+"</option>";
  126. }
  127. })
  128. $(id).html(html);
  129. }
  130. }
  131. }
  132. });
  133. }
  134. /**
  135. * 加载分公司下拉控件数据
  136. */
  137. Common.prototype.initFgsbyUserFgsidData = function(id, qxzShow, isasyncs){
  138. if(isasyncs === undefined || isasyncs) isasyncs = true;
  139. $.ajax({
  140. url: "grab/findFgsAllByUserFgsIds",
  141. type: "post",
  142. contentType:"application/json;charset=utf-8",
  143. async: isasyncs,// 同步请求 防止编辑时延迟
  144. data: JSON.stringify({}),
  145. success: function(data){
  146. if (data.success) {
  147. var list = data.data;
  148. if(list && list.length>0){
  149. var html = "";
  150. if(qxzShow === undefined || qxzShow) {
  151. html+= "<option value=''>请选择分公司</option>";
  152. }
  153. $.each(list,function (i,obj) {
  154. if(obj.name != ""){
  155. html+="<option value='"+obj.id+"'";
  156. html+=">"+obj.fgsMc+"</option>";
  157. }
  158. })
  159. $(id).html(html);
  160. }
  161. }
  162. }
  163. });
  164. }
  165. /**
  166. * 加载字典下拉框控件数据
  167. */
  168. Common.prototype.initDictdata = function(id, type, async){
  169. if(async === undefined) async = true;
  170. $.ajax({
  171. url: "dict/findAll",
  172. type: "post",
  173. contentType:"application/json;charset=utf-8",
  174. async: async,// 同步请求 防止编辑时延迟
  175. data: JSON.stringify({type: type}),
  176. success: function(data){
  177. if (data.success) {
  178. var list = data.data;
  179. if(list && list.length>0){
  180. var html="<option value=''>请选择类别</option>";
  181. $.each(list,function (i,obj) {
  182. if(obj.name != ""){
  183. html+="<option value='"+obj.value+"'";
  184. html+=">"+obj.name+"</option>";
  185. }
  186. })
  187. $(id).html(html);
  188. }
  189. }
  190. }
  191. });
  192. }
  193. /**
  194. * 初始化员工下拉框数据
  195. */
  196. Common.prototype.initUserSelect = function(id, async) {
  197. if(async === undefined) async = true;
  198. $.ajax({
  199. url: "user/findAll",
  200. type: "post",
  201. contentType:"application/json;charset=utf-8",
  202. async: async,// 同步请求 防止编辑时延迟
  203. data: JSON.stringify({}),
  204. success: function(data){
  205. if (data.success) {
  206. var list = data.data;
  207. if(list && list.length>0){
  208. var html="<option value=''>请选择业务员</option>";
  209. $.each(list,function (i,obj) {
  210. if(obj.name != ""){
  211. html+="<option value='"+obj.id+"'";
  212. html+=">"+obj.trueName+"</option>";
  213. }
  214. });
  215. $(id).html(html);
  216. }
  217. }
  218. }
  219. });
  220. }
  221. /**
  222. * 初始化业务员下拉框数据
  223. */
  224. Common.prototype.initYwyUserSelect = function(id, async) {
  225. if(async === undefined) async = true;
  226. $.ajax({
  227. url: "ywypz/findAll",
  228. type: "post",
  229. contentType:"application/json;charset=utf-8",
  230. async: async,// 同步请求 防止编辑时延迟
  231. data: JSON.stringify({}),
  232. success: function(data){
  233. if (data.success) {
  234. var list = data.data;
  235. if(list && list.length>0){
  236. var html="<option value=''>请选择业务员</option>";
  237. $.each(list,function (i,obj) {
  238. if(obj.name != ""){
  239. html+="<option value='"+obj.id+"'";
  240. html+=">"+obj.trueName+"</option>";
  241. }
  242. });
  243. $(id).html(html);
  244. }
  245. }
  246. }
  247. });
  248. }
  249. /**
  250. * 按车架号查询车型信息
  251. */
  252. Common.prototype.queryvin = function(modalId, cjh) {
  253. if(!cjh || cjh == "" || cjh.length < 17 || cjh.length > 17){
  254. Common.prototype.alert("车架号错误", "车架号必须是17位!", 2);
  255. return;
  256. }
  257. Common.prototype.loading();//加载层
  258. $.ajax({
  259. url: "bj/queryvin",
  260. type: "post",
  261. contentType:"application/json;charset=utf-8",
  262. data: JSON.stringify({cjh: cjh}),
  263. success: function(data){
  264. Common.prototype.closeload();//去除加载层
  265. if (data.success) {
  266. var obj = data.data;
  267. if(obj.chexing != "") {
  268. Common.prototype.loadCheXingData(modalId, obj.csh, obj.pinpai, obj.chexi, obj.chexing);
  269. }else{
  270. Common.prototype.alert("错误信息", "查无资料!", 2);
  271. }
  272. }else{
  273. Common.prototype.alert("错误信息", data.msg, 2);
  274. }
  275. }
  276. });
  277. }
  278. /**
  279. * 加载车型下拉数据
  280. */
  281. Common.prototype.loadCheXingData = function(modalId, csh, pinpai, chexi, chexing) {
  282. if(csh != "")
  283. $('#'+ modalId +" select[name='csh']").html("<option value='"+csh+"' selected>"+csh+"</option>");
  284. if(pinpai != "")
  285. $('#'+ modalId +" select[name='pinpai']").html("<option value='"+pinpai+"' selected>"+pinpai+"</option>");
  286. if(chexi != "")
  287. $('#'+ modalId +" select[name='chexi']").html("<option value='"+chexi+"' selected>"+chexi+"</option>");
  288. // $('#'+ modalId +" select[name='chexing']").html("<option value='"+chexing+"' selected>"+chexing+"</option>");
  289. $('#'+ modalId +" input[name='chexing']").val(chexing);
  290. }
  291. /**
  292. * 模态框 关闭时 里面的 清除内容 (解决模态框只请求一次服务器页面,内容不好刷新)
  293. */
  294. Common.prototype.modalHideDelHtml = function(modalId) {
  295. $('#'+modalId).on('hide.bs.modal', function () {
  296. $(this).removeData("bs.modal");
  297. //清除html
  298. $(this).find("div.modal-content").html("");
  299. })
  300. }
  301. /**
  302. * 初始化省市区下拉框数据
  303. */
  304. Common.prototype.initCitySelect = function(id, pid, async) {
  305. if(pid === undefined) pid = "1";
  306. if(async === undefined) async = true;
  307. $.ajax({
  308. url: "common/findCity",
  309. type: "post",
  310. contentType:"application/json;charset=utf-8",
  311. async: async,// 同步请求 防止编辑时延迟
  312. data: JSON.stringify({pid: pid}),
  313. success: function(data){
  314. if (data.success) {
  315. var list = data.data;
  316. if(list && list.length>0){
  317. var html="<option value=''>请选择</option>";
  318. $.each(list,function (i,obj) {
  319. if(obj.name != ""){
  320. html+="<option data-id='"+obj.id+"' value='"+obj.name+"'";
  321. html+=">"+obj.name+"</option>";
  322. }
  323. });
  324. $(id).html(html);
  325. }
  326. }
  327. }
  328. });
  329. }
  330. /**
  331. * 提示框
  332. */
  333. Common.prototype.alert = function(title, text, type){
  334. text = text || "";
  335. var typeStr = "info";
  336. if(type == 1){
  337. typeStr = "success";
  338. }else if(type == 2){
  339. typeStr = "error";
  340. }
  341. swal({title: title, text: text, type: typeStr, confirmButtonColor: "#1ab394"});
  342. }
  343. /* 按枚举数据下拉框加载公共方法 *****************************************************************************************************/
  344. Common.prototype.loadSelectDataByEnum = function(id, data, defaultkey, defaultvalue){
  345. defaultkey = defaultkey || "";
  346. defaultvalue = defaultvalue || "";
  347. if(id && data){
  348. var html = "";
  349. if(defaultkey != ""){
  350. html+= "<option value='"+defaultvalue+"'>"+defaultkey+"</option>";
  351. }
  352. for(var k in data){
  353. html+="<option value='" + k + "'";
  354. html+=">" + data[k] + "</option>";
  355. }
  356. $(id).html(html);
  357. }
  358. }
  359. /* 枚举数据 *****************************************************************************************************/
  360. var ENUM = {};
  361. // 车辆类型
  362. ENUM.cllx = {
  363. "1": "事故车",
  364. "2": "二手车",
  365. "3": "新车",
  366. "4": "配件",
  367. "5": "商用车",
  368. "6": "其他"
  369. };
  370. // 变速箱类型
  371. ENUM.bsxlx = {
  372. "1": "自动",
  373. "2": "手动",
  374. "3": "手动一体"
  375. };
  376. // 燃油类型
  377. ENUM.rylx = {
  378. "1": "汽油",
  379. "2": "柴油",
  380. "3": "电动",
  381. "4": "油电混动"
  382. };
  383. // 使用性质
  384. ENUM.syxz = {
  385. "1": "非营运",
  386. "2": "租赁",
  387. "3": "租赁非营运",
  388. "4": "营运",
  389. "5": "预约出租",
  390. "6": "特种车辆",
  391. "7": "教练"
  392. };
  393. // 所有人性质
  394. ENUM.syrxz = {
  395. "1": "私户",
  396. "2": "公户"
  397. };
  398. // 进口方式
  399. ENUM.jkfs = {
  400. "1": "进口",
  401. "2": "平行进口",
  402. "3": "中规"
  403. };
  404. // 事故原因
  405. ENUM.sgyy = {
  406. "1": "碰撞",
  407. "2": "水淹",
  408. "3": "火烧",
  409. "4": "其他"
  410. };
  411. // 发拍类型
  412. ENUM.fptype = {
  413. pttj: 0,
  414. dx: 1
  415. };
  416. w.Common = new Common();
  417. w.Common.ENUM = ENUM;
  418. })(window);