<template>
  <div class="basic-main" style="height: 100%">
    <criteria-paged :model="model" :pager='false' v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial >
          <div class="row">
            <div class="col-sm-2" >
              <label class="font_normal_body" for="startDate">开始日期:</label>
              <datepicker id="startDate" placeholder="开始日期" style="width: 60%"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2" >
              <label  class="font_normal_body" for="endDate">结束日期:</label>
              <datepicker id="endDate" placeholder="结束日期" style="width: 60%"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <res-select-group :show-component="['company','operator']" :initres="$parent.$parent.initres"  @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
<!--            <div class="col-sm-3 form-group" >-->
<!--              <label class="font_normal_body" for="org">公&emsp;&emsp;司:</label>-->
<!--              <right-tree id="org" @re-res="$parent.$parent.getRes" style="width: 60%"-->
<!--              ></right-tree>-->
<!--            </div>-->
<!--            <div class="col-sm-2 form-group">-->
<!--              <label class="font_normal_body" for="oper">人&emsp;&emsp;员:</label>-->
<!--              <v-select id="oper" style="width: 60%"-->
<!--                          :multiple="false"-->
<!--                        @change="$parent.$parent.getOpe"-->
<!--                          :value.sync="model.f_operatorid"-->
<!--                            v-model="model.f_operatorid"-->
<!--                        :options='$parent.$parent.userresid' placeholder='请选择'-->
<!--                        condition="f_operatorid in {}">-->
<!--              </v-select>-->
<!--            </div>-->
            <div class="col-sm-2 form-group">
              <label class="font_normal_body" title="参数:付款方式查询">付款方式</label>
              <v-select :value.sync="model.f_payment" multiple
                        v-model="model.f_payment"
                        :options='$parent.$parent.payment' placeholder='请选择'
                        condition="f_payment in {}"
                        close-on-select></v-select>
            </div>
          </div>
          <div class="span" style = "float:right;">
            <button class="button_search" @click="$parent.$parent.searchData()">查询</button>
            <report-print id='gasprice' top='3cm' left='0' width='100%' height='100%' :preview="true"></report-print>
            <report-excel id='gasprice'></report-excel>
          </div>
        </div>
      </criteria>
      <div  partial='list' v-el:handcollect id='gasprice' style="overflow-y: scroll">
        <table class='tableprint' style="margin: 0px auto">
          <thead>
          <tr>
            <th :colspan='$parent.tablen' style="font-weight: normal; text-align: left;">
              <h3 style="text-align: center">操作员收款日结账单</h3>
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.tablen' style="font-weight: normal; text-align: center;">
              时间区间：{{$refs.criteria.model.startDate}} - {{ $refs.criteria.model.endDate }}<br/>
              打印时间：{{$parent.printTime}}
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.tablen' style="font-weight: normal; text-align: center;">
              <div>
                <span v-show="$parent.orgname[0]">公司：{{$parent.orgname}}</span>
                <span v-show="$parent.depname[0]"> 部门：{{$parent.depname}}</span>
                <span v-show="$parent.operatorname[0]">人员：{{$parent.operatorname}}</span>
              </div>
            </th>
          </tr>
          </thead>
          <tr>
            <td :colspan='$parent.tablen' class="noborder">
              {{{ model.data.substring(26,model.data.length-8) }}}
            </td>
          </tr>
          <tfoot>
          <tr style="text-align: left">
            <th :colspan='Math.floor($parent.tablen/3)'>财务审核：</th>
            <th :colspan='Math.round($parent.tablen/3)'>收款审核：</th>
            <th :colspan='Math.round($parent.tablen/3)'>收款员：</th>
          </tr>
          </tfoot>
        </table>
      </div>
    </criteria-paged>
  </div>
</template>

<script>
import {DataModel, HttpResetClass} from 'vue-client'
  import co from 'co'

let getData = function * (self) {
    new HttpResetClass().load("POST",'api/af-revenue/sql/manageSingleTable',
    {
      data: {
        tablename: 't_user',
        condition: `1=1`
      }
    },
    {resolveMsg: null, rejectMsg: null})
    .then((res) => {
      self.userresid = res.data.map(x => {
        return {label: x.name , value: x.id}
      })
    })
}
  export default {
    title: '操作员收款日结账单',
    props: ['data'],
    data () {
      return {
        printTime: this.$login.toStandardTimeString(),
        depresid: [],
        userresid: [],
        initres: {
          org:[this.$login.f.orgid],
          user:[]
        },
        //f_orgid: '',
        // f_depid: this.$login.f.depids,
        // f_operatorid: '',
        // operatorid: [],
        // depid: [],
        tablen: 0,
        orgname: '',
        // depname: '',
        operatorname: '',
        orgCondtionStr: '',
        model: new DataModel('api/af-revenue/report/chargePrick', {startDate: 'this.model.startDate', endDate: 'this.model.endDate',
          f_orgid: 'this.model.f_orgid'}),
        reportStr: null,
        show: false,
      }
    },
    ready () {
      let load = new HttpResetClass()
      load.load("POST",'api/af-revenue/sql/singleTableParam',
        {
          data: {
            items: 'name label,id value',
            tablename: 't_user',
            condition: `state = '在职' and f_department_name is not null`
          }
        },
        {resolveMsg: null, rejectMsg: null})
        .then((res) => {
          this.userresid = res.data
        })
      this.$refs.paged.$refs.criteria.model.startDate = this.$login.toStandardDateString() + ' 00:00:00'
      this.$refs.paged.$refs.criteria.model.endDate = this.$login.toStandardDateString() + ' 23:59:59'
      console.log(this.$login.f)
    },
    methods: {
      searchData () {
        this.$refs.paged.$refs.criteria.search()
      },
      selfSearch (args) {
        this.printTime = this.$login.toStandardTimeString()

        let orgcondition = '1 = 1'
        if (this.orgCondtionStr) {
          orgcondition += this.orgCondtionStr
        }
        this.$refs.paged.$refs.criteria.model.f_orgid = orgcondition
        this.$refs.paged.search(args)
      },
      getRes (condition,obj) {
        console.log('gs>>>>>>>>>>>>', obj)
        this.orgCondtionStr = condition
        this.orgname = obj.orgnames.map(item => item.split('-')[0]).toString()
        this.operatorname = this.userresid.filter(x => obj.operatornames.includes(x.value)).map(x=>x.label).toString()

      }
    },
    watch: {
      'model.data' (val) {
        this.tablen = val.split('</tr>').map(item => item.split('</td>').length-1).reduce((x, y) => x > y ? x : y)
      }
    },
    computed: {
      payment() {
        return [...this.$appdata.getParam('付款方式查询')]
      }
    }
  }
</script>
<style scoped>
  .noborder{
    border: none;
  }
</style>
