tools.js 22 KB

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