areaList.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. getProvince(province, city, area) {
  89. let PList = [];
  90. for (let i = 0; i < addressList.length; i++) {
  91. PList.push({
  92. id: addressList[i].id,
  93. name: addressList[i].name
  94. });
  95. if (addressList[i].cityList) {
  96. for (let j = 0; j < addressList[i].cityList.length; j++) {
  97. PList.push({
  98. id: addressList[i].cityList[j].id,
  99. name: addressList[i].cityList[j].name
  100. });
  101. if (addressList[i].cityList[j].areaList) {
  102. for (let n = 0; n < addressList[i].cityList[j].areaList.length; n++) {
  103. PList.push({
  104. id: addressList[i].cityList[j].areaList[n].id,
  105. name: addressList[i].cityList[j].areaList[n].name
  106. });
  107. }
  108. };
  109. };
  110. }
  111. };
  112. PList.sort(function (a, b) {
  113. return a.id - b.id
  114. });
  115. let provinceKey = "";
  116. PList.map(function (item) {
  117. if (province) {
  118. if (province == item.id) {
  119. provinceKey = item.name;
  120. };
  121. if (city == item.id) {
  122. provinceKey = provinceKey + "/" + item.name;
  123. };
  124. if (area == item.id) {
  125. provinceKey = provinceKey + "/" + item.name;
  126. };
  127. };
  128. });
  129. return provinceKey;
  130. }
  131. }