import Api from "../../model/api"; import {getDataSet, getEventParam, showLoading} from "../../utils/utils"; import {studentTypes} from "../../model/enum"; import User from "../../model/user"; import Config from "../../model/config"; Component({ properties: { perType: Number, jobId: Number, studentTypeData: Array, code: String, parentIds: String, isShowJob: { type: Boolean, value: true } }, observers: { perType: async function (perType) { const jobData = await this.changeJobData(perType); if (jobData) { let jobIndex = this.findIndex(jobData, this.data.jobId); this.setData({jobIndex}) } if (perType) { let typeIndex = this.findIndex(this.data.studentTypeData, perType); this.setData({typeIndex}) } }, jobId: function (newV) { if (newV && this.data.jobData) { let jobIndex = this.findIndex(this.data.jobData, newV); this.setData({jobIndex}) } }, code: function (newV) { if (newV) { let deptIndex = this.findIndex2(this.data.deptData, this.data.code) this.setData({deptIndex}) } }, parentIds: async function (parentIds) { if (parentIds) { showLoading(); parentIds = parentIds.split(",") let area = []; let areaData = []; if (parentIds.length > 0) { for (let i = 2; i < parentIds.length; i++) { const res = await Api.getRegionList({parentId: parentIds[i - 1]}) let obj = res.data.find(item => item.id == parentIds[i]); area.push(obj.name); areaData.push(obj.code); } } let areaStr = area.join("/") let deptData = []; if (parentIds.length > 0) { const res = await Api.getUnitList({ parentId: parentIds[parentIds.length - 1] }) deptData = res.data; } let deptIndex = this.findIndex2(deptData, this.data.code) this.setData({ areaStr, deptData, deptIndex, areaData }) wx.hideLoading() } } }, data: { deptData: [], jobData: [], show: false, typeIndex: -1, deptIndex: -1, jobIndex: -1, studentTypesEnum: studentTypes, areaStr: '', areaData: [], user: {}, }, methods: { async changeJobData(perType) { if (perType == studentTypes.COMMUNITY_WORKER || perType == studentTypes.NATIONAL_TRAINING) { const res = await Api.getPulishDict(Config.DICT.COMMUNITY_WORKER_TYPE); this.setData({ jobData: res.data, }) return res.data; } if (perType == studentTypes.OTHER || perType == studentTypes.STREET_WORK) { const res = await Api.getPulishDict(Config.DICT.OTHER_WORKER_TYPE); this.setData({ jobData: res.data, }) return res.data; } }, findIndex(arr, value) { return arr.findIndex(item => item.dictValue == value); }, findIndex2(arr, value) { return arr.findIndex(item => item.unitcode == value); }, async bindChange(e) { const field = getDataSet(e, "field"); const value = getEventParam(e, 'value'); if (this.data[field] == value) { return } this.setData({ [field]: value, areaStr: '', areaData: [], deptIndex: -1, deptData: [], jobIndex: -1, }, async () => { await this.changeJobData(this.data.studentTypeData[this.data.typeIndex].dictValue); }) this.triggerEvent("student", { perType: this.data.studentTypeData[this.data.typeIndex].dictValue, code: "", jobId: "", errMsg: '' }) }, bindJobChange(e) { const field = getDataSet(e, "field"); const value = getEventParam(e, 'value'); this.setData({ [field]: value, }) this.triggerEvent("student", { perType: this.data.studentTypeData[this.data.typeIndex].dictValue, jobId: this.data.jobData[this.data.jobIndex].dictValue }) }, bindDeptChange(e) { const field = getDataSet(e, "field"); const value = getEventParam(e, 'value'); this.setData({ [field]: value }) let perType = this.data.studentTypeData[this.data.typeIndex].dictValue; let code = ""; let errMsg = ""; if (perType == studentTypes.COMMUNITY_WORKER) { if (this.data.areaData.length == 4) { code = this.data.areaData[3]; } else { errMsg = "社区工作者必须选择四级行政区" } } console.log("点击单位", this.data.deptData[value].unitcode) this.triggerEvent("student", { perType: this.data.studentTypeData[this.data.typeIndex].dictValue, code: this.data.deptData[value].unitcode, errMsg }) }, async changeArea(e) { const areaData = getEventParam(e, "codes"); const ids = getEventParam(e, "ids"); const areaStr = getEventParam(e, "areaStr"); let perType = this.data.studentTypeData[this.data.typeIndex].dictValue; let deptData = []; if ((perType == studentTypes.OTHER && ids.length > 0) || (perType != studentTypes.STREET_WORK && ids.length == 4)) { const res = await Api.getUnitList({ parentId: ids[ids.length - 1] }) deptData = res.data; } this.setData({ areaData, areaStr, deptIndex: -1, deptData, }) let code = ""; let errMsg = "请选择单位"; if (perType == studentTypes.STREET_WORK) { if (ids.length == 4) { code = areaData[3]; } else { errMsg = "街道工作者必须选择四级行政区" } } else if (perType == studentTypes.NATIONAL_TRAINING) { if (ids.length > 2) { code = areaData[areaData.length - 1]; } else { errMsg = "全国培训必须选择三级以上行政区" } } console.log("点击单位区域", code) this.triggerEvent("student", { perType: this.data.studentTypeData[this.data.typeIndex].dictValue, code, errMsg, }) }, showArea(e) { this.setData({ show: true, }) }, } });