tools.js 9.7 KB

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