channel-route.vue 10.9 KB
Newer Older
邓春圆's avatar
邓春圆 committed
1 2 3 4 5
<script>
import {DICT_TYPE, getDictDatas} from "@/utils/dict";
import PackagingType from "@/views/ecw/channel/componrnts/packaging-type.vue";
import {getChannelList} from "@/api/ecw/channel";
import AirFreightRouteTemplate from "@/views/ecw/offer/components/airFreightRouteTemplate.vue";
邓春圆's avatar
邓春圆 committed
6
import {createWarehouseLineChannelPackaging, getAirLineChannelPackagingList} from "@/api/ecw/customerContacts";
邓春圆's avatar
邓春圆 committed
7 8 9 10 11

export default {
  name: "channel-route",
  components: {AirFreightRouteTemplate, PackagingType},
  mounted() {
邓春圆's avatar
邓春圆 committed
12
    getChannelList({lineId: this.lineId}).then((res) => (this.channelList = res.data));
邓春圆's avatar
邓春圆 committed
13 14 15
    this.getRouteDetails(this.lineId, (value) => {
      this.form.channelList = this.setChannelData(value)
    })
邓春圆's avatar
邓春圆 committed
16
  },
邓春圆's avatar
邓春圆 committed
17

邓春圆's avatar
邓春圆 committed
18 19 20 21
  data() {
    return {
      form: {
        "lineId": 0,
邓春圆's avatar
邓春圆 committed
22 23 24 25 26 27 28 29 30 31
        channelList: [{
          "channelIds": "",
          "packagingCreateReqVOList": [
            {
              "airWeightLimit": 0,
              "packagingTypes": "",
              "priceStepClearanceCreateReqVOList": []
            }
          ]
        }],
邓春圆's avatar
邓春圆 committed
32 33 34 35 36 37 38 39 40 41 42
      },
      channelList: [],
      dialogVisible: false,
    }
  },
  computed: {
    DICT_TYPE() {
      return DICT_TYPE
    },
    deletePackagingTypes() {
      let a = []
邓春圆's avatar
邓春圆 committed
43
      this.form.channelList.forEach(item => {
邓春圆's avatar
邓春圆 committed
44 45 46
        item.packagingCreateReqVOList.forEach(i => {
          a.push(...i.packagingTypes)
        })
邓春圆's avatar
邓春圆 committed
47 48
      })
      return a
邓春圆's avatar
邓春圆 committed
49
    },
邓春圆's avatar
邓春圆 committed
50
    channelIdBlackList() {
邓春圆's avatar
邓春圆 committed
51
      let arr = []
邓春圆's avatar
邓春圆 committed
52 53
      this.form.channelList.forEach(i => {
        arr.push(...i.channelIds)
邓春圆's avatar
邓春圆 committed
54 55 56 57 58 59
      })
      return arr
    },
    // 线路id
    lineId() {
      return Number(this.$route.query.id);
邓春圆's avatar
邓春圆 committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73
    }
  },
  methods: {
    deleteFn(index) {
      this.form.channelPackagingList.splice(index, 1)
    },
    getDictDatas,
    //添加包装类型
    addPackaging(index) {
      let p = {
        airWeightLimit: '',
        packagingTypes: [],
        priceStepClearanceCreateReqVOList: [],
      }
邓春圆's avatar
邓春圆 committed
74
      let arr = this.form.channelList[index].packagingCreateReqVOList
邓春圆's avatar
邓春圆 committed
75
      arr.push(p)
邓春圆's avatar
邓春圆 committed
76 77 78
      this.$set(this.form.channelList[index], 'packagingCreateReqVOList', arr);
    },
    newChannelsAdd(index) {
79
      this.form.channelList.splice(index + 1, 0, {
邓春圆's avatar
邓春圆 committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
        "channelIds": "",
        "packagingCreateReqVOList": [
          {
            "airWeightLimit": 0,
            "packagingTypes": "",
            "priceStepClearanceCreateReqVOList": []
          }
        ]
      },)
    },
    channelsDelete(index) {
      this.form.channelList.splice(index, 1)
    },
    deletePackag(index, indexx) {
      let arr = this.form.channelList;
      arr[index].packagingCreateReqVOList.splice(indexx, 1);
      this.form.channelList = arr;
邓春圆's avatar
邓春圆 committed
97
    },
邓春圆's avatar
邓春圆 committed
98 99 100 101 102
    getRouteDetails(id, callback = () => {
    }) {
      getAirLineChannelPackagingList(id).then((r) => {
        callback(r.data)
      })
邓春圆's avatar
邓春圆 committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    },
    setChannelData(list = []) {
      let arr = []
      list.forEach((i, index) => {
        if (index === 0) {
          arr.push({channelIds: i.channelIds, packagingCreateReqVOList: [i]})
        } else {
          if (i.channelIds === list[index - 1].channelIds) {
            arr[arr.length - 1].packagingCreateReqVOList.push(i)
          } else {
            arr.push({channelIds: i.channelIds, packagingCreateReqVOList: [i]})
          }
        }
      })
      arr.forEach(i => {
        i.channelIds = i.channelIds ? i.channelIds.split(',') : []
        i.packagingCreateReqVOList.forEach(item => {
          item.packagingTypes = item.packagingTypes ? item.packagingTypes.split(',') : [];
          item.priceStepClearanceCreateReqVOList = item.lineChannelPriceStepClearanceBackVOList || [];
          item.lineChannelPriceStepClearanceBackVOList = null;
邓春圆's avatar
邓春圆 committed
123 124 125 126
          item.priceStepClearanceCreateReqVOList.forEach(itemm => {
            itemm.clearancePriceUnit = item.clearancePriceUnit
            itemm.clearanceVolumeUnit = item.clearanceVolumeUnit
          })
邓春圆's avatar
邓春圆 committed
127 128
        })
      })
邓春圆's avatar
邓春圆 committed
129 130
      if (arr.length === 0) {
        return [{
邓春圆's avatar
邓春圆 committed
131 132 133 134 135 136 137 138 139 140
          "channelIds": "",
          "packagingCreateReqVOList": [
            {
              "airWeightLimit": 0,
              "packagingTypes": "",
              "priceStepClearanceCreateReqVOList": []
            }
          ]
        }]
      }
邓春圆's avatar
邓春圆 committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
      return arr;

    },
    getChannelDate(value) {
      let obj = Object.assign({}, value)
      let arr = []
      obj.channelList.forEach(i => {
        i.packagingCreateReqVOList.forEach(item => {
          item.channelIds = i.channelIds.join(',');
          let p = {
            "airWeightLimit": item.airWeightLimit,
            "channelIds": item.channelIds,
            "clearancePriceUnit": item.priceStepClearanceCreateReqVOList[0].clearancePriceUnit,
            "clearanceVolumeUnit": item.priceStepClearanceCreateReqVOList[0].clearanceVolumeUnit,
            "lineId": this.lineId,
            "packagingTypes": item.packagingTypes.join(','),
            priceStepClearanceCreateReqVOList: this.getPriceStepClearanceCreateReqVOList(item.priceStepClearanceCreateReqVOList)
          }
          arr.push(p)
        })
      })
      return {
        lineId: this.lineId,
        packagingCreateReqVOList: arr,
      }
    },
    getPriceStepClearanceCreateReqVOList(list) {
      let arr = []
      list.forEach(i => {
        arr.push({
          "clearancePrice": i.clearancePrice,
          "endNum": i.endNum,
          "startNum": i.startNum
        })
      })
      return arr
    },
    submit() {
179
      if (!this.validation()) return
邓春圆's avatar
邓春圆 committed
180 181 182 183 184 185 186 187 188 189
      createWarehouseLineChannelPackaging(this.getChannelDate(this.form)).then(r => {
        this.$message.success('保存成功');
        this.$router.back()
      })
    },
    copy(value) {
      this.getRouteDetails(value.id, (value) => {
        this.form.channelList = this.setChannelData(value)
        this.$message.success('复制成功。')
      })
邓春圆's avatar
邓春圆 committed
190 191 192
    },
    validation() {
      let flag = true
邓春圆's avatar
邓春圆 committed
193
      try {
194 195 196
        this.form.channelList.forEach((item, index) => {
          if (!item.channelIds.length) {
            throw `渠道${index + 1}没有选择航道`;
邓春圆's avatar
邓春圆 committed
197
          }
198 199 200
          item.packagingCreateReqVOList.forEach((itemm, indexx) => {
            if (!itemm.packagingTypes.length) {
              throw `渠道${index + 1}-包装类型${indexx + 1},没有选择包装类型。`;
邓春圆's avatar
邓春圆 committed
201
            }
邓春圆's avatar
邓春圆 committed
202
            if (!(itemm.airWeightLimit > 0)) {
203 204
              throw `渠道${index + 1}-包装类型${indexx + 1},没有输入空运订单重量上限。`;

邓春圆's avatar
邓春圆 committed
205
            }
206 207
            let check = (indexxx) => {
              return `渠道${index + 1}-包装类型${indexx + 1}- 第${indexxx + 1}价格输入有问题。`
邓春圆's avatar
邓春圆 committed
208

邓春圆's avatar
邓春圆 committed
209
            }
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
            itemm.priceStepClearanceCreateReqVOList.forEach((itemmm, indexxx) => {
              if (!itemmm.clearancePrice || itemmm.clearancePrice === '') {
                throw check(indexxx);
              }
              if (!itemmm.clearancePriceUnit || itemmm.clearancePriceUnit === '') {

                throw check(indexxx);
              }
              if (!itemmm.clearanceVolumeUnit || itemmm.clearanceVolumeUnit === '') {
                throw check(indexxx);
              }
              if (isNaN(itemmm.endNum) || itemmm.endNum === '') {
                throw check(indexxx);
              }
              if (isNaN(itemmm.startNum) || itemmm.startNum === '') {
                throw check(indexxx);
              }
邓春圆's avatar
邓春圆 committed
227 228 229
              // if (!itemmm.weightUnit || itemmm.weightUnit === '') {
              //   throw check(indexxx);
              // }
230
            })
邓春圆's avatar
邓春圆 committed
231 232
          })
        })
邓春圆's avatar
邓春圆 committed
233 234 235 236
      } catch (e) {
        flag = false
        console.log(e.Error, 'eee')
        this.$message.warning(e);
237
      }
邓春圆's avatar
邓春圆 committed
238
      return flag
邓春圆's avatar
邓春圆 committed
239
    }
邓春圆's avatar
邓春圆 committed
240 241 242 243 244 245
  }
}
</script>

<template>
  <div style="padding: 20px">
邓春圆's avatar
邓春圆 committed
246
    <div style="margin-bottom: 15px">
邓春圆's avatar
邓春圆 committed
247
      <span>路线:{{ $route.query.startWarehouseTitle }}{{ $route.query.destWarehouseTitle }}</span>
邓春圆's avatar
邓春圆 committed
248 249
      <span style="margin-left: 30px;">运输方式:空运专线</span>
    </div>
邓春圆's avatar
邓春圆 committed
250
    <el-card style="margin-bottom: 10px" v-for="(itemOuter,index) in form.channelList" :key="index">
邓春圆's avatar
邓春圆 committed
251 252 253 254 255
      <template #header>
        <el-row :gutter="20" type="flex" align="middle">
          <el-col :span="1">渠道{{ index + 1 }}
          </el-col>
          <el-col :span="3">
邓春圆's avatar
邓春圆 committed
256
            <el-select multiple v-model="itemOuter.channelIds">
邓春圆's avatar
邓春圆 committed
257
              <el-option
邓春圆's avatar
邓春圆 committed
258 259 260
                :disabled="channelIdBlackList.includes(item.channelId.toString()) && (!itemOuter.channelIds.includes(item.channelId.toString()))"
                v-for="item in channelList" :value="item.channelId.toString()" :key="item.channelId"
                :label="$l(item, 'name')"></el-option>
邓春圆's avatar
邓春圆 committed
261 262
            </el-select>
          </el-col>
邓春圆's avatar
邓春圆 committed
263 264
          <el-col :span="3">
            <el-button size="mini" type="primary" @click="newChannelsAdd(index)">新增渠道</el-button>
邓春圆's avatar
邓春圆 committed
265
          </el-col>
邓春圆's avatar
邓春圆 committed
266 267
          <el-col :span="3">
            <el-button size="mini" type="danger" :disabled="form.channelList.length === 1" @click="channelsDelete(index)">
邓春圆's avatar
邓春圆 committed
268 269
              删除当前渠道
            </el-button>
邓春圆's avatar
邓春圆 committed
270
          </el-col>
邓春圆's avatar
邓春圆 committed
271
          <el-col :span="3">
邓春圆's avatar
邓春圆 committed
272
            <air-freight-route-template :lineId="lineId" @copy="copy">
邓春圆's avatar
邓春圆 committed
273
              <el-button size="mini" v-if="index === 0" type="text">选择渠道包装模板</el-button>
邓春圆's avatar
邓春圆 committed
274
            </air-freight-route-template>
邓春圆's avatar
邓春圆 committed
275 276 277 278 279 280 281 282 283 284 285 286
          </el-col>
        </el-row>
      </template>
      <div style="display: flex;justify-content: space-between;">
        <h1>
          <span style="color: red;font-size: 14px;font-weight: 700;">*</span>
          渠道包装列表
        </h1>
        <div>
          <el-button type="primary" @click="addPackaging(index)">添加包装类型</el-button>
        </div>
      </div>
邓春圆's avatar
邓春圆 committed
287
      <el-row :gutter="20" v-for="(itemm, indexx) in itemOuter.packagingCreateReqVOList"
邓春圆's avatar
邓春圆 committed
288 289 290 291
              style="margin-bottom: 50px; border-bottom: 1px solid #cccccc" :key="indexx">
        <el-col :span="2">包装类型{{ indexx + 1 }}:</el-col>
        <el-col :span="5">
          <el-select multiple v-model="itemm.packagingTypes">
邓春圆's avatar
邓春圆 committed
292
            <el-option
邓春圆's avatar
邓春圆 committed
293 294 295
              :disabled="deletePackagingTypes.includes(item.value) && (!itemm.packagingTypes.includes(item.value))"
              v-for="item in getDictDatas(DICT_TYPE.ECW_PACKAGING_TYPE)" :value="item.value" :key="item.value"
              :label="$l(item, 'label')"></el-option>
邓春圆's avatar
邓春圆 committed
296 297 298
          </el-select>
        </el-col>
        <el-col :span="16">
邓春圆's avatar
邓春圆 committed
299
          <!--          v-if="itemOuter.packagingCreateReqVOList[indexx].length"-->
邓春圆's avatar
邓春圆 committed
300
          <packaging-type key-arr="priceStepClearanceCreateReqVOList"
邓春圆's avatar
邓春圆 committed
301 302 303
                          v-model="itemOuter.packagingCreateReqVOList[indexx]">
            <el-button @click="deletePackag(index,indexx)" :disabled="itemOuter.packagingCreateReqVOList.length === 1"
                       type="danger">删除包装类型{{ indexx + 1 }}
邓春圆's avatar
邓春圆 committed
304 305 306 307 308
            </el-button>
          </packaging-type>
        </el-col>
      </el-row>
    </el-card>
邓春圆's avatar
邓春圆 committed
309 310 311
    <div class="footer">
      <el-button type="primary" @click="submit">保存</el-button>
    </div>
邓春圆's avatar
邓春圆 committed
312 313 314 315
  </div>
</template>

<style scoped lang="scss">
邓春圆's avatar
邓春圆 committed
316 317 318 319
.footer {
  position: fixed;
  bottom: 20px;
}
邓春圆's avatar
邓春圆 committed
320
</style>