UNPKG

igi_orion_cignacmb

Version:

Censors words out of text

113 lines (101 loc) 3.75 kB
var CentralWidget = require('./select'); var allIndustryName = require('../lib/dic/industry'); var allIndustryType = require('../lib/dic/industryCategory'); var allCareerName = require('../lib/dic/careerName'); var select = $.extend({}, CentralWidget, { //这是一个类,用 new 关键字实例化放到vm的 form 上 type: 'career', //组件的类别,用于service层动态对比配置进行实例化 candidateArray: [], industries: allIndustryName, industryCategories: [], careerNames: [], visible: true, industry: '', industryCategory: '', careerName: '', detail: '', setValue: function (value) { //设置值 var that = this; that.value = value; }, getValue: function () { //获取值 var that = this; var result = [] if (that.value) { if (that.value.indexOf('-') > -1) { result = that.value.split('-')[0] } } else { result = that.value } return that.value; }, getIndustryTypeByIndustryName: function (industryNameId) { var list = []; for (var i = 0; i < allIndustryType.length; i++) { var industryCategory = allIndustryType[i]; if (industryCategory.key.substring(0, 2) == industryNameId) { list.push(industryCategory); } } this.industryCategories = list; return this.industryCategories; }, getCareerNameByIndustryType: function (industryTypeId) { var list = []; for (var i = 0; i < allCareerName.length; i++) { var careerName = allCareerName[i]; if (careerName.parentKey == industryTypeId) { list.push(careerName); } } this.careerNames = list; return this.careerNames; }, fix: function () { var that = this; var industry = that.industry; var industryCategory = that.industryCategory; //处理候选数组 if (industry) { that.getIndustryTypeByIndustryName(industry); } if (industryCategory) { that.getCareerNameByIndustryType(industryCategory); } //处理城市选项是否在候选列表中 var candidateArray = that.industryCategories; var isValueInCandidateArray = false; //如果已选值不在候选值中,重置选项为空 for (var i = 0; i < candidateArray.length; i++) { var item = candidateArray[i]; if (item['key'] && item.key === that.industryCategory) { isValueInCandidateArray = true; } if (item['id'] && item.id === that.industryCategory) { isValueInCandidateArray = true; } } if (!isValueInCandidateArray) { that.industryCategory = '' that.careerNames = [] that.value = '' } //处理地区选项是否在候选列表中 candidateArray = that.careerNames; isValueInCandidateArray = false; //如果已选值不在候选值中,重置选项为空 for (var i = 0; i < candidateArray.length; i++) { var item = candidateArray[i]; if (item['key'] && (item.key === that.value)) { isValueInCandidateArray = true; } if (item['id'] && (item.id === that.value)) { isValueInCandidateArray = true; } } if (!isValueInCandidateArray) { that.value = '' } } }); module.exports = select;