| | |
| | | * @author Tevin |
| | | */ |
| | | |
| | | import ChinaLocations from '@components/forms/chinaArea/ChinaLocations'; |
| | | import { $locations } from '@components/forms/chinaArea/ChinaLocations'; |
| | | import { Tools } from '@components/common/Tools'; |
| | | |
| | | export class SmartAddress { |
| | |
| | | } |
| | | this.wordData = {}; |
| | | const wordArr = this._splitWord(word); |
| | | ChinaLocations.onReady(() => { |
| | | $locations.onReady(() => { |
| | | this._checkPhone(wordArr); |
| | | this._checkCompany(wordArr); |
| | | this._checkUser(wordArr); |
| | |
| | | |
| | | _checkAddress(list) { |
| | | const adrLabelReg = /地址|详细地址|公司地址|联系地址|地区|所在地区/; |
| | | for (let i = 0, item; (item = list[i]); i++) { |
| | | if (!item.content) { |
| | | continue; |
| | | } |
| | | if (item.label) { |
| | | if (adrLabelReg.test(item.label)) { |
| | | this._parseAddress(item.content); |
| | | list.splice(i, 1); |
| | | break; |
| | | $locations.getLocationTree(3, chinaTree => { |
| | | for (let i = 0, item; (item = list[i]); i++) { |
| | | if (!item.content) { |
| | | continue; |
| | | } |
| | | } else { |
| | | if (this._isAddress(item.content)) { |
| | | this._parseAddress(item.content); |
| | | list.splice(i, 1); |
| | | break; |
| | | if (item.label) { |
| | | if (adrLabelReg.test(item.label)) { |
| | | this._parseAddress(item.content); |
| | | list.splice(i, 1); |
| | | break; |
| | | } |
| | | } else { |
| | | if (this._isAddress(chinaTree, item.content)) { |
| | | this._parseAddress(chinaTree, item.content); |
| | | list.splice(i, 1); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | _isAddress(content) { |
| | | _isAddress(tree, content) { |
| | | content = content.replace('中国', ''); |
| | | const provinceNames = ChinaLocations.getLocationTree() |
| | | .map(lv1 => lv1.label.replace('特别行政区', '').replace('省', '')); |
| | | const provinceNames = tree.map(lv1 => lv1.label.replace('特别行政区', '').replace('省', '')); |
| | | for (let province of provinceNames) { |
| | | if (content.indexOf(province) >= 0) { |
| | | return true; |
| | |
| | | return false; |
| | | } |
| | | |
| | | _parseAddress(content) { |
| | | _parseAddress(chinaTree, content) { |
| | | content = content.replace('中国', ''); |
| | | const chinaTree = ChinaLocations.getLocationTree(); |
| | | // 省份处理 --- |
| | | const provinceTailReg = /特别行政区|自治区|省|市$/; |
| | | for (let province of chinaTree) { |
| | |
| | | this.wordData.street = content; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |