<template>
  <view class="page">
    <u-navbar
      title="事件上报"
      back-icon-color="#FFFFFF"
      title-color="#FFFFFF"
      leftText="返回"
      :autoBack="true"
      :placeholder="true"
    />
    <view class="view-forms">
      <uni-forms
        ref="valiForm"
        :rules="rules"
        :modelValue="valiFormData"
        label-position="top"
      >
        <uni-forms-item label="事件标题" name="">
          <uni-easyinput
            v-model="valiFormData.name"
            placeholder="请输入事件标题"
          />
        </uni-forms-item>
        <uni-forms-item label="事件类型" name="">
          <uni-data-select
            v-model="value"
            :localdata="rangeSelect"
            @change="changeSelect"
            label="事件类型"
          />
        </uni-forms-item>
        <uni-forms-item label="事件地址" name="">
          <uni-easyinput
            v-model="valiFormData.age"
            placeholder="请输入事件地址"
          />
        </uni-forms-item>
        <uni-forms-item label="发生时间" name="">
          <uni-easyinput
            v-model="valiFormData.age"
            placeholder="请输入发生时间"
          />
        </uni-forms-item>
        <uni-forms-item label="事件等级" name="">
          <uni-data-select
            v-model="value"
            :localdata="rangeSelect"
            @change="changeSelect"
            label="事件等级"
          />
        </uni-forms-item>
        <uni-forms-item label="所属网格" name="">
          <uni-data-select
            v-model="value"
            :localdata="rangeSelect"
            @change="changeSelect"
            label="所属网格"
          />
        </uni-forms-item>
        <uni-forms-item label="事件详情" name="introduction">
          <uni-easyinput
            type="textarea"
            v-model="valiFormData.introduction"
            placeholder="请输入事件详情"
          />
        </uni-forms-item>
      </uni-forms>
    </view>

    <view class="footer">
      <button class="btn-add" @click="submit('valiForm')">提交</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      rangeSelect: [
        { value: 0, text: "一级" },
        { value: 1, text: "二级" },
        { value: 2, text: "三级" },
      ],
      // 校验表单数据
      valiFormData: {
        name: "",
        age: "",
        introduction: "",
      },
      // 校验规则
      rules: {
        name: {
          rules: [
            {
              required: true,
              errorMessage: "姓名不能为空",
            },
          ],
        },
        age: {
          rules: [
            {
              required: true,
              errorMessage: "年龄不能为空",
            },
            {
              format: "number",
              errorMessage: "年龄只能输入数字",
            },
          ],
        },
      },
    };
  },
  computed: {},
  onLoad() {},
  onReady() {},
  methods: {
    changeSelect(e) {},
    submit(ref) {
      this.$refs[ref]
        .validate()
        .then((res) => {
          console.log("success", res);
          uni.showToast({
            title: `校验通过`,
          });
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.view-forms {
  padding: 30rpx 20rpx 240rpx 20rpx;

  /deep/.uni-forms-item__label {
    background-image: url("@/static/images/umale/icon_ind.png");
    background-size: 100%;
    background-position: bottom;
    background-repeat: no-repeat;
    height: auto;
    & > text {
      line-height: 0;
    }
    & > text {
      font-size: 30rpx;
      font-family: PingFang SC-Bold, PingFang SC;
      // font-weight: bold;
      color: #2e2f31;
    }

    & > .is-required {
      color: #dd524d;
      font-weight: bold;
    }
  }

  /deep/ .uni-easyinput {
    margin-top: 19rpx;
    background: #ffffff;
    box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
    border-radius: 16rpx;
  }

  /deep/ .uni-stat-box {
    margin-top: 19rpx;
    background: #ffffff;
    box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
    border-radius: 16rpx;
  }
}
.footer {
  position: fixed;
  bottom: 0;
  z-index: 1;
  width: 100%;
  background: #ffffff;
  border: 1px solid #dce3ec;
  padding: 18rpx 28rpx 60rpx 28rpx;
  .btn-add {
    font-size: 36rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    height: 88rpx;
    background: linear-gradient(90deg, #3976f1 0%, #3ca0f6 100%);
    border-radius: 16rpx;
    color: #ffffff;
  }
}
</style>
