<template>
  <div id="meterInfoTest">
    <div style="flex: 1.5" class="flex"  >
      <div class="flex">
        <criteria-paged :model="model" v-ref:paged>
          <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch"
                    v-show="$parent.searchshow">
            <div novalidate class="form-inline auto" style="background-color: white" partial>
              <div class="row">
                <res-select-group  :show-component="['company']" :initres="$parent.$parent.initres"  @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
                <div class="col-sm-3 form-group" >
                  <label for="f_input_date" class="font_normal_body">开始日期</label>
                  <datepicker  placeholder="开始日期" style="width:60%"
                               v-model="model.f_startDate"
                               :value.sync="model.f_startDate"
                               :format="'yyyy-MM-dd HH:mm:ss'"
                               class="datepicker"
                               cond-value="f_hand_date >= '{}'"
                               :show-reset-button="true"
                               class="select"
                  >
                  </datepicker>
                </div>
                <div class="col-sm-3 form-group" >
                  <label for="f_input_date" class="font_normal_body">结束日期</label>
                  <datepicker  placeholder="结束日期" style="width:60%"
                               v-model="model.f_endDate"
                               :value.sync="model.f_endDate"
                               :format="'yyyy-MM-dd HH:mm:ss'"
                               class="datepicker"
                               cond-value="f_hand_date <= '{}'"
                               :show-reset-button="true"
                  >
                  </datepicker>
                </div>
                <div class="col-sm-3 form-group">
                  <label class="font_normal_body">抄&ensp;表&ensp;员</label>
                  <v-select :value.sync="model.f_inputtor" v-model='model.f_inputtor'
                            style="width:60%"
                            cond-value="f_inputtor = '{}'"
                            :options='$parent.$parent.inputtores' placeholder='抄表员'
                            close-on-select
                            v-el:cc></v-select>
                </div>
                <div class="span" style="float:right;">
                  <button class="button_search" @click="search()">查 询</button>
                  <export-excel :data="{condition: $parent.$parent.condition,condValue: $parent.$parent.condValueStr}"
                                :field="$parent.$parent.getfield"
                                sqlurl="rs/logic/saleExport" sql-name="inputtorSummary"
                                template-name='抄表记录'
                                :choose-col="true"></export-excel>
                  <div
                    :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                    @click="$parent.$parent.hidden()" class="button_spacing" style="float: right"></div>
                </div>
              </div>
              <div class="row" v-show="$parent.$parent.criteriaShow">
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body" for="f_meter_classify">气表类型</label>
                  <v-select :options='$parent.$parent.meterType'
                            :value.sync="model.f_meter_classify"
                            default-value="'机表'"
                            close-on-select cond-value="f_meter_classify = '{}'"
                            placeholder='气表类型' value-single="true"
                            style="width: 60%"  v-model="model.f_meter_classify"></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body" for="f_hand_state">抄表状态</label>
                  <v-select :value.sync="model.f_hand_state"
                            :options='$parent.$parent.handstate'
                            default-value="'有效'"
                            placeholder='状态' close-on-select
                            cond-value="f_hand_state = '{}'"
                            search v-model='model.f_hand_state' v-ref:brand></v-select>
                </div>
              </div>
            </div>
          </criteria>
          <data-grid :model="model" v-ref:grid class="list_area table_sy" partial='list'>
            <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>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">{{$index + 1}}</td>
              <td style="text-align: center;"><nobr>{{row.f_inputtor}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.todo_count}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.done_count}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.image_count}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.manual_count}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.auto_count}}</nobr></td>
            </template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

<script>
import {PagedList} from 'vue-client'
import {toStartAndEndDateString} from '../../Util'
export default {
  'title': '抄表员抄表汇总',
  data () {
    return {
      model: new PagedList('rs/sql/inputtorSummary', 20),
      // 控制查询条件显示
      searchshow: true,
      // 公司下拉
      initres: {
        org: [this.$login.f.orgid],
        dep: [],
        user: []
      },
      f_filialeid: this.$login.f.f_orgid,
      allorgid: [],
      f_orgid: '',
      criteriaShow: false,
      condition: '',
      getfield: {
        'f_inputtor': '抄表员',
        'todo_count': '任务待办数',
        'done_count': '总提交数',
        'image_count': '照片数量',
        'manual_count': '手动录入数量',
        'auto_count': '自动识别数量'
      },
      inputtores: [{label: '全部', value: ''}],
      meterType: [{label: '全部', value: ''},{label: '机表', value: '机表'},{label: '气量卡表', value: '气量卡表'},{label: '金额卡表', value: '金额卡表'}],
      orgCondtionStr: '',
      condValueStr: ''
    }
  },
  async ready () {
    this.$refs.paged.$refs.criteria.model.f_startDate = this.$login.toStartAndEndDateString()[0] + ' 00:00:00'
    this.$refs.paged.$refs.criteria.model.f_endDate = this.$login.toStandardDateString() + ' 23:59:59'
    this.search()
    await this.getinputtores()
    this.$refs.paged.$refs.criteria.search()
  },
  methods: {
    async updateParams () {
      console.log('重新加载抄表员！！！！！', this.f_filialeid)
      await this.$LoadParams.loadParam(this.f_filialeid)
      await this.$GetSaleParam.initinputtor()
      this.inputtores = []
      this.inputtores.push({label: '全部', value: ''})
      this.inputtores.push({label: '微信公众号', value: '微信公众号'})
      if (this.allorgid != null) {
        this.allorgid.forEach((res) => {
          this.inputtores = this.inputtores.concat(this.$GetSaleParam.getresinputtor(res))
        })
      }
    },

    async getinputtores () {
      // 获取抄表员
      let rs = []
      if (this.$login.f.f_gasman.length > 0) {
        for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
          let temp = {
            label: this.$login.f.f_gasman[i].name,
            value: this.$login.f.f_gasman[i].name
          }
          rs.push(temp)
        }
      }
      this.inputtores = [{label: '全部', value: ''}, ...rs]
      await this.$LoadParams.loadParam(this.$login.f.orgid)
    },
    async getRes (condition, obj) {
      this.orgCondtionStr = condition
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    search () {
      this.$refs.paged.$refs.criteria.search()
    },
    selfSearch (args) {
      console.log('>>> args = ', args)
      if (!this.f_orgid) {
        this.f_orgid = this.$login.f.orgid
      }
      let f_orgstr = this.orgCondtionStr ? this.orgCondtionStr : "and h.f_orgid in ('" + this.f_orgid + "')"
      args.condValueStr = `${args.condValueStr === undefined ? '1=1' : args.condValueStr} ` + f_orgstr
      this.model.search(args.condition, args.model, args.condValueStr)
      this.condition = args.condition
      this.condValueStr = args.condValueStr
    }
  },
  watch: {
    async 'orgCondtionStr' (val) {
      let res = val.match(/'(.*?)'/)
      this.$refs.paged.$refs.criteria.model.f_inputtor = []
      console.log('正则提取:', res && res[1])
      if (res) {
        this.f_filialeid = res[1]
        if (res.input != null) {
          let resorgid = res.input.substring(res.input.indexOf("'"))
          if (resorgid != null && resorgid != '') {
            resorgid = resorgid.substring(0, resorgid.lastIndexOf("'") + 1)
            // resorgid = resorgid.replaceAll("'","");
            resorgid = resorgid.replace(/'/g, '')
            this.allorgid = resorgid.split(',')
          }
        }
        this.updateParams()
      }
    }
  },
  computed: {
    handstate () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('表单状态')]
    }
  }
}
</script>
<style >
.datapanel {
  color: #333;
  background-color: white;
  padding: 10px 20px;
  border-radius: 15px;
}
</style>

