<template>
  <a-drawer width="55%" :label-col="4" :wrapper-col="14" :visible="open" @close="onClose">
    <a-divider orientation="left">
      <b>{{ formTitle }}</b>
    </a-divider>
    <a-form-model ref="form" :model="form" :rules="rules">
      <a-row>
        <a-col :span="10">
          <a-form-model-item label="加油站地址" prop="gasStation">
            <a-input v-model="form.gasStation" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        >
          </a-col>
        <a-col :span="10">
          <a-form-model-item label="分类" prop="categoryName">
            <a-input v-model="form.categoryName" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
      </a-row>
      <a-row>
        <a-col :span="10">
          <a-form-model-item label="油卡卡号" prop="gasCode">
            <a-input v-model="form.gasCode" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10">
          <!-- <a-form-model-item label="油卡类型" prop="gasCardType">
            <a-input v-model="form.gasCardType" placeholder="请输入油卡卡号" :disabled="true" /> </a-form-model-item -->
            <a-form-item label="油卡类型">
        <a-select placeholder="暂无信息" v-model="form.gasCardType" style="width: 100%" allow-clear :disabled="true">
          <a-select-option v-for="(d, index) in dict.type['gas_car_type']" :key="index" :value="d.value">{{
            d.label
          }}</a-select-option>
        </a-select>
      </a-form-item>
        </a-col>
      </a-row>

      <a-row>
        <a-col :span="10"
          ><a-form-model-item label="名称：" prop="plateNumber">
            <a-input v-model="form.itemName" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="交易时间" prop="tradingHour">
            <a-input v-model="form.tradingHour" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
      </a-row>

      <a-row>
        <a-col :span="10">
          <a-form-model-item label="交易ID" prop="tradingId">
            <a-input v-model="form.tradingId" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="油品" prop="gasType">
            <a-input v-model="form.gasType" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
      </a-row>

      <a-row>
        <a-col :span="10">
          <a-form-model-item label="加油升数（升）" prop="litres">
            <a-input v-model="form.litres" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="加油金额（元）" prop="amount">
            <a-input v-model="form.amount" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
      </a-row>
      <a-row>
        <a-col :span="10">
          <a-form-model-item label="卡内余额（元）" prop="balance">
            <a-input v-model="form.balance" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="申请人" prop="applyUserName">
            <a-input v-model="form.applyUserName" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
      </a-row>
      <a-form-model-item label="票据" prop="invoiceUrl">
            <!-- <a-input v-model="form.invoiceUrl" placeholder="暂无信息" :disabled="true" />  -->
            <img
              class="invoiceUrl"
              :src="form.invoiceUrl"
              alt=""
              @click="bigImgs(form.invoiceUrl)"
            /> 
            </a-form-model-item
        >
      <a-form-model-item label="备注" prop="remark">
        <a-input v-model="form.remark" placeholder="暂无信息" type="textarea" allow-clear :disabled="true" />
      </a-form-model-item>
      <div class="bottom-control">
        <a-space>
          <!-- <a-button type="primary" :loading="submitLoading" @click="submitForm">
            保存
          </a-button> -->
          <a-button type="dashed" @click="cancel"> 取消 </a-button>
        </a-space>
      </div>
    </a-form-model>
  </a-drawer>
</template>

<script>
import { getFuelConsumptionLog, addFuelConsumptionLog, updateFuelConsumptionLog } from '@/api/clw/fuelConsumptionLog'

export default {
  name: 'CreateForm',
  props: {},
  components: {},
  dicts:['gas_car_type'],
  data() {
    return {
      submitLoading: false,
      formTitle: '',
      // 表单参数
      form: {
        createTime: null,

        createBy: null,

        gasId: null,

        gasCardType: null,

        categoryId: null,

        categoryName: null,

        plateNumber: null,

        tradingHour: null,

        tradingId: null,

        gasCode: null,

        gasType: null,

        litres: null,

        amount: null,

        balance: null,

        remark: null,
      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {},
    }
  },
  filters: {},
  created() {},
  computed: {},
  watch: {},
  mounted() {},
  methods: {
    onClose() {
      this.open = false
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.formType = 1
      this.form = {
        createTime: null,

        createBy: null,

        gasId: null,

        gasCardType: null,

        categoryId: null,

        categoryName: null,

        plateNumber: null,

        tradingHour: null,

        tradingId: null,

        gasCode: null,

        gasType: null,

        litres: null,

        amount: null,

        balance: null,

        remark: null,
      }
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate(row, ids) {
      // console.log('--------row', row)
      this.reset()
      this.formType = 2
      const ID = row ? row.id : ids
      getFuelConsumptionLog(ID).then((response) => {
        this.form = response.data
        this.open = true
        this.formTitle = '油耗登记详情'
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.submitLoading = true
          if (this.form.ID !== undefined && this.form.ID !== null) {
            updateFuelConsumptionLog(this.form)
              .then((response) => {
                this.$message.success('修改成功', 3)
                this.open = false
                this.$emit('ok')
              })
              .finally(() => {
                this.submitLoading = false
              })
          } else {
            addFuelConsumptionLog(this.form)
              .then((response) => {
                this.$message.success('新增成功', 3)
                this.open = false
                this.$emit('ok')
              })
              .finally(() => {
                this.submitLoading = false
              })
          }
        } else {
          return false
        }
      })
    },
    bigImgs(src){
      window.open(src)
    }
  },
}
</script>
<style lang="less" scoped>
/deep/.ant-col{
  margin-right: 40px;
}
/deep/.ant-select{
 color: #000;
}
/deep/.ant-input{
 color: #000;
}

</style>