<template>
  <div class="flex">
    <criteria-paged :model="model" 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="form-group col-sm-4" >
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code" placeholder='客户编号'
                     condition="f_userinfo_code = '{}'" @keyup.enter="search()">
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">用户姓名</label>
              <input type="text" class="input_search"
                     style="width:60%"
                     v-model="model.f_user_name"
                     condition="f_user_name = '{}'"
                     placeholder="用户姓名"/>
            </div>

            <div class="form-group col-sm-4 button-range" >
              <button class="button_search" style="margin-right: 10px"  @click="$parent.$parent.changeprice()" >调价</button>
              <button class="button_search" style="margin-right: 10px"  @click="search()" >查询</button>
              <button class="button_search" style="margin-right: 10px"  @click="$parent.$parent.cancle()" >取消</button>
              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_top': $parent.$parent.criteriaShow2,'button_shrink_bottom': !$parent.$parent.criteriaShow2}"
                   @click="$parent.$parent.hidden()"></div>
            </div>
            <div class="row" v-show="$parent.$parent.criteriaShow2">
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">收费时间</label>
                <datepicker placeholder='收费时间' style="width:60%"
                            v-model="model.startDate"
                            :value.sync="model.startDate"
                            :format="'yyyy-MM-dd 00:00:00'"
                            :show-reset-button="true"
                            condition="f_start_date >= '{}'">
                </datepicker>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">&emsp;&emsp;至&emsp;</label>
                <datepicker placeholder='结束时间' style="width:60%"
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            :format="'yyyy-MM-dd 23:59:59'"
                            :show-reset-button="true"
                            condition="f_end_date <= '{}'">
                </datepicker>
              </div>
            </div>
          </div>
          </div>
      </criteria>
      <data-grid :model="model" class="table_sy"  partial='list' v-ref:grid :optional="true">
        <template partial='head'>
          <th>
            <input type="checkbox" @click="$parent.$parent.$parent.addOrRemove($parent.$parent.$parent.selectAll)"
                   :checked="$parent.$parent.$parent.selectAll">
          </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>
        </template>
        <template partial='body'>
          <td style="text-align:center">
            <input type="checkbox" v-model="$parent.$parent.$parent.selecteds" :value="row">
          </td>
          <td style="text-align:center">{{row.f_userinfo_code}}</td>
          <td style="text-align:center">{{row.f_user_name}}</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;white-space: nowrap;">{{row.f_address}}</td>
          <td style="text-align:center;white-space: nowrap;">{{row.f_real_amount}}</td>
          <td style="text-align:center;white-space: nowrap;">{{row.f_surplus_fee}}</td>
          <td style="text-align:center;white-space: nowrap;">{{row.f_start_date}}</td>
          <td style="text-align:center;white-space: nowrap;">{{row.f_end_date}}</td>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  export default {
    title: '补差记录',
    data () {
      return {
        model: new PagedList('rs/sql/cardSurpDetail', 20, {}),
        condition: '',
        criteriaShow2:false,
        f_filialeid: this.$login.f.orgid,
        selecteds:[],
        usertypes: this.$appdata.getParam('用户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')] : [],
      }
    },
    props:['sellid'],
    ready () {
      this.search()
    },
    methods: {
      hidden(){
        this.criteriaShow2 = !this.criteriaShow2
      },
      cancle(){
        this.$dispatch('cancel')
      },
    async  changeprice(){
        console.log("this.selectes",this.selecteds)
        let param = {
          selecteds: this.selecteds,
          f_operator: this.$login.f.name,
          f_operatorid: this.$login.f.id,
          f_orgid: this.$login.f.orgid,
          f_orgname: this.$login.f.orgs,
          f_depid: this.$login.f.depids,
          f_depname: this.$login.f.deps,
          f_start_date : this.$refs.paged.$refs.criteria.model.startDate,
          f_end_date : this.$refs.paged.$refs.criteria.model.endDate
        }
        await  this.$resetpost('rs/logic/cardSurpSelling', {data: param}, {
          resolveMsg: '补差成功',
          rejectMsg: '补差失败'
        }).then((res) => {
          if (res.data) {
            this.$dispatch('cancel', this.selecteds),
            this.search()
          }
        })
      },
      addOrRemove (is) {
        console.log('this,', is)
        this.selecteds = []
        if (!is) { // 添加本页所有数据到ids中
          this.model.rows.forEach((row) => {
            this.selecteds.push(row)
          })
          this.selectAll = true
        } else { // 从ids中取消所有的数据
          this.selecteds = []
          this.selectAll = false
        }
        console.log('selectdde', this.selecteds)
      },
      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      selfSearch (args) {

        this.condition = `${args.condition} and f_orgid in (${this.curorgid})`
        this.model.search(args.condition, args.model)
      },
    },
    watch: {
      selecteds () {
        console.log('框框的长度', this.selecteds.length)
      }
    },
    computed: {
    }
  }
</script>
