<template>
  <div id="unit" class="flex-row">
    <all-user-files v-ref:alluser :row="row" @select-changed="selected" style="width:50%"></all-user-files>
    <div class="flex" style="width:50%">
      <p class="bg-info text-center" style="padding: 8px;">分表信息</p>
      <total-split-list v-ref:totalsplit :data="row" style="height:200px;"></total-split-list>
      <split-list v-ref:split :data="row" style="height:500px;"></split-list>
      <div style="text-align:right;margin-top:10px;margin-right:50px;">
        <button class="btn btn-success" @click="confirm()"  :disabled='!$v.valid'>确&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;认</button>
        <button class="btn btn-default" @click="clean()" style="width:80px;margin-left:20px;">取&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;消</button>
      </div>
    </div>
  </div>
</template>
<script>
/**
*发票分配汇总组件
*/
// import * as Util from '../../Util'
export default {
  title: '总分表管理',
  data () {
    return {
      row: null,
      all: false
    }
  },
  methods: {
    selected (obj) {
      this.row = obj.val
    },
    confirm () {
      this.$showMessage('确定添加该表为总表？', ['confirm', 'cancel']).then((res) => {
        if (res === 'confirm') {
          if (this.$refs.split.ids.length > 0) {
            this.$refs.split.model.condition = this.$refs.split.model.condition + 'and f_user_id in (' + this.$refs.split.ids + ')'
          }
          this.$LogicService.addSplit(this.row, this.$refs.split.model.condition).then((res) => {
            this.$refs.alluser.$refs.paged.$refs.cri.search()
            this.$refs.totalsplit.getUpdate(this.row.f_user_id)
            this.$refs.split.search({items: '*', condition: '1=1', tablename: 'V_user_table', orderitem: 'f_userinfo_id'})
            this.$refs.split.ids = []
          }).catch((error) => {
            this.$refs.alluser.$refs.paged.$refs.cri.search()
            this.$refs.totalsplit.getUpdate(this.row.f_user_id)
            this.$refs.split.search({items: '*', condition: '1=1', tablename: 'V_user_table', orderitem: 'f_userinfo_id'})
            this.$refs.split.ids = []
            throw error
          })
        } else if (res === 'cancel') {

        }
      })
    }
  }
}
</script>
