<template>
  <view class="container-main">
    <u-form :model="form" ref="uForm" label-width="150rpx">
      <u-form-item label="姓名">
        <u-input v-model="form.name" />
      </u-form-item>
      <u-form-item label="身份证">
        <u-input v-model="form.identification" />
      </u-form-item>
      <u-form-item label="手机号">
        <u-input v-model="form.phonenumber" />
      </u-form-item>
      <u-form-item label="收款账号">
        <u-input v-model="form.accountNumber" />
      </u-form-item>
      <u-form-item
        label="事故类型"
        right-icon="arrow-down-fill"
        :right-icon-style="{ fontSize: '10rpx' }"
      >
        <u-input v-model="form.accidentType" />
      </u-form-item>
      <u-form-item label="事故描述">
        <u-input v-model="form.accidentdentDescription" type="textarea" />
      </u-form-item>
      <u-form-item label="上传图片">
        <u-upload
          :action="action"
          max-count="3"
          @on-success="uploadSuccess"
          width="160"
          height="170"
        >
        </u-upload>
      </u-form-item>
    </u-form>
    <u-select v-model="show" :list="list" @confirm="clickConfirm"></u-select>
    <fixedButton @click="submit" />
  </view>
</template>

<script>
import moment from "@/utils/moment.min.js";
import fixedButton from "@/components/fixedButton/fixedButton.vue";
import { addRecord } from "@/api/shianliaoning/clasims.js";
import config from "@/config.js";
export default {
  components: {
    fixedButton,
  },
  data() {
    return {
      baseUrl: config.baseUrl,
      action: config.baseUrl + "/common/uploadMinioonfile", // 上传的图片服务器地址
      fileList: [],
      show: false,
      list: [
        {
          value: 0,
          label: "食物中毒",
        },
      ],
      form: {
        name: "",
        identification: "",
        phonenumber: "",
        accountNumber: "",
        accidentType: "",
        accidentdentDescription: "",
        enterprise_name: "",
        enterpriseId: "",
        status: 0,
        appliactionTime: "",
        accidentPhotos: "",
      },
    };
  },
  onLoad(option) {
    this.form.enterprise_name = option.enterprise_name;
    this.form.enterpriseId = option.enterpriseId;
  },
  methods: {
    //选择器
    clickConfirm(e) {
      this.form.accidentType = e[0].label;
    },
    //上传成功
    uploadSuccess(e) {
      url = e.url.split("/");
      let url =
        url[url.length - 4] +
        "/" +
        url[url.length - 3] +
        "/" +
        url[url.length - 2] +
        "/" +
        url[url.length - 1];
      this.fileList.push(url);
    },
    //提交
    submit() {
      this.form.accidentPhotos = this.fileList.toString();
      this.form.appliactionTime = moment().format("YYYY-MM-DD");
      addRecord(this.form).then((res) => {
        uni.showToast({
          title: "提交成功",
        });
        setTimeout(() => {
          uni.reLaunch({
            url: "/sub-public/food-lipei/food-lipei",
          });
        }, 500);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.container-main {
  background-color: #fff;
  box-sizing: border-box;
  padding: 20rpx 40rpx;
}
</style>
