<template>
  <div id="unit" class="flex-row">
    <arrears-list v-if="all === false" v-ref:list :row="row" @select-changed="selected"></arrears-list>
    <all-user v-if="all === true" v-ref:messagelist :row="row" @select-changed="selected"></all-user>
    <message-list v-ref:message :data="row" style="width: 60%"></message-list>
  </div>
</template>
<script>
/**
*发票分配汇总组件
*/

export default {
  title: '短信管理',
  data () {
    return {
      row: null,
      all: false
    }
  },
  methods: {
    selected (obj) {
      this.row = obj.val
    }
  },
  events: {
    'create' (condition, userdefinedMessage) {
      let data = {
        userdefinedMessage: userdefinedMessage,
        condition: condition,
        f_fengongsi: this.$login.f.f_fengongsi,
        f_parentname: this.$login.f.f_parentname
      }
      if (userdefinedMessage) {
        data.mark = 'defined'
      } else {
        data.mark = 'nodefined'
      }
      this.$LogicService.createMessage(data).then((res) => {
        // this.$refs.list.search()
        this.$refs.message.$refs.paged.$refs.cri.search()
        this.$refs.message.model.condition = 'convert(varchar(10),f_create_date,120) = ' + "'" + this.$login.toStandardDateString() + "'"
        this.$refs.list.ids = []
        this.$refs.message.ids = []
      }).catch((error) => {
        this.$refs.message.$refs.paged.$refs.cri.search()
        this.$refs.message.model.condition = 'convert(varchar(10),f_create_date,120) = ' + "'" + this.$login.toStandardDateString() + "'"
        this.$refs.list.ids = []
        this.$refs.message.ids = []
      })
    },
    'success' () {
      this.$refs.message.$refs.paged.$refs.cri.search()
      this.$refs.list.ids = []
      this.$refs.message.ids = []
    },
    'error' () {
      this.$refs.message.$refs.paged.$refs.cri.search()
      this.$refs.list.ids = []
      this.$refs.message.ids = []
    },
    'all' (type) {
      console.log('type', type)
      if (type === '欠费') {
        this.all = false
      } else if (type === '全部') {
        this.all = true
      }
    }
  }
}
</script>
