<template>
  <el-dialog :title="$t('editFee.title')" :visible.sync="visible" width="50%">
    <el-form :model="editFeeInfo" label-width="120px">
      <el-form-item :label="$t('editFee.startTime')" required>
        <el-date-picker v-model="editFeeInfo.startTime" type="datetime" :placeholder="$t('editFee.startTimePlaceholder')"
          value-format="yyyy-MM-dd HH:mm:ss" style="width:100%">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('editFee.endTime')" required>
        <el-date-picker v-model="editFeeInfo.endTime" type="datetime" :placeholder="$t('editFee.endTimePlaceholder')"
          value-format="yyyy-MM-dd HH:mm:ss" style="width:100%">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('editFee.maxEndTime')" required>
        <el-date-picker v-model="editFeeInfo.maxEndTime" type="datetime"
          :placeholder="$t('editFee.maxEndTimePlaceholder')" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%">
        </el-date-picker>
      </el-form-item>
      <template v-if="editFeeInfo.computingFormula == '1102'">
        <el-form-item :label="$t('editFee.rateCycle')" required>
          <el-input v-model="editFeeInfo.rateCycle" :placeholder="$t('editFee.rateCyclePlaceholder')"></el-input>
        </el-form-item>
        <el-form-item :label="$t('editFee.rate')" required>
          <el-input v-model="editFeeInfo.rate" :placeholder="$t('editFee.ratePlaceholder')"></el-input>
        </el-form-item>
        <el-form-item :label="$t('editFee.rateStartTime')" required>
          <el-date-picker v-model="editFeeInfo.rateStartTime" type="datetime"
            :placeholder="$t('editFee.rateStartTimePlaceholder')" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%">
          </el-date-picker>
        </el-form-item>
      </template>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">{{ $t('common.cancel') }}</el-button>
      <el-button type="primary" @click="_doEidtFee">{{ $t('common.submit') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateFee } from '@/api/fee/listCarFeeApi'

export default {
  name: 'EditFee',
  data() {
    return {
      visible: false,
      editFeeInfo: {
        feeId: '',
        startTime: '',
        endTime: '',
        feeFlag: '',
        maxEndTime: '',
        computingFormula: '',
        rateCycle: '',
        rate: '',
        rateStartTime: ''
      }
    }
  },
  methods: {
    open(fee) {
      this.editFeeInfo = { ...fee }
      this.visible = true
    },
    close() {
      this.visible = false
    },
    _doEidtFee() {
      // 验证逻辑
      updateFee(this.editFeeInfo).then(response => {
        if (response.code === 0) {
          this.$message.success(this.$t('common.updateSuccess'))
          this.$emit('success')
          this.close()
        } else {
          this.$message.error(response.msg)
        }
      }).catch(error => {
        this.$message.error(error.message)
      })
    }
  }
}
</script>