<template>
  <div class="flex-row" v-show="!showdetail">
    <div id='app1' class="basic-main" >
      <criteria-paged :model="model" :pager='true' v-ref:paged>
        <criteria partial='criteria' @condition-changed='$parent.search' v-ref:cri>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" novalidate partial>
            <div class="row">
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户编号</label>
                <input @keyup.enter="search" style="width:60%" type="text" class="input_search"
                       v-model="model.f_userinfo_code" placeholder='客户编号'
                       condition="f_userinfo_code like '%{}%'" v-el:xq v-next-el='userinfocode' v-el:username
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户名称</label>
                <input @keyup.enter="search" style="width:60%" type="text" class="input_search"
                       v-model="model.f_user_name" placeholder='客户名称'
                       condition="f_user_name like '%{}%'" v-el:xq v-next-el='username' v-el:username
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户地址</label>
                <input @keyup.enter="search" style="width:60%" type="text" class="input_search" v-model="model.f_area"
                       placeholder='地址'
                       condition="f_address like '%{}%'" v-el:xq v-next-el='address' v-el:area
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&nbsp;&nbsp;&nbsp;表号&nbsp;&nbsp;&nbsp;</label>
                <input @keyup.enter="search" style="width:60%" type="text" class="input_search"
                       v-model="model.f_meternumber" placeholder='表号'
                       condition="f_meternumber like '%{}%'" v-next-el='meternumber' v-el:meternumber
                >
              </div>
            <div style="float:right">
              <button class="button_search button_spacing" @click="search()">查询</button>
              <button class="button_clear button_spacing" @click="clear">清空</button>
              <export-excel :data="$parent.$parent.getCondition" class="button_export button_spacing"
                            :field="$parent.$parent.getfield"  :sumname="$parent.$parent.sumName"
                            :header="$parent.$parent.other"
                            sqlurl="api/af-revenue/logic/openapi/exportfile" sql-name="webmeter_getNoMetereadData" template-name='未上报查询'
                            :choose-col="true"></export-excel>

              <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">&nbsp;&nbsp;&nbsp;公司&nbsp;&nbsp;&nbsp;</label>
              <right-tree @re-res="$parent.$parent.getorg" width="60%"
                          :initresid='$parent.$parent.org'></right-tree>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">客户类型</label>
              <v-select style="width:60%" id="f_user_type"
                        v-model="model.f_user_type"
                        placeholder='客户类型'
                        :value.sync="model.f_user_type"
                        @change="$parent.$parent.userTypeChange()"
                        :options='$parent.$parent.usertypes'
                        condition="f_user_type = '{}'"
                        close-on-select>
              </v-select>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">用气性质</label>
              <v-select style="width:60%" id="f_gasproperties"
                        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.sync="model.f_meter_brand"
                v-model="model.f_meter_brand"
                :options='$parent.$parent.meterbrands'
                close-on-select
                condition="f_meter_brand='{}'">
              </v-select>
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">气表型号</label>
              <v-select
                        placeholder='气表型号'
                        :value.sync="model.f_meter_style"
                        v-model="model.f_meter_style"
                        :options='$parent.$parent.meterstyle[model.f_meter_brand]'
                        close-on-select
                        condition="f_meter_style='{}'">
              </v-select>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">用户状态</label>
              <v-select
                placeholder='用户状态'
                value-single="true"
                style="width:60%"
                :value.sync="model.f_user_state"
                v-model="model.f_user_state"
                :options='$parent.$parent.userstate'
                close-on-select condition="f_user_state ='{}'">
              </v-select>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">开始时间</label>
              <datepicker style="width:60%" id="startdate" placeholder="开始时间"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 00:00:00'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">结束时间</label>
              <datepicker style="width:60%" id="enddate" placeholder="结束日期"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 23:59:59'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group" >
              <label  class="font_normal_body" title="开户时间大于">开户时间</label>
              <datepicker  placeholder="开户时间大于" style="width:60%"
                           v-model="model.f_open_start_date"
                           :value.sync="model.f_open_start_date"
                           :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  class="font_normal_body" title="开户时间小于">开户时间</label>
              <datepicker  placeholder="开户时间小于" style="width:60%"
                           v-model="model.f_open_end_date"
                           :value.sync="model.f_open_end_date"
                           :format="'yyyy-MM-dd'"
                           :show-reset-button="true"
                           condition="f_open_date <= '{} 23:59:59'">
              </datepicker>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid id="lostuserlist" :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <template partial='head'>
          <tr>
            <th style="text-align:center">
              <nobr>序号</nobr>
            </th>
            <th style="text-align:center">
              <nobr>未上报日期</nobr>
            </th>
            <th style="text-align:center">
              <nobr>开户时间</nobr>
            </th>
            <th style="text-align:center">
              <nobr>客户编号</nobr>
            </th>
            <th style="text-align:center">
              <nobr>客户名称</nobr>
            </th>
            <th style="text-align:center">
              <nobr>客户电话</nobr>
            </th>
            <th style="text-align:center">
              <nobr>客户地址</nobr>
            </th>
            <th style="text-align:center">
              <nobr>客户类型</nobr>
            </th>
            <th style="text-align:center">
              <nobr>用气性质</nobr>
            </th>
            <th style="text-align:center">
              <nobr>表号</nobr>
            </th>
            <th style="text-align:center">
              <nobr>气表厂家</nobr>
            </th>
            <th style="text-align:center" >
              <nobr>气表型号</nobr>
            </th>
            <th style="text-align:center" >
              <nobr>用户状态</nobr>
            </th>
            <th style="text-align:center" >
              <nobr>组织机构</nobr>
            </th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align:center">{{$index+1}}</td>
          <td style="text-align:center">{{row.f_date}}</td>
          <td style="text-align:center">{{row.f_open_date}}</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_name}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.f_user_phone}}</nobr></td>
          <td><nobr>{{row.f_address}}</nobr></td>
          <td style="text-align:center">{{row.f_user_type}}</td>
          <td style="text-align:center">{{row.f_gasproperties}}</td>
          <td style="text-align:center"><nobr>{{row.f_meternumber}}</nobr></td>
          <td style="text-align:center">
            <nobr>{{row.f_meter_brand}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_meter_style}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_user_state}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_orgname}}</nobr>
          </td>

        </template>
      </data-grid>
    </criteria-paged>
  </div>
  </div>
  <div class="flex-row" v-if="showdetail">
    <user-info-detail-manage-new :f_userinfo_id="rowdata.f_userinfo_id" @cancel-main="cancel"></user-info-detail-manage-new>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import * as Util from '../../../Util'
  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 =  Util.toStandardDateString() +' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = Util.toStandardDateString() + ' 23:59:59'
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums;

  }
  export default {
    title: '未上报查询',
    props: ['data'],
    data() {
      return {
        model: new PagedList('api/af-revenue/sql/webmeter_getNoMetereadData', 20, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        getfield:{
          'f_userinfo_code':'客户编号','f_user_name':'客户名称', 'f_date': '未上报日期', 'f_open_date': '开户时间',
          'f_address':'客户地址','f_user_type':'客户类型','f_gasproperties':'用气性质',
          'f_meternumber':'表号',
          'f_meter_brand':'气表厂家','f_orgname':'组织机构'},
        showdetail:false,
        rowdata:{},
        startDate: '',
        endDate: '',
        criteriaShow:false,
        outlets: [],
        other: [],
        sumsmodel: {},
        gasproperties:[{label: '全部', value: ''}],
        operator: [],
        meterbrands: [],
        meterstyle:{},
        orgCondtionStr: ` and f_orgid = '${this.$login.f.orgid}'`,
        orgid:[this.$login.f.orgid],
        condition: '1=1',
        org:[this.$login.f.orgid]

      }
    },
    ready() {
      readySomething(this)
    },
    methods: {
      getotherfooter() {
        this.other = [];

        let firstLine = [`导出时间: ${this.$login.toStandardTimeString()}`];


        let secondLine = [
          `开始时间: ${this.$refs.paged.$refs.cri.model.startDate}`,
          `结束时间: ${this.$refs.paged.$refs.cri.model.endDate}`
        ];

        this.other.push(firstLine);
        this.other.push(secondLine);

        console.log('Header Data:', this.other);
      },
      userTypeChange () {
        this.gasproperties=[{label: '全部', value: ''}]
        if(this.$refs.paged.$refs.cri.model && this.$refs.paged.$refs.cri.model.f_user_type) {
          this.$refs.paged.$refs.cri.model.f_gasproperties=''
          console.log(this.$refs.paged.$refs.cri.model.f_user_type[0])
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
        }
        else{
          this.gasproperties =[{label: '全部', value: ''}]
        }
      },
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      showmsg(obj){
        this.rowdata = obj
        this.showdetail = true
      },
      cancel() {
        this.showdetail = false
      },
      initParams () {
        // 初始化气表品牌
        let brandArr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          if(item.value.f_meter_type==='物联网表'){
            let temp = {}
            temp.label = item.label
            temp.value = item.value.f_meter_brand
            brandArr.push(temp)

            let styleArr = [{label: '全部', value: ''}]
            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]
      },
      search(args) {
        this.startDate = this.$refs.paged.$refs.cri.model.startDate
        this.endDate = this.$refs.paged.$refs.cri.model.endDate
        if (this.endDate == '' || this.startDate == '') {
          return this.$showMessage("时间区间的开始和结束时间不能为空！")
        }
        this.condition = args.condition = this.$refs.paged.$refs.cri.condition + `${this.orgCondtionStr}`
        this.model.search(args.condition, args.model)
      },
      getorg(obj) {
        if (obj.resids.length>0) {
          this.orgCondtionStr = " and f_orgid in " + plugin.convertToIn(obj.resids)
        }else
        {
          this.orgCondtionStr = " and f_orgid = " + this.$login.f.orgid
        }
      },
      clearmsg() {
        this.$refs.paged.$refs.cri.model = {}
      }
    },
    watch: {
      sumsmodel:{
        handler: function(val) {
          this.getotherfooter();
        },
        deep: true
      },
    },
    computed: {
      getCondition() {
        let condition=this.$refs.paged.$refs.cri.condition + this.orgCondtionStr
        return {
            condition: condition  ,
            startDate:`${this.$refs.paged.$refs.cri.model.startDate}`,
            endDate:`${this.$refs.paged.$refs.cri.model.endDate}`
        }

      },
      usertypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      userstate() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户状态')]
      }
    }
  }
</script>
<style>
  .form-input-group label {
    text-align: right;
    width: auto;
  }

  .mystyle {
    float: right;
    padding-right: 10%;
  }

  .mystyle1 {
    padding-top: 10px;

  }

  .mystyle2 {
    width: 100%;
    height: 35px;
    /*background: #00A3F0;*/
    padding-left: 15px;
    float: left;
  }

  .datapanel {
    color: #333;
    background-color: white;
    box-shadow: darkgrey 0.5px 0.5px 0.5px 0.5px;
    padding: 10px 30px 10px 30px;
    border-radius: 15px;
  }
</style>
