tools.js 9.0 KB

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