<template>
  <div id="unit" class="flex-row" style="width: 100%">

    <div v-if="all == 'user'" class="flex binary-left" :style="{width: messlist==='mess' ? '50%' : '100%'}">
      <account-bill-list :rollback="messlist == 'mess' ? false : true" @allchange3="allchange3()" @allchange4="allchange4()" class="binary-left" v-ref:messagelist :row="row" @select-changed="selected"></account-bill-list>
    </div>
    <div v-show="messlist == 'mess'" class="flex binary-left"  :style="{width: all==='' ? '100%' : '50%'}" >
      <account-message-list @allchange="allchange()" @allchange2="allchange2()" v-ref:message class="datapanel" :data="row"></account-message-list>
    </div>
  </div>
</template>
<script>
/**
*发票分配汇总组件
*/
import Vue from 'vue'
import co from 'co'
export default {
  title: '账单推送',

  data () {
    return {
      row: null,
      all: 'user',
      messlist: 'mess'
    }
  },
  ready () {
    console.log('all', this.all)
  },
  methods: {

    allchange () {
      this.all = ''
      console.log('=-=========>', this.all)
    },
    allchange2 () {
      this.all = 'user'
      console.log('=-=========>', this.all)
    },
    allchange3 () {
      this.messlist = ''
      console.log('=-=====this.messlist====>', this.messlist)
    },
    allchange4 () {
      this.messlist = 'mess'
      console.log('=-=====this.messlist====>', this.messlist)
    },
    allchange5 () {
      this.all = 'arr'
      this.messlist = ''
      console.log('=-=====this.messlist====>', this.messlist)
    },
    allchange6 () {
      this.all = 'arr'
      this.messlist = 'mess'
      console.log('=-=====this.messlist====>', this.messlist)
    },
    selected (obj) {
      this.row = obj.val
    }
  },
  events: {
    'create' (condition, userdefinedMessage, downDate, sendtype, startDate, endDate, msg) {
      console.log(startDate,endDate)
      let data = {
        // 短信模板
        userdefinedMessage: msg,
        // 条件
        condition: condition,
        downDate: downDate,
        startDate: startDate,
        endDate: endDate,
        // 短信类型
        sendtype: '账单推送',
        f_operator: Vue.$login.f.name,
        f_operatorid: Vue.$login.f.id,
        f_orgid: Vue.$login.f.orgid,
        f_orgname: Vue.$login.f.orgs,
        f_depid: Vue.$login.f.depids,
        f_depname: Vue.$login.f.deps,
        f_zoneid: Vue.$login.f.zoneid,
        f_zones: Vue.$login.f.zones
      }
      if (userdefinedMessage) {
        data.mark = 'defined'
      } else {
        data.mark = 'nodefined'
      }
      console.log('查看make参数', data)
      this.$LogicService.createCustomMessage(data).then((res) => {
        console.log('查看短信返回参数', data)
        console.log(res.data)
        if (res.data.success) {
          this.$showMessage(`成功生成短信${res.data.success}条,生成失败${res.data.fail}条`)
          this.$refs.messagelist.$refs.paged.$refs.cri.search()
          this.$refs.messagelist.ids = []
        } else {
          this.$showMessage(`短信生成失败`)
        }
      }).catch((error) => {
        this.$showMessage(`短信生成失败`)
        this.$refs.messagelist.$refs.paged.$refs.cri.search()
        this.$refs.messagelist.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 = 'arr'
      } else if (type === '全部') {
        this.all = 'user'
      }
    }
  }
}
</script>
<style>
  .datapanel {
    color: #333;
    background-color: white;
    box-shadow: darkgrey 0.5px 0.5px 0.5px 0.5px ;
    padding: 10px 10px 5px 10px;
    border-radius:10px;
    width: 50%;
  }
</style>
