tools.js 21 KB

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