tools.js 8.7 KB

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