<!-- @format -->

<template>
  <view class="container">
    <u-form ref="uForm" :model="form" labelWidth="160" labelPosition="top">
      <u-form-item label="绑定人真实姓名">
        <u-input disabled :value="form.name"></u-input>
      </u-form-item>
      <u-form-item label="绑定账号">
        <u-input disabled :value="form.userName"> </u-input>
      </u-form-item>
      <u-form-item label="单位统一社会信用代码" prop="mechanismName">
        <u-input
          :required="true"
          placeholder="请输入单位的信用代码"
          v-model="form.mechanismName"
        ></u-input>
      </u-form-item>
      <u-form-item label="单位管理码" prop="mechanismPassword">
        <u-input
          :required="true"
          placeholder="请输入单位管理码"
          v-model="form.mechanismPassword"
        ></u-input>
      </u-form-item>
      <u-form-item>
        <u-button @click="onSubmit" type="primary">提交</u-button>
      </u-form-item>
    </u-form>
  </view>
</template>
<script>
import { userBindMechanism } from "@/api/personRegistered";
export default {
  data() {
    return {
      form: {
        name: "",

        password: "", //注册密码
        mechanismName: "", //社会代码
        mechanismPassword: "", //单位管理码
        userName: "", //个人账号
      },
      rules: {
        mechanismName: [
          {
            required: true,
            message: "社会代码不能为空",
            trigger: "blur",
          },
        ],
        mechanismPassword: [
          {
            required: true,
            message: "单位管理码不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  onReady() {
    //如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
    this.$refs.uForm.setRules(this.rules);
  },

  onLoad(options) {
    this.form.name = options.name;
    this.form.userName = options.idNum;
    this.form.password = options.password;
  },
  methods: {
    onSubmit() {
      this.$refs.uForm.validate().then((res) => {
        uni.showLoading({
          title: "提交中...",
        });
        userBindMechanism(this.form).then(() => {
          uni.showToast({
            title: "提交成功",
            duration: 2000,
          });
          uni.navigateBack({
            delta: 2,
          });
        });
      });
    },
  },
};
</script>
<style lang="scss">
.container {
  height: 100vh;
  background: rgb(248, 249, 250);
  padding: 30rpx;
}
</style>
