<template>
  <div class="app-container" :style="{height:height+'px'}">
    <van-nav-bar
      title="单位用户注册"
      left-arrow
      fixed
      placeholder
      @click-left="onClickLeft"
    />
    <van-form @submit="getSubmit">
      <van-field
        readonly
        clickable
        name="picker"
        :value="value"
        label="供求类型"
        placeholder="点击选择供求类型"
        @click="showPicker = true"
        required
        :rules="[{ required:true }]"
      />
      <van-popup v-model="showPicker" position="bottom">
        <van-picker
          show-toolbar
          :columns="columns"
          @confirm="onConfirm"
          @cancel="showPicker = false"
        />
      </van-popup>
      <van-field v-model="form.phone" type="tel" label="手机号" placeholder="请输入手机号" required :rules="[{ required:true }]" />
      <van-field
        v-model="form.code"
        center
        clearable
        label="验证码"
        placeholder="图形验证码"
        required :rules="[{ required:true }]"
      >
        <template #button>
          <img class="code-img" :src="codeUrl" @click="getCode" />
        </template>
      </van-field>
      <van-field v-model="form.password" type="password" label="密码" placeholder="请输入密码" required :rules="[{ required:true }]"/>
      <van-field v-model="confirmPassWord" type="password" label="确认密码" placeholder="请再次输入密码" required :rules="[{ required:true }]"/>

      <van-field v-model="form.companyName" label="公司名称" placeholder="请输入公司名称" required :rules="[{ required:true }]"/>
      <van-field v-model="form.realname" label="负责人姓名" placeholder="请输入负责人姓名" required :rules="[{ required:true }]"/>
      <van-field v-model="form.idCardNum" label="身份证号" placeholder="请输入法人身份证号" required :rules="[{ required:true }]"/>
      <van-field v-model="form.companyCode" label="社会信用代码" placeholder="请输入公司的社会信用代码" required :rules="[{ required:true }]"/>
      <van-field v-model="form.companyLicense" label="营业执照号" placeholder="请输入公司的营业执照号" required :rules="[{ required:true }]"/>
      <van-field v-model="form.address" label="联系地址" placeholder="请输入联系地址" />
      <div class="submit">
        <p>我已阅读并同意<span>《农村产权交易信息服务平台会员注册协议》</span></p>
        <van-button round block type="info" color="#007E72" native-type="submit">立即注册</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { getCodeImg } from "@/api/login";
import { userRegister } from "@/api/register/index";
export default {
  name: "companyRegister",
  data() {
    return {
      height:0,
      tel:'',
      value:'',
      confirmPassWord:'',
      showPicker: false,
      columns:[],
      form: {
        phone: "", //账号
        code: "", //验证码
        password: "", //密码
        realname: "", //姓名
        idCardNum: "", //身份证号
        address: "", //地址
        uuid:'',//图形验证码ID
        memberType:2,
        economicType:1,
        companyName:'',
        companyLicense:'',
        companyCode:''
      },
      codeUrl:''
    };
  },
  created() {
    this.getCode();
    this.getDicts("economic_type").then(res => {
      res.data.map(item => {
        this.columns.push(item.dictLabel);
      });
    });
    this.height = document.body.clientHeight
  },
  methods: {
    getCode() {
      getCodeImg().then((res) => {
        this.form.uuid = res.uuid;
        this.codeUrl = "data:image/gif;base64," + res.img;
      });
    },
    onConfirm(value, index) {
      this.value = value;
      this.showPicker = false;
      this.form.supplyDemandType = index + 1 ;
    },
    getSubmit(){
      console.log(this.form)
      userRegister(this.form).then((res) => {
        console.log(res)
      });
    }
  },
};
</script>

<style scoped lang="scss">
.app-container {
  background-color: #FFF;
  .code-img {
    width: 220px;
  }
}
.submit{
  position: absolute;
  bottom: 5%;
  width: 90%;
  left: 5%;
  p{
    text-align: center;
    margin-bottom: 0.2rem;
    span{
      color: #007E72;
    }
  }
}
</style>
