tools.js 14 KB

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