<template>
  <div id="unit" class="flex-row">
    <div class="basic-main">
      <div class="flex">
        <criteria-paged :model="model" v-ref:paged>
          <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch">
            <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
              <div class="row">
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">组织机构</label>
                  <res-select
                    :initresid='$parent.$parent.curorgid'
                    @res-select="$parent.$parent.getorg"
                    is-mul="false"
                    restype='organization'
                  >
                  </res-select>
                </div>
                <div class="form-group col-sm-2" >
                  <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 = '{}'" >
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">客户名称</label>
                  <input type="text" class="input_search" style="width:60%"
                         v-model="model.f_user_name" placeholder='客户名称'
                         condition="f_user_name = '{}'">
                </div>

                <div class="form-group col-sm-2">
                  <label class="font_normal_body" style="color: #c52323">气价变更时间</label>
                  <datepicker placeholder="气价变更时间"
                              style="padding: 2px;width: 60%"
                              v-model="model.f_change_date"
                              :value.sync="model.f_change_date"
                              :format="'yyyy-MM-dd'"
                  ></datepicker>
                </div>
                <div class="span" style="float:right;">&nbsp;&nbsp;
                  <button class="button_new" style="width: max-content" v-show="$parent.$parent.pricechange" @click="$parent.$parent.priceshow()">批量调价</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <button class="button_search" @click="search()" v-el:cx>查询</button>
                  <button class="button_clear" @click="$parent.$parent.clear()">清空</button>
                  <export-excel :data="$parent.$parent.getCondition" :footer="$parent.$parent.footer"
                                :field="$parent.$parent.getfield"
                                sqlurl="rs/logic/saleExport" sql-name="new_get_UserCharge" 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="form-group col-sm-2" >
                  <label class="font_normal_body">开始日期</label>
                  <datepicker placeholder="开始日期"
                              style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd'"
                  ></datepicker>
                </div>
                <div class="form-group col-sm-2" >
                  <label class="font_normal_body">结束日期</label>
                  <datepicker placeholder="结束日期"
                              style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd'"
                  ></datepicker>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">客户地址</label>
                  <input type="text" class="input_search" style="width:60%" style="width:60%" v-model="model.f_address" placeholder='客户地址'
                         condition="u3.f_address like '%{}%'">
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">电&emsp;&emsp;话</label>
                  <input type="text" class="input_search" style="width:60%"  v-model="model.f_user_phone" placeholder='电话'
                         condition="f_user_phone like '%{}%'">
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">表&emsp;&emsp;号</label>
                  <input type="text" class="input_search" style="width:60%" style="width:60%" v-model="model.f_meternumber" placeholder='表号'
                         condition="f_meternumber like '%{}%'">
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">状&emsp;&emsp;态</label>
                  <v-select id="price_states"
                            v-model="model.price_states"
                            placeholder='调价状态'
                            style="width: 60%"
                            :value.sync="model.price_states"
                            :options='$parent.$parent.price_states'
                            condition="f_change_price1 {}"
                            close-on-select></v-select>
                </div>
<!--                <div class="form-group col-sm-2">-->
<!--                  <label class="font_normal_body">气表类型</label>-->
<!--                  <v-select id="f_source"-->
<!--                            v-model="model.f_source"-->
<!--                            placeholder='气表类型'-->
<!--                            style="width: 60%"-->
<!--                            :value.sync="model.f_source"-->
<!--                            :options='$parent.$parent.source'-->
<!--                            condition="f_source='{}'"-->
<!--                            close-on-select></v-select>-->
<!--                </div>-->
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">用户类型</label>
                  <v-select id="f_user_tye"
                            v-model="model.f_user_type"
                            placeholder='用户类型'
                            style="width: 60%"
                            @change="$parent.$parent.userTypeChange"
                            :value.sync="model.f_user_type"
                            :options='$parent.$parent.userTypes'
                            condition="u2.f_user_type = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">气价类型</label>
                  <v-select id="f_price_type"
                            v-model="model.price_type"
                            placeholder='气价类型'
                            :value-single="true"
                            style="width: 60%"
                            :value.sync="model.price_type"
                            @change="$parent.$parent.priceTypeChange"
                            :options='$parent.$parent.priceTypes'
                            condition="sp.f_price_type = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">气&emsp;&emsp;价</label>
                  <v-select id="f_price_name"
                            v-model="model.price_name"
                            placeholder='气价名称'
                            style="width: 60%"
                            :value.sync="model.price_name"
                            :options='$parent.$parent.price_name'
                            condition="sp.id = '{}'"
                            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>
                  <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>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">{{$index+1}}</td>
              <th style="text-align: center;">{{row.f_userinfo_code}}</th>
              <th style="text-align: center;">{{row.f_meternumber}}</th>
              <th style="text-align: center;">{{row.f_user_name}}</th>
              <th style="text-align: center;">{{row.f_user_type}}</th>
              <th style="text-align: center;">{{row.f_meter_type}}</th>
              <th style="text-align: center;">{{row.f_price_name}}</th>
              <th style="text-align: center;">{{row.stair_gas1}}</th>
              <th style="text-align: center;">{{row.stair_gas2}}</th>
              <th style="text-align: center;">{{row.stair_gas3}}</th>
              <th style="text-align: center;">{{row.f_stair_price1}}</th>
              <th style="text-align: center;">{{row.f_stair_price2}}</th>
              <th style="text-align: center;">{{row.f_stair_price3}}</th>
              <th style="text-align: center;">
                <div v-if="!row.f_surplus_fee">
                  <button type="button" name="button" class="btn btn-link"
                          @click.stop="$parent.$parent.$parent.calculation(row)  && row.states === 1">调价补差
                  </button>

                </div>
                <div v-else>
                  {{row.f_change_price1}}
                </div>

              </th>
              <th style="text-align: center;">{{row.f_change_price2}}</th>
              <th style="text-align: center;">{{row.f_change_price3}}</th>
              <th style="text-align: center;">{{row.f_surplus_fee1}}</th>
              <th style="text-align: center;">{{row.f_surplus_fee2}}</th>
              <th style="text-align: center;">{{row.f_surplus_fee3}}</th>
              <th style="text-align: center;">{{row.f_pregas}}</th>
              <th style="text-align: center;">{{row.f_surplus_fee}}</th>
<!--              <th style="text-align: center;">{{row.f_change_date}}</th>-->
              <th style="text-align: center;">{{row.f_last_tablebase}}</th>
              <th style="text-align: center;">{{row.f_tablebase}}</th>
              <th style="text-align: center;">{{row.f_tablebase-row.f_last_tablebase}}</th>
              <th style="text-align: center;">{{row.f_source}}</th>
              <th style="text-align: center;">{{row.f_input_date}}</th>
              <th style="text-align: center;">{{row.f_last_input_date}}</th>

              <th style="text-align: center;">{{row.startday}}</th>
              <th style="text-align: center;">{{row.startpregas}}</th>

              <th style="text-align: center;">{{row.endday}}</th>
              <th style="text-align: center;">{{row.f_pregas}}</th>
              <th style="text-align: center;">{{row.f_stair_gas1}}</th>
              <th style="text-align: center;">{{row.f_stair_gas2}}</th>
              <th style="text-align: center;">{{row.f_stair_gas3}}</th>
              <th style="text-align: center;">{{row.f_operate_date}}</th>
              <th style="text-align: center;">
                <button type="button" name="button" class="btn btn-link" v-if="row.f_surplus_fee"
                        @click.stop="$parent.$parent.$parent.delectHand(row)  && row.states === 1">冲正
                </button>
                <!--                <button type="button" name="button" class="btn btn-link" v-if="!row.f_new_price"-->
                <!--                        @click.stop="$parent.$parent.$parent.enter(row)  && row.states === 1">补差-->
                <!--                </button>-->
              </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
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              补差气量:&emsp;{{sumsmodel.f_pregas}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              补差金额:&emsp;{{sumsmodel.f_surplus_fee}}
            </td>
          </tr>
        </table>
        <modal :show.sync="show">
          <header slot="modal-header" class="modal-header">
            <h4 class="modal-title">调 价 补 差</h4>
          </header>
          <article slot="modal-body" class="modal-body">
            <div class="flex">
            <div class="row" v-if="model.model.price_type==='阶梯气价'">
            <div class="row">
              <div class="form-group col-sm-6">
                <label class="font_normal_body col-sm-9"><span v-if="operatorrow">({{operatorrow.f_stair_price1}})</span>一阶补差单价</label>
                <input type="text" class="form-control" v-model="f_change_price1">
              </div>
            </div>
            <div class="row" >
              <div class="form-group col-sm-6">
                <label class="font_normal_body col-sm-9"><span v-if="operatorrow">({{operatorrow.f_stair_price2}})</span>二阶补差单价</label>
                <input type="text" class="form-control" v-model="f_change_price2">
              </div>
            </div>
            <div class="row">
              <div class="form-group col-sm-6 ">
                <label class="font_normal_body col-sm-9"><span v-if="operatorrow">({{operatorrow.f_stair_price3}})</span>三阶补差单价</label>
                <input type="text" class="form-control" v-model="f_change_price3">
              </div>
            </div>
            </div>
            <div v-else>
              <div class="form-group col-sm-4">
                <label class="font_normal_body">补差单价</label>
                <input type="text" class="form-control" v-model="f_change_price1">
              </div>
            </div>
            </div>
          </article>
          <footer slot="modal-footer" class="modal-footer">
            <button class="button_search" @click="priceadjustment">生成调价补差表</button>
            <button type="button" class="btn btn-default" @click='close'>取消</button>
          </footer>
        </modal>
        <work-busy :is-busy="locking" v-show="locking"></work-busy>
      </div>
    </div>
  </div>
</template>

<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  import Vue from 'vue'
  import co from 'co'

  let readySomething = async function (self) {
    self.$refs.paged.$refs.criteria.model.startDate = self.$login.toStandardDateString()
    self.$refs.paged.$refs.criteria.model.endDate = self.$login.toStandardDateString()
    self.$refs.paged.$refs.criteria.model.f_change_date = ''
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
    getPrice(self)
    self.$showAlert('请输入[气价变更时间,气价类型]后进行查询！', 'warning', 2000)
    self.pricechange = false

  }
  let getPrice = async function(self) {
    self.$resetpost('rs/sql/getpriceid', {data: {f_filialeids: self.f_filialeid}}, {
      resolveMsg: null,
      rejectMsg: null
    }).then((res) => {
      console.log('气价信息-------->',res.data)
      let rs = []
      for (let i = 0; i < res.data.length; i++) {
        let temp = {
          label: res.data[i].f_price_name+`(${res.data[i].id})`,
          type:res.data[i].f_price_type,
          flage: res.data[i].f_user_type,
          value: res.data[i].id
        }
        rs.push(temp)
      }
      console.log(rs)
      self.pricers = [ ...rs]
      self.priceTypeChange()
    })
  }
  let asyncReadyGen = async function (self) {
    // 获取营收参数
    await self.$LoadParams.loadMeterBook(self.f_filialeid)
    // self.loadMeterBooks()
    // await self.$MagGetSaleParam.initinputtor()
    // await self.getinputtores()
    // console.log('-----------------', self.$login.f.orgid)
    // await self.initSlice(self.$login.f.orgid)
    await self.initSlice(self.$login.f.orgid)
    await self.getinputtores()
    await self.$GetSaleParam.initinputtor()
    self.getfield = self.config.excelHeaders
    await self.initmeterbook()
    self.$refs.paged.$refs.cri.model.performDate = self.$login.toStandardDateString()
    self.search()

  }

  export default {
    title: '调价补差',
    data () {
      return {
        f_orgid: '',
        footer: [],
        other:[],
        pricechange: true,
        criteriaShow: false,
        f_change_price1:0,
        sumsmodel:[],
        f_change_price2:0,
        f_change_price3:0,
        pricers: [{label: '全部', value: '', flage: ''}],
        price_name: [],
        price_states: [{label: '全部', value: ''}, {label: '已调价', value: ' is not null'}, {label: '未调价', value: 'is null'}],
        pricetime_statesoptions: [{label: '全部', value: ''}, {label: '调价时间前', value: '1'}, {label: '调价时间后', value: '0'}],
        source: [{label: '卡表抄表', value: '卡表抄表'}, {label: '机表抄表', value: '机表抄表'}],
        userTypes: this.$appdata.getParam('用户类型') ? [...this.$appdata.getParam('用户类型')] : [],
        priceTypes: this.$appdata.getParam('气价类型') ? [ ...this.$appdata.getParam('气价类型')] : [],
        condition: '',
        locking: false,
        model: new PagedList('rs/sql/new_get_UserCharge', 20, {
          f_change_date: 'this.model.f_change_date === "" ? "1911-01-01" : this.model.f_change_date',
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate',
          price_states: 'this.model.price_states[0]',
          addSelectParam: 'this.model.addSelectParam'
        },{
          f_pregas: 0,
          f_surplus_fee: 0
        }),
        config: {
          defaultPrint: [],
          excelHeaders: {
            'f_userinfo_code': '用户编号',
            'f_meternumber': '表号',
            'f_user_name': '用户姓名',
            'f_user_type': '用户类型',
            'f_meter_type': '气表类型',
            'f_price_name': '气价名称',
            'f_stair_gas1': '一阶气量',
            'f_stair_gas2': '二阶气量',
            'f_stair_gas3': '三阶气量',
            'f_stair_price1': '一阶单价',
            'f_stair_price2': '二阶单价',
            'f_stair_price3': '三阶单价',
            'f_change_price1': '一阶补差单价',
            'f_change_price2': '二阶补差单价',
            'f_change_price3': '三阶补差单价',
            'f_surplus_fee1': '一阶补差金额',
            'f_surplus_fee2': '二阶补差金额',
            'f_surplus_fee3': '三阶补差金额',
            'f_last_tablebase': '上期底数',
            'f_tablebase': '本期底数',
            'f_pregas': '补差气量',
            'f_surplus_fee': '补差金额',
            'f_source': '差价来源'
          }
        },
        f_new_price: '',
        pricetime_states: '',
        show: false,
        addSelectParam: '',
        meterbooks: [{label: '全部', value: ''}],  // 抄表册
        inputtoreser: [{label: '全部', value: ''}],
        bookSliceArea: [],
        inputtores2: [],
        curorgid: [this.$login.f.orgid],
        f_filialeid: this.$login.f.orgid,
        operatortype: '',
        operatorrow: {},
        f_prices: [{label: '全部', value: ''}]
        // joinTable:'',
      }
    },
    ready () {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
      this.inputtores2 = this.inputtores
      asyncReadyGen(this)
    },
    methods: {
      getotherfooter () {
        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)
      },
      getprice(row){
        this.show = true

      },
      async sliceChange () {
        this.$set('$refs.paged.$refs.criteria.model.f_meter_book', [])
        let val2 = this.$refs.paged.$refs.criteria.model.f_book_slice_area
        if (val2.length > 0) {
          let condition = ` 1=1 and f_orgid ='${this.f_filialeid}' and f_book_state='有效' `
          let aaa = '('
          val2.forEach((item) => {
            aaa = aaa + `'${item}',`
          })
          aaa = aaa + `'')`
          condition = condition + ` and f_book_slice_area in ${aaa} `
          let param = {
            items: '*',
            tablename: 't_meter_book',
            condition: condition,
            orderitem: 'id'
          }
          let getMeterBooks = await this.$resetpost('rs/sql/singleTable_OrderBy', {data: param}, {
            resolveMsg: null,
            rejectMsg: '获取营收参数出错！！！'
          })
          if (getMeterBooks.data) {
            if (getMeterBooks.data.length > 0) {
              let rs = []
              getMeterBooks.data.forEach((item) => {
                let temp = {
                  label: item.f_book_name,
                  value: item.id
                }
                rs.push(temp)
              })
              this.meterbooks = [{label: '全部', value: ''}, ...rs]
            } else {
              this.meterbooks = [{label: '全部', value: ''}]
            }
          }
        } else {
          this.meterbooks = [{label: '全部', value: ''}]
        }
      },
      async initSlice (val) {
        if (val) {
          let getAllArea = await this.$resetpost('/rs/search', {
            source: 'this.getParentByType($organization$).getAllChildrens().where(row.getType() == $zone$)',
            userid: this.$login.f.id
          }, {resolveMsg: null, rejectMsg: '获取片区出错！！！'})
          let arr = getAllArea.data.filter((res) => {
            return res.parentid == val
          })
          this.bookSliceArea = []
          arr.forEach((res) => {
            this.bookSliceArea.push({label: res.name, value: res.name})
          })
        }
      },
      async inputtorchange () {
        let val = this.$refs.paged.$refs.criteria.model.f_inputtor
        if (val != null && val != '') {
          let param = {
            items: '*',
            tablename: 't_meter_book',
            condition: ` 1=1 and f_inputtor = '${val}' and f_orgid ='${this.f_filialeid}' and f_book_state='有效' `,
            orderitem: 'id'

          }
          let getMeterBooks = await this.$resetpost('rs/sql/manage_singleTable', {data: param}, {
            resolveMsg: null,
            rejectMsg: '获取营收参数出错！！！'
          })
          if (getMeterBooks.data) {
            if (getMeterBooks.data.length > 0) {
              let rs = []
              getMeterBooks.data.forEach((item) => {
                let temp = {
                  label: item.f_book_name,
                  value: item.id
                }
                rs.push(temp)
              })
              this.meterbooks = [{label: '全部', value: ''}, ...rs]
              // this.$set('$refs.paged.$refs.criteria.model.f_meter_book',[getMeterBooks.data[0].id]);
            } else {
              this.$set('$refs.paged.$refs.criteria.model.f_meter_book', [])
              this.meterbooks = [{label: '全部', value: ''}]
            }
          } else {
            this.$set('$refs.paged.$refs.criteria.model.f_meter_book', [])
          }
        } else {
          this.$set('$refs.paged.$refs.criteria.model.f_meter_book', [])
          this.meterbooks = [{label: '全部', value: ''}]
          this.initmeterbook()
        }
      },
      async initmeterbook (orgstr) {
        if (orgstr == null) {
          orgstr = this.f_filialeid
        }
        // 获取新的抄表册,先去清理所有的抄表册
        this.$GetSaleParam.meterbooks = []
        // 开始加载新的抄表册
        await this.$LoadParams.loadMeterBook(orgstr)
        this.meterbooks = [{label: '全部', value: ''}, ...this.$GetSaleParam.getMeterBooks()]
      },
      async updateParams () {
        // await this.$MagLoadParams.loadParam(this.f_filialeid)
        this.inputtoreser = []
        this.inputtoreser.push({label: '全部', value: ''})
        await this.initSlice(this.f_filialeid)
        this.inputtoreser = this.$GetSaleParam.getresinputtor(this.f_filialeid)

      },
      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.inputtoreser = [{label: '全部', value: ''}, ...rs]
      },
      loadMeterBooks () {
        this.meterbooks = [...this.meterbooks, ...this.$GetSaleParam.getMeterBooks()]
      },
      getorg (val) {
        this.f_filialeid = val[0]
      },
      DateDiffer (Date_end, Date_start) {
        if (Date_start === '') {
          return 1
        }
        Date_start = Date_start + ' 00:00:00'
        let date1 = new Date(Date_start)
        let date2 = new Date(Date_end)
        date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
        date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate())
        const diff = date2.getTime() - date1.getTime()
        const diffDate = diff / (24 * 60 * 60 * 1000)
        return diffDate
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
        priceTypeChange () {
        console.log(1)
        this.price_name = []
        if (this.$refs.paged.$refs.criteria.model.f_user_type) {
          if (this.$refs.paged.$refs.criteria.model.price_type) {
            console.log(2)
            for (let i = 0; i < this.pricers.length; i++) {
              if (this.pricers[i].type === this.$refs.paged.$refs.criteria.model.price_type && this.pricers[i].flage === this.$refs.paged.$refs.criteria.model.f_user_type[0]) {
                let rs = {
                  type:this.pricers[i].type,
                  label: this.pricers[i].label,
                  value: this.pricers[i].value
                }
                this.price_name.push(rs)
              }
            }
          }
        }
        // 选择全部时就放进去所有的气价
        // if (this.price_name.length === 0) {
        //   for (let i = 0; i < this.pricers.length; i++) {
        //     let rs = {
        //       type:this.pricers[i].type,
        //       label: this.pricers[i].label,
        //       value: this.pricers[i].value
        //     }
        //     this.price_name.push(rs)
        //   }
        // }
      },
      // 用户类型发生改变
      userTypeChange () {
        this.price_name = []
        if (this.$refs.paged.$refs.criteria.model.price_type) {
          if (this.$refs.paged.$refs.criteria.model.price_type) {
            for (let i = 0; i < this.pricers.length; i++) {
              if (this.pricers[i].type === this.$refs.paged.$refs.criteria.model.price_type && this.pricers[i].flage === this.$refs.paged.$refs.criteria.model.f_user_type[0]) {
                let rs = {
                  type: this.pricers[i].type,
                  label: this.pricers[i].label,
                  value: this.pricers[i].value
                }
                this.price_name.push(rs)
              }
            }
          }
        }
      },
      // 冲正
      delectHand (row) {
        this.$showMessage('冲正后不可恢复，确定冲正吗？', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            row.f_operator = this.$login.f.name
            row.f_operatorid = this.$login.f.id
            row.f_orgid = this.$login.f.orgid
            row.f_orgname = this.$login.f.orgs
            row.f_depid = this.$login.f.depids
            row.f_depname = this.$login.f.deps
            this.$resetpost('rs/logic/newpriceAdjustmentOffset', {data: row}).then(() => {
              // this.$dispatch('refresh', '正在处理', row)
              this.selfSearch(this.model)
            })
          }
        })
      },
      priceshow () {
        this.operatorrow = this.model.rows[0]
        this.show = true
        this.f_change_price1 = 0
        this.f_change_price2 = 0
        this.f_change_price3 = 0
        this.pricetime_states = ''
        this.operatortype = 'batch'
      },
      close () {
        this.f_change_price1 = 0
        this.f_change_price2 = 0
        this.f_change_price3 = 0
        this.show = false
        this.f_new_price = 0.0
      },
      async priceadjustment () {
        // if (this.pricetime_states == '') {
        //   this.$showAlert('请选择调价时间类型!!!', 'warning', 3000)
        //   return
        // }
        // if (this.f_new_price == '') {
        //   this.$showAlert('请输入价格!!!', 'warning', 3000)
        //   return
        // }
        if (this.operatortype == 'one') {
          this.enter()
        } else if (this.operatortype == 'batch') {
          this.$showMessage('确认生成补差记录吗?', ['cancel', 'confirm']).then(
            (response) => {
              if (response === 'confirm') {
                this.show = false
                this.locking = true
                this.getAdjustData()
              }
            })
        }
      },
      calculation (row) {
        this.f_change_price1 = 0,
        this.f_change_price2 = 0,
        this.f_change_price3 = 0,
        this.pricetime_states = ''
        this.show = true
        this.operatorrow = row
        this.operatortype = 'one'
      },
      async enter () {
        let param = {
          f_state: '有效',
          f_change_price1:this.f_change_price1,
          f_change_price2:this.f_change_price2,
          f_change_price3:this.f_change_price3,
          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.model.model.startDate + ' 00:00:00',
          f_end_date: this.model.model.endDate + ' 23:59:59',
          f_change_date: this.model.model.f_change_date,
          row: this.operatorrow
        }
        await this.$resetpost('rs/logic/newpriceAdjustment', {data: param}, {resolveMsg: '调价补差成功!', rejectMsg: '调价补差失败!'})
        this.operatorrow = {}
        this.show = false
        this.selfSearch(this.model)
      },
      async getAdjustData () {
        try {
          let param = {
            f_state: '有效',
            pricetime_states: this.pricetime_states,
            f_resource: '机表抄表',
            f_change_price1:this.f_change_price1,
            f_change_price2:this.f_change_price2,
            f_change_price3:this.f_change_price3,
            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.model.model.startDate + ' 00:00:00',
            f_end_date: this.model.model.endDate + ' 23:59:59',
            f_change_date: this.model.model.f_change_date,  //调价时间
            condition: ''
          }
          let searchCondition = {
            data: {
              condition: this.condition,
              f_change_date: this.model.model.f_change_date === '' ? '1911-01-01' : this.model.model.f_change_date,
              startDate: this.model.model.startDate,
              endDate: this.model.model.endDate, addSelectParam: '', price_states: 'not'
            }
          }
          param.condition = searchCondition
          let res = await this.$resetpost('rs/logic/newpriceAdjustmentAll', {data: param}, {
            resolveMsg: null,
            rejectMsg: null
          })
          if (res.data) {
            this.$showMessage(`本次调价用户数：${res.data.allsize},调价成功数量:${res.data.successsize},无需调价数量:${res.data.nodealsize},调价错误数量:${res.data.errorsize}`, ['confirm'])
          }
          this.close()
          this.$refs.paged.$refs.criteria.search()
          this.locking = false
          this.pricetime_states = ''
          this.f_new_price = ''
        } catch (error) {
          this.$showAlert('生成调价补差表失败!!!', 'error', 3)
          this.locking = false
        }
      },
      search () {
        this.selfSearch()
      },
      async selfSearch (args) {
        this.f_prices = [{label: '全部', value: ''}]
        args.model.addSelectParam = ''
        // args.model.joinTable =''
        if ( this.$refs.paged.$refs.criteria.model.price_type == '') {
          this.$showAlert('请输入[气价类型]后进行查询！', 'warning', 2000)
          this.model.rows = []
          this.pricechange = false
          return
        }
        if ( this.$refs.paged.$refs.criteria.model.f_change_date == '') {
          this.$showAlert('请输入[气价变更时间]后进行查询！', 'warning', 2000)
          this.model.rows = []
          this.pricechange = false
          return
        }
        if (args.model.price_states.toString() === '' || args.model.price_states.toString() === ' >0') {
          this.pricechange = false
          // args.model.addSelectParam = 'u5.f_surplus_fee,u5.id,u5.f_state,u5.f_new_price,u5.f_old_price,u5.f_change_price,u5.f_whether_pay,u5.f_sell_id,'
          // args.model.joinTable = 'left join t_surplus_detail u5 on u5.f_handplan_id = u1.f_handplan_id'
        } else {
          if(args.model.price_name[0] && args.model.price_type && args.model.price_states[0] && args.model.price_states[0]==='is null'){
            this.pricechange = true
          }else {
            this.pricechange = false
          }

        }
        this.condition = `${args.condition} and u2.f_orgid = '${this.f_filialeid}'`
        await this.model.search(this.condition, args.model)
        let arr2 = this.model.rows.filter((value, index, array) => {
          return array.findIndex(item => item.key === value.key && item.f_price === value.f_price) === index
        })
        let rs = [{label: '全部', value: ''}]
        arr2.forEach(function (item) {
          console.log('item', item.f_price)
          let temp = {
            label: item.f_price,
            value: item.f_price
          }
          rs.push(temp)
        })
        this.f_prices = rs
        console.log('this.f_price', this.f_prices)
      },
      clear () {
        Object.keys(this.$refs.paged.$refs.criteria.model).forEach((key) => {
          this.$refs.paged.$refs.criteria.model[key] = ''
        })
      }
    },
    computed: {
      getCondition () {
        return {
          f_change_date:this.$refs.paged.$refs.criteria.model.f_change_date,
          startDate:this.$refs.paged.$refs.criteria.model.startDate,
          endDate: this.$refs.paged.$refs.criteria.model.endDate,
          condition: this.condition
        }
      },
      getfield () {
        return this.config.excelHeaders
      }
    },
    watch: {
      async 'f_filialeid' (val) {
        // 更新抄表册
        this.$refs.paged.$refs.criteria.model.f_meter_book = []
        this.$refs.paged.$refs.criteria.model.f_book_slice_area = []
        this.$refs.paged.$refs.criteria.model.f_inputtor = []
        this.meterbooks = [{label: '全部', value: ''}]
        if (this.f_filialeid) {
          getPrice(this)
        }
      },
      sumsmodel: {
        handler: function (val) {
          this.getotherfooter()
        },
        deep: true
      }
    }
  }
</script>

<style>
</style>
