@@ -7,6 +7,22 @@ Vue.component("ns-routes-selector", {
77 . post ( )
88 . success ( function ( resp ) {
99 that . routes = resp . data . routes
10+
11+ // provinces
12+ let provinces = { }
13+ if ( resp . data . provinces != null && resp . data . provinces . length > 0 ) {
14+ for ( const province of resp . data . provinces ) {
15+ let countryCode = province . countryCode
16+ if ( typeof provinces [ countryCode ] == "undefined" ) {
17+ provinces [ countryCode ] = [ ]
18+ }
19+ provinces [ countryCode ] . push ( {
20+ name : province . name ,
21+ code : province . code
22+ } )
23+ }
24+ }
25+ that . provinces = provinces
1026 } )
1127 } ,
1228 data : function ( ) {
@@ -24,6 +40,10 @@ Vue.component("ns-routes-selector", {
2440 routeCode : "default" ,
2541 inputName : inputName ,
2642 routes : [ ] ,
43+
44+ provinces : { } , // country code => [ province1, province2, ... ]
45+ provinceRouteCode : "" ,
46+
2747 isAdding : false ,
2848 routeType : "default" ,
2949 selectedRoutes : selectedRoutes ,
@@ -45,6 +65,7 @@ Vue.component("ns-routes-selector", {
4565 this . isAdding = true
4666 this . routeType = "default"
4767 this . routeCode = "default"
68+ this . provinceRouteCode = ""
4869 this . $emit ( "add" )
4970 } ,
5071 cancel : function ( ) {
@@ -57,11 +78,33 @@ Vue.component("ns-routes-selector", {
5778 }
5879
5980 let that = this
60- this . routes . forEach ( function ( v ) {
61- if ( v . code == that . routeCode ) {
62- that . selectedRoutes . push ( v )
81+
82+ // route
83+ let selectedRoute = null
84+ for ( const route of this . routes ) {
85+ if ( route . code == this . routeCode ) {
86+ selectedRoute = route
87+ break
6388 }
64- } )
89+ }
90+
91+ if ( selectedRoute != null ) {
92+ // province route
93+ if ( this . provinceRouteCode . length > 0 && this . provinces [ this . routeCode ] != null ) {
94+ for ( const province of this . provinces [ this . routeCode ] ) {
95+ if ( province . code == this . provinceRouteCode ) {
96+ selectedRoute = {
97+ name : selectedRoute . name + "-" + province . name ,
98+ code : province . code
99+ }
100+ break
101+ }
102+ }
103+ }
104+
105+ that . selectedRoutes . push ( selectedRoute )
106+ }
107+
65108 this . $emit ( "change" , this . selectedRoutes )
66109 this . cancel ( )
67110 } ,
@@ -80,30 +123,43 @@ Vue.component("ns-routes-selector", {
80123 <div class="ui divider"></div>
81124 </div>
82125 <div v-if="isAdding" style="margin-bottom: 1em">
83- <div class="ui fields inline">
84- <div class="ui field">
85- <select class="ui dropdown" v-model="routeType">
86- <option value="default">[默认线路]</option>
87- <option value="user">自定义线路</option>
88- <option value="isp">运营商</option>
89- <option value="china">中国省市</option>
90- <option value="world">全球国家地区</option>
91- <option value="agent">搜索引擎</option>
92- </select>
93- </div>
94-
95- <div class="ui field">
96- <select class="ui dropdown" v-model="routeCode" style="width: 10em">
97- <option v-for="route in routes" :value="route.code" v-if="route.type == routeType">{{route.name}}</option>
98- </select>
99- </div>
100-
101- <div class="ui field">
102- <button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
103- <a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
104- </div>
105- </div>
126+ <table class="ui table">
127+ <tr>
128+ <td class="title">选择类型 *</td>
129+ <td>
130+ <select class="ui dropdown auto-width" v-model="routeType">
131+ <option value="default">[默认线路]</option>
132+ <option value="user">自定义线路</option>
133+ <option value="isp">运营商</option>
134+ <option value="china">中国省市</option>
135+ <option value="world">全球国家地区</option>
136+ <option value="agent">搜索引擎</option>
137+ </select>
138+ </td>
139+ </tr>
140+ <tr>
141+ <td>选择线路 *</td>
142+ <td>
143+ <select class="ui dropdown auto-width" v-model="routeCode">
144+ <option v-for="route in routes" :value="route.code" v-if="route.type == routeType">{{route.name}}</option>
145+ </select>
146+ </td>
147+ </tr>
148+ <tr v-if="routeCode.length > 0 && provinces[routeCode] != null">
149+ <td>选择省/州</td>
150+ <td>
151+ <select class="ui dropdown auto-width" v-model="provinceRouteCode">
152+ <option value="">[全域]</option>
153+ <option v-for="province in provinces[routeCode]" :value="province.code">{{province.name}}</option>
154+ </select>
155+ </td>
156+ </tr>
157+ </table>
158+ <div>
159+ <button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
160+ <a href="" title="取消" @click.prevent="cancel">取消</a>
161+ </div>
106162 </div>
107- <button class="ui button tiny" type="button" @click.prevent="add">+</button>
163+ <button class="ui button tiny" type="button" @click.prevent="add" v-if="!isAdding" >+</button>
108164</div>`
109165} )
0 commit comments