tools.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import {
  2. message
  3. } from 'antd';
  4. import {
  5. provinceList,
  6. patentTypeList,
  7. patentStateList,
  8. techFieldList,
  9. technicalSourceList,
  10. catagoryList,
  11. intellectualGetList
  12. } from './dataDic.js';
  13. module.exports = {
  14. addressInit: function (_cmbProvince, _cmbCity, _cmbArea, defaultProvince, defaultCity, defaultArea) {
  15. var cmbProvince = document.getElementById(_cmbProvince);
  16. var cmbCity = document.getElementById(_cmbCity);
  17. var cmbArea = document.getElementById(_cmbArea);
  18. function cmbSelect(cmb, str) {
  19. for (var i = 0; i < cmb.options.length; i++) {
  20. if (cmb.options[i].value == str) {
  21. cmb.selectedIndex = i;
  22. return;
  23. }
  24. }
  25. }
  26. function cmbAddOption(cmb, str, obj) {
  27. var option = document.createElement("OPTION");
  28. cmb.options.add(option);
  29. option.innerText = str;
  30. option.value = str;
  31. option.obj = obj;
  32. }
  33. function changeCity() {
  34. cmbArea.options.length = 0;
  35. if (cmbCity.selectedIndex == -1) return;
  36. var item = cmbCity.options[cmbCity.selectedIndex].obj;
  37. for (var i = 0; i < item.areaList.length; i++) {
  38. cmbAddOption(cmbArea, item.areaList[i], null);
  39. }
  40. cmbSelect(cmbArea, defaultArea);
  41. }
  42. function changeProvince() {
  43. cmbCity.options.length = 0;
  44. cmbCity.onchange = null;
  45. if (cmbProvince.selectedIndex == -1) return;
  46. var item = cmbProvince.options[cmbProvince.selectedIndex].obj;
  47. for (var i = 0; i < item.cityList.length; i++) {
  48. cmbAddOption(cmbCity, item.cityList[i].name, item.cityList[i]);
  49. }
  50. cmbSelect(cmbCity, defaultCity);
  51. changeCity();
  52. cmbCity.onchange = changeCity;
  53. }
  54. for (var i = 0; i < provinceList.length; i++) {
  55. cmbAddOption(cmbProvince, provinceList[i].name, provinceList[i]);
  56. }
  57. cmbSelect(cmbProvince, defaultProvince);
  58. changeProvince();
  59. cmbProvince.onchange = changeProvince;
  60. },
  61. splitUrl: function (string, i, url) {
  62. let theList = [];
  63. let theArr = [];
  64. if (string) {
  65. theArr = string.split(i);
  66. theArr.map(function (item, i) {
  67. theList.push({
  68. uid: -i,
  69. url: url + item,
  70. response: {
  71. data: item
  72. }
  73. });
  74. });
  75. }
  76. return theList;
  77. },
  78. getBase64: function (img, callback) {
  79. const reader = new FileReader();
  80. reader.addEventListener('load', () => callback(reader.result));
  81. reader.readAsDataURL(img);
  82. },
  83. beforeUpload: function (file) {
  84. // debugger
  85. // const isJPG = file.type === 'image/jpeg/document';
  86. // if (!isJPG) {
  87. // message.error('You can only upload JPG file!');
  88. // }
  89. // const isLt2M = file.size / 1024 / 1024 < 2;
  90. // if (!isLt2M) {
  91. // message.error('Image must smaller than 2MB!');
  92. // }
  93. // return isJPG && isLt2M;
  94. },
  95. beforeUploadFile: function (file) {
  96. // debugger
  97. // const isJPG = file.type === 'image/jpeg/document';
  98. // if (!isJPG) {
  99. // message.error('You can only upload JPG file!');
  100. // }
  101. // const isLt2M = file.size / 1024 / 1024 < 2;
  102. // if (!isLt2M) {
  103. // message.error('Image must smaller than 2MB!');
  104. // }
  105. // return isJPG && isLt2M;
  106. },
  107. getTime: function (e, t) {
  108. if (e && !t) {
  109. var d = new Date(e);
  110. d = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " ";
  111. // + (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) + ":" +
  112. // (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) + ":" +
  113. // (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
  114. return d;
  115. } else if (e && t) {
  116. var d1 = new Date(e);
  117. var d2 = new Date(e);
  118. d2 = d2.setMonth(d1.getMonth() + t);
  119. d2 = new Date(d2)
  120. d2 = d2.getFullYear() + "-" + (d2.getMonth() + 1) + "-" + d2.getDate() + " ";
  121. return d2;
  122. } else {
  123. return '';
  124. }
  125. },
  126. getPatentType: function (e) {
  127. if (e) {
  128. let theType = '';
  129. patentTypeList.map(function (item) {
  130. if (item.value == e) {
  131. theType = item.key;
  132. };
  133. });
  134. return theType;
  135. }
  136. },
  137. getPatentState: function (e) {
  138. if (e) {
  139. let theState = '';
  140. patentStateList.map(function (item) {
  141. if (item.value == e) {
  142. theState = item.key;
  143. };
  144. });
  145. return theState;
  146. }
  147. },
  148. getTechnicalSource: function (e) {
  149. if (e) {
  150. let theSource = '';
  151. technicalSourceList.map(function (item) {
  152. if (item.value == e) {
  153. theSource = item.key;
  154. };
  155. });
  156. return theSource;
  157. }
  158. },
  159. getTechField: function (field1, field2, field3) {
  160. let fieldList = [];
  161. for (let i = 0; i < techFieldList.length; i++) {
  162. fieldList.push({
  163. value: techFieldList[i].value,
  164. label: techFieldList[i].label
  165. });
  166. if (techFieldList[i].children) {
  167. for (let j = 0; j < techFieldList[i].children.length; j++) {
  168. fieldList.push({
  169. value: techFieldList[i].children[j].value,
  170. label: techFieldList[i].children[j].label
  171. });
  172. if (techFieldList[i].children[j].children) {
  173. for (let n = 0; n < techFieldList[i].children[j].children.length; n++) {
  174. fieldList.push({
  175. value: techFieldList[i].children[j].children[n].value,
  176. label: techFieldList[i].children[j].children[n].label
  177. });
  178. }
  179. };
  180. };
  181. }
  182. };
  183. fieldList.sort(function (a, b) { return a.value - b.value });
  184. let fieldKey= "";
  185. fieldList.map(function (item) {
  186. if (field1 == item.value) {
  187. fieldKey = item.label;
  188. };
  189. if (field2 == item.value) {
  190. fieldKey = fieldKey + "/" + item.label;
  191. };
  192. if (field3 == item.value) {
  193. fieldKey = fieldKey + "/" + item.label;
  194. };
  195. });
  196. return fieldKey;
  197. },
  198. getCatagory: function (e) {
  199. if (e) {
  200. let theType = '';
  201. catagoryList.map(function (item) {
  202. if (item.value == e) {
  203. theType = item.key;
  204. };
  205. });
  206. return theType;
  207. }
  208. },
  209. getIntellectualObtainWay: function (e) {
  210. if (e) {
  211. let theType = '';
  212. intellectualGetList.map(function (item) {
  213. if (item.value == e) {
  214. theType = item.key;
  215. };
  216. });
  217. return theType;
  218. }
  219. }
  220. }