tools.js 9.4 KB

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