2021-05-30 16:31:12 +08:00
|
|
|
// 选择多个线路
|
|
|
|
|
Vue.component("ns-routes-selector", {
|
2022-08-09 21:04:30 +08:00
|
|
|
props: ["v-routes", "name"],
|
2021-05-30 16:31:12 +08:00
|
|
|
mounted: function () {
|
|
|
|
|
let that = this
|
|
|
|
|
Tea.action("/ns/routes/options")
|
|
|
|
|
.post()
|
|
|
|
|
.success(function (resp) {
|
2021-08-09 13:56:11 +08:00
|
|
|
that.routes = resp.data.routes
|
2024-03-14 20:41:36 +08:00
|
|
|
|
|
|
|
|
// 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
|
2021-05-30 16:31:12 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
data: function () {
|
2021-08-09 13:56:11 +08:00
|
|
|
let selectedRoutes = this.vRoutes
|
|
|
|
|
if (selectedRoutes == null) {
|
|
|
|
|
selectedRoutes = []
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 21:04:30 +08:00
|
|
|
let inputName = this.name
|
|
|
|
|
if (typeof inputName != "string" || inputName.length == 0) {
|
|
|
|
|
inputName = "routeCodes"
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-30 16:31:12 +08:00
|
|
|
return {
|
2021-08-09 13:56:11 +08:00
|
|
|
routeCode: "default",
|
2022-08-09 21:04:30 +08:00
|
|
|
inputName: inputName,
|
2021-05-30 16:31:12 +08:00
|
|
|
routes: [],
|
2024-03-14 20:41:36 +08:00
|
|
|
|
|
|
|
|
provinces: {}, // country code => [ province1, province2, ... ]
|
|
|
|
|
provinceRouteCode: "",
|
|
|
|
|
|
2021-08-09 13:56:11 +08:00
|
|
|
isAdding: false,
|
|
|
|
|
routeType: "default",
|
2022-08-09 21:04:30 +08:00
|
|
|
selectedRoutes: selectedRoutes,
|
2021-05-30 16:31:12 +08:00
|
|
|
}
|
2021-08-09 13:56:11 +08:00
|
|
|
},
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-05-30 16:31:12 +08:00
|
|
|
methods: {
|
|
|
|
|
add: function () {
|
|
|
|
|
this.isAdding = true
|
2021-08-09 13:56:11 +08:00
|
|
|
this.routeType = "default"
|
|
|
|
|
this.routeCode = "default"
|
2024-03-14 20:41:36 +08:00
|
|
|
this.provinceRouteCode = ""
|
2022-08-09 21:04:30 +08:00
|
|
|
this.$emit("add")
|
2021-05-30 16:31:12 +08:00
|
|
|
},
|
|
|
|
|
cancel: function () {
|
|
|
|
|
this.isAdding = false
|
2022-08-09 21:04:30 +08:00
|
|
|
this.$emit("cancel")
|
2021-05-30 16:31:12 +08:00
|
|
|
},
|
|
|
|
|
confirm: function () {
|
2021-08-09 13:56:11 +08:00
|
|
|
if (this.routeCode.length == 0) {
|
2021-05-30 16:31:12 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let that = this
|
2024-03-14 20:41:36 +08:00
|
|
|
|
|
|
|
|
// route
|
|
|
|
|
let selectedRoute = null
|
|
|
|
|
for (const route of this.routes) {
|
|
|
|
|
if (route.code == this.routeCode) {
|
|
|
|
|
selectedRoute = route
|
|
|
|
|
break
|
2021-05-30 16:31:12 +08:00
|
|
|
}
|
2024-03-14 20:41:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 21:04:30 +08:00
|
|
|
this.$emit("change", this.selectedRoutes)
|
2021-05-30 16:31:12 +08:00
|
|
|
this.cancel()
|
|
|
|
|
},
|
|
|
|
|
remove: function (index) {
|
2021-08-09 13:56:11 +08:00
|
|
|
this.selectedRoutes.$remove(index)
|
2022-08-09 21:04:30 +08:00
|
|
|
this.$emit("change", this.selectedRoutes)
|
2021-05-30 16:31:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
template: `<div>
|
2022-08-09 21:04:30 +08:00
|
|
|
<div v-show="selectedRoutes.length > 0">
|
2021-08-09 13:56:11 +08:00
|
|
|
<div class="ui label basic text small" v-for="(route, index) in selectedRoutes" style="margin-bottom: 0.3em">
|
2022-08-09 21:04:30 +08:00
|
|
|
<input type="hidden" :name="inputName" :value="route.code"/>
|
2021-05-30 16:31:12 +08:00
|
|
|
{{route.name}} <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="ui divider"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="isAdding" style="margin-bottom: 1em">
|
2024-03-14 20:41:36 +08:00
|
|
|
<table class="ui table">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="title">选择类型 *</td>
|
|
|
|
|
<td>
|
|
|
|
|
<select class="ui dropdown auto-width" v-model="routeType">
|
|
|
|
|
<option value="default">[默认线路]</option>
|
|
|
|
|
<option value="user">自定义线路</option>
|
|
|
|
|
<option value="isp">运营商</option>
|
|
|
|
|
<option value="china">中国省市</option>
|
|
|
|
|
<option value="world">全球国家地区</option>
|
|
|
|
|
<option value="agent">搜索引擎</option>
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>选择线路 *</td>
|
|
|
|
|
<td>
|
|
|
|
|
<select class="ui dropdown auto-width" v-model="routeCode">
|
|
|
|
|
<option v-for="route in routes" :value="route.code" v-if="route.type == routeType">{{route.name}}</option>
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr v-if="routeCode.length > 0 && provinces[routeCode] != null">
|
|
|
|
|
<td>选择省/州</td>
|
|
|
|
|
<td>
|
|
|
|
|
<select class="ui dropdown auto-width" v-model="provinceRouteCode">
|
|
|
|
|
<option value="">[全域]</option>
|
|
|
|
|
<option v-for="province in provinces[routeCode]" :value="province.code">{{province.name}}</option>
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
<div>
|
|
|
|
|
<button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
|
|
|
|
|
<a href="" title="取消" @click.prevent="cancel">取消</a>
|
|
|
|
|
</div>
|
2021-05-30 16:31:12 +08:00
|
|
|
</div>
|
2024-03-14 20:41:36 +08:00
|
|
|
<button class="ui button tiny" type="button" @click.prevent="add" v-if="!isAdding">+</button>
|
2021-05-30 16:31:12 +08:00
|
|
|
</div>`
|
|
|
|
|
})
|