<template>
  <div class="n-app-container">
    <el-card v-if="!showFull" shadow="never" style="margin-bottom:20px;">
      <h4>重新计算服务商费用</h4>
      <div class="clearfix">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item>
            <el-select v-model="freightRecalculationDto.channelId" placeholder="渠道名称" clearable filterable>
              <el-option
                v-for="item in channels"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="发货时间">
            <div class="block">
              <el-date-picker
                v-model="freightRecalculationDto.date"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                value-format="yyyy-MM-dd"
                end-placeholder="结束日期"
              />
            </div>
          </el-form-item>
          <el-form-item>
            <el-button @click="freightRecalculation">重算</el-button>
          </el-form-item>
        </el-form>
      </div>
      <slot />
    </el-card>
  </div>
</template>

<script>
import { _getDeliverChannel } from '@/api/baseInfo'
import { _freightRecalculation } from '@/api/financeDelivery'
export default {
  name: 'FinanceTool',
  data() {
    return {
      channels: [],
      date: [],
      freightRecalculationDto:
      {
        channelId: '',
        date: []
      }
    }
  },
  mounted() {
    _getDeliverChannel().then(response => {
      this.channels = response
    })
  },
  methods: {
    freightRecalculation() {
      debugger
      if (this.freightRecalculationDto.date.length > 0) {
        this.freightRecalculationDto.start = this.freightRecalculationDto.date[0]
        this.freightRecalculationDto.end = this.freightRecalculationDto.date[1]
      } else {
        this.$message.error('必须选择开始时间和结束时间')
        return
      }
      if (this.freightRecalculationDto.channelId == 0 || this.freightRecalculationDto.channelId == '') {
        this.$message.error('必须选择渠道')
        return
      }
      _freightRecalculation(this.freightRecalculationDto).then(res => {
        this.$message.success('重置成功，请耐心等待后台重算结束')
      })
    }
  }}
</script>

