<template>
  <div class="partyAuthApply">
    <div class="tips">党员名单中未有你的信息，请完善资料等待审核。</div>
    <div class="form-item__group">
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>党员姓名</h2>
          </div>
          <div class="form-item__right">
            <input placeholder="请输入" v-model="form.name" :maxlength="20"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>身份证号</h2>
          </div>
          <div class="form-item__right">
            <input placeholder="请输入" v-model="form.idNumber" :maxlength="18"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>手机号码</h2>
          </div>
          <div class="form-item__right">
            <input placeholder="请输入" v-model="form.phone" :maxlength="11"/>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>党组织</h2>
          </div>
          <div class="form-item__right">
            <AiPagePicker type="custom" @select="handleSelectParty" :ops="{url:`./selectPartyOrg?id=${form.partyOrgId}`,label:'name',}">
              <AiMore v-model="form.partyOrgName"/>
            </AiPagePicker>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>入党时间</h2>
          </div>
          <div class="form-item__right">
            <div class="ai-area" @click="isShowDate = true">
              <div class="ai-area__wrapper">
                <span class="label" v-if="form.joinPartyTime">{{ form.joinPartyTime }}</span>
                <i v-else>请选择</i>
                <u-icon name="arrow-right" color="#ddd"/>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="form-item">
        <div class="form-item__wrapper">
          <div class="form-item__title">
            <i>*</i>
            <h2>党员类型</h2>
          </div>
          <div class="form-item__right">
            <AiSelect dict="partyType" v-model="form.partyType"></AiSelect>
          </div>
        </div>
      </div>
    </div>

    <u-picker mode="time" :params="dataParams" v-model="isShowDate" @confirm="onDateChange"></u-picker>
    <div class="btn-wrapper">
      <div class="btn" hover-class="text-hover" @click="submit">提交</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "partyAuthApply",
  data() {
    return {
      isShowDate: false,
      dataParams: {
        year: true,
        month: true,
        day: true
      },
      form: {
        name: '',
        idNumber: '',
        phone: '',
        partyOrgId: '',
        partyOrgName: '',
        joinPartyTime: '',
        partyType: '',
        partyStatus: '0',
      }
    }
  },
  computed: {
    ...mapState(['user'])
  },
  onLoad(o) {
    console.log(o);
    uni.setNavigationBarTitle({
      title: '申请党员'
    });
    if(this.user.partyId?.length > 0) {
      this.getDetail()
    } else {
      this.form.name = o.name
      this.form.idNumber = o.idNumber
    }
  },
  methods: {
    onDateChange(e) {
      this.form.joinPartyTime = `${e.year}-${e.month}-${e.day}`
    },
    handleSelectParty(v) {
      this.form.partyOrgId = v.id
      this.form.partyOrgName = v.name
    },
    getDetail() {
      this.$instance.post(`/app/appparty/detail?id=${this.user.partyId}`).then(res=> {
        if(res?.data) {
          this.form = res.data
          delete this.form.auditOpinion
        }
      })
    },
    submit() {
      if (!this.form.name) {
        return this.$toast('请输入党员姓名')
      }
      if (!this.form.idNumber) {
        return this.$toast('身份证号')
      }
      if (!this.form.phone.length) {
        return this.$toast('请输入手机号')
      }
      if(!this.form.partyOrgId) {
        return this.$toast('请选择党组织')
      }
      if(!this.form.joinPartyTime) {
        return this.$toast('请选择入党时间')
      }
      if(!this.form.partyType) {
        return this.$toast('请选择党员类型')
      }
      this.$loading()
      this.$instance.post(`/app/appparty/addOrUpdateForWX`, {
        ...this.form,
      }).then(res => {
        if (res.code == 0) {
          this.$toast('提交成功')
          this.$store.dispatch('getUserInfo')
          uni.removeStorageSync('lastSelectedParty');
          setTimeout(() => {
            uni.redirectTo({url: `./partyAuthSuccess`})
          }, 600)
        }
        this.$hideLoading()
      })
    }
  }
}
</script>

<style lang="scss">
.partyAuthApply {
  padding-bottom: 140px;

  .title {
    padding: 16px 32px 0 32px;
    box-sizing: border-box;
    background: #fff;
    font-size: 36px;
    font-weight: 600;
  }

  .tips {
    line-height: 1.3;
    padding: 32px 32px;
    color: #FF883C;
    font-size: 30px;
    text-align: justify;
    background: #FFF8F3;
  }

  .form-item__group {
    margin-bottom: 24px;
    background: #fff;
  }

  .form-item {
    padding-left: 32px;

    .form-item__checkbox {
      width: 100%;

      div {
        width: 100%;
        height: 80px;
        line-height: 80px;
        margin-bottom: 24px;
        text-align: center;
        background: #FFFFFF;
        border-radius: 16px;
        color: #333333;
        font-size: 28px;
        border: 1px solid #CCCCCC;

        &.active {
          background: #4181FF;
          color: #fff;
          border-color: #4181FF;
        }
      }
    }

    // .form-item__radio {
    //   display: flex;
    //   align-items: center;
    //   flex-wrap: wrap;

    //   div {
    //     width: 212px;
    //     height: 80px;
    //     line-height: 80px;
    //     margin-right: 16px;
    //     margin-bottom: 8px;
    //     text-align: center;
    //     background: #FFFFFF;
    //     border-radius: 16px;
    //     color: #333333;
    //     font-size: 28px;
    //     border: 1px solid #CCCCCC;

    //     &:nth-of-type(3n) {
    //       margin-right: 0;
    //     }

    //     &.active {
    //       background: #4181FF;
    //       color: #fff;
    //       border-color: #4181FF;
    //     }
    //   }
    // }

    .ai-area__wrapper {
      display: flex;
      align-items: center;
      padding-left: 100px;

      span {
        color: #333;
        font-size: 30px;
      }

      i {
        color: #999;
        font-size: 30px;
      }

      image {
        width: 16px;
        height: 8px;
      }
    }

    .form-item__wrapper {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 128px;
      padding-right: 28px;
      border-bottom: 1px solid #DDDDDD;
      box-sizing: border-box;

      input {
        flex: 1;
        height: 100%;
        text-align: right;
        color: #333;
        padding-right: 10px;
      }

      .form-item__right {
        display: flex;
        align-items: center;
        font-size: 32px;

        span {
          max-width: 400px;
          margin-right: 8px;
          color: #333333;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        i {
          margin-right: 8px;
          color: #999999;
        }
      }
    }

    &:last-child {
      .form-item__wrapper {
        border-bottom: none;
      }
    }

    .form-item__title {
      display: flex;
      align-items: center;

      i {
        font-size: 32px;
        color: #FF4466;
      }

      span {
        font-size: 28px;
        color: #999999;
      }

      h2 {
        padding: 0 4px;
        font-weight: 400;
        font-size: 32px;
        color: #333333;
      }
    }


    // &.form-item__imgs, &.form-item__textarea {
    //   .form-item__wrapper {
    //     display: block;
    //     height: auto;
    //     padding-bottom: 32px;
    //   }

    //   textarea {
    //     width: 100%;
    //     height: 90px;
    //   }

    //   .form-item__title {
    //     padding: 32px 0;
    //   }

    //   .form-item__right {
    //     padding-left: 18px;
    //   }
    // }
  }
}
</style>
