tools.js 20 KB

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