<template>
  <div class="JudgeContent">
    <u-collapse-item title="家庭信息" :open="true">
      <div class="contents">
        <u-form :model="forms" ref="uForm" label-width="auto" :border-bottom="false">
          <u-form-item label="户主姓名" prop="judgeName" required >
            <u-input type="text" v-model="forms.judgeName" placeholder="请输入"  input-align="right" />
          </u-form-item>
          <u-form-item label="性别" prop="judgeSex" required right-icon="arrow-right">
            <u-input type="text" v-model="forms.judgeSexText" placeholder="请选择" disabled @click="isShowSex=true" input-align="right" />
            <u-select v-model="isShowSex" :list="$dict.getDict('sex')" value-name="dictValue" label-name="dictName" @confirm="selectSex"></u-select>
          </u-form-item>
          <u-form-item label="联系电话" prop="judgePhone" required >
            <u-input type="text" v-model="forms.judgePhone" placeholder="请输入" input-align="right" />
          </u-form-item>
          <u-form-item label="家庭住址" prop="judgeAddress" required>
            <u-input type="text" v-model="forms.judgeAddress" placeholder="请输入" input-align="right" />
          </u-form-item>
          <u-form-item label="纠纷类别" prop="judgeDisputeCategory" required right-icon="arrow-right">
            <u-input type="text" v-model="forms.judgeDisputeCategoryText" placeholder="请选择" disabled @click="isShowCategory=true" input-align="right" />
            <u-select v-model="isShowCategory" :list="$dict.getDict('qujingDisputeCategory')" value-name="dictValue" label-name="dictName" @confirm="selectCategory"></u-select>
          </u-form-item>
        </u-form>
      </div>
    </u-collapse-item>
    <div class="list-content">
      <div class="title">排查内容</div>
      <div class="item" v-for="(item, index) in riskList" :key="index">
        <div class="left">
          <u-icon name="checkmark-circle-fill" color="#3399FF" size="46" v-if="item.isCheck" @click="riskClick(index, false)"></u-icon>
          <span v-else @click="riskClick(index, true)"></span>
        </div>
        <div class="right">
          {{ item.dictName }}
        </div>
      </div>
      
    </div>

    <div class="btn" @click="confirm">
      <span>提交</span>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  name: 'JudgeContent',
  components: {},
  props: {},
  data() {
    return {
      forms: {
        judgeName: '',
        judgeSex: '',
        judgeSexText: '',
        judgePhone: '',
        judgeAddress: '',
        judgeRiskList: [],
        judgeDisputeCategory: '',
        judgeDisputeCategoryText: ''
      },
      id: '',
      isShowSex: false,
      riskList: [],
      isShowCategory: false,
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad(option) {
    this.id = option.id
    this.$dict.load('sex', 'qujingRisk', 'qujingDisputeCategory').then(() => {
      this.riskList = this.$dict.getDict('qujingRisk')
      this.riskList.map((item) => {
        item.isCheck = false
      })
    })
  },
  onShow() {
    document.title = '研判分析'
  },
  methods: {
    selectSex (e) {
      this.forms.judgeSex = e[0].value
      this.forms.judgeSexText = e[0].label
    },
    selectCategory (e) {
      this.forms.judgeDisputeCategory = e[0].value
      this.forms.judgeDisputeCategoryText = e[0].label
    },
    riskClick(index, status) {
      this.riskList[index].isCheck = status
      this.$forceUpdate()
    },
    confirm() {
      if(this.flag) return
      this.forms.judgeRiskList = []
      this.riskList.map((item) => {
        if(item.isCheck) {
          this.forms.judgeRiskList.push(item.dictValue)
        }
      })
      if (!this.forms.judgeName) {
        return this.$u.toast('请输入户主姓名')
      }
      if (!this.forms.judgeSexText) {
        return this.$u.toast('请选择性别')
      }
      if (!this.forms.judgePhone) {
        return this.$u.toast('请输入联系电话')
      }
      if (!this.forms.judgeAddress) {
        return this.$u.toast('请输入家庭住址')
      }
      if (!this.forms.judgeDisputeCategoryText) {
        return this.$u.toast('请选择纠纷类别')
      }
      if (!this.forms.judgeRiskList.length) {
        return this.$u.toast('请选择排查内容')
      }
      this.flag = true
      this.submit()
    },
    submit() { 
      var params = {...this.forms}
      params.id = this.id
      params.judgeRisk = this.forms.judgeRiskList.join(',')
      this.$http.post(`/app/appclapeventinfoqujing/judge`, {...params}).then((res) => {
        if (res.code == 0) {
          this.$u.toast('提交成功！')
          uni.$emit('updateDeatil')
          uni.$emit('getListInit')
          setTimeout(() => {
            uni.navigateBack()
          }, 600)
        }
      })
    },
  },
}
</script>

<style scoped lang="scss">
.JudgeContent {
  height: 100%;

  .u-form-item__body {
    border-bottom: 1px solid #ddd;
  }

  .contents {
    padding-bottom: 24px;

    ::v-deep .u-form {

      .u-form-item {
        // padding: 0 45px !important;

        .u-form-item__body {
          .u-form-item--right__content__slot {
            padding-bottom: 0;

            .u-input {
              // text-align: right !important;
            }
          }
        }
      }
      

    }
  }

  ::v-deep .u-collapse-head {
    padding: 32px;
    box-sizing: border-box;
    background-color: #fff;
    border-bottom: 1px solid #D8DDE6;

    .u-collapse-title {
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      color: #000;
    }
  }

  .list-content {
    padding-bottom: 180px;
    .title {
      line-height: 112px;
      background: #FFF;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      color: #000;
      padding-left: 32px;
      box-sizing: border-box;
      border-bottom: 1px solid #D8DDE6;
    }
    .item {
      padding: 28px 32px;
      background-color: #fff;
      margin-bottom: 24px;
      .left {
        display: inline-block;
        width: calc(100% - 622px);
        span {
          display: inline-block;
          width: 36px;
          height: 36px;
          background: #FFF;
          border: 1px solid #B3B3B3;
          border-radius: 50%;
          vertical-align: middle;
        }
        ::v-deep .u-icon {
          vertical-align: middle;
        }
      }
      .right {
        display: inline-block;
        width: 622px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        font-size: 28px;
        color: #000;
        text-align: justify;
        line-height: 44px;
        vertical-align: middle;
      }
    }
  }

  .btn {
    position: fixed;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    background: #3975c6;
    padding: 34px 0;
    text-align: center;
    font-size: 32px;
    font-weight: 500;
    color: #ffffff;
  }

  .right-span {
    display: inline-block;
    width: 100%;
    text-align: right;
  }
  ::v-deep .AiPagePicker {
    width: 100%;
    text-align: right;
  }
}
</style>
