tools.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. scaleList,
  20. companyType,
  21. industryList,
  22. contractTypeList,
  23. contractStateList,
  24. demandTypeList,
  25. achievementCategoryList,
  26. techAuditStatusList,
  27. maturityList,
  28. transferModeList,
  29. innovationList,
  30. orderStatusList,
  31. } from './dataDic.js';
  32. import { techFieldList } from './DicTechFieldList.js'
  33. module.exports = {
  34. splitUrl: function (string, i, url) {
  35. let theList = [];
  36. let theArr = [];
  37. if (string && string.length) {
  38. theArr = string.split(i);
  39. theArr.map(function (item, i) {
  40. theList.push({
  41. uid: -i,
  42. url: url + item,
  43. response: {
  44. data: item
  45. }
  46. });
  47. });
  48. }
  49. return theList;
  50. },
  51. getBase64: function (img, callback) {
  52. const reader = new FileReader();
  53. reader.addEventListener('load', () => callback(reader.result));
  54. reader.readAsDataURL(img);
  55. },
  56. beforeUpload: function (file) {
  57. // debugger
  58. // const isJPG = file.type === 'image/jpeg/document';
  59. // if (!isJPG) {
  60. // message.error('You can only upload JPG file!');
  61. // }
  62. // const isLt2M = file.size / 1024 / 1024 < 2;
  63. // if (!isLt2M) {
  64. // message.error('Image must smaller than 2MB!');
  65. // }
  66. // return isJPG && isLt2M;
  67. },
  68. beforeUploadFile: function (file) {
  69. // debugger
  70. // const isJPG = file.type === 'image/jpeg/document';
  71. // if (!isJPG) {
  72. // message.error('You can only upload JPG file!');
  73. // }
  74. // const isLt2M = file.size / 1024 / 1024 < 2;
  75. // if (!isLt2M) {
  76. // message.error('Image must smaller than 2MB!');
  77. // }
  78. // return isJPG && isLt2M;
  79. },
  80. getTime: function (e, t) {
  81. if (e && !t) {
  82. var d = new Date(e);
  83. d = d.getFullYear() + "-" +
  84. ((d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)) + "-" +
  85. (d.getDate() < 10 ? '0' + d.getDate() : d.getDate()) + " ";
  86. // + (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) + ":" +
  87. // (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) + ":" +
  88. // (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
  89. return d;
  90. } else if (e && t) {
  91. var d1 = new Date(e);
  92. var d2 = new Date(e);
  93. d2 = d2.setMonth(d1.getMonth() + t);
  94. d2 = new Date(d2)
  95. d2 = d2.getFullYear() + "-" +
  96. ((d2.getMonth() + 1) < 10 ? '0' + (d2.getMonth() + 1) : (d2.getMonth() + 1)) + "-" +
  97. (d2.getDate() < 10 ? '0' + d2.getDate() : d2.getDate()) + " ";
  98. return d2;
  99. } else {
  100. return '';
  101. }
  102. },
  103. getPatentType: function (e) {
  104. if (e) {
  105. let theType = '';
  106. patentTypeList.map(function (item) {
  107. if (item.value == e) {
  108. theType = item.key;
  109. };
  110. });
  111. return theType;
  112. }
  113. },
  114. getPatentState: function (e) {
  115. if (e) {
  116. let theState = '';
  117. patentStateList.map(function (item) {
  118. if (item.value == e) {
  119. theState = item.key;
  120. };
  121. });
  122. return theState;
  123. }
  124. },
  125. getPatentField: function (e) {
  126. if (e) {
  127. let theState = '';
  128. patentFieldList.map(function (item) {
  129. if (item.value == e) {
  130. theState = item.key;
  131. };
  132. });
  133. return theState;
  134. }
  135. },
  136. getTechnicalSource: function (e) {
  137. if (e) {
  138. let theSource = '';
  139. technicalSourceList.map(function (item) {
  140. if (item.value == e) {
  141. theSource = item.key;
  142. };
  143. });
  144. return theSource;
  145. }
  146. },
  147. getTechField: function (field1, field2, field3) {
  148. let fieldList = [];
  149. for (let i = 0; i < techFieldList.length; i++) {
  150. fieldList.push({
  151. value: techFieldList[i].value,
  152. label: techFieldList[i].label
  153. });
  154. if (techFieldList[i].children) {
  155. for (let j = 0; j < techFieldList[i].children.length; j++) {
  156. fieldList.push({
  157. value: techFieldList[i].children[j].value,
  158. label: techFieldList[i].children[j].label
  159. });
  160. if (techFieldList[i].children[j].children) {
  161. for (let n = 0; n < techFieldList[i].children[j].children.length; n++) {
  162. fieldList.push({
  163. value: techFieldList[i].children[j].children[n].value,
  164. label: techFieldList[i].children[j].children[n].label
  165. });
  166. }
  167. };
  168. };
  169. }
  170. };
  171. fieldList.sort(function (a, b) {
  172. return a.value - b.value
  173. });
  174. let fieldKey = "";
  175. fieldList.map(function (item) {
  176. if (field1 && Number(field1) == item.value) {
  177. fieldKey = item.label;
  178. };
  179. if (field2 == item.value) {
  180. fieldKey = fieldKey + "/" + item.label;
  181. };
  182. if (field3 == item.value) {
  183. fieldKey = fieldKey + "/" + item.label;
  184. };
  185. });
  186. return fieldKey;
  187. },
  188. getCatagory: function (e) {
  189. if (e) {
  190. let theType = '';
  191. catagoryList.map(function (item) {
  192. if (item.value == e) {
  193. theType = item.key;
  194. };
  195. });
  196. return theType;
  197. }
  198. },
  199. getIntellectualObtainWay: function (e) {
  200. if (e) {
  201. let theType = '';
  202. intellectualGetList.map(function (item) {
  203. if (item.value == e) {
  204. theType = item.key;
  205. };
  206. });
  207. return theType;
  208. }
  209. },
  210. getConversionForm: function (e) {
  211. if (e) {
  212. let theType = '';
  213. conversionFormList.map(function (item) {
  214. if (item.value == e) {
  215. theType = item.key;
  216. };
  217. });
  218. return theType;
  219. }
  220. },
  221. getAnnualReportState: function (e) {
  222. if (e) {
  223. let theType = '';
  224. annualReportStateList.map(function (item) {
  225. if (item.value == e) {
  226. theType = item.key;
  227. };
  228. });
  229. return theType;
  230. }
  231. },
  232. getCognizanceState: function (e) {
  233. if (e) {
  234. let theType = '';
  235. cognizanceStateList.map(function (item) {
  236. if (item.value == e) {
  237. theType = item.key;
  238. };
  239. });
  240. return theType;
  241. }
  242. },
  243. getTechnologyState: function (e) {
  244. if (e) {
  245. let theType = '';
  246. technologyStateList.map(function (item) {
  247. if (item.value == e) {
  248. theType = item.key;
  249. };
  250. });
  251. return theType;
  252. }
  253. },
  254. //显示用户认证状态
  255. getAuditState: function (e) {
  256. if (e) {
  257. let theType = '';
  258. auditStatusList.map(function (item) {
  259. if (item.value == e) {
  260. theType = item.key;
  261. };
  262. });
  263. return theType;
  264. }
  265. },
  266. getCopyrightState: function (e) {
  267. if (e) {
  268. let theType = '';
  269. copyrightStateList.map(function (item) {
  270. if (item.value == e) {
  271. theType = item.key;
  272. };
  273. });
  274. return theType;
  275. }
  276. },
  277. downloadFile: function (path, fileName) {
  278. window.open(globalConfig.context + '/open/downloadFile?path=' + path + '&fileName=' + fileName)
  279. },
  280. techDownloadFile: function (url, id) {
  281. window.open(globalConfig.context + url + '?id=' + id)
  282. },
  283. copyrightDownloadFile: function (id, sign, url) {
  284. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign)
  285. },
  286. newDownloadFile: function (id, sign, url,type) {
  287. if (!type ) {
  288. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign);
  289. };
  290. if ( type ) {
  291. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign + '&type=' + type);
  292. };
  293. },
  294. companySearch(input, option) {
  295. return option.props.children.indexOf(input) >= 0
  296. },
  297. getInUrgentTime(date, inUrgent) {
  298. let now = new Date(date);
  299. for (var i = 1; i <= inUrgent;) {
  300. now.setDate(now.getDate() + 1);
  301. if (!vocations[getKey(now)]) {
  302. i++;
  303. };
  304. };
  305. return now;
  306. function getKey(date) {
  307. var year = date.getFullYear(),
  308. month = date.getMonth() + 1,
  309. day = date.getDate();
  310. year = "" + year;
  311. month = (month > 9 ? "" : "0") + month;
  312. day = (day > 9 ? "" : "0") + day;
  313. return year + month + day;
  314. }
  315. },
  316. getStepList(pid,url) {
  317. let stepList = [];
  318. $.ajax({
  319. method: "get",
  320. dataType: "json",
  321. crossDomain: false,
  322. cache: false,
  323. url: globalConfig.context + url + "?pid=" + pid,
  324. success: function (data) {
  325. if (!data.data) {
  326. if (data.error && data.error.length ) {
  327. return;
  328. };
  329. };
  330. for (var item in data.data) {
  331. stepList.push(
  332. <Timeline.Item key={item}>
  333. <span>{module.exports.getPatentState(data.data[item].state)}</span>
  334. {module.exports.getTime(data.data[item].recordTime)}
  335. </Timeline.Item>
  336. )
  337. };
  338. }.bind(this),
  339. });
  340. return stepList;
  341. },
  342. //各种通过接口获取下拉列表
  343. setPatentStateOption(permission) {
  344. let theArr = [];
  345. patentStateList.map(function (item) {
  346. for (let i = 0; i < permission.length; i++) {
  347. if (item.value == permission[i]) {
  348. theArr.push(item);
  349. };
  350. };
  351. });
  352. return theArr;
  353. },
  354. setUserContactsList(){
  355. let theOption = [];
  356. $.ajax({
  357. method: "get",
  358. dataType: "json",
  359. crossDomain: false,
  360. url: globalConfig.context + '/api/user/getContacts',
  361. success: function (data) {
  362. if (!data.data) {
  363. if ( data.error && data.error.length ) {
  364. message.warning(data.error[0].message);
  365. };
  366. return;
  367. };
  368. for (let item in data.data) {
  369. let theData = data.data[item];
  370. theOption.push(
  371. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  372. );
  373. };
  374. }
  375. });
  376. return theOption;
  377. },
  378. setAdminContactsList(uid){
  379. let theOption = [];
  380. $.ajax({
  381. method: "get",
  382. dataType: "json",
  383. crossDomain: false,
  384. url: globalConfig.context + '/api/admin/getContacts',
  385. data:{ "uid": uid },
  386. success: function (data) {
  387. if (!data.data) {
  388. if ( data.error && data.error.length ) {
  389. message.warning(data.error[0].message);
  390. };
  391. return;
  392. };
  393. for (let item in data.data) {
  394. let theData = data.data[item];
  395. theOption.push(
  396. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  397. );
  398. };
  399. }
  400. });
  401. return theOption;
  402. },
  403. //高企培育资料完成情况(比重)
  404. getProportion(uid,callback){
  405. $.ajax({
  406. method: "get",
  407. dataType: "json",
  408. crossDomain: false,
  409. url: globalConfig.context + '/api/admin/proportion',
  410. data:{ "uid": uid },
  411. success: function (data) {
  412. if (!data.data) {
  413. if ( data.error && data.error.length ) {
  414. message.warning(data.error[0].message);
  415. };
  416. data.data = {}
  417. callback(data.data);
  418. };
  419. callback(data.data);
  420. }
  421. });
  422. },
  423. //保存高企培育资料完成情况
  424. saveProportion(id,uid,sign,status){
  425. $.ajax({
  426. method: "post",
  427. dataType: "json",
  428. crossDomain: false,
  429. url: globalConfig.context + '/api/admin/confirmProportion',
  430. data:{
  431. "id": id,
  432. "uid":uid,
  433. "sign":sign,
  434. "status":status
  435. },
  436. success: function (data) {
  437. if (!data.data) {
  438. if ( data.error && data.error.length ) {
  439. message.warning(data.error[0].message);
  440. };
  441. return;
  442. };
  443. }
  444. });
  445. },
  446. //获取window.location.search传的值
  447. getSearchUrl(e){
  448. let searchURL = e;
  449. let theObj = {};
  450. searchURL = searchURL.substring(1, searchURL.length);
  451. theObj[searchURL.split("&")[0].split("=")[0]] = searchURL.split("&")[0].split("=")[1];
  452. if ( searchURL.split("&")[1] ) {
  453. theObj[searchURL.split("&")[1].split("=")[0]] = searchURL.split("&")[1].split("=")[1];
  454. if ( searchURL.split("&")[2] ) {
  455. theObj[searchURL.split("&")[2].split("=")[0]] = searchURL.split("&")[2].split("=")[1];
  456. };
  457. };
  458. return theObj;
  459. },
  460. //预览接口
  461. getPreview(id,url,sign,callback){
  462. $.ajax({
  463. method: "get",
  464. dataType: "json",
  465. crossDomain: false,
  466. url: globalConfig.context + "/api/admin/preview/" + url,
  467. data:{
  468. "id": id,
  469. "sign": sign
  470. },
  471. success: function (data) {
  472. if (!data.data) {
  473. if ( data.error && data.error.length ) {
  474. message.warning(data.error[0].message);
  475. };
  476. };
  477. callback('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(location.origin + globalConfig.context + "/open/preview?" + data.data));
  478. }
  479. });
  480. },
  481. //获取企业规模
  482. getScaleState(e) {
  483. if (e) {
  484. let theType = '';
  485. scaleList.map(function (item) {
  486. if (item.value == e) {
  487. theType = item.key;
  488. };
  489. });
  490. return theType;
  491. }
  492. },
  493. //获取企业类型
  494. getCompanyType(type1, type2) {
  495. let companyTypeList = [];
  496. for (let i = 0; i < companyType.length; i++) {
  497. companyTypeList.push({
  498. value: companyType[i].value,
  499. label: companyType[i].label
  500. });
  501. if (companyType[i].children) {
  502. for (let j = 0; j < companyType[i].children.length; j++) {
  503. companyTypeList.push({
  504. value: companyType[i].children[j].value,
  505. label: companyType[i].children[j].label
  506. });
  507. };
  508. }
  509. };
  510. companyTypeList.sort(function (a, b) {
  511. return a.value - b.value
  512. });
  513. let typeKey = "";
  514. companyTypeList.map(function (item) {
  515. if (type1 == item.value) {
  516. typeKey = item.label;
  517. };
  518. if (type2 == item.value) {
  519. typeKey = typeKey + "/" + item.label;
  520. };
  521. });
  522. return typeKey;
  523. },
  524. //获取企业行业
  525. getIndustryType(e) {
  526. if (e) {
  527. let theType = '';
  528. companyType.map(function (item) {
  529. if (item.value == e) {
  530. theType = item.key;
  531. };
  532. });
  533. return theType;
  534. }
  535. },
  536. //获取合同状态
  537. getContractType: function (e) {
  538. if (e) {
  539. let theType = '';
  540. contractTypeList.map(function (item) {
  541. if (item.value == e) {
  542. theType = item.key;
  543. };
  544. });
  545. return theType;
  546. }
  547. },
  548. //获取合同类型
  549. getContractState: function (e) {
  550. if (e) {
  551. let theType = '';
  552. contractStateList.map(function (item) {
  553. if (item.value == e) {
  554. theType = item.key;
  555. };
  556. });
  557. return theType;
  558. }
  559. },
  560. //获取需求类型
  561. getDemandType: function (e) {
  562. if (e) {
  563. let theType = '';
  564. demandTypeList.map(function (item) {
  565. if (item.value == e) {
  566. theType = item.key;
  567. };
  568. });
  569. return theType;
  570. }
  571. },
  572. //获取成果类型
  573. getAchievementCategory: function (e) {
  574. if (e) {
  575. let theType = '';
  576. achievementCategoryList.map(function (item) {
  577. if (item.value == e) {
  578. theType = item.key;
  579. };
  580. });
  581. return theType;
  582. }
  583. },
  584. //获取需求和成果审核状态
  585. getTechAuditStatus: function (e) {
  586. if (e) {
  587. let theType = '';
  588. techAuditStatusList.map(function (item) {
  589. if (item.value == e) {
  590. theType = item.key;
  591. };
  592. });
  593. return theType;
  594. }
  595. },
  596. //获取需求和成果审核状态
  597. getMaturity: function (e) {
  598. if (e) {
  599. let theType = '';
  600. maturityList.map(function (item) {
  601. if (item.value == e) {
  602. theType = item.key;
  603. };
  604. });
  605. return theType;
  606. }
  607. },
  608. //获取需求和成果审核状态
  609. getTransferMode: function (e) {
  610. if (e) {
  611. let theType = '';
  612. transferModeList.map(function (item) {
  613. if (item.value == e) {
  614. theType = item.key;
  615. };
  616. });
  617. return theType;
  618. }
  619. },
  620. //获取创新度状态
  621. getInnovation: function (e) {
  622. if (e) {
  623. let theType = '';
  624. innovationList.map(function (item) {
  625. if (item.value == e) {
  626. theType = item.key;
  627. };
  628. });
  629. return theType;
  630. }
  631. },
  632. //获取创新度状态
  633. getOrderStatus: function (e) {
  634. if (e) {
  635. let theType = '';
  636. orderStatusList.map(function (item) {
  637. if (item.value == e) {
  638. theType = item.key;
  639. };
  640. });
  641. return theType;
  642. }
  643. }
  644. }