tools.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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. getInUrgentTime(date, inUrgent,callback) {
  297. let now = new Date(date);
  298. let theYear = now.getFullYear();
  299. $.ajax({
  300. type: "POST",
  301. dataType: "json",
  302. crossDomain: false,
  303. url: globalConfig.context + '/open/html/json/vacations' + theYear,
  304. success: (result)=>{
  305. if (!data.data) {
  306. if ( data.error && data.error.length ) {
  307. message.warning(data.error[0].message);
  308. };
  309. } else {
  310. for (var i = 1; i <= inUrgent;) {
  311. now.setDate(now.getDate() + 1);
  312. if (!vocations[getKey(now)]) {
  313. i++;
  314. };
  315. };
  316. callback(now);
  317. };
  318. }
  319. });
  320. function getKey(date) {
  321. var year = date.getFullYear(),
  322. month = date.getMonth() + 1,
  323. day = date.getDate();
  324. year = "" + year;
  325. month = (month > 9 ? "" : "0") + month;
  326. day = (day > 9 ? "" : "0") + day;
  327. return year + month + day;
  328. }
  329. },
  330. getStepList(pid,url) {
  331. let stepList = [];
  332. $.ajax({
  333. method: "get",
  334. dataType: "json",
  335. crossDomain: false,
  336. cache: false,
  337. url: globalConfig.context + url + "?pid=" + pid,
  338. success: function (data) {
  339. if (!data.data) {
  340. if (data.error && data.error.length ) {
  341. return;
  342. };
  343. };
  344. for (var item in data.data) {
  345. stepList.push(
  346. <Timeline.Item key={item}>
  347. <span>{module.exports.getPatentState(data.data[item].state)}</span>
  348. {module.exports.getTime(data.data[item].recordTime)}
  349. </Timeline.Item>
  350. )
  351. };
  352. }.bind(this),
  353. });
  354. return stepList;
  355. },
  356. //各种通过接口获取下拉列表
  357. setPatentStateOption(permission) {
  358. let theArr = [];
  359. patentStateList.map(function (item) {
  360. for (let i = 0; i < permission.length; i++) {
  361. if (item.value == permission[i]) {
  362. theArr.push(item);
  363. };
  364. };
  365. });
  366. return theArr;
  367. },
  368. setUserContactsList(){
  369. let theOption = [];
  370. $.ajax({
  371. method: "get",
  372. dataType: "json",
  373. crossDomain: false,
  374. url: globalConfig.context + '/api/user/getContacts',
  375. success: function (data) {
  376. if (!data.data) {
  377. if ( data.error && data.error.length ) {
  378. message.warning(data.error[0].message);
  379. };
  380. return;
  381. };
  382. for (let item in data.data) {
  383. let theData = data.data[item];
  384. theOption.push(
  385. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  386. );
  387. };
  388. }
  389. });
  390. return theOption;
  391. },
  392. setAdminContactsList(uid){
  393. let theOption = [];
  394. $.ajax({
  395. method: "get",
  396. dataType: "json",
  397. crossDomain: false,
  398. url: globalConfig.context + '/api/admin/getContacts',
  399. data:{ "uid": uid },
  400. success: function (data) {
  401. if (!data.data) {
  402. if ( data.error && data.error.length ) {
  403. message.warning(data.error[0].message);
  404. };
  405. return;
  406. };
  407. for (let item in data.data) {
  408. let theData = data.data[item];
  409. theOption.push(
  410. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  411. );
  412. };
  413. }
  414. });
  415. return theOption;
  416. },
  417. //高企培育资料完成情况(比重)
  418. getProportion(uid,callback){
  419. $.ajax({
  420. method: "get",
  421. dataType: "json",
  422. crossDomain: false,
  423. url: globalConfig.context + '/api/admin/proportion',
  424. data:{ "uid": uid },
  425. success: function (data) {
  426. if (!data.data) {
  427. if ( data.error && data.error.length ) {
  428. message.warning(data.error[0].message);
  429. };
  430. data.data = {}
  431. callback(data.data);
  432. };
  433. callback(data.data);
  434. }
  435. });
  436. },
  437. //保存高企培育资料完成情况
  438. saveProportion(id,uid,sign,status){
  439. $.ajax({
  440. method: "post",
  441. dataType: "json",
  442. crossDomain: false,
  443. url: globalConfig.context + '/api/admin/confirmProportion',
  444. data:{
  445. "id": id,
  446. "uid":uid,
  447. "sign":sign,
  448. "status":status
  449. },
  450. success: function (data) {
  451. if (!data.data) {
  452. if ( data.error && data.error.length ) {
  453. message.warning(data.error[0].message);
  454. };
  455. return;
  456. };
  457. }
  458. });
  459. },
  460. //获取window.location.search传的值
  461. getSearchUrl(e){
  462. let searchURL = e;
  463. let theObj = {};
  464. searchURL = searchURL.substring(1, searchURL.length);
  465. theObj[searchURL.split("&")[0].split("=")[0]] = searchURL.split("&")[0].split("=")[1];
  466. if ( searchURL.split("&")[1] ) {
  467. theObj[searchURL.split("&")[1].split("=")[0]] = searchURL.split("&")[1].split("=")[1];
  468. if ( searchURL.split("&")[2] ) {
  469. theObj[searchURL.split("&")[2].split("=")[0]] = searchURL.split("&")[2].split("=")[1];
  470. };
  471. };
  472. return theObj;
  473. },
  474. //预览接口
  475. getPreview(id,url,sign,callback){
  476. $.ajax({
  477. method: "get",
  478. dataType: "json",
  479. crossDomain: false,
  480. url: globalConfig.context + "/api/admin/preview/" + url,
  481. data:{
  482. "id": id,
  483. "sign": sign
  484. },
  485. success: function (data) {
  486. if (!data.data) {
  487. if ( data.error && data.error.length ) {
  488. message.warning(data.error[0].message);
  489. };
  490. };
  491. callback('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(location.origin + globalConfig.context + "/open/preview?" + data.data));
  492. }
  493. });
  494. },
  495. //获取企业规模
  496. getScaleState(e) {
  497. if (e) {
  498. let theType = '';
  499. scaleList.map(function (item) {
  500. if (item.value == e) {
  501. theType = item.key;
  502. };
  503. });
  504. return theType;
  505. }
  506. },
  507. //获取企业类型
  508. getCompanyType(type1, type2) {
  509. let companyTypeList = [];
  510. for (let i = 0; i < companyType.length; i++) {
  511. companyTypeList.push({
  512. value: companyType[i].value,
  513. label: companyType[i].label
  514. });
  515. if (companyType[i].children) {
  516. for (let j = 0; j < companyType[i].children.length; j++) {
  517. companyTypeList.push({
  518. value: companyType[i].children[j].value,
  519. label: companyType[i].children[j].label
  520. });
  521. };
  522. }
  523. };
  524. companyTypeList.sort(function (a, b) {
  525. return a.value - b.value
  526. });
  527. let typeKey = "";
  528. companyTypeList.map(function (item) {
  529. if (type1 == item.value) {
  530. typeKey = item.label;
  531. };
  532. if (type2 == item.value) {
  533. typeKey = typeKey + "/" + item.label;
  534. };
  535. });
  536. return typeKey;
  537. },
  538. //获取企业行业
  539. getIndustryType(e) {
  540. if (e) {
  541. let theType = '';
  542. companyType.map(function (item) {
  543. if (item.value == e) {
  544. theType = item.key;
  545. };
  546. });
  547. return theType;
  548. }
  549. },
  550. //获取合同状态
  551. getContractType: function (e) {
  552. if (e) {
  553. let theType = '';
  554. contractTypeList.map(function (item) {
  555. if (item.value == e) {
  556. theType = item.key;
  557. };
  558. });
  559. return theType;
  560. }
  561. },
  562. //获取合同类型
  563. getContractState: function (e) {
  564. if (e) {
  565. let theType = '';
  566. contractStateList.map(function (item) {
  567. if (item.value == e) {
  568. theType = item.key;
  569. };
  570. });
  571. return theType;
  572. }
  573. },
  574. //获取需求类型
  575. getDemandType: function (e) {
  576. if (e) {
  577. let theType = '';
  578. demandTypeList.map(function (item) {
  579. if (item.value == e) {
  580. theType = item.key;
  581. };
  582. });
  583. return theType;
  584. }
  585. },
  586. //获取成果类型
  587. getAchievementCategory: function (e) {
  588. if (e) {
  589. let theType = '';
  590. achievementCategoryList.map(function (item) {
  591. if (item.value == e) {
  592. theType = item.key;
  593. };
  594. });
  595. return theType;
  596. }
  597. },
  598. //获取需求和成果审核状态
  599. getTechAuditStatus: function (e) {
  600. if (e) {
  601. let theType = '';
  602. techAuditStatusList.map(function (item) {
  603. if (item.value == e) {
  604. theType = item.key;
  605. };
  606. });
  607. return theType;
  608. }
  609. },
  610. //获取需求和成果审核状态
  611. getMaturity: function (e) {
  612. if (e) {
  613. let theType = '';
  614. maturityList.map(function (item) {
  615. if (item.value == e) {
  616. theType = item.key;
  617. };
  618. });
  619. return theType;
  620. }
  621. },
  622. //获取需求和成果审核状态
  623. getTransferMode: function (e) {
  624. if (e) {
  625. let theType = '';
  626. transferModeList.map(function (item) {
  627. if (item.value == e) {
  628. theType = item.key;
  629. };
  630. });
  631. return theType;
  632. }
  633. },
  634. //获取创新度状态
  635. getInnovation: function (e) {
  636. if (e) {
  637. let theType = '';
  638. innovationList.map(function (item) {
  639. if (item.value == e) {
  640. theType = item.key;
  641. };
  642. });
  643. return theType;
  644. }
  645. },
  646. //获取创新度状态
  647. getOrderStatus: function (e) {
  648. if (e) {
  649. let theType = '';
  650. orderStatusList.map(function (item) {
  651. if (item.value == e) {
  652. theType = item.key;
  653. };
  654. });
  655. return theType;
  656. }
  657. }
  658. }