igi_orion_cignacmb
Version:
Censors words out of text
409 lines (385 loc) • 18.4 kB
JavaScript
var CentralWidget = require('./CentralWidget');
var allProvinces = require('../lib/dic/provinces');
var allCities = require('../lib/dic/cities');
var allDistricts = require('../lib/dic/districts');
var addressByMobileProvinces = require('../res_component/mobileSelect/address/address')
var addressByMobileProvincesForCrs = require('../res_component/mobileSelect/address/crsAddress')
var config = require('../config/config')
var address = $.extend({}, CentralWidget, { //这是一个类,用 new 关键字实例化放到vm的 form 上
type: 'address', //组件的类别,用于service层动态对比配置进行实例化
provinces: allProvinces,
addressByMobile: addressByMobileProvinces,
addressByMobileForCrs: addressByMobileProvincesForCrs,
cities: [],
districts: [],
province: '',
city: '',
district: '',
detail: '',
detailVisible: true,
provinceId: (Math.random() * 100000),
cityId: (Math.random() * 100000),
districtId: (Math.random() * 100000),
manageCom: '',
cityControl: '',
value: '',
contactDetailedAddress: '',
getCitiesByProvince: function (proId) {
avalon.log('proId', proId);
var list = [];
for (var i = 0; i < allCities.length; i++) {
var city = allCities[i];
if (city.id.substring(0, 2) == proId) {
list.push(city);
}
}
this.cities = list;
this.citiesFilter(this.cities)
return this.cities;
},
getDistrictsByCity: function (cityId) {
var list = [];
for (var i = 0; i < allDistricts.length; i++) {
var district = allDistricts[i];
if (district.id.substring(0, 4) == cityId) {
list.push(district);
}
}
this.districts = list;
return this.districts;
},
getDefaultCodeArray: function () {
var provinceShowArray = ['11', '31', '44', '33', '32', '51', '37', '21', '42', '50', '12', '61', '43', '41', '36', '35']
var cityShowArray = ['3302', '3502', '2102']
// 3302
// 3502
// 2102
var manageComShowByCode = [
{code: '8604000001', name: '湖北省', id: '42', cityId: '', cityName: '', cityIsShow: true},
{code: '8615000001', name: '重庆市', id: '50', cityId: '', cityName: '', cityIsShow: true},
{code: '8610000001', name: '上海市', id: '31', cityId: '', cityName: '', cityIsShow: true},
{code: '8602000001', name: '北京市', id: '11', cityId: '', cityName: '', cityIsShow: true},
{code: '8603000001', name: '广东省', id: '44', cityId: '', cityName: '', cityIsShow: true},
{code: '8601000001', name: '深圳市', id: '44', cityId: '4403', cityName: '', cityIsShow: true},
{code: '8603020001', name: '佛山市', id: '44', cityId: '4406', cityName: '', cityIsShow: true},
{code: '8607000001', name: '陕西省', id: '61', cityId: '', cityName: '', cityIsShow: true},
{code: '8612000001', name: '青岛市', id: '37', cityId: '3702', cityName: '', cityIsShow: true},
{code: '8605000001', name: '江苏省', id: '32', cityId: '', cityName: '', cityIsShow: true},
{code: '8618000001', name: '天津市', id: '12', cityId: '', cityName: '', cityIsShow: true},
{code: '8608000001', name: '成都市', id: '51', cityId: '5101', cityName: '', cityIsShow: true},
{code: '8605030001', name: '苏州市', id: '32', cityId: '3205', cityName: '', cityIsShow: true},
{code: '8609000001', name: '山东省', id: '37', cityId: '', cityName: '', cityIsShow: true},
{code: '8611000001', name: '浙江省', id: '33', cityId: '3302', cityName: '宁波市', cityIsShow: false},
{code: '8617000001', name: '江西省', id: '36', cityId: '', cityName: '', cityIsShow: true},
{code: '8606000001', name: '辽宁省', id: '21', cityId: '2102', cityName: '大连市', cityIsShow: false},
{code: '8605040001', name: '南通市', id: '32', cityId: '3206', cityName: '', cityIsShow: true},
{code: '8605010001', name: '常州市', id: '32', cityId: '3204', cityName: '', cityIsShow: true},
{code: '8616000001', name: '河南省', id: '41', cityId: '', cityName: '', cityIsShow: true},
{code: '8613000001', name: '长沙市', id: '43', cityId: '4301', cityName: '', cityIsShow: true},
{code: '8611010001', name: '绍兴市', id: '33', cityId: '3306', cityName: '', cityIsShow: true},
{code: '8603010001', name: '东莞市', id: '44', cityId: '4419', cityName: '', cityIsShow: true},
{code: '8605020001', name: '无锡市', id: '32', cityId: '3202', cityName: '', cityIsShow: true},
{code: '8609010001', name: '烟台市', id: '37', cityId: '3706', cityName: '', cityIsShow: true},
{code: '8619000001', name: '福建省', id: '35', cityId: '3502', cityName: '厦门市', cityIsShow: false},
]
var resultList = {
provinceShowArray: provinceShowArray,
cityShowArray: cityShowArray,
manageComShowByCode: manageComShowByCode
}
return resultList
},
citiesFilter: function (cities) {
var manageComShowByCode = this.getDefaultCodeArray().manageComShowByCode
var cityShowArray = this.getDefaultCodeArray().cityShowArray
var list = []
if (config.spcialCityHide.indexOf(window.urlParams.productNo.toString()) > -1) {
var list1 = []
for (var i = 0; i < cities.length; i++) {
var citiesItem = cities[i];
if (citiesItem.id != '2102') {
list1.push(citiesItem)
}
}
if (this.city == '2102') {
this.city = ''
}
this.cities = list1
cities = list1
}
if (this.manageCom) {
for (var i = 0; i < manageComShowByCode.length; i++) {
var manageComShowByCodeItem = manageComShowByCode[i];
if (this.manageCom == manageComShowByCodeItem.code) {
for (var j = 0; j < cities.length; j++) {
var citiesItem = cities[j];
if (manageComShowByCodeItem.cityIsShow) {
if (!manageComShowByCodeItem.cityId) {
list.push(citiesItem)
} else if (manageComShowByCodeItem.cityId == citiesItem.id) {
list.push(citiesItem)
}
} else {
if (manageComShowByCodeItem.cityId != citiesItem.id) {
list.push(citiesItem)
}
}
}
}
}
this.cities = list
} else if (this.cityControl == '1') {
for (var i = 0; i < cities.length; i++) {
var citiesItem = cities[i];
if (citiesItem.id != '3502' && citiesItem.id != '3302') {
list.push(citiesItem)
}
}
if (this.city == '3502' || this.city == '3302') {
this.city = ''
}
this.cities = list
}
},
provincesFilter: function () {
var provinceShowArray = this.getDefaultCodeArray().provinceShowArray
var manageComShowByProvince = this.getDefaultCodeArray().manageComShowByCode
var list = []
var listForMobile = []
var listForMobileByCrs = []
if (this.manageCom) {
for (var i = 0; i < manageComShowByProvince.length; i++) {
var manageComShowByProvinceItem = manageComShowByProvince[i];
if (this.manageCom == manageComShowByProvinceItem.code) {
for (var j = 0; j < this.provinces.length; j++) {
var provinceItem = this.provinces[j];
if (provinceItem.id == manageComShowByProvinceItem.id) {
list.push(provinceItem)
var childs = []
var childForCrs = []
for (var k = 0; k < this.addressByMobile[j].childs.length; k++) {//筛选市
var listForMobileChildItem = this.addressByMobile[j].childs[k];
if (manageComShowByProvinceItem.cityIsShow) {
if (!manageComShowByProvinceItem.cityId) {
childs.push(listForMobileChildItem)
childForCrs.push(this.addressByMobileForCrs[j].childs[k])
} else if (manageComShowByProvinceItem.cityId == listForMobileChildItem.id) {
childs.push(listForMobileChildItem)
childForCrs.push(this.addressByMobileForCrs[j].childs[k])
}
} else {
if (manageComShowByProvinceItem.cityId != listForMobileChildItem.id) {
childs.push(listForMobileChildItem)
childForCrs.push(this.addressByMobileForCrs[j].childs[k])
}
}
}
this.addressByMobile[j].childs = childs
this.addressByMobileForCrs[j].childs = childForCrs
listForMobile.push(this.addressByMobile[j])
listForMobileByCrs.push(this.addressByMobileForCrs[j])
}
}
}
}
console.log('list_list', JSON.stringify(list))
this.provinces = list
this.addressByMobile = listForMobile
this.addressByMobileForCrs = listForMobileByCrs
} else if (this.cityControl == '1') {
for (var i = 0; i < provinceShowArray.length; i++) {
var provinceShowArrayItem = provinceShowArray[i];
for (var j = 0; j < this.provinces.length; j++) {
var provinceItem = this.provinces[j];
if (provinceItem.id == provinceShowArrayItem) {
list.push(provinceItem)
if (this.addressByMobile[j].id == '33') {
var childs = []
var childsForCrs = []
for (var k = 0; k < this.addressByMobile[j].childs.length; k++) {
var childsItem = this.addressByMobile[j].childs[k];
if (childsItem.id != '3302') {
childs.push(childsItem)
childsForCrs.push(this.addressByMobileForCrs[j].childs[k])
}
}
this.addressByMobile[j].childs = childs
this.addressByMobileForCrs[j].childs = childs
}
if (this.addressByMobile[j].id == '35') {
var childs = []
var childsForCrs = []
for (var k = 0; k < this.addressByMobile[j].childs.length; k++) {
var childsItem = this.addressByMobile[j].childs[k];
if (childsItem.id != '3502') {
childs.push(childsItem)
childsForCrs.push(this.addressByMobileForCrs[j].childs[k])
}
}
this.addressByMobile[j].childs = childs
this.addressByMobileForCrs[j].childs = childs
}
if (config.spcialCityHide.indexOf(window.urlParams.productNo.toString()) > -1) {
if (this.addressByMobile[j].id == '21') {
var childs = []
var childsForCrs = []
for (var k = 0; k < this.addressByMobile[j].childs.length; k++) {
var childsItem = this.addressByMobile[j].childs[k];
if (childsItem.id != '2102') {
childs.push(childsItem)
childsForCrs.push(this.addressByMobileForCrs[j].childs[k])
}
}
this.addressByMobile[j].childs = childs
this.addressByMobileForCrs[j].childs = childs
}
}
listForMobile.push(this.addressByMobile[j])
listForMobileByCrs.push(this.addressByMobileForCrs[j])
}
}
}
this.provinces = list
this.addressByMobile = listForMobile
this.addressByMobileForCrs = listForMobileByCrs
}
},
combineChineseName: function () {
//生成中文全地址
//地址
var that = this;
var str1 = that.province;
var str2 = that.city;
var str3 = that.district;
var str4 = that.detail;
var cn1, cn2, cn3, cn4;
avalon.log("combineChineseName()", str1, str2, str3, str4)
if (str1 == '' && str1 != '0') {
cn1 = ''
} else {
var result = '';
for (var i = 0; i < allProvinces.length; i++) {
var item = allProvinces[i];
if (str1 == item['id']) {
result = item['name']
}
}
// return result;
cn1 = result;
}
if (str2 == '' && str2 != '0') {
cn2 = ''
} else {
var result = '';
// avalon.log(cities.length);
for (var i = 0; i < allCities.length; i++) {
var item = allCities[i];
if (str2 == item['id']) {
result = item['name'];
}
}
// return result;
cn2 = result;
}
if (str3 == '' && str3 != '0') {
cn3 = ''
} else {
var result = '';
for (var i = 0; i < allDistricts.length; i++) {
var item = allDistricts[i];
if (str3 == item['id']) {
result = item['name']
}
}
cn3 = result;
// return result;
}
if (str4) {
cn4 = str4;
} else {
cn4 = ''
}
return cn1 + cn2 + cn3 + cn4
},
fix: function () { //自动修复,将省市区的选项,候选项目修复正确
var that = this;
this.provincesFilter()
console.log('province_province', that.province)
var province = that.province;
var city = that.city;
//处理候选数组
if (!province) {
that.province = ''
that.city = ''
that.cities = []
that.districts = []
that.district = ''//传值后台需要置空
}
if (province) {
that.getCitiesByProvince(province);
}
if (city) {
that.getDistrictsByCity(city);
}
//如果省不在候选数组则清空
var isExist = false
for (var i = 0; i < that.provinces.length; i++) {
var item = that.provinces[i];
if (item.id == province) {
isExist = true
}
}
if (!isExist) {
that.province = '';
that.city = ''
that.cities = []
that.districts = []
that.district = ''//传值后台需要置空
}
//处理城市选项是否在候选列表中
var candidateArray = that.cities;
var isValueInCandidateArray = false;
//如果已选值不在候选值中,重置选项为空
for (var i = 0; i < candidateArray.length; i++) {
var item = candidateArray[i];
if (item['key'] && item.key === that.city) {
isValueInCandidateArray = true;
}
if (item['id'] && item.id === that.city) {
isValueInCandidateArray = true;
}
}
if (!isValueInCandidateArray) {
that.city = ''
that.districts = []
that.district = ''
}
//处理地区选项是否在候选列表中
candidateArray = that.districts;
isValueInCandidateArray = false;
//如果已选值不在候选值中,重置选项为空
for (var i = 0; i < candidateArray.length; i++) {
var item = candidateArray[i];
if (item['key'] && (item.key === that.district)) {
isValueInCandidateArray = true;
}
if (item['id'] && (item.id === that.district)) {
isValueInCandidateArray = true;
}
}
if (!isValueInCandidateArray) {
that.district = ''
}
that.value = that.detail
avalon.log(that.value + ':执行了fix操作')
},
getValue: function () {
var that = this;
return that.detail;
},
setValue: function (detail) {
var that = this;
that.detail = detail;
},
});
module.exports = address;