<template>
  <div class="Add">
    <div class="flex mar-b16">
      <div class="label">
        <span class="tips">*</span>党员信息
      </div>
      <div class="value">
        <AiPagePicker type="party" @select="handlePartySelect" single>
          <AiMore v-model="form.partyName" placeholder="请选择"/>
        </AiPagePicker>
      </div>
    </div>
    <div class="flex mar-b16">
      <div class="label">
        <span class="tips">*</span>积分操作
      </div>
      <div class="value">
        <AiSelect dict="partyIntegralType" v-model="form.integralType"></AiSelect>
      </div>
    </div>
    <div class="flex mar-b16">
      <div class="label">
        <span class="tips">*</span>积分分值
      </div>
      <div class="value">
        <u-input v-model="form.integral" type="number" maxlength="6" placeholder="请输入" placeholder-style="font-size:16px;" :height="32" input-align="right"/>
      </div>
    </div>
    <div class="flex">
      <div class="label">
        <span class="tips">*</span>调整说明
      </div>
    </div>
    <div class="text-area">
      <u-input v-model="form.remark" type="textarea" :height="150" :auto-height="true" maxlength="200" placeholder="请输入调整说明" placeholder-style="font-size:16px;" />
      <div class="hint">{{ form.remark.length }}/200</div>
    </div>
    <div class="footer" @click="confirm">
      <div class="btn">确认提交</div>
    </div>
  </div>
</template>

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

export default {
  name: 'Add',
  data() {
    return {
      form: {
        partyName: '',
        partyId: '',
        integralType: '',
        integral: '',
        remark: '',
      },
      isFlag: true
    }
  },
  computed: {
    ...mapState(['user']),
  },
  created() {
    this.$dict.load('partyIntegralType')
  },
  onShow() {
    document.title = '积分调整'
  },
  methods: {
    rules() {
      return {
        partyId: '请选择党员信息',
        integralType: '请选择积分操作',
        integral: '请输入积分分值',
        remark: '请输入调整说明',
      }
    },
    confirm() {
      const rules = this.rules()
      for (let v of Object.keys(rules)) {
        if (!this.form[v]) {
          return this.$u.toast(rules[v])
        }
      }
      if(!this.isFlag) {
        return
      }
      this.isFlag = false
      this.$http.post('/app/apppartyintegralinfo/add', {
        partyIntegralList: [{...this.form}],
      }).then(res => {
        if (res.code == 0) {
          this.$u.toast('提交成功')
          uni.$emit('reload')
          setTimeout(() => {
            uni.navigateBack({
              delta: 1
            })
          }, 600)
        }
      }).catch((err) => {
        this.$u.toast(err)
      })
    },
    handlePartySelect(e) {
      this.form.partyId = e[0].id
      this.form.partyName = e[0].name
    }
  },
}
</script>

<style lang="scss" scoped>
.Add {
  .flex{
    display: flex;
    justify-content: space-between;
    padding: 34px 32px 34px 12px;
    font-size: 32px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #333;
    line-height: 44px;
    background-color: #fff;
    .label{
      width: 150px;
      .tips{
        font-size: 32px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #F46;
      }
    }
    .value{
      span{
        display: inline-block;
        margin-right: 12px;
      }
      .color-999{
        color: #999;
      }
    }
  }
  .mar-b16{
    margin-bottom: 16px;
  }
  .text-area{
    width: 100%;
    padding: 0 32px 32px;
    background-color: #fff;
    box-sizing: border-box;
    .hint{
      width: 100%;
      color: #999;
      text-align: right;
    }
  }
  .footer {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
  }
  .btn {
    width: 100%;
    height: 112px;
    line-height: 112px;
    text-align: center;
    background: #3975C6;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #fff;
  }
}
</style>
