index.vue 13.1 KB
Newer Older
1 2 3
<template>
    <div>
        <div class="filters mb-10">
dragondean@qq.com's avatar
dragondean@qq.com committed
4
            {{$t('运输方式')}}
5 6
            <dict-selector :type='DICT_TYPE.ECW_TRANSPORT_TYPE' v-model="transportType" :placeholder="$t('请选择运输方式')" :filter="transportFilter" style="width:150px" />

dragondean@qq.com's avatar
dragondean@qq.com committed
7 8
            {{$t('始发地')}}
            <el-select :placeholder="$t('请选择始发地')" v-model="exportCity" clearable>
9 10 11
                <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
12 13
            {{$t('目的地')}}
            <el-select :placeholder="$t('请选择目的地')" v-model="importCity" clearable>
14 15
                <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
16

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

dragondean@qq.com's avatar
dragondean@qq.com committed
24 25 26
        </div>
        <div class="mb-10">
            <el-radio-group v-model="checkAll">
dragondean@qq.com's avatar
dragondean@qq.com committed
27 28
                <el-radio :label="true">{{$t('全选')}}</el-radio>
                <el-radio :label="false">{{$t('全不选')}}</el-radio>
dragondean@qq.com's avatar
dragondean@qq.com committed
29
            </el-radio-group>
30 31
        </div>
        <el-row class="" :gutter="10">
32
            <template v-for="(item, index) in filteredRouterList">
33 34 35
                <el-col :span="12" :key="item.value">
                    <el-card  class="mb-10">
                        <div slot="header">
dragondean@qq.com's avatar
dragondean@qq.com committed
36 37
                            {{$l(item, 'label')}}
                            <el-link type="primary" @click.native="toggleHide(item.value)" style="float:right">{{item._hide ? $t('展开') : $t('折叠')}}</el-link>
38
                        </div>
dragondean@qq.com's avatar
dragondean@qq.com committed
39 40
                        <!--table需要给一个key,否则全选的时候不会自动更新渲染-->
                        <el-table v-if="!hideMap[item.value]" :data="item.routerList" :span-method="SpanMethod" border :key="selectedRoutes.length + item.value">
41
                            <el-table-column :label="$t('始发仓')" prop="startTitleZh">
42
                                <template slot-scope="{row}">
dragondean@qq.com's avatar
dragondean@qq.com committed
43
                                    {{$l(row, 'startTitle')}}
44 45
                                </template>
                            </el-table-column>
46
                            <el-table-column :label="$t('目的仓')" prop="destTitleZh" >
dragondean@qq.com's avatar
dragondean@qq.com committed
47 48 49 50
                                <template slot-scope="{row}">
                                    {{$l(row, 'destTitle')}}
                                </template>
                            </el-table-column>
51
                            <el-table-column :label="$t('渠道')" prop="startTitleZh" v-if="type == 'air'">
dragondean@qq.com's avatar
dragondean@qq.com committed
52 53 54 55
                                <template slot-scope="{row}">
                                    {{$l(row.channel, 'name')}}
                                </template>
                            </el-table-column>
56 57 58 59 60
                            <el-table-column v-if="showAttr" :label="$t('商品特性')" prop="startTitleZh">
                              <template slot-scope="{row}">
                                {{ getAttrNames(row.attrId) }}
                              </template>
                            </el-table-column>
dragondean@qq.com's avatar
dragondean@qq.com committed
61
                            <el-table-column :label="$t('操作')" prop="">
62
                                <template slot="header">
63
                                    <el-checkbox @change="toggleGroupChecker(index, $event)" v-model="groupChecker[item.value]"></el-checkbox>
64
                                </template>
65
                                <template slot-scope="{row}">
dragondean@qq.com's avatar
dragondean@qq.com committed
66
                                    <el-checkbox :checked="getSelectedIndex(row) > -1" @change="toggleChecker(row, $event)"></el-checkbox>
67 68 69 70 71 72 73 74 75 76 77 78 79
                                </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'
80
import {getProductAttrList} from "@/api/ecw/productAttr";
81
import Template from "@/views/cms/template";
82
export default {
83 84
  components: {Template},
  props:{
85 86 87 88 89 90
      value: {
          type: Array
      },
      option: Object,
      // 类型,sea海运,air空运
      type: String
91
    },
92 93 94 95 96 97 98 99 100
    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
101
            channelId: null,
102 103
            selectedRoutes: [], // 勾选的路线渠道
            hideMap: {}, // 折叠状态
dragondean@qq.com's avatar
dragondean@qq.com committed
104
            checkAll: null,
105
            groupChecker: {}, // 分组全选状态
106
            attrList:[], // 商品特性
107 108 109 110
        }
    },
    computed:{
        importCityList(){
111
            return this.tradeCityList.filter(item => item.type == 1 || item.type == 3)
112 113
        },
        exportCityList(){
114
            return this.tradeCityList.filter(item => item.type == 2 || item.type == 3)
115
        },
116 117 118 119 120 121 122 123 124 125 126 127 128 129
        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
        },
130
        // 根据选择的渠道筛选
dragondean@qq.com's avatar
dragondean@qq.com committed
131
        availChannelList(){
132
          return this.channelList.filter(item => !this.channelId || this.channelId == item.channelId)
dragondean@qq.com's avatar
dragondean@qq.com committed
133
        },
134 135
        filteredRouterList(){
            let transportTypeList = []
dragondean@qq.com's avatar
dragondean@qq.com committed
136
            this.transportTypeDicts
137
                .filter(this.transportFilter)
dragondean@qq.com's avatar
dragondean@qq.com committed
138 139 140 141 142 143 144 145
                .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){
                                routerList.push(Object.assign({
                                        _merge: item.cssClass == 'channel' ? this.availChannelList.length || 1 : 1,
146
                                        channel: item.cssClass == 'channel' ? this.availChannelList[0] || { channelId: 0} : {channelId: 0},
dragondean@qq.com's avatar
dragondean@qq.com committed
147 148 149 150 151 152 153 154
                                    }, router)
                                )
                                // 字典的cssClass =channel则表示渠道相关(空运,海空联运)
                                if(item.cssClass == 'channel'){
                                    this.availChannelList.slice(1).forEach(channel => {
                                        routerList.push(Object.assign({channel, _merge: 0}, router))
                                    })
                                }
155
                            }
dragondean@qq.com's avatar
dragondean@qq.com committed
156
                        })
157

dragondean@qq.com's avatar
dragondean@qq.com committed
158 159
                        let child = {
                            label: item.label,
dragondean@qq.com's avatar
dragondean@qq.com committed
160
                            labelEn: item.labelEn,
dragondean@qq.com's avatar
dragondean@qq.com committed
161 162 163 164 165
                            value: item.value,
                            _hide: false, // 是否折叠
                            routerList: routerList
                        }
                        transportTypeList.push(child)
166
                    }
dragondean@qq.com's avatar
dragondean@qq.com committed
167
                })
168
            return transportTypeList
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
        },
        // 是否显示商品特性(渠道)
        showAttr(){
            return this.type == 'air'
        },
        // 显示产品特性
        getAttrName(){
          return (id) => {
            let item = this.attrList.find(item => item.id == id)
            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(',')
          }
188 189 190 191 192 193 194 195 196 197 198
        }
    },
    watch:{
        exportCity(){
            this.getOpenedRouterList()
        },
        importCity(){
            this.getOpenedRouterList()
        },
        selectedRoutes(val){
            this.$emit('input', val)
dragondean@qq.com's avatar
dragondean@qq.com committed
199 200 201 202 203 204 205 206
            // 如果选择发生变化
            let total = 0
            this.filteredRouterList.forEach(item => {
                total += item.routerList.length
            })
            if(total != val.length && val.length){
                this.checkAll = null
            }
207 208 209
        },
        value(val){
            this.selectedRoutes = val || []
dragondean@qq.com's avatar
dragondean@qq.com committed
210 211 212 213 214 215 216 217 218 219
        },
        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)
                    })
                })
            }
220 221 222 223 224
        },
        option(option){
            if(option){
                this.changeOption()
            }
225

226 227 228 229 230 231 232 233
        }
    },
    created(){
        getChannelList().then(res => {
            this.channelList = res.data
        })
        getTradeCityList().then(res => {
            this.tradeCityList = res.data
dragondean@qq.com's avatar
dragondean@qq.com committed
234 235
            // 路线需要过滤失效的进出口城市,所以在程序加载后再加载路线
            this.getOpenedRouterList()
236
        })
237

238 239 240
        if(this.value && this.value.length){
            this.selectedRoutes = this.value
        }
241 242 243 244

        if(this.option){
            this.changeOption()
        }
245 246 247 248 249 250

        // 如果显示特性,则需要查询特数据备用
        if(this.showAttr){
            this.getAttrList()
        }

251 252
    },
    methods:{
253 254 255 256 257
      getAttrList(){
        getProductAttrList().then(res => {
          this.attrList = res.data
        })
      },
258 259
        changeOption(){
            if(!this.option) return
dragondean@qq.com's avatar
dragondean@qq.com committed
260 261 262 263
            this.importCity = +this.option.importCity || null
            this.exportCity = +this.option.exportCity || null
            this.transportType = this.option.transportId || null
            this.channelId = +this.option.channelId || null
264
        },
265 266 267 268 269 270 271 272
        // 全选、全不选 某个运输方式所有线路
        toggleGroupChecker(index, selected){
            let routerList = this.filteredRouterList[index].routerList
            console.log(routerList.length, selected)
            routerList.forEach(router => {
                this.toggleChecker(router, selected)
            })
        },
273 274 275 276 277 278 279 280
        getOpenedRouterList(){
            let params = {}
            if(this.exportCity){
                params.startCityId = this.exportCity
            }
            if(this.importCity){
                params.destCityId = this.importCity
            }
281 282 283
            openedRouterList(params).then(res => this.openedRouterList = res.data.filter(item => {
                return this.exportCityIds.indexOf(item.startCityId) > -1 && this.importCityIds.indexOf(item.destCityId) > -1
            }))
284 285 286
        },
        // 切换路线选择
        toggleChecker(router, selected){
dragondean@qq.com's avatar
dragondean@qq.com committed
287
            // this.getSelectedIndex(router)
288 289 290 291 292 293 294 295 296
            /* this.selectedRoutes.forEach((item, i)=>{
                if(item.lineId == router.id && item.shippingChannelId == item.channel.id){
                    index = i
                    break
                }
            }) */
            if(selected){
                this.selectedRoutes.push({
                    lineId: router.id,
297 298
                    channelId: router.channel.channelId,
                    transportId: router.transportType
299 300 301
                })
            }else{
                let index = this.getSelectedIndex(router)
dragondean@qq.com's avatar
dragondean@qq.com committed
302
                if(index > -1){
303 304
                    this.selectedRoutes.splice(index, 1)
                }
305

306 307 308
            }
        },
        getSelectedIndex(router){
dragondean@qq.com's avatar
dragondean@qq.com committed
309
            return this.selectedRoutes.findIndex(item => {
310
                return item.lineId == router.id && item.channelId == router.channel.channelId
dragondean@qq.com's avatar
dragondean@qq.com committed
311
            })
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
        },
        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])
328 329 330 331 332
        },
        // 运输方式筛选
        transportFilter(item){
          return (this.type == 'sea' ? ['1','2'] : ['3', '4']).indexOf(item.value) > -1
        },
333 334 335 336 337 338 339
    }
}
</script>
<style scoped>
.mb-10{
    margin-bottom: 10px
}
340
</style>