channel-route.vue 11 KB
Newer Older
lanbaoming's avatar
lanbaoming committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
<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";
import {createWarehouseLineChannelPackaging, getAirLineChannelPackagingList} from "@/api/ecw/customerContacts";

export default {
  name: "channel-route",
  components: {AirFreightRouteTemplate, PackagingType},
  mounted() {
    getChannelList({lineId: this.lineId}).then((res) => (this.channelList = res.data));
    this.getRouteDetails(this.lineId, (value) => {
      this.form.channelList = this.setChannelData(value)
    })
  },

  data() {
    return {
      form: {
        "lineId": 0,
        channelList: [{
          "channelIds": "",
          "packagingCreateReqVOList": [
            {
              "airWeightLimit": 0,
              "packagingTypes": "",
              "priceStepClearanceCreateReqVOList": []
            }
          ]
        }],
      },
      channelList: [],
      dialogVisible: false,
    }
  },
  computed: {
    DICT_TYPE() {
      return DICT_TYPE
    },
    deletePackagingTypes() {
      return (index) => {
        let a = []
        this.form.channelList[index].packagingCreateReqVOList.forEach(i => {
          a.push(...i.packagingTypes)
        })
        return a
      }
    },
    channelIdBlackList() {
      let arr = []
      this.form.channelList.forEach(i => {
        arr.push(...i.channelIds)
      })
      return arr
    },
    // 线路id
    lineId() {
      return Number(this.$route.query.id);
    }
  },
  methods: {
    deleteFn(index) {
      this.form.channelPackagingList.splice(index, 1)
    },
    getDictDatas,
    //添加包装类型
    addPackaging(index) {
      let p = {
        airWeightLimit: '',
        packagingTypes: [],
        priceStepClearanceCreateReqVOList: [],
      }
      let arr = this.form.channelList[index].packagingCreateReqVOList
      arr.push(p)
      this.$set(this.form.channelList[index], 'packagingCreateReqVOList', arr);
    },
    newChannelsAdd(index) {
      this.form.channelList.splice(index + 1, 0, {
        "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;
    },
    getRouteDetails(id, callback = () => {
    }) {
      getAirLineChannelPackagingList(id).then((r) => {
        callback(r.data)
      })
    },
    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;
          item.priceStepClearanceCreateReqVOList.forEach(itemm => {
            itemm.clearancePriceUnit = item.clearancePriceUnit
            itemm.clearanceVolumeUnit = item.clearanceVolumeUnit
          })
        })
      })
      if (arr.length === 0) {
        return [{
          "channelIds": "",
          "packagingCreateReqVOList": [
            {
              "airWeightLimit": 0,
              "packagingTypes": "",
              "priceStepClearanceCreateReqVOList": []
            }
          ]
        }]
      }
      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() {
      if (!this.validation()) return
      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('复制成功。')
      })
    },
    validation() {
      let flag = true
      try {
        this.form.channelList.forEach((item, index) => {
          if (!item.channelIds.length) {
            throw `渠道${index + 1}没有选择航道`;
          }
          item.packagingCreateReqVOList.forEach((itemm, indexx) => {
            if (!itemm.packagingTypes.length) {
              throw `渠道${index + 1}-包装类型${indexx + 1},没有选择包装类型。`;
            }
            if (!(itemm.airWeightLimit > 0)) {
              throw `渠道${index + 1}-包装类型${indexx + 1},没有输入空运订单重量上限。`;

            }
            let check = (indexxx) => {
              return `渠道${index + 1}-包装类型${indexx + 1}- 第${indexxx + 1}价格输入有问题。`

            }
            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);
              }
              // if (!itemmm.weightUnit || itemmm.weightUnit === '') {
              //   throw check(indexxx);
              // }
            })
          })
        })
      } catch (e) {
        flag = false
        console.log(e.Error, 'eee')
        this.$message.warning(e);
      }
      return flag
    }
  }
}
</script>

<template>
  <div style="padding: 20px">
    <div style="margin-bottom: 15px">
      <span>目的国:{{ $route.query.destCountryName }}</span>
      <span>路线:{{ $route.query.startWarehouseTitle }}{{ $route.query.destWarehouseTitle }}</span>
      <span style="margin-left: 30px;">运输方式:空运专线</span>
    </div>
    <el-card style="margin-bottom: 10px" v-for="(itemOuter,index) in form.channelList" :key="index">
      <template #header>
        <el-row :gutter="20" type="flex" align="middle">
          <el-col :span="1">渠道{{ index + 1 }}
          </el-col>
          <el-col :span="3">
            <el-select multiple v-model="itemOuter.channelIds">
              <el-option
                  :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>
            </el-select>
          </el-col>
          <el-col :span="3">
            <el-button size="mini" type="primary" @click="newChannelsAdd(index)">新增渠道</el-button>
          </el-col>
          <el-col :span="3">
            <el-button size="mini" type="danger" :disabled="form.channelList.length === 1"
                       @click="channelsDelete(index)">
              删除当前渠道
            </el-button>
          </el-col>
          <el-col :span="3">
            <air-freight-route-template :lineId="lineId" @copy="copy">
              <el-button size="mini" v-if="index === 0" type="text">选择渠道包装模板</el-button>
            </air-freight-route-template>
          </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>
      <el-row :gutter="20" v-for="(itemm, indexx) in itemOuter.packagingCreateReqVOList"
              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">
            <el-option
                :disabled="deletePackagingTypes(index).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>
          </el-select>
        </el-col>
        <el-col :span="16">
          <!--          v-if="itemOuter.packagingCreateReqVOList[indexx].length"-->
          <packaging-type key-arr="priceStepClearanceCreateReqVOList"
                          v-model="itemOuter.packagingCreateReqVOList[indexx]">
            <el-button @click="deletePackag(index,indexx)" :disabled="itemOuter.packagingCreateReqVOList.length === 1"
                       type="danger">删除包装类型{{ indexx + 1 }}
            </el-button>
          </packaging-type>
        </el-col>
      </el-row>
    </el-card>
    <div class="footer">
      <el-button type="primary" @click="submit">保存</el-button>
    </div>
  </div>
</template>

<style scoped lang="scss">
.footer {
  position: fixed;
  bottom: 20px;
}
</style>