<template>
  <div class="app-approvalShipping">
    <h1>{{$t('申请信息')}}【{{$t('出货信息')}}】</h1>
    <el-descriptions :column="6" border>
      <el-descriptions-item :label="$t('自编号')">{{boxBackVO.selfNo}}</el-descriptions-item>
      <el-descriptions-item :label="$t('运输方式')">
        <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="boxBackVO.transportType" />
      </el-descriptions-item>
      <el-descriptions-item :label="$t('出货渠道')">
        {{getShipChannelName(boxBackVO.shippingChannelId)}}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('柜型')">
        {{cabinetLabel}}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('体积/重量')">
        {{getVolumeWeight(loadDetail.totalStatistics)}}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('货柜状态')">
        {{boxBackVO.shipmentStatusText}}
      </el-descriptions-item>
    </el-descriptions>
    <div v-if="approvalInfo.applyReason">
      <h1>{{$t('申请原因')}}</h1>
      <div>
        {{approvalInfo.applyReason}}
      </div>
    </div>

    <el-table :data="loadDetail.sectionOrderList" border class="mt-10">
      <el-table-column prop="orderNo" :label="$t('订单号')" align="center">
        <template v-slot="{row}">
          <el-button type="text" @click="jumpOrderDetail(row)">{{row.orderNo}}</el-button>
        </template>
      </el-table-column>
      <el-table-column :label="$t('货物信息')" align="center" width="500px">
        <template v-slot="{row}">
          <section>
            <div v-for="(item, index) in row.goodsList" :key="index">
              <div>{{index+1}}：{{$l(item, 'prodTitle')}}</div>
            </div>
          </section>
        </template>
      </el-table-column>
      <el-table-column :label="$t('收费箱数')" align="center" prop="num"></el-table-column>
      <el-table-column :label="$t('收费体积')" align="center" prop="chargeVolume"></el-table-column>
      <el-table-column :label="$t('收费重量')" align="center" prop="chargeWeight"></el-table-column>
      <el-table-column :label="$t('加价金额')" align="center">
        <template slot-scope="{row}" v-if="details">
          <div>
            {{$t('运费')}}：{{details.freightFee || 0}}{{ currencyMap[details.freightCurrencyId]}}/{{unitMap[details.freightUnitId]}}
          </div>
          <div>
            {{$t('清关费')}}：{{details.clearanceFee || 0}}{{ currencyMap[details.clearanceCurrencyId]}}/{{unitMap[details.clearanceUnitId]}}
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { approvalDetail } from "@/api/ecw/box";
import { getSeaStatus, getTotlContent } from "../shippingSea/utils";
import { getCabinetPage } from "@/api/ecw/cabinet";
import { getChannelList } from "@/api/ecw/channel";
import Decimal from "decimal.js";
import Template from "@/views/cms/template/index.vue";
import {getUnitList} from "@/api/ecw/unit";
import {getCurrencyList} from "@/api/ecw/currency";

/**
 * 批量加价审核详情
 */
export default {
  name: "BatchMakeUpDetail",
  components: {Template},
  props: {
    processId: {
      type: [Number, String],
    },
    type: String,
  },
  data() {
    return {
      unitList:[],
      currencyList:[],
      approvalInfo: {},
      boxBackVO: {},
      loadDetail: {},
      // 柜型
      cabinetLabel: "",
      //渠道
      channelList: [],
      // 弹出配置
      dialogConfig: {
        title: "",
        visible: false,
      },
      srcStrs: [],
    };
  },
  created() {
    getUnitList().then(res => this.unitList = res.data)
    getCurrencyList().then(res => this.currencyList = res.data)
    getChannelList().then((res) => (this.channelList = res.data));
  },
  methods: {
    getTotlContent,
    /* 获取详情 */
    getApprovalDetail(processId) {
      approvalDetail({ approvalId: processId }).then((res) => {
        this.approvalInfo = res.data.approvalInfo;
        this.boxBackVO = res.data.boxBackVO;
        this.loadDetail = res.data.loadDetail;
      });
    },
    /* 获取柜型 */
    getCabinetLabel(cabinetId) {
      getCabinetPage(null).then((response) => {
        const cabinetList = response.data.list;
        for (const cabinetItem of cabinetList) {
          if (cabinetItem.id == cabinetId) {
            this.cabinetLabel = cabinetItem.name;
            break;
          }
        }
      });
    },
    /* 合计 */
    calcSum(goodsList) {
      let sum = 0;
      goodsList.forEach((element) => {
        sum = Decimal.add(sum, element.num).toNumber();
      });
      return sum;
    },
    /* 跳转订单详情 */
    jumpOrderDetail(row) {
      this.$router.push("/order/detail?orderId=" + row.orderId);
    },
  },
  watch: {
    processId: {
      immediate: true,
      handler(val) {
        this.getApprovalDetail(val);
      },
    },
    boxBackVO(val) {
      // 柜型
      this.getCabinetLabel(val.cabinetId);
    },
  },
  computed: {
    /* 渠道 */
    getShipChannelName() {
      return (shippingChannelId) => {
        for (const channelItem of this.channelList) {
          if (channelItem.channelId == shippingChannelId) {
            return this.$l(channelItem, "name");
          }
        }
      };
    },
    /* 体积重量 */
    getVolumeWeight() {
      return (total) => {
        return this.getTotlContent(total);
      };
    },
    /* 是否显示卸柜箱数 */
    isShowColumn() {
      return (shippingVO) => {
        return getSeaStatus(shippingVO) >= 182 ? true : false;
      };
    },
    details(){
      if(!this.approvalInfo) return null
      return JSON.parse(this.approvalInfo?.details)
    },
    currencyMap(){
      let map = {}
      this.currencyList.forEach(item => {
        map[item.id] = this.$l(item, 'title')
      })
      return map
    },
    unitMap(){
      let map = {}
      this.unitList.forEach(item => {
        map[item.id] = this.$l(item, 'title')
      })
      return map
    },
  },
};
</script>

<style lang="scss" scoped>
.el-image {
  border-radius: 5px;
  background-color: #ebeef5;
  box-shadow: 0 0 5px 1px #ccc;
  ::v-deep .el-image__inner {
    transition: all 0.3s;
    cursor: pointer;
    &:hover {
      transform: scale(1.2);
    }
  }
  ::v-deep .image-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    color: #909399;
    font-size: 30px;
  }
}
</style>
