<template>
  <view class="form-container">
    <!-- 表单标题 -->
    <view class="form-title">
      <text class="title-text">用车申请表</text>
      <view class="title-line"></view>
    </view>
    <uni-forms ref="form" :modelValue="form" :rules="rules" label-position="top" label-width="150" class="custom-form">
      <flow-note :taskForm="taskForm"></flow-note>
      <!-- 当前节点 -->
      <uni-forms-item label="当前节点" class="form-item" v-if="taskName">
        <uni-tag :inverted="true" type="primary" :text="taskName"></uni-tag>
      </uni-forms-item>

      <!-- 流程发起人 -->
      <uni-forms-item label="填报人" class="form-item">
        <b style="font-size:30rpx;">{{ applierUserName }}</b>
      </uni-forms-item>

      <!-- 填报日期 -->
      <uni-forms-item label="填报日期" class="form-item">
        <text>{{ form.applyDate }}</text>
      </uni-forms-item>

      <!-- 借款类型 -->
      <uni-forms-item label="申请用途" required class="form-item" name="carUsage">
        <uni-data-checkbox v-model="form.carUsage" :localdata="carUsageOptions" :disabled="taskName != '用车申请'"
          @change="hanldeChangeType"></uni-data-checkbox>
      </uni-forms-item>

      <!-- 选择项目 -->
      <uni-forms-item label="选择项目" required class="form-item" v-if="form.carUsage == 0" name="projectId">
        <u-button type="primary" @click="openProject = true" v-if="taskName == '用车申请'">+ 选择项目</u-button>
        <ProjectPicker :visible.sync="openProject" :selected.sync="selectedProject" @confirm="handleConfirm" />
        <ProjectInfo :project="projectObj"></ProjectInfo>
      </uni-forms-item>
    </uni-forms>
  </view>
</template>

<script>
import { parseTime } from "@/utils/common.js"
import { complete, rejectTask, returnList, returnTask, getNextFlowNode, delegate, flowTaskForm, } from "@/api/flowable/todo";
import { listCar, getCar } from "@/api/oa/car/car";
import { listCarApproval, getCarApproval, updateCarApproval, addCarApproval, modifyCarApproval } from '@/api/oa/car/carApproval'
import { listProject, getProject } from "@/api/oa/project/project";
import { getUserByRole } from "@/api/system/role";
import { getUsersManageLeader } from '@/api/system/post.js'
import FlowNote from '@/pages/components/flowNote.vue';
import ProjectPicker from '@/pages/components/ProjectPicker.vue';
import ProjectInfo from '@/pages/components/ProjectInfo.vue';
import Auditor from "@/pages/components/auditor.vue";
export default {
  components: {
    FlowNote,
    ProjectPicker,
    ProjectInfo,
    Auditor
  },
  props: {
    taskForm: Object,
    taskName: String,
    startUserName: String,
  },
  data() {
    return {
      form: {
        applyDate: '',
        projectId: '',
        carUsage:'0',
      },
      rules: {},
      openProject: false,
      projectObj: {},
      selectedProject: {},
      carUsageOptions: [{
        text: '项目用车',
        value: '0',
        disable: false
      }, {
        text: '非项目用车',
        value: '1',
        disable: false
      }, {
        text: '工会用车',
        value: '2',
        disable: false
      }, {
        text: '党委用车',
        value: '3',
        disable: false
      }, {
        text: '团委用车',
        value: '4',
        disable: false
      }],
      dept: 0,
    }
  },
  created() {
    this.applierUserName = this.startUserName;
    this.initForm();
  },
  methods: {
    initForm() {
      getCarApproval(this.taskForm.formId).then(res => {
        if (res.data) {

        } else {
          this.form.applyDate = parseTime(new Date(), "{y}-{m}-{d}");
        }
      })
    },
    handleConfirm(project) {
      this.selectedProject = project;
      this.projectObj = project;
      this.form.projectId = project.projectId;
    },
    hanldeChangeType(val) {
      if (val == '2' || val == '3' || val == '4') {
        this.dept = 0;
      }
      else
        this.dept = this.$store.getters.deptId;
    }
  },
}

</script>

<style lang="scss" scoped></style>