tools.js 20 KB

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