<template>
  <div id='meterbookEntry' class="flex-row binary">
    <div class="binary-left">
      <mbpeople-list @childre="childre" v-ref:mbpeople_list></mbpeople-list>
    </div>
    <div class="binary-right">
      <add-tobook v-ref:selectbok :usernum="rowsdata.length" v-if="AddTobookShow"></add-tobook>
    </div>
  </div>
</template>

<script>
  import MbpeopleList from './MbpeopleList'
  import AddTobook from './AddTobook'
  import {HttpResetClass} from 'vue-client'

  export default {
    name: 'meterbookEntry',
    components: {AddTobook, MbpeopleList},
    title: '添加用户到抄表册',
    data () {
      return {
        AddTobookShow: true,
        rowsdata: null,
        condition: '',
      }
    },
    created () {
    },
    ready () {

    },
    methods: {
      childre(val){
        this.$refs.selectbok.selectbook(val)
      },
      refresh () {
        // this.AddTobookShow = false
        // this.$nextTick(() => {
        //   this.AddTobookShow = true
        // })
      }
    },
    events: {
      'add-tobook-refresh' () {
        this.refresh()
      },
      'add-tobook-confirm' (model) {
        model.userfilesids = []
        let msg = '确认将选中的用户全部移入表册？'
        var alluser=[]
        if (this.rowsdata === null || this.rowsdata.length == 0) {
          msg = '确认将查询出来的用户全部移入表册？'
          let http = new HttpResetClass()
          http.load('POST', 'rs/sql/mb_peopleList', {
            data: {
              condition: this.condition
            }
          }, {resolveMsg: null, rejectMsg: null}).then((res) => {
            res.data.forEach((item) => {
              model.userfilesids.push(item.f_userfiles_id + '')
            })
            alluser=res.data
          })
        } else {
          model.userfilesids = this.rowsdata
          alluser = this.$refs.mbpeople_list.rowsdata[0]
        }

        // 变成可以直接使用的格式
        this.$showMessage(msg, ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            this.$resetpost('rs/logic/saveBookuser', {model: model,rowsdata: alluser}, {
              resolveMsg: '保存成功',
              rejectMsg: '保存失败！！'
            }).then(() => {
              // 刷新查询
              this.$refs.mbpeople_list.rowsdata = []
              this.$refs.mbpeople_list.getmeterbook()
              this.rowsdata = []
              this.$parent.meterbookEntryShow = false
              this.$refs.mbpeople_list.unnullrowdata = []
              this.$refs.mbpeople_list.radio = []
              this.refresh()
              this.$refs.mbpeople_list.$refs.paged.$refs.cri.search()
            })
          }
        })
      }
    }
  }
</script>

<style lang="less">
  #meterbookEntry {
    height: 700px;
  }
</style>
