home-v1.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. var vm = new Vue({
  2. el: '#app',
  3. data: {
  4. title: "",
  5. statisticsTime: "",
  6. month: "",
  7. lastMonth: "",
  8. monthModuleTypeDtos: [],
  9. v1s: [],
  10. v1sBackup: [],
  11. pMark: "",
  12. pYear: 0,
  13. pMonth: 0,
  14. totals: [0, 0, 0],
  15. modelPrefixs: [],
  16. lines: [],
  17. diffs: [0, 0, 0],
  18. modelSizes: [],
  19. modelPrefix: "All",
  20. modelSize: "All",
  21. line: "All",
  22. order: "0"
  23. },
  24. mounted() {
  25. this.init()
  26. this.getModuleTypeOverviewByMark()
  27. },
  28. watch: {
  29. lines: function () {
  30. this.$nextTick(function () {
  31. if (this.modelPrefix === "undefined" || this.modelPrefix === "") {
  32. this.modelPrefix = "All";
  33. }
  34. $("#selectModelPrefix").val(this.modelPrefix);
  35. if (this.modelSize === "undefined" || this.modelSize === "") {
  36. this.modelSize = "";
  37. }
  38. $("#selectModelSize").val(this.modelSize);
  39. if (this.line === "undefined" || this.line === "") {
  40. this.line = "All";
  41. }
  42. $("#selectLine").val(this.line);
  43. this.onClickFilter();
  44. this.sort(this.order);
  45. });
  46. }
  47. },
  48. methods: {
  49. onHref(url) {
  50. window.location.href = url;
  51. },
  52. init() {
  53. let width = document.body.clientWidth - 120;
  54. let homeTop = document.querySelector("#homeTop");
  55. let homeTable1 = document.querySelector("#homeTable1");
  56. let homeTable2 = document.querySelector("#homeTable2");
  57. homeTop.style.width = width + 'px';
  58. homeTable1.style.width = width + 'px';
  59. homeTable2.style.width = width + 'px';
  60. this.readCookie();
  61. if (this.pYear == 0 || this.pMonth == 0 || this.pYear == "undefined" || this.pMonth == "undefined") {
  62. let now = new Date();
  63. let nowYear = now.getFullYear();
  64. let nowMonth = now.getMonth() + 1;
  65. let nowDay = now.getDate();
  66. if (nowMonth >= 12) {
  67. nowYear++;
  68. }
  69. if (nowDay >= 21) {
  70. nowMonth++
  71. if (nowMonth > 12) {
  72. nowMonth = 1;
  73. }
  74. }
  75. $("#selectYear").val(nowYear);
  76. $("#selectMonth").val(nowMonth);
  77. this.pYear = nowYear;
  78. this.pMonth = nowMonth;
  79. this.writeCookie();
  80. } else {
  81. $("#selectMark").val(this.pMark);
  82. $("#selectYear").val(this.pYear);
  83. $("#selectMonth").val(this.pMonth);
  84. }
  85. },
  86. refresh() {
  87. this.writeCookie();
  88. this.getModuleTypeOverviewByMark()
  89. },
  90. getModuleTypeOverviewByMark() {
  91. let _this = this
  92. this.readCookie();
  93. axios
  94. .get('/Home/GetModuleTypeOverviewByMarkV1',
  95. {
  96. params: {
  97. mark: _this.pMark,
  98. year: _this.pYear,
  99. month: _this.pMonth
  100. }
  101. })
  102. .then(function (response) {
  103. _this.title = response.data.title
  104. _this.statisticsTime = response.data.statisticsTime
  105. _this.month = response.data.month
  106. _this.lastMonth = response.data.lastMonth
  107. _this.monthModuleTypeDtos = response.data.monthModuleTypeDtos
  108. _this.v1s = response.data.monthModuleTypeDtosV1s
  109. _this.v1sBackup = _this.v1s
  110. _this.initModelPrefixs()
  111. _this.initModelSizes()
  112. _this.initLines()
  113. if (_this.v1s !== undefined) {
  114. _this.totals[0] = 0;
  115. _this.totals[1] = 0;
  116. _this.totals[2] = 0;
  117. for (var i = 0; i < _this.v1s.length; i++) {
  118. _this.totals[0] += _this.v1s[i].planCapacity;
  119. _this.totals[0] += _this.v1s[i].lastModuleCapacity;
  120. _this.totals[1] += _this.v1s[i].capacity;
  121. }
  122. _this.totals[2] = _this.totals[1] - _this.totals[0];
  123. }
  124. _this.cdiffs()
  125. })
  126. .catch(function (error) {
  127. console.log(error)
  128. });
  129. },
  130. lastMonthClick() {
  131. let year = $('#selectYear option:selected').val()
  132. let minYear = $('#selectYear option:first').val()
  133. let month = $('#selectMonth option:selected').val()
  134. month--
  135. if (month === 0) {
  136. month = 12
  137. year--
  138. if (year < minYear) {
  139. year = minYear
  140. }
  141. }
  142. $("#selectYear").val(year)
  143. $("#selectMonth").val(month)
  144. this.writeCookie();
  145. this.getModuleTypeOverviewByMark()
  146. },
  147. nextMonthClick() {
  148. let year = $('#selectYear option:selected').val()
  149. let maxYear = $('#selectYear option:last').val()
  150. let month = $('#selectMonth option:selected').val()
  151. month++
  152. if (month === 13) {
  153. month = 1
  154. year++
  155. if (year > maxYear) {
  156. year = maxYear
  157. }
  158. }
  159. $("#selectYear").val(year)
  160. $("#selectMonth").val(month)
  161. this.writeCookie();
  162. this.getModuleTypeOverviewByMark()
  163. },
  164. writeCookie() {
  165. document.cookie = 'pMark=' + $('#selectMark option:selected').val();
  166. document.cookie = 'pYear=' + $('#selectYear option:selected').val();
  167. document.cookie = 'pMonth=' + $('#selectMonth option:selected').val()
  168. document.cookie = 'pOrder=' + this.order;
  169. document.cookie = 'pModelPrefix=' + $('#selectModelPrefix option:selected').val()
  170. document.cookie = 'pModelSize=' + $("#selectModelSize").val();
  171. document.cookie = 'pLine=' + $('#selectLine option:selected').val()
  172. },
  173. readCookie() {
  174. this.pMark = document.cookie.replace(/(?:(?:^|.*;\s*)pMark\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  175. this.pYear = document.cookie.replace(/(?:(?:^|.*;\s*)pYear\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  176. this.pMonth = document.cookie.replace(/(?:(?:^|.*;\s*)pMonth\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  177. let order = document.cookie.replace(/(?:(?:^|.*;\s*)pOrder\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  178. this.order = parseInt(order);
  179. this.modelPrefix = document.cookie.replace(/(?:(?:^|.*;\s*)pModelPrefix\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  180. this.modelSize = document.cookie.replace(/(?:(?:^|.*;\s*)pModelSize\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  181. this.line = document.cookie.replace(/(?:(?:^|.*;\s*)pLine\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  182. },
  183. sort(order) {
  184. this.order = order;
  185. this.writeCookie();
  186. if (order === 0) {
  187. this.v1s.sort(function (a, b) {
  188. return (b.planCapacity + b.lastModuleCapacity) - (a.planCapacity + a.lastModuleCapacity);
  189. });
  190. }
  191. if (order === 1) {
  192. this.v1s.sort(function (a, b) {
  193. return b.difference - a.difference;
  194. });
  195. }
  196. if (order === 2) {
  197. this.v1s.sort(function (a, b) {
  198. return a.difference - b.difference;
  199. });
  200. }
  201. if (order === 3) {
  202. this.v1s.sort(function (a, b) {
  203. return (b.planCapacity + b.lastModuleCapacity) - (a.planCapacity + a.lastModuleCapacity);
  204. });
  205. }
  206. if (order === 4) {
  207. this.v1s.sort(function (a, b) {
  208. return (a.planCapacity + a.lastModuleCapacity) - (b.planCapacity + b.lastModuleCapacity);
  209. });
  210. }
  211. },
  212. planSort(order) {
  213. this.order = order;
  214. this.writeCookie();
  215. if (order === 1) {
  216. this.v1s.sort(function (a, b) {
  217. return (b.planCapacity + b.lastModuleCapacity) - (a.planCapacity + a.lastModuleCapacity);
  218. });
  219. }
  220. if (order === 2) {
  221. this.v1s.sort(function (a, b) {
  222. return (a.planCapacity + a.lastModuleCapacity) - (b.planCapacity + b.lastModuleCapacity);
  223. });
  224. }
  225. },
  226. onClickFilter() {
  227. let modelPrefix = $("#selectModelPrefix").val();
  228. let modelSize = $("#selectModelSize").val();
  229. let line = $("#selectLine").val();
  230. var ms = [];
  231. for (var i = 0; i < this.v1sBackup.length; i++) {
  232. ms.push(this.v1sBackup[i])
  233. }
  234. if (modelPrefix != "All") {
  235. for (var i = 0; i < ms.length; i++) {
  236. var len = modelPrefix.length;
  237. if (ms[i].models[0].substring(0, len) != modelPrefix) {
  238. ms.splice(i, 1);
  239. i--;
  240. }
  241. }
  242. }
  243. if (modelSize != "All") {
  244. ms = this.fuzzyQuery(ms, modelSize);
  245. }
  246. switch (line) {
  247. case "All":
  248. break;
  249. case "待排配":
  250. for (var i = 0; i < ms.length; i++) {
  251. if (ms[i].lines.length > 0) {
  252. ms.splice(i, 1);
  253. i--;
  254. }
  255. }
  256. break;
  257. default:
  258. for (var i = 0; i < ms.length; i++) {
  259. var b = false;
  260. for (var j = 0; j < ms[i].lines.length; j++) {
  261. if (ms[i].lines[j].line.toString() === line) {
  262. b = true;
  263. break;
  264. }
  265. }
  266. if (b === false) {
  267. ms.splice(i, 1);
  268. i--;
  269. }
  270. }
  271. }
  272. this.writeCookie();
  273. this.v1s = ms;
  274. },
  275. fuzzyQuery(list, keyWord) {
  276. var arr = [];
  277. for (var i = 0; i < list.length; i++) {
  278. if (list[i].models[0].substring(0, 5).indexOf(keyWord) >= 0) {
  279. arr.push(list[i]);
  280. }
  281. }
  282. return arr;
  283. },
  284. initModelPrefixs() {
  285. var ms = ["All"];
  286. for (var i = 0; i < this.v1sBackup.length; i++) {
  287. var len = 2;
  288. var modelPrefix = this.v1sBackup[i].models[0].substring(0, len);
  289. switch (modelPrefix) {
  290. case "GT":
  291. if (this.v1sBackup[i].models[0].substring(0, 4) === "GTP-") {
  292. if (ms.indexOf("GTP") === -1) {
  293. ms.push("GTP");
  294. }
  295. }
  296. break;
  297. case "FT":
  298. if (this.v1sBackup[i].models[0].substring(0, 4) === "FTP-") {
  299. if (ms.indexOf("FTP") === -1) {
  300. ms.push("FTP");
  301. }
  302. }
  303. break;
  304. default:
  305. if (ms.indexOf(modelPrefix) === -1) {
  306. ms.push(modelPrefix)
  307. }
  308. }
  309. }
  310. this.modelPrefixs = ms;
  311. },
  312. initModelSizes() {
  313. var ms = ["All"];
  314. for (var i = 0; i < this.v1sBackup.length; i++) {
  315. var modelPrefix = this.v1sBackup[i].models[0].substring(0, 2);
  316. switch (modelPrefix) {
  317. case "GT":
  318. if (this.v1sBackup[i].models[0].substring(0, 4) === "GTP-") {
  319. let s = this.v1sBackup[i].models[0].substring(6, 9);
  320. if (ms.indexOf(s) === -1) {
  321. ms.push(s);
  322. }
  323. }
  324. break;
  325. case "FT":
  326. if (this.v1sBackup[i].models[0].substring(0, 4) === "FTP-") {
  327. let s = this.v1sBackup[i].models[0].substring(6, 9);
  328. if (ms.indexOf(s) === -1) {
  329. ms.push(s);
  330. }
  331. }
  332. break;
  333. default:
  334. let s = this.v1sBackup[i].models[0].substring(2, 5);
  335. if (ms.indexOf(s) === -1) {
  336. ms.push(s);
  337. }
  338. }
  339. }
  340. this.modelSizes = ms;
  341. },
  342. initLines() {
  343. var ms = ["All"];
  344. if (this.pMark === "2F") {
  345. for (var i = 1; i <= 12; i++) {
  346. ms.push(i)
  347. }
  348. }
  349. if (this.pMark === "1F") {
  350. for (var i = 1; i <= 6; i++) {
  351. ms.push(i)
  352. }
  353. }
  354. ms.push("待排配")
  355. this.lines = ms;
  356. },
  357. cdiffs() {
  358. this.diffs = [0, 0, 0];
  359. for (var i = 0; i < this.v1s.length; i++) {
  360. if (this.v1s[i].difference > 0) {
  361. this.diffs[0] += this.v1s[i].difference;
  362. } else {
  363. this.diffs[1] += this.v1s[i].difference;
  364. }
  365. this.diffs[2] += this.v1s[i].difference;
  366. }
  367. }
  368. }
  369. })