tools.js 21 KB

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