<template>
  <div id='InvoiceEntry' class="flex-row binary">
    <div class="binary-left" v-if="sellgas">
      <charge-list v-ref:charge_list></charge-list>
    </div>
    <div class="binary-right" v-if="sellgas">
      <information-input v-if="InformationInputShow"></information-input>
    </div>
    <div  v-if="!sellgas">
      <invoice-information-input v-if="InformationInputShow"></invoice-information-input>
    </div>
  </div>
</template>

<script>
  import ChargeList from './ChargeList'
  import InformationInput from './InformationInput'
  import InvoiceInformationInput from './InvoiceInformationInput'

  export default {
    name: 'InvoiceEntry',
    props: ['sellgas'],
    components: {InformationInput, ChargeList, InvoiceInformationInput},
    title: '发票信息录入',
    data () {
      return {
        InformationInputShow: true
      }
    },
    created () {
    },
    ready () {
      // 什么叫前台啊? (战术后仰)
    },
    methods: {
      refresh () {
        this.InformationInputShow = false
        this.$nextTick(() => { this.InformationInputShow = true })
      }
    },
    events: {
      'information-input-refresh' () {
        this.refresh()
      },
      'information-input-confirm' (model) {
        let rowsdata = this.$refs.charge_list.rowsdata
        // 选择的收费记录id串
        let sellingIdSrt = ''
        for (let row of rowsdata) {
          for (let r of row) {
            if (r) {
              sellingIdSrt += (r + ',')
            }
          }
        }
        if (!sellingIdSrt) {
          this.$showMessage('请选择发票对应的收费记录')
          return
        }
        // 变成可以直接使用的格式
        sellingIdSrt = (sellingIdSrt = '(' + sellingIdSrt).slice(0, sellingIdSrt.length - 1) + ')'
        console.log(sellingIdSrt)
        this.$resetpost('rs/logic/saveInvoice', {model: model, updateIds: sellingIdSrt}, {resolveMsg: '保存成功', rejectMsg: '保存发票信息失败！！'}).then(() => {
          // 刷新查询
          this.$refs.charge_list.rowsdata = []
          this.$refs.charge_list.radio = []
          this.refresh()
          this.$refs.charge_list.$refs.paged.$refs.cri.search()
        })
      }
    }
  }
</script>

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