<template>
  <section class="AddGird">
    <div class="item-flex">
      <div class="label">
        <span class="tips">*</span>姓名
      </div>
      <div class="value">
        <u-input type="text" placeholder="请输入" input-align="right" placeholder-style="color:#999;font-size:16px;" height="48" v-model="name" maxlength="50"/>
      </div>
    </div>
    <div class="item-flex">
      <div class="label">
        <span class="tips">*</span>手机号
      </div>
      <div class="value">
        <u-input type="text" placeholder="请输入" input-align="right" placeholder-style="color:#999;font-size:16px;" height="48" v-model="phone" maxlength="50"/>
      </div>
    </div>
    <div class="item-flex">
      <div class="label">
        <span class="tips">*</span>所属网格
      </div>
      <div class="value">
        <AiPagePicker type="custom" v-model="selectGird" valueObj nodeKey="id" :ops="{url:'./SelectGird',label: 'girdName'}" formType="2">
          <AiMore v-model="selectGird.girdName"/>
        </AiPagePicker>
      </div>
      <div class="footer" @click="confirm">确认添加</div>
    </div>
  </section>
</template>

<script>
import {mapState} from 'vuex'

export default {
  data() {
    return {
      name: '',
      phone: '',
      selectGird: {}
    }
  },
  computed: {...mapState(['user'])},
  onLoad() {
    this.name = this.user.name || ''
    this.phone = this.user.phone || ''
  },
  onShow() {
    document.title = '网格员信息申报'
  },
  methods: {
    confirm() {
      if (!this.name) {
        return this.$u.toast('请输入姓名')
      }
      if (!this.phone) {
        return this.$u.toast('请输入手机号')
      }
      if (!this.selectGird.girdName) {
        return this.$u.toast('请选择所属网格')
      }
      this.$http.post(`/app/appgirdmemberapply/girdMemberCheck?name=${this.name}&phone=${this.phone}&girdName=${this.selectGird.girdName}`).then((res) => {
        if (res.code == 0) {
          uni.$emit('updateGird')
          this.linkTo('./AddUserSuccess?status=1')
        }
      }).catch((err) => {
        this.linkTo('./AddUserSuccess?status=0')
      })
    },

    linkTo(url) {
      uni.navigateTo({url})
    },
  }
}
</script>

<style lang="scss" scoped>
.AddGird {
  .item-flex {
    display: flex;
    padding: 34px 32px;
    background-color: #fff;
    font-size: 32px;
    font-family: PingFangSC-Regular, PingFang SC;
    margin-bottom: 16px;

    .label {
      font-weight: 400;
      color: #333333;
      line-height: 22px;
      width: 150px;

      .tips {
        display: inline-block;
        width: 16px;
        color: #F46;
        line-height: 44px;
      }
    }

    .value {
      width: calc(100% - 150px);
      line-height: 44px;
      text-align: right;
      color: #666;

      img {
        width: 32px;
        height: 32px;
        vertical-align: middle;
        margin-left: 8px;
      }
    }

    .color-999 {
      color: #999;
    }
  }

  .footer {
    width: 100%;
    height: 112px;
    line-height: 112px;
    background: #1365DD;
    position: fixed;
    bottom: 0;
    left: 0;
    text-align: center;
    font-size: 36px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFF;
  }
}
</style>
