// 选择多个线路 Vue.component("ns-routes-selector", { props: ["v-routes", "name"], mounted: function () { let that = this Tea.action("/ns/routes/options") .post() .success(function (resp) { that.routes = resp.data.routes // provinces let provinces = {} if (resp.data.provinces != null && resp.data.provinces.length > 0) { for (const province of resp.data.provinces) { let countryCode = province.countryCode if (typeof provinces[countryCode] == "undefined") { provinces[countryCode] = [] } provinces[countryCode].push({ name: province.name, code: province.code }) } } that.provinces = provinces }) }, data: function () { let selectedRoutes = this.vRoutes if (selectedRoutes == null) { selectedRoutes = [] } let inputName = this.name if (typeof inputName != "string" || inputName.length == 0) { inputName = "routeCodes" } return { routeCode: "default", inputName: inputName, routes: [], provinces: {}, // country code => [ province1, province2, ... ] provinceRouteCode: "", isAdding: false, routeType: "default", selectedRoutes: selectedRoutes, } }, watch: { routeType: function (v) { this.routeCode = "" let that = this this.routes.forEach(function (route) { if (route.type == v && that.routeCode.length == 0) { that.routeCode = route.code } }) } }, methods: { add: function () { this.isAdding = true this.routeType = "default" this.routeCode = "default" this.provinceRouteCode = "" this.$emit("add") }, cancel: function () { this.isAdding = false this.$emit("cancel") }, confirm: function () { if (this.routeCode.length == 0) { return } let that = this // route let selectedRoute = null for (const route of this.routes) { if (route.code == this.routeCode) { selectedRoute = route break } } if (selectedRoute != null) { // province route if (this.provinceRouteCode.length > 0 && this.provinces[this.routeCode] != null) { for (const province of this.provinces[this.routeCode]) { if (province.code == this.provinceRouteCode) { selectedRoute = { name: selectedRoute.name + "-" + province.name, code: province.code } break } } } that.selectedRoutes.push(selectedRoute) } this.$emit("change", this.selectedRoutes) this.cancel() }, remove: function (index) { this.selectedRoutes.$remove(index) this.$emit("change", this.selectedRoutes) } } , template: `
{{route.name}}  
选择类型 *
选择线路 *
选择省/州
  取消
` })