index.vue 14.9 KB
Newer Older
1 2
<template>
    <div>
3
        <div class="filters mb-10" v-if="showFilter">
4 5 6 7
            <template v-if="!type">
                {{$t('运输方式')}}
                <dict-selector :type='DICT_TYPE.ECW_TRANSPORT_TYPE' v-model="transportType" :placeholder="$t('请选择运输方式')" :filter="transportFilter" style="width:150px" />
            </template>
dragondean@qq.com's avatar
dragondean@qq.com committed
8 9
            {{$t('始发地')}}:
            <el-select :placeholder="$t('请选择始发地')" v-model="exportCity" clearable>
10 11 12
                <el-option v-for="item in exportCityList" :key="item.id" :label="item.titleZh" :value="item.id" />
            </el-select>

dragondean@qq.com's avatar
dragondean@qq.com committed
13 14
            {{$t('目的地')}}:
            <el-select :placeholder="$t('请选择目的地')" v-model="importCity" clearable>
15 16
                <el-option v-for="item in importCityList" :key="item.id" :label="item.titleZh" :value="item.id" />
            </el-select>
dragondean@qq.com's avatar
dragondean@qq.com committed
17

18
            <template v-if="type != 'sea'">
19 20
              {{$t('出货渠道')}}:
              <el-select :placeholder="$t('请选择目渠道')" v-model="channelId" clearable>
dragondean@qq.com's avatar
dragondean@qq.com committed
21
                <el-option v-for="item in channelList" :key="item.channelId" :label="item.nameZh" :value="item.channelId" />
22 23 24
              </el-select>
            </template>

dragondean@qq.com's avatar
dragondean@qq.com committed
25
        </div>
26
        <div class="mb-10 flex-row" v-if="showFilter">
dragondean@qq.com's avatar
dragondean@qq.com committed
27
            <el-radio-group v-model="checkAll">
dragondean@qq.com's avatar
dragondean@qq.com committed
28 29
                <el-radio :label="true">{{$t('全选')}}</el-radio>
                <el-radio :label="false">{{$t('全不选')}}</el-radio>
dragondean@qq.com's avatar
dragondean@qq.com committed
30
            </el-radio-group>
31
            <el-link class="ml-20" type="danger">{{$t('已选择{n}条路线', {n: selectedRoutes.length})}}</el-link>
32 33
        </div>
        <el-row class="" :gutter="10">
34
            <template v-for="(item, index) in filteredRouterList">
35 36 37
                <el-col :span="12" :key="item.value">
                    <el-card  class="mb-10">
                        <div slot="header">
dragondean@qq.com's avatar
dragondean@qq.com committed
38 39
                            {{$l(item, 'label')}}
                            <el-link type="primary" @click.native="toggleHide(item.value)" style="float:right">{{item._hide ? $t('展开') : $t('折叠')}}</el-link>
40
                        </div>
dragondean@qq.com's avatar
dragondean@qq.com committed
41
                        <!--table需要给一个key,否则全选的时候不会自动更新渲染-->
42
                        <el-table v-if="!hideMap[item.value]" :data="item.routerList" :span-method="SpanMethod" border :key="item.value">
43
                            <el-table-column :label="$t('始发仓')" prop="startTitleZh">
44
                                <template slot-scope="{row}">
dragondean@qq.com's avatar
dragondean@qq.com committed
45
                                    {{$l(row, 'startTitle')}}
46 47
                                </template>
                            </el-table-column>
48
                            <el-table-column :label="$t('目的仓')" prop="destTitleZh" >
dragondean@qq.com's avatar
dragondean@qq.com committed
49 50 51 52
                                <template slot-scope="{row}">
                                    {{$l(row, 'destTitle')}}
                                </template>
                            </el-table-column>
53
                            <el-table-column :label="$t('渠道')" prop="startTitleZh" v-if="[3,4].indexOf(+item.value) > -1">
dragondean@qq.com's avatar
dragondean@qq.com committed
54 55 56 57
                                <template slot-scope="{row}">
                                    {{$l(row.channel, 'name')}}
                                </template>
                            </el-table-column>
58 59
                            <el-table-column v-if="showAttr" :label="$t('商品特性')" prop="startTitleZh">
                              <template slot-scope="{row}">
60 61 62 63 64
                                <!--{{ getAttrNames(row.attrId) }}-->
                                <template v-if="row.channel && row.channel.attrNameList">
                                  {{row.channel.attrNameList.join(',')}}
                                </template>

65 66
                              </template>
                            </el-table-column>
dragondean@qq.com's avatar
dragondean@qq.com committed
67
                            <el-table-column :label="$t('操作')" prop="">
68
                                <template slot="header">
69
                                    <el-checkbox @change="toggleGroupChecker(index, $event)" v-model="groupChecker[item.value]"></el-checkbox>
70
                                </template>
71
                                <template slot-scope="{row}">
72 73
                                    <!--给一个Key让他在全选后更新渲染-->
                                    <el-checkbox :key="getSelectedIndex(row)" :checked="getSelectedIndex(row) > -1" @change="toggleChecker(row, $event)"></el-checkbox>
74 75 76 77 78 79 80 81 82 83 84 85 86
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-card>
                </el-col>
            </template>
        </el-row>
    </div>
</template>
<script>
import {getChannelList} from '@/api/ecw/channel'
import {getTradeCityList} from '@/api/ecw/region'
import {openedRouterList} from '@/api/ecw/warehouse'
87
import {getProductAttrList} from "@/api/ecw/productAttr";
88
import Template from "@/views/cms/template";
89
export default {
90 91
  components: {Template},
  props:{
92 93 94 95 96
      value: {
          type: Array
      },
      option: Object,
      // 类型,sea海运,air空运
97 98 99 100 101
      type: String,
      showFilter:{
        type: Boolean,
        default: true
      }
102
    },
103 104 105 106 107 108 109 110 111
    data(){
        return {
            transportTypeDicts: this.getDictDatas(this.DICT_TYPE.ECW_TRANSPORT_TYPE),
            channelList:[],
            tradeCityList:[],
            openedRouterList:[], // 开放路线
            transportType: null, // 运输方式
            importCity: null, // 目的地(进口城市)
            exportCity: null, // 始发地(出口城市)
dragondean@qq.com's avatar
dragondean@qq.com committed
112
            channelId: null,
113 114
            selectedRoutes: [], // 勾选的路线渠道
            hideMap: {}, // 折叠状态
dragondean@qq.com's avatar
dragondean@qq.com committed
115
            checkAll: null,
116
            groupChecker: {}, // 分组全选状态
117
            attrList:[], // 商品特性
118
            inited: false
119

120 121 122 123
        }
    },
    computed:{
        importCityList(){
124
            return this.tradeCityList.filter(item => item.type == 1 || item.type == 3)
125 126
        },
        exportCityList(){
127
            return this.tradeCityList.filter(item => item.type == 2 || item.type == 3)
128
        },
129 130 131 132 133 134 135 136 137 138 139 140 141 142
        exportCityIds(){
            let ids = []
            this.exportCityList.forEach(item => {
                ids.push(item.id)
            })
            return ids
        },
        importCityIds(){
            let ids = []
            this.importCityList.forEach(item => {
                ids.push(item.id)
            })
            return ids
        },
143
        // 根据选择的渠道筛选
dragondean@qq.com's avatar
dragondean@qq.com committed
144
        availChannelList(){
145
          return this.channelList.filter(item => !this.channelId || this.channelId == item.channelId)
dragondean@qq.com's avatar
dragondean@qq.com committed
146
        },
147 148
        filteredRouterList(){
            let transportTypeList = []
dragondean@qq.com's avatar
dragondean@qq.com committed
149
            this.transportTypeDicts
150
                .filter(this.transportFilter)
dragondean@qq.com's avatar
dragondean@qq.com committed
151 152 153 154 155 156
                .filter(transport => !this.channelId || transport.cssClass == 'channel')
                .forEach(item => {
                    if(this.transportType === null || this.transportType == '' || this.transportType == item.value){
                        let routerList = []
                        this.openedRouterList.forEach(router => {
                            if(router.transportType == item.value){
157 158 159 160 161 162 163
                                let availChannels = []
                                // 空运相关的,没有可用的渠道则不显示线路
                                if(item.cssClass === 'channel'){
                                  availChannels = this.availChannelList.filter(channel => channel.countryId == router.destCountryId)
                                  if(!availChannels.length) return
                                }

dragondean@qq.com's avatar
dragondean@qq.com committed
164
                                routerList.push(Object.assign({
165 166
                                        _merge: item.cssClass == 'channel' ? availChannels.length || 1 : 1,
                                        channel: item.cssClass == 'channel' ? availChannels[0] || { channelId: 0} : {channelId: 0},
dragondean@qq.com's avatar
dragondean@qq.com committed
167 168 169 170
                                    }, router)
                                )
                                // 字典的cssClass =channel则表示渠道相关(空运,海空联运)
                                if(item.cssClass == 'channel'){
171
                                  availChannels.slice(1).forEach(channel => {
dragondean@qq.com's avatar
dragondean@qq.com committed
172 173 174
                                        routerList.push(Object.assign({channel, _merge: 0}, router))
                                    })
                                }
175
                            }
dragondean@qq.com's avatar
dragondean@qq.com committed
176
                        })
177

dragondean@qq.com's avatar
dragondean@qq.com committed
178 179
                        let child = {
                            label: item.label,
dragondean@qq.com's avatar
dragondean@qq.com committed
180
                            labelEn: item.labelEn,
dragondean@qq.com's avatar
dragondean@qq.com committed
181 182 183 184 185
                            value: item.value,
                            _hide: false, // 是否折叠
                            routerList: routerList
                        }
                        transportTypeList.push(child)
186
                    }
dragondean@qq.com's avatar
dragondean@qq.com committed
187
                })
188
            return transportTypeList
189 190 191 192 193 194 195 196
        },
        // 是否显示商品特性(渠道)
        showAttr(){
            return this.type == 'air'
        },
        // 显示产品特性
        getAttrName(){
          return (id) => {
197
            let item = this.attrList.find(item => item.id === +id)
198 199 200 201 202 203 204 205 206 207
            if(!item) return ''
            return this.$l(item, 'attrName')
          }
        },
        // 显示多个商品特性
        getAttrNames(){
          return (ids) => {
            if(!ids) return ''
            return ids.split(',').filter( item => !!item).map(id => this.getAttrName(id)).join(',')
          }
208 209 210 211 212 213 214
        }
    },
    watch:{
        exportCity(){
            this.getOpenedRouterList()
        },
        importCity(){
215 216
          this.getChannelList()
          this.getOpenedRouterList()
217 218 219
        },
        selectedRoutes(val){
            this.$emit('input', val)
dragondean@qq.com's avatar
dragondean@qq.com committed
220 221 222 223 224 225 226 227
            // 如果选择发生变化
            let total = 0
            this.filteredRouterList.forEach(item => {
                total += item.routerList.length
            })
            if(total != val.length && val.length){
                this.checkAll = null
            }
228 229 230
        },
        value(val){
            this.selectedRoutes = val || []
dragondean@qq.com's avatar
dragondean@qq.com committed
231 232 233 234 235 236 237 238 239 240
        },
        checkAll(val){
            if(val === true || val === false){
                console.log('选中全部')
                this.filteredRouterList.forEach(item => {
                    item.routerList.forEach(router => {
                        if(this.getSelectedIndex(router) > -1 != val )this.toggleChecker(router, val)
                    })
                })
            }
241 242 243 244 245
        },
        option(option){
            if(option){
                this.changeOption()
            }
246 247 248
        },
      // 显示的路线发生变化之后,清空已勾选的路线
      filteredRouterList(){
249 250 251 252 253 254
        if(this.inited){
          this.selectedRoutes = []
          Object.keys(this.groupChecker).forEach(key => {
            this.groupChecker[key] = false
          })
        }
255
      }
256
    },
257
    async created(){
258
      this.getChannelList()
259 260 261 262 263 264
      this.tradeCityList = (await getTradeCityList()).data
      // 路线需要过滤失效的进出口城市,所以在程序加载后再加载路线
      await this.getOpenedRouterList()
      if(this.option){
        this.changeOption()
      }
265

266 267 268 269
      await this.$nextTick()
      if(this.value && this.value.length){
          this.selectedRoutes = this.value
      }
270

271 272 273 274
      // 如果显示特性,则需要查询特数据备用
      if(this.showAttr){
        this.getAttrList()
      }
275 276 277

      await this.$nextTick()
      this.inited = true
278 279
    },
    methods:{
280 281 282 283 284 285
      async getChannelList(){
        let query = {
          cityId: this.importCity
        }
        this.channelList = (await getChannelList(query)).data
      },
286 287 288 289 290
      getAttrList(){
        getProductAttrList().then(res => {
          this.attrList = res.data
        })
      },
291 292
        changeOption(){
            if(!this.option) return
dragondean@qq.com's avatar
dragondean@qq.com committed
293 294 295 296
            this.importCity = +this.option.importCity || null
            this.exportCity = +this.option.exportCity || null
            this.transportType = this.option.transportId || null
            this.channelId = +this.option.channelId || null
297
        },
298 299 300 301 302 303 304 305
        // 全选、全不选 某个运输方式所有线路
        toggleGroupChecker(index, selected){
            let routerList = this.filteredRouterList[index].routerList
            console.log(routerList.length, selected)
            routerList.forEach(router => {
                this.toggleChecker(router, selected)
            })
        },
306
        async getOpenedRouterList(){
307 308 309 310 311 312 313
            let params = {}
            if(this.exportCity){
                params.startCityId = this.exportCity
            }
            if(this.importCity){
                params.destCityId = this.importCity
            }
314 315 316 317
            const res = await openedRouterList(params)
            this.openedRouterList = res.data.filter(item => {
              return this.exportCityIds.indexOf(item.startCityId) > -1 && this.importCityIds.indexOf(item.destCityId) > -1
            })
318 319 320
        },
        // 切换路线选择
        toggleChecker(router, selected){
dragondean@qq.com's avatar
dragondean@qq.com committed
321
            // this.getSelectedIndex(router)
322 323 324 325 326 327 328
            /* this.selectedRoutes.forEach((item, i)=>{
                if(item.lineId == router.id && item.shippingChannelId == item.channel.id){
                    index = i
                    break
                }
            }) */
            if(selected){
329 330
                // 先判断是否已勾选
                if(this.getSelectedIndex(router) > -1) return
331 332
                this.selectedRoutes.push({
                    lineId: router.id,
333
                    shippingChannelId: router.channel.channelId,
334
                    transportId: router.transportType
335 336 337
                })
            }else{
                let index = this.getSelectedIndex(router)
dragondean@qq.com's avatar
dragondean@qq.com committed
338
                if(index > -1){
339 340
                    this.selectedRoutes.splice(index, 1)
                }
341

342 343 344
            }
        },
        getSelectedIndex(router){
dragondean@qq.com's avatar
dragondean@qq.com committed
345
            return this.selectedRoutes.findIndex(item => {
346
                return item.lineId == router.id && item.shippingChannelId == router.channel.channelId
dragondean@qq.com's avatar
dragondean@qq.com committed
347
            })
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
        },
        SpanMethod({ row, column, rowIndex, columnIndex }){
            if (columnIndex < 2 ) {
                return {
                    rowspan: row._merge,
                    colspan: 1
                }
            }
            return {
                rowspan: 1,
                colspan: 1
            }
        },
        // 折叠,展开
        toggleHide(value){
            this.$set(this.hideMap, value, !this.hideMap[value])
364 365 366
        },
        // 运输方式筛选
        transportFilter(item){
367 368
          // 未指定类型则全部可用
          if(!this.type) return true
369 370
          return (this.type == 'sea' ? ['1','2'] : ['3', '4']).indexOf(item.value) > -1
        },
371 372 373 374 375 376 377
    }
}
</script>
<style scoped>
.mb-10{
    margin-bottom: 10px
}
378
</style>