<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="createTime">
            <a-input v-model="form.createTime" 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="deptName">
            <a-input v-model="form.deptName" 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-row>
        <a-col :span="10"
          ><a-form-model-item label="车牌号" prop="plateNumber">
            <a-input v-model="form.plateNumber" placeholder="暂无信息" :disabled="true"  /> </a-form-model-item
        ></a-col>
        <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-row>
      <a-row>
        <a-col :span="10">
          <a-form-model-item label="上次加油量（升）" prop="prevFuelCharge">
            <a-input v-model="form.prevFuelCharge" placeholder="暂无信息" :disabled="true"  /> </a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="上次消耗金额（元）" prop="prevLoseAmount">
            <a-input v-model="form.prevLoseAmount" placeholder="暂无信息" :disabled="true"  /> </a-form-model-item
        ></a-col>
      </a-row>
      <a-row>
        <a-col :span="10"
          ><a-form-model-item label="本次划拨金额（元）" prop="currentAmount">
            <a-input v-model="form.currentAmount" placeholder="暂无信息" :disabled="true"  /> </a-form-model-item
        ></a-col>
        <a-col :span="10">
          <a-form-item label="审核状态">
            <a-select
              placeholder="暂无信息"
              v-model="form.applyStatus"
              style="width: 100%"
              allow-clear
              :disabled="true"
            >
              <a-select-option v-for="(d, index) in dict.type['apply_status']" :key="index" :value="d.value">{{
                d.label
              }}</a-select-option>
            </a-select>
          </a-form-item></a-col>
      </a-row>

      <a-form-model-item label="备注" prop="remark">
        <a-input v-model="form.remark" placeholder="暂无信息" :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 { getOilSkimmingLog, addOilSkimmingLog, updateOilSkimmingLog } from '@/api/clw/oilSkimmingLog'

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

        createBy: null,

        categoryId: null,

        categoryName: null,

        deptId: null,

        deptName: null,

        plateNumber: null,

        gasCode: null,

        prevFuelCharge: null,

        prevLoseAmount: null,

        currentAmount: null,

        remark: null,

        applyStatus: 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,

        categoryId: null,

        categoryName: null,

        deptId: null,

        deptName: null,

        plateNumber: null,

        gasCode: null,

        prevFuelCharge: null,

        prevLoseAmount: null,

        currentAmount: null,

        remark: null,

        applyStatus: null,
      }
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleInfo(row, ids) {
      // this.reset()
      this.formType = 2
      const id = row ? row.id : ids
      getOilSkimmingLog(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) {
            updateOilSkimmingLog(this.form)
              .then((response) => {
                this.$message.success('修改成功', 3)
                this.open = false
                this.$emit('ok')
              })
              .finally(() => {
                this.submitLoading = false
              })
          } else {
            addOilSkimmingLog(this.form)
              .then((response) => {
                this.$message.success('新增成功', 3)
                this.open = false
                this.$emit('ok')
              })
              .finally(() => {
                this.submitLoading = false
              })
          }
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="less" scoped>
/deep/.ant-col{
  margin-right: 40px;
}
</style>
