// 选择多个线路 Vue.component("ns-routes-selector", { props: ["v-routes"], mounted: function () { let that = this Tea.action("/ns/routes/options") .post() .success(function (resp) { that.routes = resp.data.routes }) }, data: function () { let selectedRoutes = this.vRoutes if (selectedRoutes == null) { selectedRoutes = [] } return { routeCode: "default", routes: [], 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" }, cancel: function () { this.isAdding = false }, confirm: function () { if (this.routeCode.length == 0) { return } let that = this this.routes.forEach(function (v) { if (v.code == that.routeCode) { that.selectedRoutes.push(v) } }) this.cancel() }, remove: function (index) { this.selectedRoutes.$remove(index) } } , template: `
{{route.name}}  
 
` })