<template>
  <div class="auto">
    <validator name='v'>
      <form class="form-horizontal">
        <p class="bg-info text-center" style="padding: 8px;">销户信息</p>
        <div class="row" style="margin-top:10px;">
          <span class="col-sm-2 col-sm-offset-1"><strong>已选中户数: {{model.count}}</strong></span>
        </div>
        <div class="row" style="margin-top:10px;">
          <div class="form-group" :class="[$v.f_reason.required ? 'has-error' : 'has-success']">
            <label for="f_reason" class=" col-sm-2 control-label">销户原因:</label>
            <div class="col-sm-8">
              <textarea class="form-control" v-model="model.f_reason" v-validate:f_reason='{required: true }' rows="3" placeholder="请填写原因"></textarea>
            </div>
          </div>
        </div>
      </form>
      <div style="text-align:right;height:auto;margin-top:30px;margin-right:50px;">
        <button class="btn btn-success width-60" @click="confirm()"  :disabled='!$v.valid'>确认</button>
        <button class="btn btn-default width-60" @click="clean()" style="width:80px;margin-left:20px;">取消</button>
      </div>
    </validator>
  </div>
</template>
<script>
/**
*综合业务
表具停用组件
*/
export default {
  title: '批量销户',
  data () {
    return {
      model: {
        count: 0,
        discount: 0,
        f_reason: '',
        userinfo: {}
      }
    }
  },
  props: ['useraccount'],
  ready () {
    this.useraccount.forEach((item) => {
      if (item.f_user_state === '正常') {
        this.model.count = this.model.count + 1
        this.model.userinfo = item
      } else if (item.f_user_state = '销户') {
        this.model.discount = this.model.discount + 1
      }
    })
  },
  methods: {
    confirm () {
      this.model.f_reality_count = this.model.count
      this.$FileService.batchOperate(this.model, '销户').then((res) => {
        this.$dispatch('success', '批量销户', this.row, res)
      }).catch((error) => {
        if (error.state === 603) {
          this.$error('重复提交')
          return
        }
        this.$dispatch('error', '批量销户', this.row, error)
      })
    },
    clean () {
      this.$info('取消操作')
      this.$dispatch('clean', '批量销户', this.row)
    }
  }
}
</script>

<style>
</style>
