tools.js 21 KB

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