<template>
  <basic-container>
    <avue-form :option="option" v-model="form" @submit="handleSubmit"/>
  </basic-container>
</template>

<script>
  import {leaveProcess} from "@/api/work/process";
  import {publicevent} from "../../../../api/work/process";

  export default {
    data() {
      return {
        form: {},
        option: {
          group: [
            {
              icon: 'el-icon-info',
              label: '填写--报事工单',
              prop: 'group1',
              column: [
                {
                  label: '受理人',
                  prop: 'auditor',
                  type: 'select',
                  dicUrl: `/api/blade-user/user-list`,
                  props: {
                    label: "account",
                    value: "id"
                  },
                  span: 8,
                  rules: [
                    {
                      required: true,
                      message: '请选择受理人员',
                      trigger: 'blur'
                    }
                  ]
                },
                {
                  label: '姓名',
                  prop: 'name',
                  span: 8,
                  rules: [
                    {
                      required: true,
                      message: '请填写姓名',
                      trigger: 'blur'
                    }
                  ]
                },
                {
                  label: '联系方式',
                  prop: 'tel',
                  span: 8,
                  rules: [
                    {
                      required: true,
                      message: '请填写联系方式',
                      trigger: 'blur'
                    }
                  ]
                },
                {
                  label: '所在地点',
                  prop: 'location',
                  span: 8,
                  rules: [
                    {
                      required: false,
                      message: '请填写所在地点',
                      trigger: 'blur'
                    }
                  ]
                },
                {
                  label: '事件描述',
                  prop: 'eventDetail',
                  type: 'textarea',
                  span: 24,
                  rules: [
                    {
                      required: true,
                      message: '请填写事件详情',
                      trigger: 'blur'
                    }
                  ]
                },
              ]
            },
          ],
        }
      }
    },
    methods: {
      handleSubmit() {
        const params = {
          processDefinitionId: this.$route.params.processDefinitionId,
          ...this.form,
        };
        publicevent(params).then(resp => {
          const data = resp.data;
          if (data.success) {
            this.$message.success(data.msg);
            this.$router.$avueRouter.closeTag();
            this.$router.push({path: `/order/publicevent`});
          } else {
            this.$message.error(data.msg || '提交失败');
          }
        });
      }
    }
  }
</script>
