<template>
  <div class="formEdit">
    <div class="title">
      <span></span>请确认并校准您输入的内容：
    </div>
    <div class="list">
      <div class="item">
        <div class="label">
          <span>户主姓名</span>
          <div class="edit" @click="editName=true">
            <img src="./img/edit.png" alt="">修改
          </div>
        </div>
        <div class="value">
          <u-input type="text" class="right" placeholder="请输入" height="44" input-align="center" v-model="info.name" :clearable="false" v-if="editName"></u-input>
          <span v-else>{{info.name || '请输入'}}</span>
        </div>
      </div>
      <div class="item">
        <div class="label">
          <span>性别</span>
          <div class="edit" @click="showSex=true">
            <img src="./img/edit.png" alt="">修改
          </div>
        </div>
        <div class="value">
          <span>{{ $dict.getLabel('sex', info.sex) || '请选择'}}</span>
        </div>
      </div>
      <div class="item">
        <div class="label">
          <span>联系电话</span>
          <div class="edit" @click="editPhone=true">
            <img src="./img/edit.png" alt="">修改
          </div>
        </div>
        <div class="value">
          <u-input type="text" class="right" placeholder="请输入" height="44" input-align="center" v-model="info.phone" :clearable="false" v-if="editPhone"></u-input>
          <span v-else>{{info.phone || '请输入'}}</span>
        </div>
      </div>
      <div class="item">
        <div class="label">
          <span>出生日期</span>
          <div class="edit" @click="showDate=true">
            <img src="./img/edit.png" alt="">修改
          </div>
        </div>
        <div class="value">
          <span>{{info.birthday || '请选择'}}</span>
        </div>
      </div>
      <div class="item">
        <div class="label">
          <span>民族</span>
          <div class="edit" @click="showNation=true">
            <img src="./img/edit.png" alt="">修改
          </div>
        </div>
        <div class="value">
          <span>{{ $dict.getLabel('nation', info.nation) || '请选择'}}</span>
        </div>
      </div>
      <div class="item">
        <div class="label">
          <span>家庭人口数</span>
          <div class="edit" @click="editHouseholdNumber=true">
            <img src="./img/edit.png" alt="">修改
          </div>
        </div>
        <div class="value">
          <u-input type="text" class="right" placeholder="请输入" height="44" input-align="center" v-model="info.householdNumber" :clearable="false" v-if="editHouseholdNumber"></u-input>
          <span v-else>{{info.householdNumber || '请输入'}}</span>
        </div>
      </div>
    </div>
    <div class="bottom-btn">
      <div class="confirm" @click="toConfirm">确认使用</div>
      <div class="cancel" @click="back">取消输入</div>
    </div>
  </div>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: 'formEdit',
  data() {
    return {
      word: '',
      info: {},
      showSex: false,
      showNation: false,
      showDate: false,
      deteParams: {year: true, month: true, day: true, hour: false, minute: false, second: false},
      editName: false,
      editPhone: false,
      editHouseholdNumber: false
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad(option) {
    uni.showLoading({title: '加载中'})
    this.word = option.word
    this.$dict.load('sex', 'nation').then(() => {
      this.getInfo()
    })
  },
  onShow() {
    document.title = '婚姻家庭纠纷入户登记表'
  },
  methods: {
    getInfo() {
      this.$http.post(`/app/appbaiduai/queryByInfo?word=${this.word}`).then((res) => {
        if (res.code === 0) {
          this.info = {...res.data}
          uni.hideLoading()
        }
      }).catch(res => {
        this.$u.toast(res)
        uni.hideLoading()
      })
    },
    confirmSex(e) {
      this.info.sex = e[0].value
    },
    confirmNation(e) {
      this.info.nation = e[0].value
    },
    dateConfirm(e) {
      this.info.birthday = `${e.year}-${e.month}-${e.day}`
    },
    toConfirm() {
      if(this.info.name == null || !this.info.name) {
        return this.$u.toast('请输入户主姓名')
      }
      if(this.info.sex == null) {
        return this.$u.toast('请选择性别')
      }
      if(this.info.phone == null || !this.info.phone) {
        return this.$u.toast('请输入联系电话')
      }
      if(this.info.birthday == null) {
        return this.$u.toast('请选择出生日期')
      }
      if(this.info.nation == null) {
        return this.$u.toast('请选择民族')
      }
      if(this.info.householdNumber == null || !this.info.householdNumber) {
        return this.$u.toast('请输入家庭人口数')
      }
      uni.navigateTo({url: `./formConfirm?word=${this.word}`})
    },
    back() {
      uni.navigateBack()
    }
  },
}
</script>

<style lang="scss" scoped>
uni-page-body {
  min-height: 100%;
  // height: 100vh;
  background: #fff;
  padding-top: 26px;
}
.formEdit {
  .title {
    padding-left: 32px;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 32px;
    color: #000;
    line-height: 48px;
    margin-bottom: 22px;
    span {
      display: inline-block;
      width: 6px;
      height: 28px;
      background: #3399FF;
      border-radius: 3px;
      margin-right: 18px;
    }
  }
  .list {
    padding-bottom: 272px;
    .item {
      text-align: center;
      margin-bottom: 64px;
      .label {
        margin-bottom: 18px;
        span {
          color: #999;
          font-size: 40px;
          font-family: PingFangSC;
          font-weight: 500;
          line-height: 60px;
          text-align: center;
        }
        .edit {
          display: inline-block;
          width: 150px;
          text-align: right;
          font-family: PingFangSC-Regular;
          font-size: 28px;
          color: #3072F5;
          vertical-align: text-bottom;
          img {
            width: 28px;
            height: 28px;
            margin: 0 12px 0 32px;
            vertical-align: middle;
          }
        }
      }
      .value {
        width: calc(100% - 150px);
        .u-input, span{
          display: inline-block;
          width: 100%;
          text-align: center;
          color: #3975c6;
          font-size: 40px;
          font-family: PingFangSC;
          font-weight: 500;
          line-height: 60px;
        }
        ::v-deep .uni-input-input {
          color: #3975c6;
          font-size: 40px;
          font-family: PingFangSC;
          font-weight: 500;
          line-height: 60px;
        }
      }
    }
  }
  .bottom-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    background-color: #fff;
    div {
      margin-left: 32px;
      width: 686px;
      height: 88px;
      border-radius: 44px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      text-align: center;
      line-height: 86px;
      margin-bottom: 32px;
    }
    .confirm {
      background: #3975C6;
      color: #fff;
    }
    .cancel {
      color: #666;
      border: 1px solid #CCC;
    }
  }
}
</style>
