<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex">
        <div style="flex:1;" class="flex" >
          <criteria-paged :model="model" v-ref:paged>
            <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
              <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
                <div class="row">
                  <div class="col-sm-2">
                    <label class="font_normal_body">客户名称</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.buyerName"
                           condition="buyerName like '%{}%'" placeholder="客户名称">
                  </div>
                  <div class="col-sm-2">
                    <label class="font_normal_body">客户电话</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.buyerPhone"
                           condition="buyerPhone like '%{}%'" placeholder="客户电话">
                  </div>
                  <div class="col-sm-2">
                    <label class="font_normal_body">身份证号</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.buyerCardNo"
                           condition="buyerCardNo 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>
                    <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">
                    <label class="font_normal_body">客户地址</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.location"
                           condition="location like '%{}%'" placeholder='客户地址'>
                  </div>
                </div>
              </div>
            </criteria>

            <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy" :classname="$parent.classname">
              <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>
                </tr>
              </template>
              <template partial='body'>
                <td style="text-align:center">
                  <button type="button" name="button" class="button_export"
                          @click.stop="$parent.$parent.$parent.confirmaddress(row)">确认选择</button>
                </td>
                <td style="text-align: center;"><nobr>
                  <span >{{$index+1}}</span>
                </nobr> </td>
                <td style="text-align: center;"><nobr>
                  <span >{{row.buyername}}</span>
                </nobr> </td>
                <td style="text-align: center;">
                  <nobr>{{row.buyerphone}}</nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>{{row.buyercardno}}</nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>{{row.sellername}}</nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>{{row.sellerphone}}</nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>{{row.sellercardno}}</nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>{{row.realno}}</nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>{{row.location}}</nobr>
                </td>
              </template>
              <template partial='foot'>
              </template>
            </data-grid>
          </criteria-paged>


        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import {PagedList} from 'vue-client'
  import { HttpResetClass } from 'vue-client'
  export default{
    data() {
      return {
        model: new PagedList('rs/sql/selTransferQuery', 20),
        criteriaShow: false,
        modelval: [],
        printshow: false,
        all: false,
        fields: {},
        rowdata:{},
        meterbrands: [],
        pricenames: [],
        gasproperties:[],
        prices: [],
        selectflag :0,
      }
    },
    props:['f_filialeid'],
    ready() {
        this.getconfig();
    },
    methods:{
      async getconfig(){
        try{
          let result = await this.$resetget("rs/vue/transfer.json", {}, {resolveMsg: null, rejectMsg: null})
          if(result.data){
            this.selectflag = result.data.flag;
          }
        }catch(e){
        }

      },
      confirmaddress (row) {
        this.$dispatch('confirmuserfiles',row)
      },
      search(){
        this.$refs.paged.$refs.cri.search()
      },
      selfSearch(args) {
        let condition  = '';
        if(this.selectflag){
          args.condition  = `${args.condition}  and flag = ${this.selectflag}`
        }else{
          args.condition  = `${args.condition}  and flag = 0`
        }
        this.model.search(args.condition+condition, args.model);
      },
      clear() {
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = ''
        })
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },

      close() {
        this.printshow = false;
        this.all = false
      },
      sortModelval() {
        let sortModel = []
        Object.keys(this.fields).forEach((key) => {
          if (this.modelval.includes(key)) {
            sortModel.push(key)
          }
        })
        this.modelval = sortModel
        console.log('选择的打印的字段', this.modelval)
      },
    },
    watch: {
      'all'(val) {
        if (val) {
          this.modelval = this.bodyData
        } else {
          this.modelval = defaultPrint.config
          this.put()
        }
      },
      'modelval.length'() {
        this.put()
      },
    }

  }


</script>
