<script>
import {getPriceSnapshotList} from "@/api/ecw/productPrice";
import {parseTime} from "../../../../utils/ruoyi";
import Template from "@/views/cms/template/index.vue";
import ShowStepPriceItem from "@/views/ecw/productPrice/components/ShowStepPriceItem.vue";

export default {
  name: "Logs",
  components: {ShowStepPriceItem, Template},
  filters: {parseTime},
  props:{
    currencyMap:{
      type:Object,
      default:() =>{
        return  {}
      }
    },
    unitMap:{
      type:Object,
      default:() =>{
        return  {}
      }
    },
  },
  data(){
    return {
      showLogsDialog: false,
      loading: false,
      logs:[]
    }
  },
  methods:{
    parseTime,
    open(id){
      this.showLogsDialog = true
      this.loading = true
      getPriceSnapshotList(id).then(res => {
        this.logs = res.data
        this.logs.forEach(item => {
          item.detail = JSON.parse(item.content)
        })
      }).finally(() => {
        this.loading = false
      })
    },
    closeLogsDialog(){
      this.logs = []
      this.showLogsDialog = false
    }
  }
}
</script>

<template>
  <el-dialog :title="$t('查看价格日志')" :visible.sync="showLogsDialog" :before-close="closeLogsDialog" width="1000px">
    <el-table :data="logs" v-loading="loading">
      <el-table-column :label="$t('序号')" type="index"></el-table-column>
      <el-table-column :label="$t('修改人')" prop="creatorName" width="200px"></el-table-column>
      <el-table-column :label="$t('修改时间')">
        <template slot-scope="{row}">{{row.createTime|parseTime}}</template>
      </el-table-column>
      <el-table-column :label="$t('修改前')">
        <template slot-scope="{row}">
          <div>{{ $t('预付') }}：<dict-tag :type="DICT_TYPE.ECW_PAY_ADVANCE" :value="row.detail.needPay" /></div>
          <div>{{ $t('单价模式') }}：<dict-tag :type="DICT_TYPE.ECW_PRICE_TYPE" :value="row.detail.priceType" /></div>
          <div v-if="row.detail.minWeight">{{ $t('最小起计量') }}：{{ row.detail.minWeight }}{{unitMap[row.detail.minWeightUnit]}}</div>

          <!----阶梯定价-->
          <template v-if="row.detail.stepPrice == 1">
            <!--老的数据格式-->
            <template v-if="row.detail.priceStepList">
              <template v-for="(item, index) in row.detail.priceStepList">
                <div class="mt-10">
                  第{{index+1}}阶段
                  {{item.startNum}} - {{item.endNum}} {{unitMap[item.weightUnit]}}
                </div>
                <template v-if="row.detail.priceType != 1">
                  <div :key="index + '_freight'" class="pl-10" >
                    运费：
                    {{item.transportPrice}} {{currencyMap[item.transportPriceUnit]}} / {{unitMap[item.transportVolumeUnit]}}
                  </div>
                  <!--空运没有清关费， 不需要显示-->
                  <div v-if="type != 'air'" :key="item.specialDictType + '_clearance'"  class="pl-10">
                    清关费：
                    {{item.clearancePrice}} {{currencyMap[item.clearancePriceUnit]}} / {{unitMap[item.clearanceVolumeUnit]}}
                  </div>
                </template>
                <div v-else class="pl-10">
                  全包价：
                  {{item.allPrice}} {{currencyMap[item.allPriceUnit]}} / {{unitMap[item.allVolumeUnit]}}
                </div>
              </template>
            </template>
            <template v-else-if="row.detail.priceType">
              <template v-for="(item, index) in row.detail.fullPriceStepList">
                <show-step-price-item
                  :value="item"
                  :unit-map="unitMap"
                  :currency-map="currencyMap"
                  :index="index"
                  :price-name="$t('全包价')"
                  field-prefix="all"
                />
              </template>
            </template>
            <template v-else>
              <template v-if="row.detail.freightPriceStepList && row.detail.freightPriceStepList.length">
                <template v-for="(item, index) in row.detail.freightPriceStepList">
                  <show-step-price-item
                    :value="item"
                    :unit-map="unitMap"
                    :currency-map="currencyMap"
                    :index="index"
                    :price-name="$t('运费')"
                    field-prefix="transport"
                  />
                </template>
              </template>
              <template v-if="row.detail.freightPriceStepList && row.detail.freightPriceStepList.length">
                <template v-for="(item, index) in row.detail.freightPriceStepList">
                  <show-step-price-item
                    :value="item"
                    :unit-map="unitMap"
                    :currency-map="currencyMap"
                    :index="index"
                    :price-name="$t('清关费')"
                    field-prefix="clearance"
                  />
                </template>
              </template>
            </template>
          </template>
          <template v-else>
            <template v-if="row.detail.priceType != 1">
              <div>
                {{$t('默认运费')}}’：
                {{row.detail.transportPrice}} {{currencyMap[row.detail.transportPriceUnit]}} / {{unitMap[row.detail.transportVolumeUnit]}}
              </div>
              <div>
                {{$t('默认清关费')}}：
                {{row.detail.clearancePrice}} {{currencyMap[row.detail.clearancePriceUnit]}} / {{unitMap[row.detail.clearanceVolumeUnit]}}
              </div>
            </template>
            <div v-else>
              {{$t('全包价')}}：
              {{row.detail.allPrice}} {{currencyMap[row.detail.allPriceUnit]}} / {{unitMap[row.detail.allVolumeUnit]}}
            </div>

            <template v-for="(item, index) in row.detail.specialList">
              <template v-if="row.detail.priceType != 1">
                <div :key="item.specialDictType + '_freight'" >
                  {{getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, item.specialDictType)}} {{$t('运费')}}}：
                  {{item.transportPrice}} {{currencyMap[item.transportPriceUnit]}} / {{unitMap[item.transportVolumeUnit]}}
                </div>
                <div :key="item.specialDictType + '_clearance'" >
                  {{getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, item.specialDictType)}} {{$t('清关费')}}：
                  {{item.clearancePrice}} {{currencyMap[item.clearancePriceUnit]}} / {{unitMap[item.clearanceVolumeUnit]}}
                </div>
              </template>
              <div v-else>
                {{getDictDataLabel(DICT_TYPE.ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS, item.specialDictType)}} {{$t('全包价')}}：
                {{item.allPrice}} {{currencyMap[item.allPriceUnit]}} / {{unitMap[item.allVolumeUnit]}}
              </div>
            </template>
          </template>

          <div v-if="row.detail.validateStartDate || row.detail.validateStartDate">有效期:{{ row.detail.validateStartDate|parseTime }}-{{ row.detail.validateEndDate|parseTime }}</div>
        </template>
      </el-table-column>

    </el-table>
  </el-dialog>
</template>

<style scoped lang="scss">

</style>
