student-area.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import Api from "../../model/api";
  2. import {getDataSet, getEventParam, showLoading} from "../../utils/utils";
  3. import {studentTypes} from "../../model/enum";
  4. import User from "../../model/user";
  5. import Config from "../../model/config";
  6. Component({
  7. properties: {
  8. perType: Number,
  9. jobId: Number,
  10. studentTypeData: Array,
  11. code: String,
  12. parentIds: String,
  13. isShowJob: {
  14. type: Boolean,
  15. value: true
  16. }
  17. },
  18. observers: {
  19. perType: async function (perType) {
  20. const jobData = await this.changeJobData(perType);
  21. if (jobData) {
  22. let jobIndex = this.findIndex(jobData, this.data.jobId);
  23. this.setData({jobIndex})
  24. }
  25. if (perType) {
  26. let typeIndex = this.findIndex(this.data.studentTypeData, perType);
  27. this.setData({typeIndex})
  28. }
  29. },
  30. jobId: function (newV) {
  31. if (newV && this.data.jobData) {
  32. let jobIndex = this.findIndex(this.data.jobData, newV);
  33. this.setData({jobIndex})
  34. }
  35. },
  36. code: function (newV) {
  37. if (newV) {
  38. let deptIndex = this.findIndex2(this.data.deptData, this.data.code)
  39. this.setData({deptIndex})
  40. }
  41. },
  42. parentIds: async function (parentIds) {
  43. if (parentIds) {
  44. showLoading();
  45. parentIds = parentIds.split(",")
  46. let area = [];
  47. let areaData = [];
  48. if (parentIds.length > 0) {
  49. for (let i = 2; i < parentIds.length; i++) {
  50. const res = await Api.getRegionList({parentId: parentIds[i - 1]})
  51. let obj = res.data.find(item => item.id == parentIds[i]);
  52. area.push(obj.name);
  53. areaData.push(obj.code);
  54. }
  55. }
  56. let areaStr = area.join("/")
  57. let deptData = [];
  58. if (parentIds.length > 0) {
  59. const res = await Api.getUnitList({
  60. parentId: parentIds[parentIds.length - 1]
  61. })
  62. deptData = res.data;
  63. }
  64. let deptIndex = this.findIndex2(deptData, this.data.code)
  65. this.setData({
  66. areaStr, deptData, deptIndex, areaData
  67. })
  68. wx.hideLoading()
  69. }
  70. }
  71. },
  72. data: {
  73. deptData: [],
  74. jobData: [],
  75. show: false,
  76. typeIndex: -1,
  77. deptIndex: -1,
  78. jobIndex: -1,
  79. studentTypesEnum: studentTypes,
  80. areaStr: '',
  81. areaData: [],
  82. user: {},
  83. },
  84. methods: {
  85. async changeJobData(perType) {
  86. if (perType == studentTypes.COMMUNITY_WORKER || perType == studentTypes.NATIONAL_TRAINING) {
  87. const res = await Api.getPulishDict(Config.DICT.COMMUNITY_WORKER_TYPE);
  88. this.setData({
  89. jobData: res.data,
  90. })
  91. return res.data;
  92. }
  93. if (perType == studentTypes.OTHER || perType == studentTypes.STREET_WORK) {
  94. const res = await Api.getPulishDict(Config.DICT.OTHER_WORKER_TYPE);
  95. this.setData({
  96. jobData: res.data,
  97. })
  98. return res.data;
  99. }
  100. },
  101. findIndex(arr, value) {
  102. return arr.findIndex(item => item.dictValue == value);
  103. },
  104. findIndex2(arr, value) {
  105. return arr.findIndex(item => item.unitcode == value);
  106. },
  107. async bindChange(e) {
  108. const field = getDataSet(e, "field");
  109. const value = getEventParam(e, 'value');
  110. if (this.data[field] == value) {
  111. return
  112. }
  113. this.setData({
  114. [field]: value,
  115. areaStr: '',
  116. areaData: [],
  117. deptIndex: -1,
  118. deptData: [],
  119. jobIndex: -1,
  120. }, async () => {
  121. await this.changeJobData(this.data.studentTypeData[this.data.typeIndex].dictValue);
  122. })
  123. this.triggerEvent("student", {
  124. perType: this.data.studentTypeData[this.data.typeIndex].dictValue,
  125. code: "",
  126. jobId: "",
  127. errMsg: ''
  128. })
  129. },
  130. bindJobChange(e) {
  131. const field = getDataSet(e, "field");
  132. const value = getEventParam(e, 'value');
  133. this.setData({
  134. [field]: value,
  135. })
  136. this.triggerEvent("student", {
  137. perType: this.data.studentTypeData[this.data.typeIndex].dictValue,
  138. jobId: this.data.jobData[this.data.jobIndex].dictValue
  139. })
  140. },
  141. bindDeptChange(e) {
  142. const field = getDataSet(e, "field");
  143. const value = getEventParam(e, 'value');
  144. this.setData({
  145. [field]: value
  146. })
  147. let perType = this.data.studentTypeData[this.data.typeIndex].dictValue;
  148. let code = "";
  149. let errMsg = "";
  150. if (perType == studentTypes.COMMUNITY_WORKER) {
  151. if (this.data.areaData.length == 4) {
  152. code = this.data.areaData[3];
  153. } else {
  154. errMsg = "社区工作者必须选择四级行政区"
  155. }
  156. }
  157. console.log("点击单位", this.data.deptData[value].unitcode)
  158. this.triggerEvent("student", {
  159. perType: this.data.studentTypeData[this.data.typeIndex].dictValue,
  160. code: this.data.deptData[value].unitcode,
  161. errMsg
  162. })
  163. },
  164. async changeArea(e) {
  165. const areaData = getEventParam(e, "codes");
  166. const ids = getEventParam(e, "ids");
  167. const areaStr = getEventParam(e, "areaStr");
  168. let perType = this.data.studentTypeData[this.data.typeIndex].dictValue;
  169. let deptData = [];
  170. if ((perType == studentTypes.OTHER && ids.length > 0) ||
  171. (perType != studentTypes.STREET_WORK && ids.length == 4)) {
  172. const res = await Api.getUnitList({
  173. parentId: ids[ids.length - 1]
  174. })
  175. deptData = res.data;
  176. }
  177. this.setData({
  178. areaData, areaStr, deptIndex: -1,
  179. deptData,
  180. })
  181. let code = "";
  182. let errMsg = "请选择单位";
  183. if (perType == studentTypes.STREET_WORK) {
  184. if (ids.length == 4) {
  185. code = areaData[3];
  186. } else {
  187. errMsg = "街道工作者必须选择四级行政区"
  188. }
  189. } else if (perType == studentTypes.NATIONAL_TRAINING) {
  190. if (ids.length > 2) {
  191. code = areaData[areaData.length - 1];
  192. } else {
  193. errMsg = "全国培训必须选择三级以上行政区"
  194. }
  195. }
  196. console.log("点击单位区域", code)
  197. this.triggerEvent("student", {
  198. perType: this.data.studentTypeData[this.data.typeIndex].dictValue,
  199. code,
  200. errMsg,
  201. })
  202. },
  203. showArea(e) {
  204. this.setData({
  205. show: true,
  206. })
  207. },
  208. }
  209. });