areaList.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import ajax from 'jquery/src/ajax/xhr.js'
  2. import $ from 'jquery/src/ajax';
  3. module.exports = {
  4. provinceSelect(addressList) {
  5. let option = [];
  6. addressList.map(function (item, i) {
  7. option.push({
  8. value: item.id,
  9. label: item.name,
  10. });
  11. });
  12. return option;
  13. },
  14. citySelect(addressList) {
  15. let option = [];
  16. addressList.map(function (item, i) {
  17. if (item.cityList == null) {
  18. item.cityList = [];
  19. }
  20. if (item.cityList.length) {
  21. let cityArr = [];
  22. item.cityList.map(function (city, n) {
  23. cityArr.push({
  24. value: city.id,
  25. label: city.name,
  26. });
  27. });
  28. option.push({
  29. value: item.id,
  30. label: item.name,
  31. children: cityArr,
  32. });
  33. } else {
  34. option.push({
  35. value: item.id,
  36. label: item.name,
  37. });
  38. }
  39. });
  40. return option;
  41. },
  42. areaSelect(addressList) {
  43. let option = [];
  44. addressList.map(function (item, i) {
  45. if (item.cityList == null) {
  46. item.cityList = [];
  47. }
  48. if (item.cityList.length) {
  49. let cityArr = [];
  50. item.cityList.map(function (city, n) {
  51. if (city.areaList == null) {
  52. city.areaList = [];
  53. }
  54. if (city.areaList.length) {
  55. let areaArr = [];
  56. city.areaList.map(function (area, j) {
  57. areaArr.push({
  58. value: area.id,
  59. label: area.name,
  60. });
  61. });
  62. cityArr.push({
  63. value: city.id,
  64. label: city.name,
  65. children: areaArr,
  66. });
  67. } else {
  68. cityArr.push({
  69. value: city.id,
  70. label: city.name,
  71. });
  72. }
  73. });
  74. option.push({
  75. value: item.id,
  76. label: item.name,
  77. children: cityArr,
  78. });
  79. } else {
  80. option.push({
  81. value: item.id,
  82. label: item.name,
  83. });
  84. }
  85. });
  86. return option;
  87. },
  88. Birthplace(addressList) {
  89. let option = [];
  90. addressList.map(function (item, i) {
  91. if (item.cityList == null) {
  92. item.cityList = [];
  93. }
  94. if (item.cityList.length) {
  95. let cityArr = [];
  96. item.cityList.map(function (city, n) {
  97. if (city.areaList == null) {
  98. city.areaList = [];
  99. }
  100. if (city.areaList.length) {
  101. let areaArr = [];
  102. // city.areaList.map(function (area, j) {
  103. // areaArr.push({
  104. // value: area.id,
  105. // label: area.name,
  106. // });
  107. // });
  108. cityArr.push({
  109. value: city.id,
  110. label: city.name,
  111. children: areaArr,
  112. });
  113. } else {
  114. cityArr.push({
  115. value: city.id,
  116. label: city.name,
  117. });
  118. }
  119. });
  120. option.push({
  121. value: item.id,
  122. label: item.name,
  123. children: cityArr,
  124. });
  125. } else {
  126. option.push({
  127. value: item.id,
  128. label: item.name,
  129. });
  130. }
  131. });
  132. return option;
  133. },
  134. getProvince(province, city, area) {
  135. let PList = [];
  136. for (let i = 0; i < addressList.length; i++) {
  137. PList.push({
  138. id: addressList[i].id,
  139. name: addressList[i].name,
  140. });
  141. if (addressList[i].cityList) {
  142. for (let j = 0; j < addressList[i].cityList.length; j++) {
  143. PList.push({
  144. id: addressList[i].cityList[j].id,
  145. name: addressList[i].cityList[j].name,
  146. });
  147. if (addressList[i].cityList[j].areaList) {
  148. for (
  149. let n = 0;
  150. n < addressList[i].cityList[j].areaList.length;
  151. n++
  152. ) {
  153. PList.push({
  154. id: addressList[i].cityList[j].areaList[n].id,
  155. name: addressList[i].cityList[j].areaList[n].name,
  156. });
  157. }
  158. }
  159. }
  160. }
  161. }
  162. PList.sort(function (a, b) {
  163. return a.id - b.id;
  164. });
  165. let provinceKey = "";
  166. PList.map(function (item) {
  167. if (province) {
  168. if (province == item.id) {
  169. provinceKey = item.name;
  170. }
  171. if (city == item.id) {
  172. provinceKey = provinceKey + "/" + item.name;
  173. }
  174. if (area == item.id) {
  175. provinceKey = provinceKey + "/" + item.name;
  176. }
  177. }
  178. });
  179. return provinceKey;
  180. },
  181. };