<template>
  <div class="auto basic-main" style="height:95%">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-2">
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="form-control" v-model="model.f_userinfo_code" style="width:60%"
                     condition="f_userinfo_code = '{}' " placeholder="客户编号"
              >
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">用户姓名</label>
              <input type="text" class="form-control" v-model="model.f_user_name" style="width:60%"
                     condition="f_user_name = '{}'" placeholder="用户姓名"
              >
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">票据状态</label>
              <v-select id="f_bill_state"
                        style="width:60%"
                        v-model="model.f_bill_state"
                        placeholder='票据状态'
                        condition="f_bill_state ='{}'"
                        :value.sync="model.f_bill_state"
                        :options='$parent.$parent.eticktypes'
                        :search="false"
                        close-on-select clear-button>
              </v-select>
            </div>
            <div style="float: right">
              <button class="button_search" @click="search()">查 询</button>
              <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.criteriaShow=!$parent.$parent.criteriaShow"
                class="button_spacing"
                style="float: right"></div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <!--            <res-select-group style="col-sm-2 form-group" :initres="$parent.$parent.initres"-->
            <!--                              :show-component="['company','department','operator']" @re-res="$parent.$parent.getRes"-->
            <!--                              v-ref:sel></res-select-group>-->
            <div class="form-group col-sm-2">
              <label class="font_normal_body">操作日期</label>
              <datepicker id="f_operate_datestarthate" placeholder="开始日期"
                          v-model="model.f_operate_datestarthate"
                          :value.sync="model.f_operate_datestarthate"
                          format="yyyy-MM-dd"
                          condition="f_operate_date >= '{}'"
                          style="width:60%">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
              <datepicker id="f_operate_dateendDate" placeholder="结束日期"
                          v-model="model.f_operate_dateendDate"
                          :value.sync="model.f_operate_dateendDate"
                          format="yyyy-MM-dd"
                          condition=" f_operate_date <= '{}'"
                          style="width:60%">
              </datepicker>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th>
              <nobr>客户编号</nobr>
            </th>
            <th>
              <nobr>客户姓名</nobr>
            </th>
            <th>
              <nobr>客户地址电话</nobr>
            </th>
            <th>
              <nobr>实收金额</nobr>
            </th>
            <th>
              <nobr>不含税金额</nobr>
            </th>
            <th>
              <nobr>发票类型</nobr>
            </th>
            <th>
              <nobr>发票代码</nobr>
            </th>
            <th>
              <nobr>发票流水号</nobr>
            </th>
            <th>
              <nobr>发票号码</nobr>
            </th>
            <th>
              <nobr>发票状态</nobr>
            </th>
            <th>
              <nobr>失败原因</nobr>
            </th>
            <th>
              <nobr>发票类型</nobr>
            </th>
            <th>
              <nobr>开票时间</nobr>
            </th>
            <th>
              <nobr>查看发票</nobr>
            </th>
            <th>
              <nobr>操作</nobr>
            </th>
          </tr>
        </template>
        <template partial='body' :model="model">
          <tr>
            <th style="text-align:center">{{ row.f_userinfo_code }}</th>
            <th style="text-align:center">{{ row.f_user_name }}</th>
            <th style="text-align:center">{{ row.f_buy_address_phone }}</th>
            <th style="text-align:center">{{ row.f_total_money }}</th>
            <th style="text-align:center">{{ row.f_tax_money }}</th>
            <th style="text-align:center">{{ row.f_invoice_category }}</th>
            <th style="text-align:center">{{ row.f_bill_code }}</th>
            <th style="text-align:center">{{ row.f_fpqqlsh }}</th>
            <th style="text-align:center">{{ row.f_bill_number }}</th>
            <th style="text-align:center">{{ row.f_bill_state }}</th>
            <th style="text-align:center">{{ row.f_remessage }}</th>
            <th style="text-align:center">{{ row.f_charge_type }}</th>
            <th style="text-align:center">{{ row.f_operate_date }}</th>
            <th style="text-align:center">
<!--              <button class="btn btn-link" v-if="row.f_local_bill_url || row.f_bill_url"-->
<!--                      @click="$parent.$parent.$parent.watch_ch(row.f_local_bill_url || row.f_bill_url)">-->
<!--                查看发票-->
<!--              </button>-->
              <button class="btn btn-link" v-if="row.f_bill_url"
                      @click="$parent.$parent.$parent.watch_ch( row.f_bill_url)">
                查看发票
              </button>
            </th>
            <th style="text-align:center">
              <template v-if="row.f_invoice_source !== '外部录入'">
                <button class="btn btn-link" v-if="row.f_bill_state==='开票成功'"
                        @click="$parent.$parent.$parent.fp_ch(row)">发票冲红
                </button>
                <button class="btn btn-link" v-if="row.f_bill_state==='待开票'"
                        @click="$parent.$parent.$parent.kp(row)">开票
                </button>
                <button class="btn btn-link" v-if="row.f_bill_state==='开票失败'"
                        @click="$parent.$parent.$parent.kp(row, true)">重新开票
                </button>
<!--                <button class="btn btn-link" v-if="['查询失败','等待查询'].includes(row.f_bill_state)"-->
<!--                        @click="$parent.$parent.$parent.fp_search(row)">电票查询-->
<!--                </button>-->
              </template>
            </th>
          </tr>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <modal v-if="show" :show.sync="show" v-ref:modal backdrop="false">
    <header slot="modal-header" class="modal-header">
      <h4 class="modal-title">撤销原因</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <validator name='v'>
        <form class="form-horizontal select-overspread">
          <div class="form-group" :class="[$v.f_cancel_reason.required ? 'has-error' : 'has-success']">
            <label class=" col-sm-3 control-label">冲红备注:</label>
            <div class="col-sm-8">
                    <textarea class="form-control" v-model="bz" rows="3"
                              placeholder="请填写冲红备注" v-validate:bz='{required: true}'></textarea>
            </div>
          </div>
        </form>
      </validator>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button v-show="show" type="button" class="button_search" @click='confirm()' :disabled="!$v.valid ">确认</button>
      <button v-show="show" type="button" class="button_clear" @click='close'>取消</button>
    </footer>
  </modal>
  <ticket-print :show="eticket_show" @toggle="eticket_toggle" v-ref:eticketbill></ticket-print>
</template>
<script>

import {PagedList} from 'vue-client'

export default {
  title: '发票管理',
  data () {
    return {
      model: new PagedList('rs/sql/eticket_query', 20),
      criteriaShow: false,
      eticket_show: false,
      orgCondtionStr: '',
      showsum_show: false,
      invoiceTypes: [{label: '专用发票', value: '专用发票'}, {label: '普通发票', value: '普通发票'}, {label: '国税发票', value: '国税发票'}],
      eticktypes: [{label: '开票成功', value: '开票成功'}, {label: '等待查询', value: '等待查询'}, {
        label: '开票失败',
        value: '开票失败'
      }, {
        label: '冲红失败',
        value: '冲红失败'
      }, {label: '冲红', value: '冲红'}, {label: '撤销', value: '撤销'}],
      show: false,
      bz: '',
      row: {},
      install_show: false
    }
  },
  ready () {
  },
  methods: {
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    selfSearch (args) {
      this.model.search(args.condition, args.model)
    },
    async confirm () {
      // row
      this.eticket_show = true
      await this.$refs.eticketbill.rushRedInvoice(this.row.sell_id, this.row.id, this.row, this.row.f_charge_type, this.row.f_invoice_type)
    },
    async fp_search (row) {
      this.eticket_show = true
      await this.$refs.eticketbill.fp_search(row, row.id)
    },
    watch_ch (src) {
      this.eticket_show = true
      this.$refs.eticketbill.watch_ch(src)
    },
    fp_ch (row) {
      this.row = row
      this.show = true
      this.bz = `对应正数发票代码:${row.f_bill_code}，号码:${row.f_bill_number}。`
    },
    close () {
      this.show = false
      this.install_show = false
    },
    kp (row, retry = false) {
      this.eticket_show = true
      this.$refs.eticketbill.openETicket(row.sell_id, row, '否', '征税', row.f_charge_type, row.f_invoice_type, retry)
    },
    eticket_toggle () {
      this.eticket_show = false
      this.show = false
      this.row = {}
      this.bz = ''
    }
  },
  computed: {
  },
  events: {
    'search' () {
      this.search()
    }
  },
  watch: {}
}
</script>
<style scoped>
th {
  text-align: center;
  padding: 2px;
}

td {
  text-align: center;
  padding: 2px;
}
</style>
