<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="applyUserName">
            <a-input v-model="form.applyUserName" placeholder="暂无信息" :disabled="true" />
          </a-form-model-item>
          
      </a-col> 
        <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-row>
      <a-row>
        <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-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-row>

      <a-row>
        <a-col :span="10"
          ><a-form-model-item label="申请时间" prop="useTime">
            <a-input v-model="form.useTime" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10"> <a-form-model-item label="加油站地址" prop="useTime">
            <a-input v-model="form.gasStation" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
      </a-row>
      <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="gasType">
            <!-- <a-input v-model="form.gasType" placeholder="暂无信息" :disabled="true" /> -->
            <a-select placeholder="请选择是否启用提醒" v-model="form.gasType" :disabled="formType == 3" disabled>
          <a-select-option v-for="(d, index) in  dict.type['gas_type']" :key="index" :value="d.value" >{{
            d.label
          }}</a-select-option>
        </a-select>
             </a-form-model-item
        ></a-col>
      </a-row>
      <a-row>
        <a-col :span="10"
          ><a-form-model-item label="加油量（升）" prop="fuelCharge">
            <a-input v-model="form.fuelCharge" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10">
          <a-form-model-item label="实收金额（元）" prop="realAmount">
            <a-input v-model="form.realAmount" placeholder="请输入实收金额" :disabled="true" /> </a-form-model-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>
      <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-form-model-item label="票据" prop="invoiceUrl">
            <img
              class="invoiceUrl"
              :src="form.invoiceUrl"
              alt=""
              @click="bigImgs(form.invoiceUrl)"
            /> 
            </a-form-model-item
        >
        <div>
          <timeLinne :list="list" :lineTitle="lineTitle" />
        </div>
      <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 { getRefuelingLog, addRefuelingLog, updateRefuelingLog } from '@/api/clw/refuelingLog'
import {  getWorkflow } from '@/api/clw/applyCarLog'
import timeLinne from '../../../../components/timeLinne.vue'
export default {
  name: 'CreateForm',
  props: {},
  components: {timeLinne},
  data() {
    return {
      submitLoading: false,
      formTitle: '',
      // 表单参数
      form: {
        createTime: null,

        createBy: null,

        categoryId: null,

        plateNumber: null,

        useTime: null,

        gasStation: null,

        remark: null,

        gasType: null,

        fuelCharge: null,

        realAmount: null,

        applyStatus: 0,
      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {},
      previewVisible: false,
      list:[],
      lineTitle:''
    }
  },
  dicts: ['apply_status','gas_type'],
  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,

        plateNumber: null,

        useTime: null,

        gasStation: null,

        remark: null,

        gasType: null,

        fuelCharge: null,

        realAmount: null,

        applyStatus: 0,
      }
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate(row, ids) {
      this.reset()
      this.formType = 2
      const id = row ? row.id : ids
      getRefuelingLog(id).then((response) => {
        this.form = response.data
        this.open = true
        this.formTitle = '非定点加油详情'
        getWorkflow(this.form.taskId).then((res) => {
        this.lineTitle='非定点加油审批'
          this.list = res.data.nodes
        })
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.submitLoading = true
          if (this.form.id !== undefined && this.form.id !== null) {
            updateRefuelingLog(this.form)
              .then((response) => {
                this.$message.success('修改成功', 3)
                this.open = false
                this.$emit('ok')
              })
              .finally(() => {
                this.submitLoading = false
              })
          } else {
            addRefuelingLog(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;
}
.invoiceUrl {
  width: 150px;
  height: 150px;
}
</style>
