tools.js 6.8 KB

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