tools.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. import { message,Timeline,Select } from 'antd';
  2. import React from 'react';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import {
  6. provinceList,
  7. patentTypeList,
  8. patentStateList,
  9. patentFieldList,
  10. techFieldList,
  11. technicalSourceList,
  12. catagoryList,
  13. intellectualGetList,
  14. conversionFormList,
  15. annualReportStateList,
  16. cognizanceStateList,
  17. technologyStateList,
  18. copyrightStateList,
  19. vocations
  20. } from './dataDic.js';
  21. module.exports = {
  22. addressInit: function (_cmbProvince, _cmbCity, _cmbArea, defaultProvince, defaultCity, defaultArea) {
  23. var cmbProvince = document.getElementById(_cmbProvince);
  24. var cmbCity = document.getElementById(_cmbCity);
  25. var cmbArea = document.getElementById(_cmbArea);
  26. function cmbSelect(cmb, str) {
  27. for (var i = 0; i < cmb.options.length; i++) {
  28. if (cmb.options[i].value == str) {
  29. cmb.selectedIndex = i;
  30. return;
  31. }
  32. }
  33. }
  34. function cmbAddOption(cmb, str, obj) {
  35. var option = document.createElement("OPTION");
  36. cmb.options.add(option);
  37. option.innerText = str;
  38. option.value = str;
  39. option.obj = obj;
  40. }
  41. function changeCity() {
  42. cmbArea.options.length = 0;
  43. if (cmbCity.selectedIndex == -1) return;
  44. var item = cmbCity.options[cmbCity.selectedIndex].obj;
  45. for (var i = 0; i < item.areaList.length; i++) {
  46. cmbAddOption(cmbArea, item.areaList[i], null);
  47. }
  48. cmbSelect(cmbArea, defaultArea);
  49. }
  50. function changeProvince() {
  51. cmbCity.options.length = 0;
  52. cmbCity.onchange = null;
  53. if (cmbProvince.selectedIndex == -1) return;
  54. var item = cmbProvince.options[cmbProvince.selectedIndex].obj;
  55. for (var i = 0; i < item.cityList.length; i++) {
  56. cmbAddOption(cmbCity, item.cityList[i].name, item.cityList[i]);
  57. }
  58. cmbSelect(cmbCity, defaultCity);
  59. changeCity();
  60. cmbCity.onchange = changeCity;
  61. }
  62. for (var i = 0; i < provinceList.length; i++) {
  63. cmbAddOption(cmbProvince, provinceList[i].name, provinceList[i]);
  64. }
  65. cmbSelect(cmbProvince, defaultProvince);
  66. changeProvince();
  67. cmbProvince.onchange = changeProvince;
  68. },
  69. splitUrl: function (string, i, url) {
  70. let theList = [];
  71. let theArr = [];
  72. if (string) {
  73. theArr = string.split(i);
  74. theArr.map(function (item, i) {
  75. theList.push({
  76. uid: -i,
  77. url: url + item,
  78. response: {
  79. data: item
  80. }
  81. });
  82. });
  83. }
  84. return theList;
  85. },
  86. getBase64: function (img, callback) {
  87. const reader = new FileReader();
  88. reader.addEventListener('load', () => callback(reader.result));
  89. reader.readAsDataURL(img);
  90. },
  91. beforeUpload: function (file) {
  92. // debugger
  93. // const isJPG = file.type === 'image/jpeg/document';
  94. // if (!isJPG) {
  95. // message.error('You can only upload JPG file!');
  96. // }
  97. // const isLt2M = file.size / 1024 / 1024 < 2;
  98. // if (!isLt2M) {
  99. // message.error('Image must smaller than 2MB!');
  100. // }
  101. // return isJPG && isLt2M;
  102. },
  103. beforeUploadFile: function (file) {
  104. // debugger
  105. // const isJPG = file.type === 'image/jpeg/document';
  106. // if (!isJPG) {
  107. // message.error('You can only upload JPG file!');
  108. // }
  109. // const isLt2M = file.size / 1024 / 1024 < 2;
  110. // if (!isLt2M) {
  111. // message.error('Image must smaller than 2MB!');
  112. // }
  113. // return isJPG && isLt2M;
  114. },
  115. getTime: function (e, t) {
  116. if (e && !t) {
  117. var d = new Date(e);
  118. d = d.getFullYear() + "-" +
  119. ((d.getMonth() + 1) < 9 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)) + "-" +
  120. (d.getDate() < 9 ? '0' + d.getDate() : d.getDate()) + " ";
  121. // + (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) + ":" +
  122. // (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) + ":" +
  123. // (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
  124. return d;
  125. } else if (e && t) {
  126. var d1 = new Date(e);
  127. var d2 = new Date(e);
  128. d2 = d2.setMonth(d1.getMonth() + t);
  129. d2 = new Date(d2)
  130. d2 = d2.getFullYear() + "-" +
  131. ((d2.getMonth() + 1) < 9 ? '0' + (d2.getMonth() + 1) : (d2.getMonth() + 1)) + "-" +
  132. (d2.getDate() < 9 ? '0' + d2.getDate() : d2.getDate()) + " ";
  133. return d2;
  134. } else {
  135. return '';
  136. }
  137. },
  138. getPatentType: function (e) {
  139. if (e) {
  140. let theType = '';
  141. patentTypeList.map(function (item) {
  142. if (item.value == e) {
  143. theType = item.key;
  144. };
  145. });
  146. return theType;
  147. }
  148. },
  149. getPatentState: function (e) {
  150. if (e) {
  151. let theState = '';
  152. patentStateList.map(function (item) {
  153. if (item.value == e) {
  154. theState = item.key;
  155. };
  156. });
  157. return theState;
  158. }
  159. },
  160. getPatentField: function (e) {
  161. if (e) {
  162. let theState = '';
  163. patentFieldList.map(function (item) {
  164. if (item.value == e) {
  165. theState = item.key;
  166. };
  167. });
  168. return theState;
  169. }
  170. },
  171. getTechnicalSource: function (e) {
  172. if (e) {
  173. let theSource = '';
  174. technicalSourceList.map(function (item) {
  175. if (item.value == e) {
  176. theSource = item.key;
  177. };
  178. });
  179. return theSource;
  180. }
  181. },
  182. getTechField: function (field1, field2, field3) {
  183. let fieldList = [];
  184. for (let i = 0; i < techFieldList.length; i++) {
  185. fieldList.push({
  186. value: techFieldList[i].value,
  187. label: techFieldList[i].label
  188. });
  189. if (techFieldList[i].children) {
  190. for (let j = 0; j < techFieldList[i].children.length; j++) {
  191. fieldList.push({
  192. value: techFieldList[i].children[j].value,
  193. label: techFieldList[i].children[j].label
  194. });
  195. if (techFieldList[i].children[j].children) {
  196. for (let n = 0; n < techFieldList[i].children[j].children.length; n++) {
  197. fieldList.push({
  198. value: techFieldList[i].children[j].children[n].value,
  199. label: techFieldList[i].children[j].children[n].label
  200. });
  201. }
  202. };
  203. };
  204. }
  205. };
  206. fieldList.sort(function (a, b) {
  207. return a.value - b.value
  208. });
  209. let fieldKey = "";
  210. fieldList.map(function (item) {
  211. if (field1 == item.value) {
  212. fieldKey = item.label;
  213. };
  214. if (field2 == item.value) {
  215. fieldKey = fieldKey + "/" + item.label;
  216. };
  217. if (field3 == item.value) {
  218. fieldKey = fieldKey + "/" + item.label;
  219. };
  220. });
  221. return fieldKey;
  222. },
  223. getCatagory: function (e) {
  224. if (e) {
  225. let theType = '';
  226. catagoryList.map(function (item) {
  227. if (item.value == e) {
  228. theType = item.key;
  229. };
  230. });
  231. return theType;
  232. }
  233. },
  234. getIntellectualObtainWay: function (e) {
  235. if (e) {
  236. let theType = '';
  237. intellectualGetList.map(function (item) {
  238. if (item.value == e) {
  239. theType = item.key;
  240. };
  241. });
  242. return theType;
  243. }
  244. },
  245. getConversionForm: function (e) {
  246. if (e) {
  247. let theType = '';
  248. conversionFormList.map(function (item) {
  249. if (item.value == e) {
  250. theType = item.key;
  251. };
  252. });
  253. return theType;
  254. }
  255. },
  256. getAnnualReportState: function (e) {
  257. if (e) {
  258. let theType = '';
  259. annualReportStateList.map(function (item) {
  260. if (item.value == e) {
  261. theType = item.key;
  262. };
  263. });
  264. return theType;
  265. }
  266. },
  267. getCognizanceState: function (e) {
  268. if (e) {
  269. let theType = '';
  270. cognizanceStateList.map(function (item) {
  271. if (item.value == e) {
  272. theType = item.key;
  273. };
  274. });
  275. return theType;
  276. }
  277. },
  278. getTechnologyState: function (e) {
  279. if (e) {
  280. let theType = '';
  281. technologyStateList.map(function (item) {
  282. if (item.value == e) {
  283. theType = item.key;
  284. };
  285. });
  286. return theType;
  287. }
  288. },
  289. getCopyrightState: function (e) {
  290. if (e) {
  291. let theType = '';
  292. copyrightStateList.map(function (item) {
  293. if (item.value == e) {
  294. theType = item.key;
  295. };
  296. });
  297. return theType;
  298. }
  299. },
  300. downloadFile: function (path, fileName) {
  301. window.open(globalConfig.context + '/open/downloadFile?path=' + path + '&fileName=' + fileName)
  302. },
  303. techDownloadFile: function (url, id) {
  304. window.open(globalConfig.context + url + '?id=' + id)
  305. },
  306. copyrightDownloadFile: function (id, sign, url) {
  307. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign)
  308. },
  309. newDownloadFile: function (id, sign, url) {
  310. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign)
  311. },
  312. companySearch(input, option) {
  313. return option.props.children.indexOf(input) >= 0
  314. },
  315. getInUrgentTime(date, inUrgent) {
  316. let now = new Date(date);
  317. for (var i = 1; i <= inUrgent;) {
  318. now.setDate(now.getDate() + 1);
  319. if (!vocations[getKey(now)]) {
  320. i++;
  321. };
  322. };
  323. return now;
  324. function getKey(date) {
  325. var year = date.getFullYear(),
  326. month = date.getMonth() + 1,
  327. day = date.getDate();
  328. year = "" + year;
  329. month = (month > 9 ? "" : "0") + month;
  330. day = (day > 9 ? "" : "0") + day;
  331. return year + month + day;
  332. }
  333. },
  334. getStepList(pid,url) {
  335. let stepList = [];
  336. $.ajax({
  337. method: "post",
  338. dataType: "json",
  339. crossDomain: false,
  340. cache: false,
  341. url: globalConfig.context + url,
  342. data: {
  343. pid: pid
  344. },
  345. success: function (data) {
  346. if (!data.data) {
  347. if (data.error && data.error.length ) {
  348. return;
  349. };
  350. };
  351. for (var item in data.data) {
  352. stepList.push(
  353. <Timeline.Item key={item}>
  354. <span>{module.exports.getPatentState(data.data[item].state)}</span>
  355. {module.exports.getTime(data.data[item].recordTime)}
  356. </Timeline.Item>
  357. )
  358. };
  359. }.bind(this),
  360. });
  361. return stepList;
  362. },
  363. //各种通过接口获取下拉列表
  364. setPatentStateOption(type) {
  365. let theArr = [];
  366. const caiwu = ['1', '3', '13'];
  367. const xiaoshou = [];
  368. switch (type) {
  369. case 'caiwu':
  370. patentStateList.map(function (item) {
  371. for (let i = 0; i < caiwu.length; i++) {
  372. if (item.value == caiwu[i]) {
  373. theArr.push()
  374. };
  375. };
  376. });
  377. return theArr;
  378. case 'caiwu':
  379. patentStateList.map(function (item) {
  380. for (let i = 0; i < caiwu.length; i++) {
  381. if (item.value == caiwu[i]) {
  382. theArr.push()
  383. };
  384. };
  385. });
  386. return theArr;
  387. }
  388. },
  389. setUserContactsList(){
  390. let theOption = [];
  391. $.ajax({
  392. method: "get",
  393. dataType: "json",
  394. crossDomain: false,
  395. url: globalConfig.context + '/api/user/getContacts',
  396. success: function (data) {
  397. if (!data.data) {
  398. if ( data.error && data.error.length ) {
  399. message.warning(data.error[0].message);
  400. };
  401. return;
  402. };
  403. for (let item in data.data) {
  404. let theData = data.data[item];
  405. theOption.push(
  406. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  407. );
  408. };
  409. }
  410. });
  411. return theOption;
  412. },
  413. setAdminContactsList(uid){
  414. let theOption = [];
  415. $.ajax({
  416. method: "get",
  417. dataType: "json",
  418. crossDomain: false,
  419. url: globalConfig.context + '/api/admin/getContacts',
  420. data:{ "uid": uid },
  421. success: function (data) {
  422. if (!data.data) {
  423. if ( data.error && data.error.length ) {
  424. message.warning(data.error[0].message);
  425. };
  426. return;
  427. };
  428. for (let item in data.data) {
  429. let theData = data.data[item];
  430. theOption.push(
  431. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  432. );
  433. };
  434. }
  435. });
  436. return theOption;
  437. }
  438. }