<template>
  <div id="unit" class="flex-row">
    <div class="basic-main">
      <div class="flex" v-if="!show">
        <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 form-group">
                  <label class="font_normal_body">&emsp;公&emsp;&emsp;司</label>
                  <right-treee @re-res="$parent.$parent.getorg"
                              :initresid='$parent.$parent.org'></right-treee>
                </div>

                <div class="col-sm-2 form-group ">
                  <label v-if="$parent.$parent.meter_classify == '卡表'" for="startDate" class="font_normal_body">&emsp;购气开始</label>
                  <label v-else for="startDate" class="font_normal_body">&emsp;抄表开始</label>
                  <datepicker id="startDate" placeholder="开始日期"
                              v-model="model.startDate"
                              style="width:60%"
                              :value.sync="model.startDate"
                              :disabled-days-of-Week="[]"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="reset">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group ">
                  <label v-if="$parent.$parent.meter_classify == '卡表'" for="startDate" class="font_normal_body">&emsp;购气结束</label>
                  <label v-else for="startDate" class="font_normal_body">&emsp;抄表结束</label>
                  <datepicker id="endDate" placeholder="结束日期"
                              v-model="model.endDate"
                              style="width:60%"
                              :value.sync="model.endDate"
                              :disabled-days-of-Week="[]"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="reset">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group ">
                  <label for="f_meter_classify"class="font_normal_body">&emsp;&emsp;表类型</label>
                  <v-select id="f_meter_classify"
                            v-model="$parent.$parent.meter_classify"
                            placeholder='表类型'
                            style="width:70%"
                            :value.sync="$parent.$parent.meter_classify"
                            :options='$parent.$parent.f_meter_classify'
                            condition="f_meter_type like '%{}'"
                            :value-single="true"
                            close-on-select >
                  </v-select>
                </div>
                <div class="span" style="float:right;">
                  <button class="btn button_search" @click="search()">查询</button>
                  <button class="btn button_clear" @click="$parent.$parent.clear()">清空</button>
                  <export-excel :data="$parent.$parent.getCondition"
                                :field="$parent.$parent.getfield"
                                :footer="$parent.$parent.footer"
                                :header="$parent.$parent.other"
                                sqlurl="api/af-revenue/logic/openapi/exportfile"
                                :sql-name="$parent.$parent.sqlName"
                                template-name='购气稽查导出'  :choose-col="true"></export-excel>
                  <print-data :model="$parent.model" :field="$parent.$parent.getfield" :defaultfield="$parent.$parent.defaultfield" print-name="稽查查询打印" :sumsmodel="$parent.$parent.sumsmodel" ></print-data>
                  <div style="float: right"  class="button_spacing" :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"    @click="$parent.$parent.hidden()"></div>
                </div>
              </div>
              <div class="row" v-show="$parent.$parent.criteriaShow">
                <div class="col-sm-2 form-group ">
                  <label class="font_normal_body">&emsp;用户类型</label>
                  <v-select :value.sync="model.f_user_type"
                            @change="$parent.$parent.userTypeChange()"
                            :options='$parent.$parent.usertypes' placeholder='请选择' v-model="model.f_user_type"
                            condition="f_user_type = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group ">
                  <label for="f_gasproperties"class="font_normal_body">&emsp;用气性质</label>
                  <v-select id="f_gasproperties"
                            style="width:60%"
                            v-model="model.f_gasproperties"
                            placeholder='用气性质'
                            :value.sync="model.f_gasproperties"
                            :options='$parent.$parent.gasproperties'
                            condition="f_gasproperties = '{}'"
                            close-on-select >
                  </v-select>
                </div>
                <div class="col-sm-2 form-group" >
                  <label class="font_normal_body">二级用气性质</label>
                  <v-select
                    placeholder='二级用气性质'
                    value-single="true"
                    :value.sync="model.f_gasproperties2"
                    v-model="model.f_gasproperties2"
                    :options='this.$appdata.getParam(model.f_gasproperties)?this.$appdata.getParam(model.f_gasproperties):[]'
                    close-on-select condition="f_gasproperties2 {}">
                  </v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">气价类型</label>
                  <v-select :value.sync="model.pricetype" v-model="model.pricetype"
                            placeholder='气价类型' :options="$parent.$parent.pricetypes"
                            condition="f_price_type = '{}'"
                            close-on-select v-ref:type>
                  </v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">气价名称</label>
                  <v-select :value.sync="model.f_price_name"
                            v-model="model.f_price_name"
                            :options="$parent.$parent.getPricenames"
                            condition="f_price_name = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&emsp;气表品牌</label>
                  <v-select :value.sync="model.f_meter_brand"
                            v-model="model.f_meter_brand"
                            :options='$parent.$parent.meterbrands' placeholder='请选择'
                            condition="f_meter_brand = '{}'"
                            close-on-select></v-select>
                </div>

                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">气表型号</label>
                  <v-select :value.sync="model.f_meter_style"
                            v-model="model.f_meter_style"
                            :options='$parent.$parent.meterstyle[model.f_meter_brand]' placeholder='请选择'
                            condition="f_meter_style = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body" title="旧客户编号">&emsp;档案编号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_olduserinfo_code"
                         condition="f_olduserinfo_code = '{}' " placeholder="档案编号">
                </div>
                <div class="col-sm-2 form-group ">
                  <label for="contain_newfile" class="font_normal_body">包含新开户</label>
                  <v-select id="contain_newfile"
                            v-model="model.contain_newfile"
                            style="width:60%"
                            :value.sync="model.contain_newfile"
                            :options='$parent.$parent.contain_newfiles'
                            :value-single="true"
                            close-on-select >
                  </v-select>
                </div>
                <div class="col-sm-2 form-group" >
                  <label  for="f_user_state" class="font_normal_body">&emsp;客户状态</label>
                  <v-select :value.sync="model.f_user_state"
                            v-model="model.f_user_state"
                            :options='$parent.$parent.userstate' placeholder='请选择'
                            condition="f_user_state = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group ">
                  <label for="f_table_state"class="font_normal_body">&emsp;&emsp;表状态</label>
                  <v-select id="f_table_state"
                            style="width:60%"
                            v-model="model.f_table_state"
                            placeholder='表状态'
                            :value.sync="model.f_table_state"
                            :options='$parent.$parent.tablestate'
                            condition="f_table_state = '{}'"
                            close-on-select >
                  </v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&emsp;&emsp;&emsp;表号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_meternumber"
                         condition="f_meternumber = '{}'" placeholder='表号'>
                </div>

                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&emsp;客户名称</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                         condition="f_user_name like '%{}%'" placeholder="客户名称">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&emsp;客户编号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code"
                         condition="f_userinfo_code like '%{}%' " placeholder="客户编号">
                </div>


                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&nbsp;&nbsp;&nbsp;小区&nbsp;&nbsp;&nbsp;</label>
                  <v-select :value.sync="model.f_residential_area"
                            class="select_list select"
                            enter-push
                            multiple = "true"
                            v-model="model.f_residential_area"
                            style="width: 60%"
                            :options='$parent.$parent.residentialArea' placeholder='选择小区'
                            close-on-select>

                  </v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&nbsp;&nbsp;&nbsp;街道&nbsp;&nbsp;&nbsp;</label>
                  <v-select :value.sync="model.f_street"
                            class="select_list select"
                            enter-push
                            :multiple = "true"
                            v-model="model.f_street"
                            style="width: 60%"
                            :options='$parent.$parent.street' placeholder='选择街道'
                            condition="f_street in {}"
                            close-on-select>

                  </v-select>
                </div>

                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&emsp;客户地址</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_address"
                         condition="f_address like '%{}%'" placeholder='客户地址'>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&emsp;客户电话</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_user_phone"
                         condition="f_user_phone like '%{}%'" placeholder="客户电话">
                </div>

                <div class="col-sm-2 form-group">
                  <label for="startOpenDate" class="font_normal_body" title="开户开始日期">开户时间</label>
                  <datepicker id="startOpenDate" placeholder="开户开始日期" style="width:60%"
                              v-model="model.startOpenDate"
                              :value.sync="model.startOpenDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_open_date >= '{} 00:00:00'">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <label for="endOpenDate" class="font_normal_body" title="开户结束日期">&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                  <datepicker id="endOpenDate" placeholder="开户结束日期" style="width:60%"
                              v-model="model.endOpenDate"
                              :value.sync="model.endOpenDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_open_date <= '{} 23:59:59'">
                  </datepicker>
                </div>
                <!--区域-->
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&emsp;&emsp;&emsp;区域</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_pcd"
                         condition="f_pcd like '%{}%'" placeholder='区域'>
                </div>
                <!--换表日期-->
                <div class="col-sm-2 form-group">
                  <label for="startDate" class="font_normal_body" title="换表开始日期">换表日期</label>
                  <datepicker id="changemeterstartDate" placeholder="换表开始日期" style="width:60%"
                              v-model="model.startchangemeterDate"
                              :value.sync="model.startchangemeterDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_changemeter_date >= '{} 00:00:00'">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <label for="endDate" class="font_normal_body" title="换表结束日期">&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                  <datepicker id="changemeterendDate" placeholder="换表结束日期" style="width:60%"
                              v-model="model.endchangemeterDate"
                              :value.sync="model.endchangemeterDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_changemeter_date <= '{} 23:59:59'">
                  </datepicker>
                </div>


                <div   class="col-sm-2 flex-row" style="white-space: nowrap">
                  <label  class="font_normal_body">&emsp;期间次数</label>
                  <div class="row">
                    <input type="text" style="width:30%" class="input_search" v-model="model.sellcishumin"
                           condition="sellcishu >= {} " placeholder="">
                    <label   class="font_normal_body">  ≤ x ≤ </label>
                    <input type="text" style="width:30%" class="input_search" v-model="model.sellcishumax"
                           condition="sellcishu <= {} " placeholder="">
                  </div>
                </div>
                <div  class="col-sm-2 flex-row" style="white-space: nowrap">
                  <label  class="font_normal_body">期间购气量</label>
                  <div class="row">
                    <input type="text" style="width:30%" class="input_search" v-model="model.sellpregasmin"
                           condition="sellpregas >= {} " placeholder="">
                    <label   class="font_normal_body">  ≤ x ≤ </label>
                    <input type="text" style="width:30%" class="input_search" v-model="model.sellpregasmax"
                           condition="sellpregas <= {} " placeholder="">
                  </div>
                </div>

                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">是否煤改气</label>
                  <v-select :value.sync="model.f_is_mgq"
                            :options='$parent.$parent.ismgq'
                            placeholder='请选择'
                            v-model="model.f_is_mgq"
                            condition="f_is_mgq = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">是否空置户</label>
                  <v-select :value.sync="model.f_is_vacant"
                            :options='$parent.$parent.isvacant'
                            placeholder='请选择'
                            v-model="model.f_is_vacant"
                            condition="f_is_vacant = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">是否孤寡老人</label>
                  <v-select :value.sync="model.f_is_alone"
                            :options='$parent.$parent.isalone'
                            placeholder='请选择'
                            v-model="model.f_is_alone"
                            condition="f_is_alone = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">是否空房</label>
                  <v-select :value.sync="model.f_is_empty"
                            :options='$parent.$parent.isempty'
                            placeholder='请选择'
                            v-model="model.f_is_empty"
                            condition="f_is_empty = '{}'"
                            close-on-select></v-select>
                </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>
                <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 v-show="$parent.$parent.$parent.meter_classify == '卡表'"><nobr>总购气次数</nobr></th>-->
    <!--            <th v-show="$parent.$parent.$parent.meter_classify == '机表'"><nobr>总抄表次数</nobr></th>-->
    <!--            <th v-show="$parent.$parent.$parent.meter_classify == '卡表'"><nobr>总购气量</nobr></th>-->
    <!--            <th v-show="$parent.$parent.$parent.meter_classify == '机表'"><nobr>总抄表气量</nobr></th>-->
                <th><nobr>期间购气次数</nobr></th>
                <th><nobr>期间购气量</nobr></th>
                <th v-show="$parent.$parent.$parent.meter_classify == '机表'"><nobr>期间抄表气量</nobr></th>
    <!--            <th v-show="$parent.$parent.$parent.meter_classify == '卡表'"><nobr>累计未购气天数</nobr></th>-->
    <!--            <th v-show="$parent.$parent.$parent.meter_classify == '机表'"><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>{{$index+1}}</nobr></td>
              <td style="text-align: center;"><nobr>
                <span @click="$parent.$parent.$parent.showmsg(row)"><a>{{row.f_userinfo_code}}</a></span>
              </nobr> </td>
              <td style="text-align: center;"><nobr>{{row.f_user_phone}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_olduserinfo_code}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_meternumber}}</nobr></td>
              <th style="text-align: center;"><nobr>{{row.f_user_name}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_user_state}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_residential_area}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_address}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_user_type}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_gasproperties}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_table_state}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_meter_type}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_meter_brand}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_meter_style}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_open_date}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_pcd}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_changemeter_date}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_gasproperties2}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_price_name}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.delivery_date}}</nobr></th>
    <!--          <th style="text-align: center;"><nobr>{{row.cishu}}</nobr></th>-->
    <!--          <th style="text-align: center;"><nobr>{{row.pregas}}</nobr></th>-->
              <th style="text-align: center;"><nobr>{{row.sellcishu}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.sellpregas}}</nobr></th>
    <!--          <th style="text-align: center;"><nobr>{{row.diffday}}</nobr></th>-->
              <th style="text-align: center;"><nobr>{{row.f_orgname}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_is_mgq}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_is_vacant}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_is_alone}}</nobr></th>
              <th style="text-align: center;"><nobr>{{row.f_is_empty}}</nobr></th>
            </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 v-if="meter_classify == '卡表'" style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">总购气量合计:&emsp;&emsp;{{sumsmodel.pregas}}</td>-->
            <td  style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">期间购气量合计:&emsp;&emsp;{{sumsmodel.sellpregas}}</td>
            <!--      <td v-if="meter_classify == '机表'" style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">总抄表气量合计:&emsp;&emsp;{{sumsmodel.pregas}}</td>-->
            <td v-if="meter_classify == '机表'" style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">期间抄表气量合计:&emsp;{{sumsmodel.sellpregas}}</td>
          </tr>
        </table>
      </div>
      <div class="flex" v-if="show">
        <user-info-detail-manage-new :f_userinfo_id="rowdata.f_userinfo_id" @cancel-main="cancel"></user-info-detail-manage-new>
      </div>
    </div></div>
</template>
<script>
  /**
   *用户档案查询列表以及添加操作组件
   */
  import RightTreee from './RightTree.vue'
  import {HttpResetClass, PagedList} from 'vue-client'
  import Vue from 'vue'
  import plugin from 'system-clients/src/plugins/GetLoginInfoService'

  let readySomething = async function (self) {
    await self.$MagLoadParams.loadParam()
    self.initParams()
    // self.$refs.paged.$refs.cri.model.startDate =  self.$login.toStandardDateString() + ' 00:00:00'
    // self.$refs.paged.$refs.cri.model.endDate =  self.$login.toStandardDateString() + ' 23:59:59'
    let year = new Date().getFullYear()
    self.$refs.paged.$refs.cri.model.startDate =  year+'-01-01'
    self.$refs.paged.$refs.cri.model.endDate =  self.$login.toStandardDateString()

    // await self.$refs.paged.$refs.cri.search()
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
  }
  export default {
    components: {
      RightTreee,
    },
    title: '购气稽查',
    data () {
      return {
        meterbrands: [],
        other:[],
        footer:[],
        //小区
        residentialArea: [],
        //街道
        street: [],
        pcdslist:[],
        org:[],
        criteriaShow: false,
        meter_classify:'卡表',
        filialeNameStr: null,
        filialeCodeStr: `and f_orgid = '${this.$login.f.orgid}'`,
        userid: this.$login.f.id,
        // 气表型号
        meterstyle: {},
        prices:[],
        source: `tool.getFullTree(this.getRights().where(row.getType() == $organization$))`,
        getfield:{"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号",
          "f_user_name":"客户名称","f_user_state":"客户状态","f_residential_area":"小区","f_street":"街道","f_address":"地址","f_user_type":"用户类型",
          "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
          "delivery_date":"最后购气日期","f_meter_style":"气表类型","f_open_date":"开户日期","f_pcd":"区域","f_gasproperties2":"二级用气性质",
          "f_changemeter_date":"最后一次换表时间","sellcishu":"期间购气次数","sellpregas":"期间购气量","f_orgname":"组织机构",
          "f_is_mgq": "是否煤改气", "f_is_empty": "是否空房", "f_is_vacant": "是否空置户", "f_is_alone": "是否孤寡老人"},
        model: new PagedList('api/af-revenue/sql/inspectList_sellinggas', 50,{},{sellpregas: 0}),
        rows: null,
        //orgid:'',
        sumsmodel: {},
        sqlName:'inspectList_sellinggas',
        config: {
          defaultPrint: ['f_userinfo_code','f_user_id']
        },
        f_filialeid: this.$login.f.orgid,
        show:false,
        rowdata:{},
        initres: {
          org:[this.$login.f.orgid],
          dep:[],
          user:[],
        },
        defaultfield: [],
        ismgq: [{label: '全部', value: ''},{label: '是', value: '是'},{label: '否', value: '否'}],
        isvacant: [{label: '全部', value: ''},{label: '是', value: '是'},{label: '否', value: '否'}],
        isalone: [{label: '全部', value: ''},{label: '是', value: '是'},{label: '否', value: '否'}],
        isempty: [{label: '全部', value: ''},{label: '是', value: '是'},{label: '否', value: '否'}],
      }
    },
    watch:{
      sumsmodel:{
        handler: function(val) {
          this.getotherfooter();
        },
        deep: true
      },
      meter_classify(val){
        if(val == '卡表') {
          this.url = 'api/af-revenue/sql/inspectList_sellinggas'
          this.sqlName = 'inspectList_sellinggas'
          this.getfield = {"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号",
            "f_user_name":"客户名称","f_user_state":"客户状态","f_residential_area":"小区","f_street":"街道","f_address":"地址","f_user_type":"用户类型",
            "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
            "delivery_date":"最后购气日期","f_meter_style":"气表类型","f_open_date":"开户日期","f_pcd":"区域","f_gasproperties2":"二级用气性质",
            "f_changemeter_date":"最后一次换表时间",
            "sellcishu":"期间购气次数","sellpregas":"期间购气量","f_orgname":"组织机构",
            "f_is_mgq": "是否煤改气", "f_is_empty": "是否空房", "f_is_vacant": "是否空置户", "f_is_alone": "是否孤寡老人"}
        }if(val == '物联网表'){
          this.url = 'api/af-revenue/sql/getwulw_listgas'
          this.sqlName = 'getwulw_listgas'
          this.getfield = {"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号",
            "f_user_name":"客户名称","f_user_state":"客户状态","f_residential_area":"小区","f_street":"街道","f_address":"地址","f_user_type":"用户类型",
            "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
            "delivery_date":"最后购气日期","f_meter_style":"气表类型","f_open_date":"开户日期","f_pcd":"区域","f_gasproperties2":"二级用气性质",
            "f_changemeter_date":"最后一次换表时间",
            "sellcishu":"期间购气次数","sellpregas":"期间购气量","f_orgname":"组织机构",
            "f_is_mgq": "是否煤改气", "f_is_empty": "是否空房", "f_is_vacant": "是否空置户", "f_is_alone": "是否孤寡老人"}
        }
        if(val == '机表'){
          this.url = 'api/af-revenue/sql/handinspectList_sellinggas'
          this.sqlName = 'handinspectList_sellinggas'
          this.getfield = {"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号",
            "f_user_name":"客户名称","f_user_state":"客户状态","f_residential_area":"小区","f_street":"街道","f_address":"地址","f_user_type":"用户类型",
            "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
            "delivery_date":"最后抄表日期","f_meter_style":"气表类型","f_open_date":"开户日期","f_pcd":"区域","f_gasproperties2":"二级用气性质",
            "f_changemeter_date":"最后一次换表时间",
            "sellcishu":"期间抄表次数","sellpregas":"期间抄表气量","f_orgname":"组织机构",
            "f_is_mgq": "是否煤改气", "f_is_empty": "是否空房", "f_is_vacant": "是否空置户", "f_is_alone": "是否孤寡老人"}
        }
        this.clear()
      }
    },
    ready () {
      this.getaddress(null)
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      initParams () {
        // 初始化气表品牌
        let brandArr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          console.log('item-->',item)
          let temp = {}
          temp.label = item.label
          temp.value = item.value.f_meter_brand
          brandArr.push(temp)
          // 取出对应气表型号
          let styleArr = []
          for (let row of item.value.gasmodel) {
            styleArr.push({label: row.label,value: row.value.f_meter_style})
          }
          this.meterstyle[temp.value] = styleArr
        })
        this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
        console.log('气表品牌---------->',this.meterbrands)
          //初始化气表价格
          this.prices = this.$MagGetSaleParam.getPrices();
      },
      getotherfooter(){
        // this.$refs.paged.$refs.cri.$refs.exports.otherData=[];
        // this.$refs.paged.$refs.cri.$refs.exports.footerData=[];
        this.other=[];
        this.footer=[];
        let exportdata = this.getCondition;
        let otherInData=[];
        otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`);
        let footerData=[],exportfield=this.getfield;
        footerData.push("合计");
        let self = this;
        for(var field in self.sumsmodel){
          footerData.push(`${exportfield[field]}合计:${self.sumsmodel[field]}`);
        }
        this.footer.push(footerData);
        this.other.push(otherInData);
      },
      cancel() {
        this.show = false
      },
      showmsg(obj){
        this.rowdata=obj
        this.show=true
      },
      getorg (obj) {
        if(obj.resids.length>0){
          this.filialeCodeStr =" and f_orgid in " + plugin.convertToIn(obj.resids)
          this.getaddress(obj)
        }
        else{
          this.filialeCodeStr= " and f_orgid = " + this.$login.f.orgid
          this.getaddress(null)
        }
      },
      async  getaddress(orgid){
        console.log('开始获取小区')
        let HttpReset = new HttpResetClass()
        var data = await HttpReset.load('POST', 'api/af-revenue/sql/manage_getarealist', {
          data: {
            condition: `1=1 `
          }
        }, {resolveMsg: null, rejectMsg: '获取小区失败!'})
        console.log('小区',data)
        let house = []
        for (let row of data.data){
          console.log('开始保存小区')
          house.push({label: row.f_residential_area, value: row.f_residential_area})
        }
        this.residentialArea = house

        console.log('开始获取街道')
        let streets= await HttpReset.load('POST', 'api/af-revenue/sql/manage_getstreetlist', {
            data: {
              condition: orgid == null ? `s.f_orgid = ${this.$login.f.orgid}` : `s.f_orgid in ${plugin.convertToIn(orgid.resids)}`
            }
          },{resolveMsg: null, rejectMsg: '获取街道失败!'})
        console.log('街道',streets)
        let streetValue = []
        for (let row of streets.data){
          console.log('开始保存街道')
          streetValue.push({label: row.f_street, value: row.f_street})
        }
        this.street = streetValue

        console.log('开始获取区域')
        var req = await HttpReset.load('POST','api/af-revenue/sql/address_singleTableOrderBy?pageNo=1&pageSize=9999999', {
          data: {
            items: '*',
            tablename: 't_pcd',
            orderitem: 'id',
            condition: `1=1`
          }
        }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
        let redata = []
        console.log('区域是：',req)
        req.data.forEach((row, n) => {
          redata[n] = {
            label: row.f_pcd,
            value: row.id,
            data: row,
            id: row.id
          }
        })
        console.log('获取到的小区',redata)
        this.pcdslist = redata
      },
      userTypeChange () {
        this.gasproperties=[]
        console.log("查气价")
        console.log(this.$refs.paged.model.model)

        if(this.$refs.paged.model.model !==null) {
          console.log("进if")
          this.$refs.paged.model.model.f_gasproperties=''
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.model.model.f_user_type[0])
          // this.gasproperties.push({label: '全部', value: ''})
          console.log(this.gasproperties )
        }
        else{
          this.gasproperties =[{label: '全部', value: ''}]
        }
        console.log("最终气价")
        console.log(this.gasproperties )
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      selfSearch (args) {
        console.log('9999999999999999999', this.meter_classify )
        console.log('9999999999999999999', this.meter_classify.length)
        if(this.meter_classify == '卡表'){
          this.model.url='api/af-revenue/sql/inspectList_sellinggas'
        }
        if(this.meter_classify == '机表'){
          this.model.url='api/af-revenue/sql/handinspectList_sellinggas'
        }
        if(this.meter_classify == '物联网表'){
          this.model.url= 'api/af-revenue/sql/getwulw_listgas'
        }
        if (!this.$refs.paged.$refs.cri.model.sellcishumin && !this.$refs.paged.$refs.cri.model.sellcishumax) {
          args.condition = args.condition + "and sellcishu > 0"
        }

        console.log(this.$login.f)
        if(this.$refs.paged.$refs.cri.model.startDate){
          this.model.params.startDate = `'${this.$refs.paged.$refs.cri.model.startDate} 00:00:00' `
        }else{
          this.model.params.startDate ='DATEADD(yy,DATEDIFF(yy,0,getdate()),0)'
        }
        if(this.$refs.paged.$refs.cri.model.endDate){
          this.model.params.endDate = `'${this.$refs.paged.$refs.cri.model.endDate} 23:59:59' `
        }else{
          this.model.params.endDate ='DATEADD(SS,-1,DATEADD(DD,1,CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120))))'
        }

        if(this.$refs.paged.$refs.cri.model.contain_newfile){
          if(this.$refs.paged.$refs.cri.model.contain_newfile==='否') {
            if (this.$refs.paged.$refs.cri.model.startDate === ''&&this.$refs.paged.$refs.cri.model.endDate ==='') {
              args.condition = args.condition + "and f_open_date not between DATEADD(yy,DATEDIFF(yy,0,getdate()),0) and DATEADD(SS,-1,DATEADD(DD,1,CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120))))"
            }else if (this.$refs.paged.$refs.cri.model.startDate === ''&& this.$refs.paged.$refs.cri.model.endDate !=='') {
              args.condition = args.condition + "and f_open_date not between DATEADD(yy,DATEDIFF(yy,0,getdate()),0) and "+this.model.params.endDate
            }else if (this.$refs.paged.$refs.cri.model.startDate !== ''&& this.$refs.paged.$refs.cri.model.endDate ==='') {
              args.condition = args.condition + "and f_open_date not between " + this.model.params.startDate + "and DATEADD(SS,-1,DATEADD(DD,1,CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120))))"
            }
            else {
              args.condition = args.condition + "and f_open_date not between " + this.model.params.startDate + " and " + this.model.params.endDate
            }
          }
        }
        args.condition = args.condition+ ` ${this.filialeCodeStr}`
        console.log("拼接的condition", args.condition, this.model)
        this.model.search(args.condition, args.model)
      },
      // show(){
      //   this.criteriaShow = true
      // },
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      clear(){
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          if(key != 'startDate' && key != 'endDate')
            this.$refs.paged.$refs.cri.model[key] = []
        })
        this.$refs.paged.$refs.cri.model.contain_newfile='是'
        let year = new Date().getFullYear()
        this.$refs.paged.$refs.cri.model.startDate =  year+'-01-01'
        this.$refs.paged.$refs.cri.model.endDate =  this.$login.toStandardDateString()
      }

    },
    computed: {
      gasproperties() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用气性质')]
      },
      usertypes() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      userstate() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('客户状态')]
      },
      tablestate () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表状态')]
      },
      metertypes(){
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表型号')]
      },
      pricetypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气价类型')]
      },
      getPricenames() {
        let f_user_type = this.$refs.paged.$refs.cri.model.f_user_type;
        let f_gasproperties = this.$refs.paged.$refs.cri.model.f_gasproperties;
        let pricetype = this.$refs.paged.$refs.cri.model.pricetype;
        console.log("打印一下:",f_user_type,f_gasproperties,pricetype,this.f_filialeid,this.prices)
        if(this.$refs.paged.$refs.cri.model !==null) {
          let rs = []
          let priceArr = []
          if ( pricetype.length >0) {
            let params = {
              f_price_type: pricetype[0],
              filter: this.f_filialeid,
              prices: this.prices
            }
            this.$MagGetSaleParam.getPrice(params).forEach((item) => {
              let temp = {}
              temp.label = item.label
              temp.value = item.value.f_price_name
              priceArr.push(temp)
            })
            rs = [{label: '全部', value: ''}, ...priceArr]
          }
          if (rs.length === 0) {
            console.log('rs读出来是空')
            this.$refs.paged.$refs.cri.model.f_price_name = ''
          }
          return rs
        }
      },
      f_meter_classify(){
        return [{label: '卡表', value: '卡表'},{label: '机表', value: '机表'},{label: '物联网表', value: '物联网表'} ]
        // return [{label: '卡表', value: '卡表'}]
      },
      Gasproperties2() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气属性')]
      },
      contain_newfiles(){
        return [{label: '是', value: '是'},{label: '否', value: '否'} ]
      },
      getCondition () {
        let result = {
          condition: '',
          startDate: '',
          endDate: ''
          // diffDay:' 1=1 '
        }
        result.condition = this.$refs.paged.$refs.cri.condition + this.filialeCodeStr
        let temp2 = this.$refs.paged.$refs.cri
        if (temp2.model.startDate && temp2.model.endDate) {
          result.startDate = ` '${temp2.model.startDate} 00:00:00'`
          result.endDate = ` '${temp2.model.endDate} 23:59:59'`
        } if (!temp2.model.startDate && !temp2.model.endDate) {
          result.startDate = 'new Date().getFullYear()'
          result.endDate = 'DATEADD(SS,-1,DATEADD(DD,1,CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120))))'
        }
          if (temp2.model.startDate&&!temp2.model.endDate) {
            result.startDate = ` '${temp2.model.startDate} 00:00:00'`
            result.endDate = 'DATEADD(SS,-1,DATEADD(DD,1,CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120))))'
          } if (temp2.model.endDate&&!temp2.model.startDate) {
            result.startDate = 'new Date().getFullYear()'
            result.endDate = ` '${temp2.model.endDate} 23:59:59'`
          }

        // if(temp2.model.diffday != ''){
        //   result.diffDay += " and diffDay "+ temp2.model.diffday;
        // }
        if (temp2.model.contain_newfile==='否'){
          result.condition = result.condition+" and f_open_date not between " + result.startDate + " and " + result.endDate
        }

          return result
      }
    }
  }
</script>
<style media="screen">
  .divtext {
    min-width: 50px;
    max-width: 200px;
    border: 1px solid green;
    display: inline-block;
  }
</style>

