tools.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. debugger
  179. };
  180. if (field2 == item.value) {
  181. fieldKey = fieldKey + "/" + item.label;
  182. };
  183. if (field3 == item.value) {
  184. fieldKey = fieldKey + "/" + item.label;
  185. };
  186. });
  187. return fieldKey;
  188. },
  189. getCatagory: function (e) {
  190. if (e) {
  191. let theType = '';
  192. catagoryList.map(function (item) {
  193. if (item.value == e) {
  194. theType = item.key;
  195. };
  196. });
  197. return theType;
  198. }
  199. },
  200. getIntellectualObtainWay: function (e) {
  201. if (e) {
  202. let theType = '';
  203. intellectualGetList.map(function (item) {
  204. if (item.value == e) {
  205. theType = item.key;
  206. };
  207. });
  208. return theType;
  209. }
  210. },
  211. getConversionForm: function (e) {
  212. if (e) {
  213. let theType = '';
  214. conversionFormList.map(function (item) {
  215. if (item.value == e) {
  216. theType = item.key;
  217. };
  218. });
  219. return theType;
  220. }
  221. },
  222. getAnnualReportState: function (e) {
  223. if (e) {
  224. let theType = '';
  225. annualReportStateList.map(function (item) {
  226. if (item.value == e) {
  227. theType = item.key;
  228. };
  229. });
  230. return theType;
  231. }
  232. },
  233. getCognizanceState: function (e) {
  234. if (e) {
  235. let theType = '';
  236. cognizanceStateList.map(function (item) {
  237. if (item.value == e) {
  238. theType = item.key;
  239. };
  240. });
  241. return theType;
  242. }
  243. },
  244. getTechnologyState: function (e) {
  245. if (e) {
  246. let theType = '';
  247. technologyStateList.map(function (item) {
  248. if (item.value == e) {
  249. theType = item.key;
  250. };
  251. });
  252. return theType;
  253. }
  254. },
  255. //显示用户认证状态
  256. getAuditState: function (e) {
  257. if (e) {
  258. let theType = '';
  259. auditStatusList.map(function (item) {
  260. if (item.value == e) {
  261. theType = item.key;
  262. };
  263. });
  264. return theType;
  265. }
  266. },
  267. getCopyrightState: function (e) {
  268. if (e) {
  269. let theType = '';
  270. copyrightStateList.map(function (item) {
  271. if (item.value == e) {
  272. theType = item.key;
  273. };
  274. });
  275. return theType;
  276. }
  277. },
  278. downloadFile: function (path, fileName) {
  279. window.open(globalConfig.context + '/open/downloadFile?path=' + path + '&fileName=' + fileName)
  280. },
  281. techDownloadFile: function (url, id) {
  282. window.open(globalConfig.context + url + '?id=' + id)
  283. },
  284. copyrightDownloadFile: function (id, sign, url) {
  285. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign)
  286. },
  287. newDownloadFile: function (id, sign, url,type) {
  288. if (!type ) {
  289. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign);
  290. };
  291. if ( type ) {
  292. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign + '&type=' + type);
  293. };
  294. },
  295. companySearch(input, option) {
  296. return option.props.children.indexOf(input) >= 0
  297. },
  298. getInUrgentTime(date, inUrgent) {
  299. let now = new Date(date);
  300. for (var i = 1; i <= inUrgent;) {
  301. now.setDate(now.getDate() + 1);
  302. if (!vocations[getKey(now)]) {
  303. i++;
  304. };
  305. };
  306. return now;
  307. function getKey(date) {
  308. var year = date.getFullYear(),
  309. month = date.getMonth() + 1,
  310. day = date.getDate();
  311. year = "" + year;
  312. month = (month > 9 ? "" : "0") + month;
  313. day = (day > 9 ? "" : "0") + day;
  314. return year + month + day;
  315. }
  316. },
  317. getStepList(pid,url) {
  318. let stepList = [];
  319. $.ajax({
  320. method: "get",
  321. dataType: "json",
  322. crossDomain: false,
  323. cache: false,
  324. url: globalConfig.context + url + "?pid=" + pid,
  325. success: function (data) {
  326. if (!data.data) {
  327. if (data.error && data.error.length ) {
  328. return;
  329. };
  330. };
  331. for (var item in data.data) {
  332. stepList.push(
  333. <Timeline.Item key={item}>
  334. <span>{module.exports.getPatentState(data.data[item].state)}</span>
  335. {module.exports.getTime(data.data[item].recordTime)}
  336. </Timeline.Item>
  337. )
  338. };
  339. }.bind(this),
  340. });
  341. return stepList;
  342. },
  343. //各种通过接口获取下拉列表
  344. setPatentStateOption(permission) {
  345. let theArr = [];
  346. patentStateList.map(function (item) {
  347. for (let i = 0; i < permission.length; i++) {
  348. if (item.value == permission[i]) {
  349. theArr.push(item);
  350. };
  351. };
  352. });
  353. return theArr;
  354. },
  355. setUserContactsList(){
  356. let theOption = [];
  357. $.ajax({
  358. method: "get",
  359. dataType: "json",
  360. crossDomain: false,
  361. url: globalConfig.context + '/api/user/getContacts',
  362. success: function (data) {
  363. if (!data.data) {
  364. if ( data.error && data.error.length ) {
  365. message.warning(data.error[0].message);
  366. };
  367. return;
  368. };
  369. for (let item in data.data) {
  370. let theData = data.data[item];
  371. theOption.push(
  372. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  373. );
  374. };
  375. }
  376. });
  377. return theOption;
  378. },
  379. setAdminContactsList(uid){
  380. let theOption = [];
  381. $.ajax({
  382. method: "get",
  383. dataType: "json",
  384. crossDomain: false,
  385. url: globalConfig.context + '/api/admin/getContacts',
  386. data:{ "uid": uid },
  387. success: function (data) {
  388. if (!data.data) {
  389. if ( data.error && data.error.length ) {
  390. message.warning(data.error[0].message);
  391. };
  392. return;
  393. };
  394. for (let item in data.data) {
  395. let theData = data.data[item];
  396. theOption.push(
  397. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  398. );
  399. };
  400. }
  401. });
  402. return theOption;
  403. },
  404. //高企培育资料完成情况(比重)
  405. getProportion(uid,callback){
  406. $.ajax({
  407. method: "get",
  408. dataType: "json",
  409. crossDomain: false,
  410. url: globalConfig.context + '/api/admin/proportion',
  411. data:{ "uid": uid },
  412. success: function (data) {
  413. if (!data.data) {
  414. if ( data.error && data.error.length ) {
  415. message.warning(data.error[0].message);
  416. };
  417. data.data = {}
  418. callback(data.data);
  419. };
  420. callback(data.data);
  421. }
  422. });
  423. },
  424. //保存高企培育资料完成情况
  425. saveProportion(id,uid,sign,status){
  426. $.ajax({
  427. method: "post",
  428. dataType: "json",
  429. crossDomain: false,
  430. url: globalConfig.context + '/api/admin/confirmProportion',
  431. data:{
  432. "id": id,
  433. "uid":uid,
  434. "sign":sign,
  435. "status":status
  436. },
  437. success: function (data) {
  438. if (!data.data) {
  439. if ( data.error && data.error.length ) {
  440. message.warning(data.error[0].message);
  441. };
  442. return;
  443. };
  444. }
  445. });
  446. },
  447. //获取window.location.search传的值
  448. getSearchUrl(e){
  449. let searchURL = e;
  450. let theObj = {};
  451. searchURL = searchURL.substring(1, searchURL.length);
  452. theObj[searchURL.split("&")[0].split("=")[0]] = searchURL.split("&")[0].split("=")[1];
  453. if ( searchURL.split("&")[1] ) {
  454. theObj[searchURL.split("&")[1].split("=")[0]] = searchURL.split("&")[1].split("=")[1];
  455. if ( searchURL.split("&")[2] ) {
  456. theObj[searchURL.split("&")[2].split("=")[0]] = searchURL.split("&")[2].split("=")[1];
  457. };
  458. };
  459. return theObj;
  460. },
  461. //预览接口
  462. getPreview(id,url,sign,callback){
  463. $.ajax({
  464. method: "get",
  465. dataType: "json",
  466. crossDomain: false,
  467. url: globalConfig.context + "/api/admin/preview/" + url,
  468. data:{
  469. "id": id,
  470. "sign": sign
  471. },
  472. success: function (data) {
  473. if (!data.data) {
  474. if ( data.error && data.error.length ) {
  475. message.warning(data.error[0].message);
  476. };
  477. };
  478. callback('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(location.origin + globalConfig.context + "/open/preview?" + data.data));
  479. }
  480. });
  481. },
  482. //获取企业规模
  483. getScaleState(e) {
  484. if (e) {
  485. let theType = '';
  486. scaleList.map(function (item) {
  487. if (item.value == e) {
  488. theType = item.key;
  489. };
  490. });
  491. return theType;
  492. }
  493. },
  494. //获取企业类型
  495. getCompanyType(type1, type2) {
  496. let companyTypeList = [];
  497. for (let i = 0; i < companyType.length; i++) {
  498. companyTypeList.push({
  499. value: companyType[i].value,
  500. label: companyType[i].label
  501. });
  502. if (companyType[i].children) {
  503. for (let j = 0; j < companyType[i].children.length; j++) {
  504. companyTypeList.push({
  505. value: companyType[i].children[j].value,
  506. label: companyType[i].children[j].label
  507. });
  508. };
  509. }
  510. };
  511. companyTypeList.sort(function (a, b) {
  512. return a.value - b.value
  513. });
  514. let typeKey = "";
  515. companyTypeList.map(function (item) {
  516. if (type1 == item.value) {
  517. typeKey = item.label;
  518. };
  519. if (type2 == item.value) {
  520. typeKey = typeKey + "/" + item.label;
  521. };
  522. });
  523. return typeKey;
  524. },
  525. //获取企业行业
  526. getIndustryType(e) {
  527. if (e) {
  528. let theType = '';
  529. companyType.map(function (item) {
  530. if (item.value == e) {
  531. theType = item.key;
  532. };
  533. });
  534. return theType;
  535. }
  536. },
  537. //获取合同状态
  538. getContractType: function (e) {
  539. if (e) {
  540. let theType = '';
  541. contractTypeList.map(function (item) {
  542. if (item.value == e) {
  543. theType = item.key;
  544. };
  545. });
  546. return theType;
  547. }
  548. },
  549. //获取合同类型
  550. getContractState: function (e) {
  551. if (e) {
  552. let theType = '';
  553. contractStateList.map(function (item) {
  554. if (item.value == e) {
  555. theType = item.key;
  556. };
  557. });
  558. return theType;
  559. }
  560. },
  561. //获取需求类型
  562. getDemandType: function (e) {
  563. if (e) {
  564. let theType = '';
  565. demandTypeList.map(function (item) {
  566. if (item.value == e) {
  567. theType = item.key;
  568. };
  569. });
  570. return theType;
  571. }
  572. },
  573. //获取成果类型
  574. getAchievementCategory: function (e) {
  575. if (e) {
  576. let theType = '';
  577. achievementCategoryList.map(function (item) {
  578. if (item.value == e) {
  579. theType = item.key;
  580. };
  581. });
  582. return theType;
  583. }
  584. },
  585. //获取需求和成果审核状态
  586. getTechAuditStatus: function (e) {
  587. if (e) {
  588. let theType = '';
  589. techAuditStatusList.map(function (item) {
  590. if (item.value == e) {
  591. theType = item.key;
  592. };
  593. });
  594. return theType;
  595. }
  596. },
  597. //获取需求和成果审核状态
  598. getMaturity: function (e) {
  599. if (e) {
  600. let theType = '';
  601. maturityList.map(function (item) {
  602. if (item.value == e) {
  603. theType = item.key;
  604. };
  605. });
  606. return theType;
  607. }
  608. },
  609. //获取需求和成果审核状态
  610. getTransferMode: function (e) {
  611. if (e) {
  612. let theType = '';
  613. transferModeList.map(function (item) {
  614. if (item.value == e) {
  615. theType = item.key;
  616. };
  617. });
  618. return theType;
  619. }
  620. },
  621. //获取创新度状态
  622. getInnovation: function (e) {
  623. if (e) {
  624. let theType = '';
  625. innovationList.map(function (item) {
  626. if (item.value == e) {
  627. theType = item.key;
  628. };
  629. });
  630. return theType;
  631. }
  632. },
  633. //获取创新度状态
  634. getOrderStatus: function (e) {
  635. if (e) {
  636. let theType = '';
  637. orderStatusList.map(function (item) {
  638. if (item.value == e) {
  639. theType = item.key;
  640. };
  641. });
  642. return theType;
  643. }
  644. }
  645. }