<template>
  <div id="unit" class="flex-row">
    <div class="basic-main">
      <div class="flex">
        <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="col-sm-2">
                  <label for="startDate" class="font_normal_body">开始日期</label>
                  <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_input_date >= '{} 00:00:00'">
                  </datepicker>
                </div>
                <div class="col-sm-2">
                  <label for="endDate" class="font_normal_body">结束日期</label>
                  <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_input_date <= '{} 23:59:59'">
                  </datepicker>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">&nbsp;&nbsp;&nbsp;公司&nbsp;&nbsp;&nbsp; </label>
                  <res-select restype='organization'
                              @res-select="$parent.$parent.getRes"
                              :initresid="$parent.$parent.id">
                  </res-select>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">&nbsp;&nbsp;&nbsp;部门&nbsp;&nbsp;&nbsp; </label>
                  <res-select restype='department'
                              is-mul="false"
                              @res-select="$parent.$parent.getdep"
                              :parentresid="$parent.$parent.depresid"
                              :initresid='$parent.$parent.depid'>
                  </res-select>
                </div>
                <div class="span" style="float:right;">
                  <button class="button_search button_spacing" @click="search()">查询</button>
                  <export-excel :data="$parent.$parent.getCondition"
                                :field="$parent.$parent.getfield"
                                sqlurl="rs/logic/exportfile" sql-name="manage_handplanRecord" template-name='抄表(安检户数统计)'
                                ></export-excel>
                  <handplan-print :countmodel="{model:$parent.$parent.model}" :modelval="$parent.$parent.defaultfield"
                                  :fields="$parent.$parent.getfield"></handplan-print>
                </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>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">
                <nobr>{{row.number}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_inputtor}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.jbyc}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.kbyc}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.zyc}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.jbcb}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.kbcb}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.zcb}}</nobr>
              </td>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
        <table class="table-hover">
          <tr style="position: relative" class="table-bordered">
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">
              汇总信息
            </td>
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
              机表应抄户数:&emsp;{{sumsmodel.jbyc}}
            </td>
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
              智能表应抄户数:&emsp;{{sumsmodel.kbyc}}
            </td>
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
              应抄总户数:&emsp;{{sumsmodel.zyc}}
            </td>
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
              机表实抄户数:&emsp;{{sumsmodel.jbcb}}
            </td>
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
              智能表实抄户数:&emsp;{{sumsmodel.kbcb}}
            </td>
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
              实抄总户数:&emsp;{{sumsmodel.zcb}}
            </td>
          </tr>
        </table>

      </div>
    </div>
  </div>
</template>

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

  let readySomething = async function (self) {
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
    self.$refs.paged.$refs.cri.search()
    self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
    self.initParams()

    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
  }
  export default {
    name: "handplan_report",
    title: '抄表(安检户数统计)',
    data() {
      return {
        config: {
          defaultPrint: ['number','f_inputtor','jbyc','kbyc','zyc'
            ,'jbcb','kbcb','zcb']
        },
        show:false,
        depresid: [],
        userresid: [],
        id: [this.$login.f.orgid],
        f_orgid: this.$login.f.orgid,
        f_depid: this.$login.f.depids,
        f_operatorid: this.$login.f.id,
        operatorid: [],
        depid: [],
        orgname: '',
        //合计数据
        sumsmodel: {},
        depname: '',
        operatorname: '',
        defaultfield: [],
        orgCondtionStr: '1=1',
        model: new PagedList('rs/sql/manage_handplanRecord', 20, {},{jbyc: 0,kbyc: 0,zyc: 0,jbcb: 0,kbcb: 0,zcb: 0}),
        criteriaShow: false,
      }
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      cancel() {
        this.show = false
      },
      selfSearch(args) {
        this.orgCondtionStr = 'and f_orgid = ' + this.f_orgid
        if (this.f_depid[0]) {
          this.orgCondtionStr += ' and f_depid = ' + this.f_depid
        }
        args.condition = `${args.condition} ` + this.orgCondtionStr
        this.model.search(args.condition, args.model)
        this.sumsmodel = this.$refs.paged.$refs.grid.model.sums
      },
      clear() {
        //清空部门和人员
        this.$refs.paged.$refs.cri.$refs.sel.$children[1].selectres = []
        //部门和人员变为全选
        this.$refs.paged.$refs.cri.$refs.sel.$children[1].$children[0].isSelectAll = false
        this.$refs.paged.$refs.cri.$refs.sel.$children[2].$children[0].isSelectAll = false
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })

      },
      getRes (obj) {
        this.depresid = obj
        this.f_orgid = obj
      },
      getdep (obj, val) {
        // this.depname = val[0]
        this.userresid = obj
        this.f_depid = obj
      }
    },
    watch: {
      'orgCondtionStr'(val) {
        let res = val.match(/'(.*?)'/)
        console.log('正则提取:',res && res[1])
        if (res) {
          this.f_filialeid = res[1]
          this.updateParams()
        }
      }
    },
    computed: {
      getCondition() {
        return {condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr}
      },
      getfield() {
        return {
          'number':'序号','f_inputtor':'户管员','jbyc':'机表应抄户数','kbyc':'智能表应抄户数','zyc':'应抄总户数','jbcb':'机表实抄户数',
          'kbcb':'智能表实抄户数','zcb':'实抄总户数'
        }
      }
    }
  }
</script>
