Global.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. // 网站基本信息
  2. companyInfo = {
  3. url: 'http://det.shandongewall.com/',
  4. main: 'alloutlong',
  5. year: new Date().getFullYear(),
  6. };
  7. headapi = process.env.NODE_ENV === 'development' ? '/api/' : '../';
  8. headbpi = process.env.NODE_ENV === 'development' ? '/bpi/' : 'http://cal.beswell.com:85/';
  9. headcpi = process.env.NODE_ENV === 'development' ? 'http://192.168.0.62:9010/' : 'http://cal.beswell.com:85/DataTransfer/';
  10. // 常用选项
  11. globalQuipState = function () {
  12. let option = [
  13. {
  14. value: '',
  15. label: '全部'
  16. }, {
  17. value: '0',
  18. label: '新入库'
  19. }, {
  20. value: '1',
  21. label: '未售'
  22. },
  23. ];
  24. return option
  25. };
  26. // 开始时间
  27. globalBt = function () {
  28. const et = new Date();
  29. const bt = new Date("2019-01-01 00:00:01");
  30. return [bt, et];
  31. };
  32. globalBt2 = function (days) {
  33. const et = new Date();
  34. const bt = new Date();
  35. days = days ? days : 0;
  36. bt.setTime(bt.getTime() - 3600 * 1000 * 24 * days);
  37. return [bt, et];
  38. };
  39. // 格式化时间
  40. globalfmtDate = function (datetime, length) {
  41. if ((datetime == '') || (datetime == undefined))
  42. return '';
  43. if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
  44. return '';
  45. length = !length ? 10 : length;//缺省参数
  46. return (datetime != null) ? datetime.substr(0, length) : '';
  47. };
  48. getHoursAndMin = function (datetime) {
  49. let date = new Date(datetime);
  50. h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
  51. m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  52. return h + m;
  53. }
  54. // 格式化时间去掉T
  55. nonTfmtDate = function (datetime) {
  56. if ((datetime == '') || (datetime == undefined))
  57. return '';
  58. if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
  59. return '';
  60. datetime = new Date(+new Date(datetime) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
  61. return datetime
  62. };
  63. // 格式化时间去掉T
  64. nonTfmtDatetoLength = function (datetime, length) {
  65. if ((datetime == '') || (datetime == undefined))
  66. return '';
  67. if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
  68. return '';
  69. length = !length ? 10 : length;//缺省参数
  70. datetime = new Date(+new Date(datetime) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').substr(0, length);
  71. return datetime
  72. };
  73. /**
  74. * 获取当前时间字符串
  75. * @param mYear 几年后
  76. * @param mMonth 几个月后
  77. * @returns {string}
  78. */
  79. getDate = function (mYear, mMonth) {
  80. let date = new Date();
  81. let split = "-";
  82. let year = date.getFullYear() + mYear;
  83. let month = date.getMonth() + 1 + mMonth;
  84. let strDate = date.getDate();
  85. if (month >= 1 && month <= 9) {
  86. month = "0" + month;
  87. }
  88. if (strDate >= 0 && strDate <= 9) {
  89. strDate = "0" + strDate;
  90. }
  91. let thisData = year + split + month + split + strDate;
  92. return thisData;
  93. };
  94. /**
  95. * 获取当前时间字符串
  96. * @param mDate 时间基准
  97. * @param mYear 几年后
  98. * @param mMonth 几个月后
  99. * @param mDay 几天后
  100. * @returns {string}
  101. */
  102. getDate = function (mDate, mYear, mMonth, mDay) {
  103. let date = new Date(mDate);
  104. let split = "-";
  105. let year = date.getFullYear() + mYear;
  106. let month = date.getMonth() + 1 + mMonth;
  107. let day = date.getDate() + mDay;
  108. let hh = new Date().getHours();
  109. let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
  110. let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
  111. //处理'日'越界
  112. if (day < 1) {
  113. month--;
  114. day = new Date(year, month, 0).getDate() + day;
  115. }
  116. let monthDays = new Date(year, month, 0).getDate();//这个月本应该多少天
  117. if (day > monthDays) {
  118. day = day - monthDays;
  119. month++;
  120. }
  121. //处理'月'越界
  122. if (month < 1) {
  123. year--;
  124. month += 12;
  125. }
  126. if (month > 12) {
  127. year++;
  128. month -= 12;
  129. }
  130. //10以下的月数和天数拼接0
  131. if (month >= 1 && month <= 9) {
  132. month = "0" + month;
  133. }
  134. if (day >= 0 && day <= 9) {
  135. day = "0" + day;
  136. }
  137. let thisData = year + split + month + split + day;
  138. return thisData;
  139. };
  140. // 校验内容长度
  141. globalValid = function (data, mins, maxs, text, that) {
  142. let thisVal = data;
  143. let thisLeng = thisVal.length;
  144. let min = parseInt(mins);
  145. let max = parseInt(maxs);
  146. let dispalyMin = min + 1;
  147. let title = '警告';
  148. if (thisVal == '') {
  149. that.$message({
  150. message: text + '不能为空!',
  151. type: 'warning'
  152. });
  153. return false
  154. } else if (thisLeng <= min) {
  155. that.$message({
  156. message: text + '最少' + dispalyMin + '字符!',
  157. type: 'warning'
  158. });
  159. return false
  160. } else if (thisLeng > max) {
  161. that.$message({
  162. message: text + '超出限制数量!',
  163. type: 'warning'
  164. });
  165. return false
  166. } else {
  167. return true
  168. }
  169. };
  170. // 手机号码格式
  171. globalCheckPhone = function (val) {
  172. let re = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
  173. val = val.toString();
  174. if (val.search(re) == -1) {
  175. return false;
  176. } else {
  177. return true;
  178. }
  179. };
  180. getNowDate = function () {
  181. let date = new Date();
  182. let y = date.getFullYear();
  183. let m = date.getMonth() + 1;
  184. let d = date.getDate();
  185. let H = date.getHours();
  186. let mm = date.getMinutes();
  187. let s = date.getSeconds()
  188. m = m < 10 ? "0" + m : m;
  189. d = d < 10 ? "0" + d : d;
  190. // H = H < 10 ? "0" + H : H;
  191. return y + "年" + m + "月" + d + "日";
  192. }
  193. globalcurrentWeek = function () {
  194. let weeks = new Date().getDay();
  195. return getNowDate() + ' ' + numberToWeekdays(weeks) + ' 第' + getWeekOfYear() + '周';
  196. }
  197. getWeekOfYear = function (date) {
  198. let today = new Date(date);
  199. let firstDay = new Date(today.getFullYear(), 0, 1);
  200. let dayOfWeek = firstDay.getDay();
  201. let spendDay = 1;
  202. if (dayOfWeek != 0) {
  203. spendDay = 7 - dayOfWeek + 1;
  204. }
  205. firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
  206. let d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
  207. let result = Math.ceil(d / 7);
  208. return result + 1;
  209. };
  210. // table配置项目
  211. // 每页选项
  212. pageOptions = function () {
  213. let option = [
  214. {
  215. value: 10,
  216. label: '10'
  217. }, {
  218. value: 25,
  219. label: '25'
  220. }, {
  221. value: 50,
  222. label: '50'
  223. }, {
  224. value: 100,
  225. label: '100'
  226. }, {
  227. value: 2000,
  228. label: '2000'
  229. },
  230. ];
  231. return option
  232. };
  233. // 到期日
  234. endTypeOptions = function () {
  235. let option = [
  236. {
  237. value: -99999,
  238. label: '全部'
  239. }, {
  240. value: 0,
  241. label: '已过期'
  242. }, {
  243. value: 30,
  244. label: '一个月'
  245. }, {
  246. value: 180,
  247. label: '半年'
  248. }, {
  249. value: 360,
  250. label: '一年'
  251. },
  252. ];
  253. return option
  254. }
  255. //会员类型
  256. vipOptions = function (i) {
  257. let option = [];
  258. if (i == 0) {
  259. option = [
  260. {
  261. value: -99,
  262. label: '全部'
  263. }, {
  264. value: 1,
  265. label: '年费会员'
  266. }, {
  267. value: 2,
  268. label: '充值会员'
  269. },
  270. ];
  271. } else {
  272. option = [
  273. {
  274. value: 1,
  275. label: '年费会员'
  276. }, {
  277. value: 2,
  278. label: '充值会员'
  279. },
  280. ];
  281. }
  282. return option
  283. }
  284. turnResToOption = function (data) {
  285. if (!data) return false
  286. let ids = data.map(item => {
  287. return {
  288. label: item.user_name + ' ' + item.usercode,
  289. key: item.uu_user_id,
  290. value: item.uu_user_id,
  291. }
  292. });
  293. return ids
  294. };
  295. turnResToOptionByViper = function (data) {
  296. if (!data) return false;
  297. let ids = data.map(item => {
  298. return {
  299. label: item.Name + ' ' + item.Phone,
  300. key: parseInt(item.Id),
  301. value: parseInt(item.Id),
  302. }
  303. });
  304. return ids
  305. };
  306. turnResToOptionBySimViper = function (data) {
  307. if (!data) return false;
  308. let ids = data.map(item => {
  309. return {
  310. label: item.user_name + ' ' + item.usercode,
  311. key: item.uu_user_id,
  312. value: item.uu_user_id,
  313. RemainHour: item.remain_hour,
  314. }
  315. });
  316. return ids
  317. };
  318. turnResToOptionByTempUser = function (data) {
  319. if (!data) return false;
  320. let ids = data.map(item => {
  321. return {
  322. label: item.UserName + ' ' + item.Phone,
  323. key: parseInt(item.TuId),
  324. value: parseInt(item.TuId),
  325. RemainHour: parseInt(item.RemainHour),
  326. }
  327. });
  328. return ids
  329. };
  330. turnResToOptionByCoach = function (data) {
  331. if (!data) return false;
  332. let ids = data.map(item => {
  333. return {
  334. label: item.Name + ' ' + item.Phone,
  335. key: parseInt(item.TeacherId),
  336. value: parseInt(item.TeacherId),
  337. }
  338. });
  339. return ids
  340. };
  341. turnResToOptionByUsers = function (data) {
  342. if (!data) return false
  343. let ids = data.map(item => {
  344. return {
  345. label: item.Name + ' ' + item.Phone,
  346. key: parseInt(item.Id),
  347. value: parseInt(item.Id),
  348. }
  349. })
  350. return ids
  351. }
  352. turnClassResToOption = function (data) {
  353. if (data == null) return false
  354. if (!data) return false
  355. let ids = data.map(item => {
  356. return {
  357. label: item.class_name,
  358. key: parseInt(item.class_id),
  359. value: parseInt(item.class_id),
  360. ClassColor: item.class_color,
  361. }
  362. })
  363. return ids
  364. }
  365. turnShopResToOption = function (data) {
  366. if (!data) return false;
  367. let ids = data.map(item => {
  368. return {
  369. label: item.ShopName,
  370. key: parseInt(item.ShopID),
  371. value: parseInt(item.ShopID)
  372. }
  373. })
  374. return ids
  375. };
  376. turnStdToOption = function (data) {
  377. if (!data) return false
  378. let ids = data.map(item => {
  379. return {
  380. label: item.class_name + '(' + item.begin_str + '-' + item.end_str + ')',
  381. key: parseInt(item.std_id),
  382. value: item.uu_std_id,
  383. classId: parseInt(item.class_id),
  384. ConsumeHour: item.consume_hour
  385. }
  386. })
  387. return ids
  388. };
  389. turnResToOptionByGroup = function (data) {
  390. if (!data) return false;
  391. let ids = data.map(item => {
  392. return {
  393. label: item.GroupName,
  394. key: parseInt(item.GroupId),
  395. value: parseInt(item.GroupId),
  396. }
  397. });
  398. return ids
  399. };
  400. numberToWeekdays = function (val) {
  401. switch (parseInt(val)) {
  402. case 1:
  403. return '星期一';
  404. break;
  405. case 2:
  406. return '星期二';
  407. break;
  408. case 3:
  409. return '星期三';
  410. break;
  411. case 4:
  412. return '星期四';
  413. break;
  414. case 5:
  415. return '星期五';
  416. break;
  417. case 6:
  418. return '星期六';
  419. break;
  420. case 0:
  421. return '星期天';
  422. break;
  423. }
  424. };
  425. // 获取年份列表
  426. getyearOptions = function (val) {
  427. let num = parseInt(val);
  428. let res = [];
  429. let item = {};
  430. let curYear = new Date().getFullYear();
  431. for (let i = 0; i < num; i++) {
  432. item[i] = {
  433. value: curYear - i, label: curYear - i + '年'
  434. }
  435. }
  436. return item
  437. };
  438. // 深拷贝
  439. deepClone = function (obj) {
  440. let _obj = JSON.stringify(obj),
  441. objClone = JSON.parse(_obj);
  442. return objClone
  443. };
  444. getSignStr = function (jsonStr) {
  445. return "123123123";
  446. }
  447. //课程类型
  448. courseOptions = function () {
  449. let option = [];
  450. option = [
  451. {
  452. value: 1,
  453. label: '室内课'
  454. }, {
  455. value: 2,
  456. label: '户外课'
  457. }, {
  458. value: 3,
  459. label: '线上课'
  460. }, {
  461. value: 4,
  462. label: '混合课'
  463. },
  464. ];
  465. return option
  466. }