<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>

          </div>
          <div class="span" style="float:right;">
            <button class="button_search" @click="$parent.$parent.searchData()">查询</button>
            <report-print id='gasprice4' top='1cm' left='0' width='100%' height='100%' :preview="true"></report-print>
            <report-excel id='gasprice4'></report-excel>
          </div>
        </div>
      </criteria>
      <div partial='list' v-el:handcollect id='gasprice4' style="overflow-y: scroll">
        <table class='tableprint' style="margin: 0px auto">
          <thead>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: left;">
              <h3 style="text-align: center">工程部安装户数月度报表</h3>
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: center;">
              开始时间：{{ model.model.startDate }}&nbsp;&nbsp;&nbsp;
              结束时间：{{ model.model.endDate }}
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: center;">
              打印时间：{{ $parent.printTime }}
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: center;">
              <div>
                <span v-show="$parent.orgname.trim()!=''">公司：{{ $parent.orgname }}</span>
                <span v-show="$parent.depname.trim()!=''"> 部门：{{ $parent.depname }}</span>
                <span v-show="$parent.operatorname.trim()!=''">人员：{{ $parent.operatorname }}</span>
              </div>
            </th>
          </tr>
          </thead>
        </table>
        <table class='tableprint' style="margin: 0px auto">
          <tbody>
          <tr>
            <td class="tdcenter report-primary" width="100" height="60" rowspan="2">类别\项目</td>
            <td class="tdcenter report-primary" width="300" height="30" colspan="3">用户报装</td>
          </tr>
          <tr>
            <td class="tdcenter report-primary" width="100" height="30">报建性质</td>
            <td class="tdcenter report-primary" width="100" height="30">煤改用户</td>
            <td class="tdcenter report-primary" width="100" height="30">普通用户</td>
          </tr>
          <tr>
            <td class="tdcenter bg-info" width="100" height="60" rowspan="2">民用用户</td>
            <td class="tdcenter bg-info" width="100" height="30">{{ model.data.minYong[0] ? model.data.minYong[0].f_apply_nature:'小区' }}</td>
            <td class="tdcenter bg-info" width="100" height="30">
              {{ model.data.minYong[0] ? model.data.minYong[0].meigai_hetong_housecount ? model.data.minYong[0].meigai_hetong_housecount : '0' :'0' }}
            </td>
            <td class="tdcenter bg-info" width="100" height="30">
              {{ model.data.minYong[0] ? model.data.minYong[0].putong_hetong_housecount ? model.data.minYong[0].putong_hetong_housecount : '0' :'0' }}
            </td>
          </tr>
          <tr>
            <td class="tdcenter bg-info" width="100" height="30">{{ model.data.minYong[1] ? model.data.minYong[1].f_apply_nature:'散户' }}</td>
            <td class="tdcenter bg-info" width="100" height="30">
              {{ model.data.minYong[1] ? model.data.minYong[1].meigai_hetong_housecount ? model.data.minYong[1].meigai_hetong_housecount : '0' :'0' }}
            </td>
            <td class="tdcenter bg-info" width="100" height="30">
              {{ model.data.minYong[1] ? model.data.minYong[1].putong_hetong_housecount ? model.data.minYong[1].putong_hetong_housecount : '0' :'0' }}
            </td>
          </tr>
          <tr>
            <td class="tdcenter bg-info" width="100" height="30">非居用户</td>
            <td class="tdcenter bg-info" width="100" height="30">{{ model.data.feiMinYong[0] ? model.data.feiMinYong[0].f_apply_nature:'商业' }}</td>
            <td class="tdcenter bg-info" width="100" height="30">
              {{ model.data.feiMinYong[0] ? model.data.feiMinYong[0].meigai_hetong_housecount ? model.data.feiMinYong[0].meigai_hetong_housecount : '0' : '0' }}
            </td>
            <td class="tdcenter bg-info" width="100" height="30">
              {{ model.data.feiMinYong[0] ? model.data.feiMinYong[0].putong_hetong_housecount ? model.data.feiMinYong[0].putong_hetong_housecount : '0' :'0' }}
            </td>
          </tr>
          <tr>
            <td class="tdcenter bg-info" width="100" height="30">合计</td>
            <td class="tdcenter bg-info" width="100" height="30">0</td>
            <td class="tdcenter bg-info" width="100" height="30">{{ $parent.sumMeiGai }}</td>
            <td class="tdcenter bg-info" width="100" height="30">{{ $parent.sumPuTong }}</td>
          </tr>
          <tr>
            <td class="tdcenter report-primary" width="100" height="30" colspan="2">设备名称</td>
            <td class="tdcenter report-primary" width="100" height="30" colspan="1">设备数量</td>
            <td class="tdcenter report-primary" width="100" height="30" colspan="1">设备吨位</td>
          </tr>
          <tr style="text-align: center;" v-for="i in model.data.sheBei.length">
            <td class="tdcenter bg-info" width="100" height="30" colspan="2">{{$parent.model.data.sheBei[i].f_devices_type}}</td>
            <td class="tdcenter bg-info" width="100" height="30" colspan="1">{{$parent.model.data.sheBei[i].f_devices_num}}</td>
            <td class="tdcenter bg-info" width="100" height="30" colspan="1">{{$parent.model.data.sheBei[i].f_devices_tonnage}}</td>
          </tr>
          </tbody>
          <tfoot>
          </tfoot>
        </table>
      </div>
    </criteria-paged>
  </div>
</template>

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

export default {
  title: '工程部安装户数月度报表',
  props: ['data'],
  data() {
    return {
      printTime: this.$login.toStandardTimeString(),
      depresid: [],
      userresid: [],
      f_orgid: this.$login.f.orgid,
      f_depid: this.$login.f.depids,
      f_operatorid: this.$login.f.id,
      operatorid: [],
      depid: [],
      orgname: '',
      depname: '',
      operatorname: '',
      f_inputtor: [],
      f_user_type: '',
      orgCondtionStr: '1=1',
      model: new DataModel('rs/logic/getGongCheng', {startDate: 'this.model.startDate', endDate: 'this.model.endDate'}),
      reportStr: null,
      spans: 0,
      sumMeiGai: 0,
      sumPuTong: 0
    }
  },
  ready() {
    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'
  },
  methods: {
    searchData() {
      this.$refs.paged.$refs.criteria.search()
    },
    selfSearch(args) {
      let orgcondition = 'f_orgid in (' + this.f_orgid + ')'
      this.$refs.paged.$refs.criteria.model.f_orgid = orgcondition
      this.$refs.paged.search(args)
    },
    getRes(obj) {
      this.orgname = obj.res[0]
      // this.depresid = obj.resids
      this.f_orgid = obj.resids
    }
  },
  watch: {
    'model.data' (val) {
      for (let i = 0; i < val.minYong.length; i++) {
        this.sumMeiGai += val.minYong[i].meigai_hetong_housecount
        this.sumPuTong += val.minYong[i].putong_hetong_housecount
      }
      for (let i = 0; i < val.feiMinYong.length; i++) {
        this.sumMeiGai += val.feiMinYong[i].meigai_hetong_housecount
        this.sumPuTong += val.feiMinYong[i].putong_hetong_housecount
      }
      console.log('当前显示' + this.sumMeiGai + '传参' + this.sumPuTong)
    }
  },
  computed: {}
}
</script>
<style scoped>
.noborder {
  border: none;
}
</style>
