<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:cri @condition-changed='$parent.selfSearch' >
          <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">设备编号</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_terminal_number"
                condition="f_terminal_number like '%{}%'" placeholder="设备编号">
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">设备地址</label>
                <v-select :value.sync="model.f_address"
                          v-model="model.f_address"
                          style="width: 60%"
                          condition="f_address in {}"
                          multiple="true"
                          :options='$parent.$parent.faddress' placeholder='请选择' >
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">设备名称</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_terminal_name"
                       condition="f_terminal_name like '%{}%'" placeholder="设备名称">
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">机器编号</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_machine_number"
                       condition="f_machine_number like '%{}%'" placeholder="机器编号">
              </div>
              <div class="span" style="float:right;">
                <button class="button_search button_spacing" @click="search()">查询</button>
                <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
                <export-excel :choose-col="true"
                              :data="$parent.$parent.getCondition"
                              :field="$parent.$parent.getExportField"
                              sqlurl="rs/logic/saleExport" sql-name="qc_statistics_manage" template-name='圈存机查询导出'></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 for="endDate" class="font_normal_body">组织机构</label>
              <right-tree :userid.sync='$parent.$parent.userid' :source.sync='$parent.$parent.source'  @re-res="$parent.$parent.getRes"></right-tree>
              </div>
              <div class="col-sm-2  form-group">
                <label for="startDate" class="font_normal_body">开始日期:</label>
                <datepicker id="startDate" placeholder="开始日期"
                            v-model="model.startDate" style="width: 60%"
                            :value.sync="model.startDate"
                            :disabled-days-of-Week="[]"
                            condition="f_create_time >= to_date('{} 00:00:00','yyyy-mm-dd hh24:mi:ss')"
                            :format="'yyyy-MM-dd'">
                </datepicker>
              </div>
              <div class="col-sm-2  form-group">
                <label for="endDate" class="font_normal_body"> 结束日期:</label>
                <datepicker id="endDate" placeholder="结束日期"
                            v-model="model.endDate" style="width: 60%"
                            :value.sync="model.endDate"
                            condition="f_create_time <= to_date('{} 23:59:59','yyyy-mm-dd hh24:mi:ss')"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd'">
                </datepicker>
              </div>
            </div>
          </div>
        </criteria>

        <data-grid :model="model" partial='list' class="list_area table_sy" @dblclick="$parent.dblclick" v-ref:grid>
          <template partial='head'>
            <tr>
              <th>序号</th>
              <th>设备编号</th>
              <th>设备名称</th>
              <th>机器编号</th>
              <th>设备地址</th>
              <th>设备状态</th>
              <th>失联状态</th>
              <th>交易笔数</th>
              <th>交易金额</th>
            </tr>
          </template>
          <template partial='body'>
            <td style="text-align: center;">
              <nobr>{{ $index + 1 }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_terminal_number }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_terminal_name }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_machine_number }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_address }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_state }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_online }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.onlinetimes }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_orderamount }}</nobr>
            </td>
          </template>
        </data-grid>
      </criteria-paged>

      <table class="table-hover" style="position: absolute;bottom: 6px">
        <tr 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;color: #5CB95C;font-weight: bold">
            交易金额:&emsp;<font style="color:#000;">{{ sumsmodel.f_orderamount }}</font>
          </td>
          <td
            style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">
            交易笔数:&emsp;<font style="color:#000;">{{ sumsmodel.onlinetimes }}</font>
          </td>
        </tr>
      </table>
    </div>
  </div>

</div>
</template>

<script>
import {HttpResetClass, PagedList} from 'vue-client'
import exportConfig from '../config/exportConfig'

let readyGen = async function (self) {
  self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
  self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
  self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
  this.$refs.paged.$refs.criteria.model.filiale = this.$login.f.f_fengongsi
  let HttpReset = new HttpResetClass()
  await HttpReset.load('POST', 'rs/sql/singleTable_OrderBy', {
    data: {
      items: ' distinct F_TERMINAL_NUMBER ',
      tablename: 'T_EQUIPMENT',
      condition: '  F_EQUIPMENT_TYPE =\'圈存机\' and f_state =\'正常\' ',
      orderitem: ' F_TERMINAL_NUMBER'
    }
  }, {resolveMsg: null, rejectMsg: '获取设备列表失败'}).then(res => {
    self.privilege = res.data.map(item => {
      return {label: item.f_terminal_number, value: item.f_terminal_number}
    })
  })
}
export default {
  title: '圈存机查询',
  props: [],
  data() {
    return {
      filialeNameStr: this.$login.f.orgpathnames,
      filialeCodeStr: this.$login.f.orgpathstr,
      model: new PagedList('rs/sql/qc_statistics_manage', 20,
        { startDate: 'this.model.startDate', endDate: 'this.model.endDate', filialeCodeStr: 'this.model.filialeCodeStr', filiale: 'this.model.filiale'}, {f_orderamount: '', onlinetimes: '', }),
      criteriaShow: false,
      sumsmodel: {},
      source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() != $role$))`,
      faddress:[]
    }
  },
  ready () {
    readyGen(this)
    this.getaddress()
  },
  methods: {
    async  getaddress(){
      let HttpReset = new HttpResetClass()
      var data = await HttpReset.load('POST', 'rs/sql/get_address', {
        data: {
          condition: 'F_EQUIPMENT_TYPE=\'圈存机\' and f_state=\'正常\'  '
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      console.log('地址',data)
      let address = []
      for (let row of data.data){
        address.push({label: row.f_address, value: row.f_address})
      }
      this.faddress = address
    },
    getRes(obj) {
      console.log(obj, '组织')
      this.filialeNameStr = obj.res
      this.filialeCodeStr = obj.resids
    },
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    selfSearch(args) {
      const conditionParams = this.getCondition
      this.model.params.startDate = conditionParams.startDate
      this.model.params.endDate = conditionParams.endDate
      this.model.params.condition = conditionParams.condition
      this.model.search(conditionParams.condition, args.model)
      this.$refs.paged.$refs.criteria.model.filialeCodeStr = this.filialeCodeStr
      this.exportCondition = { orderitem: `${this.model.paramSource.orderitem}` }
    },
    clear() {
      Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
        this.$refs.paged.$refs.cri.model[key] = ''
      })
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
  },
  computed: {
    getCondition() {
      const startDate = this.$refs.paged.$refs.cri.model.startDate || this.$login.toStandardDateString()
      const endDate = this.$refs.paged.$refs.cri.model.endDate || this.$login.toStandardDateString()
      const condition = this.$refs.paged.$refs.cri.condition || ''
      return {
        orderitem: 'f_paytime desc',
        startDate: startDate,
        endDate: endDate,
        condition: condition
      }
    },
    getExportField() {
      return exportConfig.valueAddedConfig
    },
  },
}

</script>

<style scoped>

</style>
