<template >
  <div class="flex-row">
    <div @keyup.enter="search1" class="basic-main">
      <criteria-paged :model="model" v-ref:paged>
        <criteria @condition-changed='$parent.search' partial='criteria' v-ref:criteria>
          <div 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
                       class="input_search" condition="f_userinfo_code like '%{}%'"
                       placeholder='客户编号'
                       style="width:60%"
                       type="text"
                       v-model="model.f_userinfo_code">
              </div>

              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户名称</label>
                <input
                       class="input_search" condition="f_user_name like '%{}%'"
                       placeholder='客户名称'
                       style="width:60%"
                       type="text"
                       v-model="model.f_user_name"
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户地址</label>
                <input  class="input_search"
                       condition="f_address like '%{}%'"
                       placeholder='客户地址'
                       style="width:60%"
                       type="text"
                       v-model="model.f_address"
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">表&ensp;&ensp;&ensp;&ensp;号</label>
                <input
                       class="input_search" condition="f_meternumber like '%{}%'"
                       placeholder='表号'
                       style="width:60%"
                       type="text"
                       v-model="model.f_meternumber">
              </div>


              <div style="float:right">
                <button @click="search()" class="button_search" v-el:cba>查询</button>
                <button @click="$parent.$parent.clearmsg" class="button_clear">清空</button>
                <export-excel
                  :choose-col="true"
                  :data="{condition: $parent.$parent.condition}"
                  :field="$parent.$parent.getfield" sql-name="manage_getNewQueryInstruct" sqlurl="rs/logic/saleExport"
                  template-name='指令查看'></export-excel>
                <div
                  :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.hidden()" class="button_spacing" style="float: right"></div>
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.criteriaShow">

<!--              <div class="col-sm-2">-->
<!--                <label class="font_normal_body">组织机构</label>-->
<!--                <res-select :initresid="$parent.$parent.org"-->
<!--                            style="width:60%"-->
<!--                            @res-select="$parent.$parent.getorg"-->
<!--                            restype='organization'>-->
<!--                </res-select>-->

<!--              </div>-->

              <!--                <div class="col-sm-2 form-group">-->
              <!--                  <label class="font_normal_body">客户类型</label>-->
              <!--                  <v-select style="width:60%" :value.sync="model.f_user_type" v-model="model.f_user_type"-->
              <!--                            placeholder='客户类型'-->
              <!--                            value-single="true"-->
              <!--                            :options='$parent.$parent.userType'-->
              <!--                            close-on-select-->
              <!--                            condition="f_user_type ='{}'"-->
              <!--                  ></v-select>-->
              <!--                </div>-->
              <!--                <div class="col-sm-2 form-group">-->
              <!--                  <label class="font_normal_body">用气性质</label>-->
              <!--                  <v-select style="width:60%" :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"-->
              <!--                            placeholder='用气性质'-->
              <!--                            value-single="true"-->
              <!--                            :options='$parent.$parent.Gasproperties'-->
              <!--                            close-on-select-->
              <!--                            condition="f_gasproperties = '{}'"-->
              <!--                  ></v-select>-->
              <!--                </div>-->

              <div class="col-sm-2 form-group">
                <label class="font_normal_body">气表品牌</label>
                <v-select
                  :options='$parent.$parent.meterbrand'

                  :value.sync="model.f_gasbrand"
                  close-on-select
                  condition="f_meter_brand='{}'"
                  placeholder='气表品牌'
                  style="width:60%"
                  v-model="model.f_gasbrand">
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">指令类型</label>
                <v-select :options='$parent.$parent.instructtype' :value.sync="model.f_instruct_type" close-on-select
                          condition="f_instruct_type='{}'"
                          placeholder='指令类型'
                          style="width:60%"
                          v-model="model.f_instruct_type"></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">执行状态</label>
                <v-select :options='$parent.$parent.instructstate' :value.sync="model.f_instruct_state" close-on-select
                          condition="f_instruct_state='{}'"
                          placeholder='执行状态'
                          style="width:60%"
                          v-model="model.f_instruct_state"
                ></v-select>
              </div>

              <div class="col-sm-2 form-group">
                <label class="font_normal_body">指令时间</label>
                <datepicker :format="'yyyy-MM-dd HH:mm:ss'" :value.sync="model.f_start_date"
                            condition="f_instruct_date >= '{}'"
                            placeholder="起始时间"
                            style="width:60%"
                            v-model="model.f_start_date"
                ></datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&emsp;&emsp;至&emsp;</label>
                <datepicker :format="'yyyy-MM-dd HH:mm:ss'" :value.sync="model.f_end_date"
                            condition="f_instruct_date <= '{}'"
                            placeholder="结束时间"
                            style="width:60%"
                            v-model="model.f_end_date"
                ></datepicker>
              </div>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" class="list_area table_sy" id="queryinstruct" partial='list' v-ref:grid>
          <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'>
            <tr>
              <td style="text-align:center">
                <nobr>{{$index+1}}</nobr>
              </td>
              <td style="text-align:center">
                <span @click="$parent.$parent.$parent.dealmsg(row)"><a>{{row.f_userinfo_code}}</a></span>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_user_name}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_address}}</nobr>
              </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_instruct_type}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_instruct_title}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_instruct_state}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_receive_state}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_instruct_date}}</nobr>
              </td>
              <td style="text-align:center"><nobr>{{row.f_send_date}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_callback_date}}</nobr></td>
              <td style="text-align:center">
                <nobr>{{row.f_orgname}}</nobr>
              </td>
            </tr>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>
<script>
  import {PagedList} from 'vue-client'
  import co from 'co'
  import * as Util from '../../../Util'
  import getLodop from '../../../plugins/LodopFuncs'
  import {HttpResetClass} from 'vue-client'
  import plugins from '../../../plugins/GetLoginInfoService'

  let readyGen = async function (self) {
    await self.$MagLoadParams.loadParam()
    self.initQueryParam()
    self.getinstructtype()
    self.getinstructstate()
    await self.$getConfig(self, 'HandManager')
    console.log('指令查看config', self.config)
    self.getfield = self.config.excelHeaders
    // self.reflash()
  }
  export default {
    title: '指令查看',
    data () {
      return {
        model: new PagedList('rs/sql/manage_getNewQueryInstruct', 50),
        row: null,
        isLoading: true,
        searchshow: true,
        criteriaShow:false,
        Gasproperties:[],
        meterbrand: [],
        userType:[],
        instructtype:[],
        instructstate:[],
        org:[this.$login.f.orgid],
        orgcondition:' and f_filialeid = ' + this.$login.f.orgid,
        show: false,
        condition:'',
        getfield: {},
        config: {
          excelHeaders: {
            'f_userinfo_code': '客户编号','f_address': '客户地址','f_user_name': '客户姓名',
            'f_meternumber': '表号','f_meter_brand': '气表品牌','f_instruct_type': '指令类型',
            'f_instruct_state': '执行状态','f_receive_state': '执行结果','f_instruct_date': '指令时间',
            'f_orgname': '组织机构',
          }
        },
      }
    },
    ready () {
      readyGen(this)
      this.$refs.paged.$refs.criteria.model.f_start_date = Util.toStandardDateString() + ' 00:00:00'
      this.$refs.paged.$refs.criteria.model.f_end_date = Util.toStandardDateString() + ' 23:59:59'
      this.$refs.paged.$refs.criteria.search()
    },
    methods: {
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      getorg(obj) {
        if(plugins.convertToIn(obj)!==null&&plugins.convertToIn(obj)!==''){
          this.orgcondition = " and f_filialeid in " + plugins.convertToIn(obj)
        }else{
          this.orgcondition = " and f_filialeid = " + this.$login.f.orgid
        }

      },
      initQueryParam () {
        let arr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          if(item.value.f_meter_type==='物联网表'){
            temp.label = item.label
            temp.value = item.value.f_meter_brand
            arr.push(temp )
          }

        })
        this.meterbrand = [{label: '全部', value: ''}, ...arr]
      },
      getinstructtype(){
        this.instructtype=[]
        let load = new HttpResetClass()
        load.load('POST', 'rs/sql/singleTableParam', {
          data: {
            items:'f_instruct_type',
            tablename:'t_instruct',
            condition:'f_instruct_type is not null  group by f_instruct_type'
          }
        },{warnMsg:null,resolveMsg:null}).then((res) => {
          this.instructtype.push({label: '全部', value: ''})
          res.data.forEach((item) => {
            this.instructtype.push({label: item.f_instruct_type, value: item.f_instruct_type})
          })
        })

      },
      getinstructstate(){
        this.instructstate=[]
        let load = new HttpResetClass()
        load.load('POST', 'rs/sql/singleTableParam', {
          data: {
            items:'f_instruct_state',
            tablename:'t_instruct',
            condition:'f_instruct_state is not null  group by f_instruct_state'
          }
        },{warnMsg:null,resolveMsg:null}).then((res) => {
          this.instructstate.push({label: '全部', value: ''})
          res.data.forEach((item) => {
            this.instructstate.push({label: item.f_instruct_state, value: item.f_instruct_state})
          })
        })

      },
      clearmsg () {
        this.$refs.paged.$refs.criteria.model = {}
      },
      clickshow () {
        this.searchshow = !this.searchshow
      },
      dealmsg (val) {
        val.model = this.model.model
        this.$emit('deal-msg', val)
      },
      search (args) {
        // this.obj.resids = this.obj.resids.replace(/\./g, ''),
        args.condition =  `${args.condition}`+this.orgcondition
        console.log(args.condition+"args.condition")
        this.condition = args.condition
        this.model.search(args.condition, args.model)
      }

    },
    computed: {
     userType () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
       Gasproperties () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
    }

    }
  }
</script>
<style>
  .form-input-group label {
    text-align: right;
    width: auto;
  }
  .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>
