<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="applicationTime">
            <a-input v-model="form.applicationTime" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="预计归还时间" prop="returnTime">
            <a-input v-model="form.returnTime" 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="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="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="driverName">
            <a-input v-model="form.driverName" placeholder="暂无信息" :disabled="true" /> </a-form-model-item
        ></a-col>
      </a-row>
      <a-row>
        <a-col :span="10"
          ><a-form-model-item label="出发地" prop="startPlace">
            <a-input v-model="form.startPlace" placeholder="暂无信息" :disabled="true" /></a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="目的地" prop="endPlace">
            <a-input v-model="form.endPlace" placeholder="暂无信息" :disabled="true" /></a-form-model-item
        ></a-col>
      </a-row>
      <a-row>
        <a-col :span="10"
          ><a-form-model-item label="是否超期" prop="startPlace">
            <a-input v-model="form.isTimeout" placeholder="暂无信息" :disabled="true" /></a-form-model-item
        ></a-col>
        <a-col :span="10"
          ><a-form-model-item label="是否超期提醒" prop="endPlace">
            <a-input v-model="form.isTips" placeholder="暂无信息" :disabled="true" /></a-form-model-item
        ></a-col>
      </a-row>
      <a-row>
        <a-col :span="10"
          ><a-form-model-item label="实际归还时间" prop="realReturnTime">
            <a-input v-model="form.realReturnTime" 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-row>
        <a-col :span="10"></a-col>
        <a-col :span="10"></a-col>
      </a-row> -->
      <!-- <a-form-model-item label="是否涉及非定点加油" prop="isNonfixedPoint">
        <a-select placeholder="请选择是否涉及非定点加油" v-model="form.isNonfixedPoint">
          <a-select-option v-for="(d, index) in isNonfixedPointOptions" :key="index" :value="d.value">{{
            d.label
          }}</a-select-option>
        </a-select>
      </a-form-model-item> -->

      <a-form-model-item label="备注" prop="remark">
        <a-input v-model="form.remark" placeholder="暂无信息" :disabled="true" />
      </a-form-model-item>
      <div>
        <template>
          <div>
           <timeLinne :list="list" :lineTitle="lineTitle"/>
          </div>
        </template>
      </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 { getApplyCarLog, addApplyCarLog, updateApplyCarLog, getWorkflow } from '@/api/clw/applyCarLog'
import timeLinne from '../../../../components/timeLinne.vue'
// import { Timeline } from 'ant-design-vue'

// Timeline.
// const TimelineItem = Timeline.Item
export default {
  name: 'CreateForm',
  props: {
    isNonfixedPointOptions: {
      type: Array,
      required: true,
    },
  },
  components: { timeLinne },
  dicts: ['apply_status'],
  data() {
    return {
      submitLoading: false,
      formTitle: '',
      // 表单参数
      form: {
        userId: null,

        applicationTime: null,

        returnTime: null,

        deptId: null,

        deptName: null,

        plateNumber: null,

        carId: null,

        driverId: null,

        driverName: null,

        isNonfixedPoint: null,

        startPlace: null,

        endPlace: null,

        applyStatus: 0,

        taskId: null,

        realReturnTime: null,

        remark: null,

        createTime: null,
      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {},
      reverse: false,
      list: [],
      lineTitle:''
    }
  },
  filters: {},
  created() {},
  computed: {
    // 监听agree颜色变化
    fontstyle() {
      return (icontent) => {
        // 使用JavaScript闭包，进行传值操作
        console.log(icontent)

        if (icontent == '1') {
          return { color: 'green' }
        } else {
          return { color: 'red' }
        }
      }
    },
  },
  watch: {},
  mounted() {},
  methods: {
    onClose() {
      this.open = false
    },
    colors(index) {
      if (index != null) {
        return '#2a9c4a'
      }
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.formType = 1
      this.form = {
        userId: null,

        applicationTime: null,

        returnTime: null,

        deptId: null,

        deptName: null,

        plateNumber: null,

        carId: null,

        driverId: null,

        driverName: null,

        isNonfixedPoint: null,

        startPlace: null,

        endPlace: null,

        applyStatus: 0,

        taskId: null,

        realReturnTime: null,

        remark: null,

        createTime: 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
      getApplyCarLog(id).then((response) => {
        let obj = response.data
        if (obj.isTimeout == '1') {
          obj.isTimeout = '已超期'
        } else if (obj.isTimeout == '0') {
          obj.isTimeout = '未超期'
        }
        if (obj.isTips == '1') {
          obj.isTips = '超期已提醒'
        } else if (obj.isTips == '0') {
          obj.isTips = '超期未提醒'
        }
        this.form = obj
        this.open = true
        this.formTitle = '用车申请详情'
        this.lineTitle='用车申请审批'
        // obj.taskId
        getWorkflow(obj.taskId).then((res) => {
          // console.log('---------流程', res)
          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) {
            updateApplyCarLog(this.form)
              .then((response) => {
                this.$message.success('修改成功', 3)
                this.open = false
                this.$emit('ok')
              })
              .finally(() => {
                this.submitLoading = false
              })
          } else {
            addApplyCarLog(this.form)
              .then((response) => {
                this.$message.success('新增成功', 3)
                this.open = false
                this.$emit('ok')
              })
              .finally(() => {
                this.submitLoading = false
              })
          }
        } else {
          return false
        }
      })
    },
    // addinCircle(item) {
    //   if (item) {
    //     for (let index = 0; index < item.length; index++) {
    //       if (item[index].status == 0) {
    //         return 'in-circle in-circle1'
    //       }
    //      else if (item[index].status == 5) {
    //         return 'in-circle in-circle2'
    //       }
    //      else if (item[index].status == 1) {
    //         return 'in-circle in-circle4'
    //       }
    //     else  if (item[index].status == 4) {
    //         return 'in-circle in-circle3'
    //       }
    //      else if (item[index].status == 2||item[index].status == 2) {
    //         return 'in-circle in-circle5'
    //       }
    //     }
    //   }
    // },
  },
}
</script>
<style lang="less" scoped>
/deep/.ant-col {
  margin-right: 40px;
}
/deep/.ant-select {
  color: #000;
}
/deep/.ant-input {
  color: #000;
}
ul.timeline-wrapper {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* 时间线 */
.timeline-item {
  position: relative;

  .timeline-box {
    text-align: center;
    position: absolute;

    .out-circle {
      width: 16px;
      height: 16px;
      background: rgba(14, 116, 218, 0.1);
      box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.1);
      /*opacity: 0.1;*/
      border-radius: 50%;
      display: flex;
      align-items: center;

      .in-circle {
        width: 8px;
        height: 8px;
        margin: 0 auto;
        background: rgba(14, 116, 218, 1);
        border-radius: 50%;
        box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.1);
      }
      .in-circle1 {
        background: #585a58 !important;
      }
      .in-circle2 {
        background: rgba(14, 116, 218, 1) !important;
      }
      .in-circle3 {
        background-color: rgb(218, 106, 14) !important;
      }
      .in-circle4{
        background:rgb(18, 164, 52)!important;
      }
      .in-circle5{
        background:rgb(201, 46, 46)!important;
      }
    }

    .long-line {
      width: 2px;
      height: 248px;
      background: rgba(14, 116, 218, 1);
      box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.1);
      opacity: 0.1;
      margin-left: 8px;
    }
    // .long-line:nth-last-child(1) {
    //   height: 0;
    // }
  }

  .timeline-content {
    box-sizing: border-box;
    margin-left: 20px;
    // height: 106px;
    padding: 0 0 0 20px;
    text-align: left;
    // margin-bottom: 30px;

    .timeline-title {
      font-size: 14px;
      word-break: break-all;
      margin-bottom: 16px;
      color: #333;
      font-weight: 500;
      /*display: inline;*/
    }

    .timeline-date {
      font-size: 16px;
      color: #333;
      font-weight: 500;
      margin-bottom: 16px;
    }
    .timeline-desc {
      font-size: 14px;
      color: #999999;
    }
  }
}
.timeline-item:last-child{
  .long-line {
      height: 0;
      min-height:0
    }
}

.timeline-item:last-of-type .timeline-content {
  margin-bottom: 0;
}
</style>
