<template>
  <div>
    <div style="flex: 1.5" class="flex">
      <div class="flex">
        <criteria-paged :model="model" v-ref:paged>
          <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch">
            <div novalidate class="form-inline auto" partial>
              <div class="row">
                <div class="form-group col-sm-3">
                  <label class="font_normal_body">客户编号</label>
                  <input type="text" class="input_search"  style="width: 60%" v-model="model.f_userinfo_code"
                         condition="f_userinfo_code like '%{}%'" placeholder='用户编号'>
                </div>
                <div class="form-group col-sm-3">
                  <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-3">
                  <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 style="float:right;margin-top: 8px" class="span">
                  <button class="button_spacing button_search" @click="search()">查 询</button>
                  <button class="button_clear button_spacing" @click="clear">清空</button>
                  <div style="float: right" class="button_spacing" :class="{'button_shrink_top': criteriaShow,'button_shrink_bottom': !criteriaShow}" @click="$parent.$parent.hidden"></div>

                </div>
              </div>
              <div class="row" v-show="$parent.$parent.criteriaShow">
                <div class="form-group col-sm-3">
                  <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="address.f_address like '%{}%'">
                </div>
                <div class="form-group col-sm-3">
                  <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-3">
                  <label class="font_normal_body">气表状态</label>
                  <v-select id="f_paytype"
                            v-model="model.f_table_state"
                            placeholder='气表状态'
                            :value.sync="model.f_table_state"
                            :options='$parent.$parent.tableStates'
                            condition="f_table_state = '{}'"
                            style="width: 60%"
                            close-on-select></v-select>
                </div>
<!--                <div class="form-group col-sm-3">-->
<!--                  <label class="font_normal_body">气表品牌</label>-->
<!--                  <v-select id="f_meter_brand"-->
<!--                            v-model="model.f_meter_brand"-->
<!--                            placeholder='气表品牌'-->
<!--                            :value.sync="model.f_meter_brand"-->
<!--                            :options='$parent.$parent.meterbrand'-->
<!--                            condition="f_meter_brand = '{}'"-->
<!--                            close-on-select style="width: 60%"></v-select>-->
<!--                </div>-->
                <div class="form-group col-sm-3">
                  <label class="font_normal_body">用气性质</label>
                  <v-select v-model="model.f_gasproperties"
                            placeholder='用气性质'
                            :value.sync="model.f_gasproperties"
                            :options='$parent.$parent.gasproperties'
                            condition="u.f_gasproperties = '{}'"
                            close-on-select style="width: 60%"></v-select>
                </div>
                <div class="form-group col-sm-3">
                  <label class="font_normal_body">卡&emsp;&emsp;号</label>
                  <input type="text" class="input_search" style="width:60%" v-model="model.f_card_id" placeholder='卡号'
                         condition="f_card_id like '%{}%'">
                </div>
              </div>
            </div>
          </criteria>
          <data-grid :model="model" v-ref:grid class="list_area table_sy" partial='list'>
            <template partial='head'>
              <tr>
                <th><nobr>序号</nobr></th>
                <th style="white-space: nowrap;">客户编号</th>
                <th>调价</th>
                <th style="white-space: nowrap;" >客户基本信息</th>
                <th style="white-space: nowrap;" >表具信息</th>
                <th style="white-space: nowrap;" >分类信息</th>
              </tr>
            </template>
            <template partial='body'>
              <td  :class="{'bg-danger' : row.f_table_state === '停用' }" style="text-align: center;">{{$index + 1}}</td>
              <td  :class="{'bg-danger' : row.f_table_state === '停用' }"><nobr>{{row.f_userinfo_code}}</nobr> </td>
              <td>
                <button type="button" name="button" class="btn btn-link"
                        @click.stop="$parent.$parent.$parent.adjust(row)">调价
                </button>
              </td>
              <td style="white-space: nowrap;" :class="{'bg-danger' : row.f_table_state === '停用' }">{{row.f_user_name}}&nbsp;&nbsp;{{row.f_user_phone}}&nbsp;&nbsp;{{row.f_address}}</td>
              <td style="white-space: nowrap;" :class="{'bg-danger' : row.f_table_state === '停用' }">{{row.f_user_id}}&nbsp;&nbsp;{{row.f_gasproperties}}&nbsp;&nbsp;{{row.f_meter_brand}}
                &nbsp;&nbsp;{{row.f_meter_style}}&nbsp;&nbsp;{{row.f_price_type}}&nbsp;&nbsp;{{row.f_price_name}}
              </td>
              <td style="white-space: nowrap;" :class="{'bg-danger' : row.f_table_state === '停用' }" style="text-align: center;">{{row.f_meter_type}}&nbsp;&nbsp;({{row.f_meter_type.includes('物联网表') ? row.f_table_state : row.f_whether_hairpin }})
              </td>


            </template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
  <modal :show.sync="show" width="1000px" title="调价补差" v-ref:modal large backdrop="false">
    <article slot="modal-body" style="height:150px" class="modal-body">
      <div class="form-group col-sm-3" :class="[this.f_unit_price<=0 ? 'has-error select-error' : '']">
        <label class="font_normal_body">单价</label>
        <input type="number" class="input_search"  min="0.00" @blur.prevent="comput()"
               style="width: 60%" v-model="f_unit_price"
               placeholder='单价'>
      </div>
      <div class="form-group col-sm-3" :class="[this.f_gas<=0 ? 'has-error select-error' : '']">
        <label class="font_normal_body">气量</label>
        <input type="number" class="input_search"  min="0.00" @blur.prevent="comput()"
               style="width: 60%" v-model="f_gas"
              placeholder='气量'>
      </div>
      <div class="form-group col-sm-3">
        <label class="font_normal_body">金额</label>
        <input type="number" class="input_search"  style="width: 60%" v-model="f_price" readonly
              placeholder='金额'>
      </div>
      <div class="form-group col-sm-12" style="margin-left: 450px;"  v-if="this.f_gas>0&&this.f_unit_price>0">
        <button class="button_search" @click="commit()">生成补差信息</button>
      </div>
    </article>

    <footer slot="modal-footer" class="modal-footer">
    </footer>

  </modal>
</template>

<script>
  import {PagedList} from 'vue-client'
const myMap = new Map()
  let asyncReadyGen = async function (self) {
    await self.$LoadParams.loadParam()
    self.initQueryParam()
  }
  export default {
    'title': '',
    data () {
      return {
        model: new PagedList('rs/sql/sale_getUser', 20),
        show: false,
        criteriaShow: false,
        row: null,
        f_unit_price: 0,
        f_gas: 0,
        f_price: 0,
        tableStates: this.$appdata.getParam('气表状态') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('气表状态')] : [],

        fileStates: this.$appdata.getParam('档案状态') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('档案状态')] : [],

        // userTypes: this.$appdata.getParam('用户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')] : [],
        gasproperties: this.$appdata.getParam('用气性质') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')] : [],

        meterbrand: []
      }
    },
    ready () {
      asyncReadyGen(this)
      this.search()
    },
    events: {
      'showfiles' (val) {
        console.log(val)
      }
    },
    methods: {
      initQueryParam () {
        let arr = []
        this.$GetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          temp.label = item.label
          temp.value = item.value.f_meter_brand
          arr.push(temp)
        })
        this.meterbrand = [{label: '全部', value: ''}, ...arr]
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      adjust (row) {
        this.row = row
        this.show = !this.show
      },
      async commit () {
        let data = {
          f_user_id: this.row.f_user_id,
          f_userfiles_id: this.row.f_userfiles_id,
          f_userinfo_id: this.row.f_userinfo_id,
          f_type: '调价补差',
          f_state: '有效',
          f_real_amount: this.f_gas,
          f_change_price: this.f_unit_price,
          f_surplus_fee: this.f_price,
          f_whether_pay: '否',
          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
        }
        await this.$resetpost('rs/entity/t_surplus_detail', data)
        this.show = false
        this.row = null
        this.f_gas = 0
        this.f_unit_price = 0
        this.f_price = 0
        this.$dispatch('refresh')
      },
      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      comput () {
        if (this.f_gas > 0 && this.f_unit_price > 0) {
          this.f_price = this.f_gas * this.f_unit_price
        }
      },
      selfSearch (args) {
        args.condition = `${args.condition} and u.f_orgid = '${this.$login.f.orgid}' `
        // args.condition=`${args.condition}`
        this.model.search(args.condition, args.model)
      }
    }
  }
</script>
<style>
  .datapanel {
    color: #333;
    background-color: white;
    padding: 10px 20px;
    border-radius: 15px;
  }
</style>
