tools.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. import {
  2. message
  3. } from 'antd';
  4. import {
  5. provinceList,
  6. patentTypeList,
  7. patentStateList,
  8. patentFieldList,
  9. techFieldList,
  10. technicalSourceList,
  11. catagoryList,
  12. intellectualGetList,
  13. conversionFormList,
  14. annualReportStateList,
  15. cognizanceStateList,
  16. technologyStateList,
  17. copyrightStateList,
  18. vocations
  19. } from './dataDic.js';
  20. module.exports = {
  21. addressInit: function (_cmbProvince, _cmbCity, _cmbArea, defaultProvince, defaultCity, defaultArea) {
  22. var cmbProvince = document.getElementById(_cmbProvince);
  23. var cmbCity = document.getElementById(_cmbCity);
  24. var cmbArea = document.getElementById(_cmbArea);
  25. function cmbSelect(cmb, str) {
  26. for (var i = 0; i < cmb.options.length; i++) {
  27. if (cmb.options[i].value == str) {
  28. cmb.selectedIndex = i;
  29. return;
  30. }
  31. }
  32. }
  33. function cmbAddOption(cmb, str, obj) {
  34. var option = document.createElement("OPTION");
  35. cmb.options.add(option);
  36. option.innerText = str;
  37. option.value = str;
  38. option.obj = obj;
  39. }
  40. function changeCity() {
  41. cmbArea.options.length = 0;
  42. if (cmbCity.selectedIndex == -1) return;
  43. var item = cmbCity.options[cmbCity.selectedIndex].obj;
  44. for (var i = 0; i < item.areaList.length; i++) {
  45. cmbAddOption(cmbArea, item.areaList[i], null);
  46. }
  47. cmbSelect(cmbArea, defaultArea);
  48. }
  49. function changeProvince() {
  50. cmbCity.options.length = 0;
  51. cmbCity.onchange = null;
  52. if (cmbProvince.selectedIndex == -1) return;
  53. var item = cmbProvince.options[cmbProvince.selectedIndex].obj;
  54. for (var i = 0; i < item.cityList.length; i++) {
  55. cmbAddOption(cmbCity, item.cityList[i].name, item.cityList[i]);
  56. }
  57. cmbSelect(cmbCity, defaultCity);
  58. changeCity();
  59. cmbCity.onchange = changeCity;
  60. }
  61. for (var i = 0; i < provinceList.length; i++) {
  62. cmbAddOption(cmbProvince, provinceList[i].name, provinceList[i]);
  63. }
  64. cmbSelect(cmbProvince, defaultProvince);
  65. changeProvince();
  66. cmbProvince.onchange = changeProvince;
  67. },
  68. splitUrl: function (string, i, url) {
  69. let theList = [];
  70. let theArr = [];
  71. if (string) {
  72. theArr = string.split(i);
  73. theArr.map(function (item, i) {
  74. theList.push({
  75. uid: -i,
  76. url: url + item,
  77. response: {
  78. data: item
  79. }
  80. });
  81. });
  82. }
  83. return theList;
  84. },
  85. getBase64: function (img, callback) {
  86. const reader = new FileReader();
  87. reader.addEventListener('load', () => callback(reader.result));
  88. reader.readAsDataURL(img);
  89. },
  90. beforeUpload: function (file) {
  91. // debugger
  92. // const isJPG = file.type === 'image/jpeg/document';
  93. // if (!isJPG) {
  94. // message.error('You can only upload JPG file!');
  95. // }
  96. // const isLt2M = file.size / 1024 / 1024 < 2;
  97. // if (!isLt2M) {
  98. // message.error('Image must smaller than 2MB!');
  99. // }
  100. // return isJPG && isLt2M;
  101. },
  102. beforeUploadFile: function (file) {
  103. // debugger
  104. // const isJPG = file.type === 'image/jpeg/document';
  105. // if (!isJPG) {
  106. // message.error('You can only upload JPG file!');
  107. // }
  108. // const isLt2M = file.size / 1024 / 1024 < 2;
  109. // if (!isLt2M) {
  110. // message.error('Image must smaller than 2MB!');
  111. // }
  112. // return isJPG && isLt2M;
  113. },
  114. getTime: function (e, t) {
  115. if (e && !t) {
  116. var d = new Date(e);
  117. d = d.getFullYear() + "-" +
  118. ((d.getMonth() + 1) < 9 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)) + "-" +
  119. (d.getDate() < 9 ? '0' + d.getDate() : d.getDate()) + " ";
  120. // + (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) + ":" +
  121. // (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) + ":" +
  122. // (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
  123. return d;
  124. } else if (e && t) {
  125. var d1 = new Date(e);
  126. var d2 = new Date(e);
  127. d2 = d2.setMonth(d1.getMonth() + t);
  128. d2 = new Date(d2)
  129. d2 = d2.getFullYear() + "-" +
  130. ((d2.getMonth() + 1) < 9 ? '0' + (d2.getMonth() + 1) : (d2.getMonth() + 1)) + "-" +
  131. (d2.getDate() < 9 ? '0' + d2.getDate() : d2.getDate()) + " ";
  132. return d2;
  133. } else {
  134. return '';
  135. }
  136. },
  137. getPatentType: function (e) {
  138. if (e) {
  139. let theType = '';
  140. patentTypeList.map(function (item) {
  141. if (item.value == e) {
  142. theType = item.key;
  143. };
  144. });
  145. return theType;
  146. }
  147. },
  148. getPatentState: function (e) {
  149. if (e) {
  150. let theState = '';
  151. patentStateList.map(function (item) {
  152. if (item.value == e) {
  153. theState = item.key;
  154. };
  155. });
  156. return theState;
  157. }
  158. },
  159. getPatentField: function (e) {
  160. if (e) {
  161. let theState = '';
  162. patentFieldList.map(function (item) {
  163. if (item.value == e) {
  164. theState = item.key;
  165. };
  166. });
  167. return theState;
  168. }
  169. },
  170. getTechnicalSource: function (e) {
  171. if (e) {
  172. let theSource = '';
  173. technicalSourceList.map(function (item) {
  174. if (item.value == e) {
  175. theSource = item.key;
  176. };
  177. });
  178. return theSource;
  179. }
  180. },
  181. getTechField: function (field1, field2, field3) {
  182. let fieldList = [];
  183. for (let i = 0; i < techFieldList.length; i++) {
  184. fieldList.push({
  185. value: techFieldList[i].value,
  186. label: techFieldList[i].label
  187. });
  188. if (techFieldList[i].children) {
  189. for (let j = 0; j < techFieldList[i].children.length; j++) {
  190. fieldList.push({
  191. value: techFieldList[i].children[j].value,
  192. label: techFieldList[i].children[j].label
  193. });
  194. if (techFieldList[i].children[j].children) {
  195. for (let n = 0; n < techFieldList[i].children[j].children.length; n++) {
  196. fieldList.push({
  197. value: techFieldList[i].children[j].children[n].value,
  198. label: techFieldList[i].children[j].children[n].label
  199. });
  200. }
  201. };
  202. };
  203. }
  204. };
  205. fieldList.sort(function (a, b) {
  206. return a.value - b.value
  207. });
  208. let fieldKey = "";
  209. fieldList.map(function (item) {
  210. if (field1 == item.value) {
  211. fieldKey = item.label;
  212. };
  213. if (field2 == item.value) {
  214. fieldKey = fieldKey + "/" + item.label;
  215. };
  216. if (field3 == item.value) {
  217. fieldKey = fieldKey + "/" + item.label;
  218. };
  219. });
  220. return fieldKey;
  221. },
  222. getCatagory: function (e) {
  223. if (e) {
  224. let theType = '';
  225. catagoryList.map(function (item) {
  226. if (item.value == e) {
  227. theType = item.key;
  228. };
  229. });
  230. return theType;
  231. }
  232. },
  233. getIntellectualObtainWay: function (e) {
  234. if (e) {
  235. let theType = '';
  236. intellectualGetList.map(function (item) {
  237. if (item.value == e) {
  238. theType = item.key;
  239. };
  240. });
  241. return theType;
  242. }
  243. },
  244. getConversionForm: function (e) {
  245. if (e) {
  246. let theType = '';
  247. conversionFormList.map(function (item) {
  248. if (item.value == e) {
  249. theType = item.key;
  250. };
  251. });
  252. return theType;
  253. }
  254. },
  255. getAnnualReportState: function (e) {
  256. if (e) {
  257. let theType = '';
  258. annualReportStateList.map(function (item) {
  259. if (item.value == e) {
  260. theType = item.key;
  261. };
  262. });
  263. return theType;
  264. }
  265. },
  266. getCognizanceState: function (e) {
  267. if (e) {
  268. let theType = '';
  269. cognizanceStateList.map(function (item) {
  270. if (item.value == e) {
  271. theType = item.key;
  272. };
  273. });
  274. return theType;
  275. }
  276. },
  277. getTechnologyState: function (e) {
  278. if (e) {
  279. let theType = '';
  280. technologyStateList.map(function (item) {
  281. if (item.value == e) {
  282. theType = item.key;
  283. };
  284. });
  285. return theType;
  286. }
  287. },
  288. getCopyrightState: function (e) {
  289. if (e) {
  290. let theType = '';
  291. copyrightStateList.map(function (item) {
  292. if (item.value == e) {
  293. theType = item.key;
  294. };
  295. });
  296. return theType;
  297. }
  298. },
  299. downloadFile: function (path, fileName) {
  300. window.open(globalConfig.context + '/open/downloadFile?path=' + path + '&fileName=' + fileName)
  301. },
  302. companySearch(input, option) {
  303. return option.props.children.indexOf(input) >= 0
  304. },
  305. getInUrgentTime(date, inUrgent) {
  306. let now = new Date(date);
  307. for (var i = 1; i <= inUrgent;) {
  308. now.setDate(now.getDate() + 1);
  309. if (!vocations[getKey(now)]) {
  310. i++;
  311. };
  312. };
  313. return now;
  314. function getKey(date) {
  315. var year = date.getFullYear(),
  316. month = date.getMonth() + 1,
  317. day = date.getDate();
  318. year = "" + year;
  319. month = (month > 9 ? "" : "0") + month;
  320. day = (day > 9 ? "" : "0") + day;
  321. return year + month + day;
  322. }
  323. }
  324. }