<template>
<!--pages/release/companyAuth/index.wxml-->
<view class="auth-page">
  <view class="company-info-box">
    <view class="form-item acea-row row-between row-middle">
      <view class="label">姓名</view>
      <view class="inp-box">
        <input type="text" :value="form.legalPersonName" @input="inpChange" data-type="name" placeholder="请填写姓名">
      </view>
    </view>
    <view class="form-item acea-row row-between row-middle">
      <view class="label">手机号</view>
      <view class="inp-box">
        <input type="text" :value="form.legalPhone" @input="inpChange" data-type="phone" placeholder="请填写手机号">
      </view>
    </view>
    <view class="form-item acea-row row-between row-middle">
      <view class="label">身份证号</view>
      <view class="inp-box">
        <input type="text" :value="form.legalPersonIdcard" @input="inpChange" data-type="idcard" placeholder="请填写身份证号">
      </view>
    </view>
    <!-- <view class="form-item noBorder">
      <view class="label">身份证</view>
      <view class="inp-box sfz">
        <view class="acea-row row-between-wrapper">
          <image src="https://download.cyjyyjy.com/sfz1.png" @tap="upCard" data-type="b" v-if="form.idcardPicBehind == ''"></image>
          <image :src="form.idcardPicBehind" @tap="upCard" data-type="b" v-else></image>
          <image src="https://download.cyjyyjy.com/sfzb.png"></image>
        </view>
        <view class="acea-row row-between-wrapper">
          <image src="https://download.cyjyyjy.com/sfz2.png" @tap="upCard" data-type="f" v-if="form.idcardPicFront == ''"></image>
          <image :src="form.idcardPicFront" @tap="upCard" data-type="f" v-else></image>
          <image src="https://download.cyjyyjy.com/sfzz.png"></image>
        </view>
        <view class="acea-row row-between-wrapper">
          <image src="https://download.cyjyyjy.com/sfz3.png" @tap="upCard" data-type="h" v-if="form.idcardPicHold == ''"></image>
          <image :src="form.idcardPicHold" @tap="upCard" data-type="h" v-else></image>
          <image src="https://download.cyjyyjy.com/sfzs.png"></image>
        </view>
      </view>
    </view> -->
  </view>
  <view class="submit-btn" @tap="submit">保存并提交</view>
	
	<view class="argeement-box">
			<checkbox-group  @change="argeementClick">
				<checkbox value="1" style="transform:scale(0.7);position: relative; top: 3rpx;" :checked="isCheck" />
			</checkbox-group>
			<view class="acea-row">
				我已阅读并同意
				<navigator url="/pages/login/agreementPage"  open-type="navigate" style="color: rgb(255, 50, 50);">《用户协议及隐私政策》</navigator>
			</view>
	</view>
</view>
</template>

<script>
// pages/release/personAuth/index.js
const util = require("../../../utils/util.js");
const app = getApp();

export default {
  data() {
    return {
      form: {
        legalPersonName: '',
        legalPhone: '',
        legalPersonIdcard: '',
        idcardPicFront: '',
        idcardPicBehind: '',
        idcardPicHold: ''
      },
      isEdit: false,
			isCheck: false
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.authInfo) {
      let authInfo = JSON.parse(decodeURIComponent(options.authInfo));
			this.isEdit = true,
      this.form.authorizationType = 2;
      this.form.id = authInfo.id;
      this.form.idcardPicHold = authInfo.idcardPicHold;
      this.form.idcardPicBehind = authInfo.idcardPicBehind;
      this.form.idcardPicFront = authInfo.idcardPicFront;
      this.form.legalPersonIdcard = authInfo.legalPersonIdcard;
      this.form.legalPhone = authInfo.legalPhone || '';
      this.form.legalPersonName = authInfo.legalPersonName;
    }
  },
  methods: {
		argeementClick(e){
			console.log(e)
			let state = e.detail.value
			if(state.length > 0) {
				this.isCheck = true
			} else{
				this.isCheck = false
			}
		},
    inpChange(e) {
      let type = e.currentTarget.dataset.type;
      let value = e.detail.value;

      if (type == 'name') {
        this.form.legalPersonName = value;
      } else if (type == 'phone') {
        this.form.legalPhone = value;
      } else if (type == 'idcard') {
        this.form.legalPersonIdcard = value;
      }
    },

    upCard(e) {
      let type = e.currentTarget.dataset.type;
      util.chooseImages(img => {
        if (type == 'f') {
          this.form.idcardPicFront = img;
        } else if (type == 'b') {
          this.form.idcardPicBehind = img;
        } else {
          this.form.idcardPicHold = img;
        }
      });
    },

    submit() {
      let form = this.form;
			if(!this.isCheck){
				uni.showToast({
				  title: '请阅读并勾选用户隐私协议',
				  icon: 'none'
				});
				return;
			}

      if (form.legalPersonName == '') {
        uni.showToast({
          title: '请填写姓名',
          icon: 'none'
        });
        return;
      } else if (form.legalPhone == '') {
        uni.showToast({
          title: '请填写手机号',
          icon: 'none'
        });
        return;
      } else if (form.legalPersonIdcard == '') {
        uni.showToast({
          title: '请填写身份证号',
          icon: 'none'
        });
        return;
      } else {
        if (this.isEdit == false) {
          app.http('post', 'EnterpriseAuthentication/createAuthenticInfoOne', this.form).then(res => {
            if (res.data.success) {
              uni.showModal({
                title: '提示！',
                content: '提交成功！请等待审核',

                success(res) {
                  uni.navigateBack({
                    delta: 1
                  });
                }

              });
            } else {
              uni.showToast({
                title: res.data.msg,
                icon: 'none'
              });
            }
          });
        } else {
          app.http('post', 'EnterpriseAuthentication/editAuthenticInfo', this.form).then(res => {
            if (res.data.success) {
              uni.showModal({
                title: '提示！',
                content: '提交成功！请等待审核',

                success(res) {
                  uni.navigateBack({
                    delta: 1
                  });
                }

              });
            } else {
              uni.showToast({
                title: res.data.msg,
                icon: 'none'
              });
            }
          });
        }
      }
    }

  }
};
</script>
<style>
@import "../companyAuth/index.css";
</style>