<template>
  <div class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-4" >
              <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 = '{}'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-4 button-range" >
              <button class="button_search" style="margin-right: 10px"  @click="search()" v-el:cba>查询</button>
              <export-excel   :data="$parent.$parent.exportParameter"
                              :field="$parent.$parent.getDetailfield"
                              :choose-col="true"
                              sqlurl="api/af-safecheck/logic/exportfile" sql-name="getCheckPlanUserListTS" template-name='安检情况明细'></export-excel>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" class="table_sy"  partial='list' 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>
          </tr>
        </template>
        <template partial='body' >
          <tr >
            <td style="text-align:center;">{{$index+1}}</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">{{row.f_user_name}}</td>
            <td style="text-align:center">{{row.f_user_type}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_address}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_plan_name}}</td>
            <td style="text-align:center">{{row.f_state}}</td>
            <td style="text-align:center">{{row.f_entry_status}}</td>
            <td style="text-align:center">{{row.f_offsite_time}}</td>
            <td style="text-align:center">{{row.f_defect_content}}</td>
            <td style="text-align:center">{{row.f_check_number}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  export default {
    title: '安检情况明细(未整合)',
    data () {
      return {
        model: new PagedList('api/af-safecheck/sql/getCheckPlanUserListTS', 50, {}),
        condition: '',
        getfield: {},
        getDetailfield:{},
        config: {
          excelHeaders: {
            'f_price_name': '气价名称', 'f_userinfo_code': '客户编号', 'f_user_name': '客户姓名', 'f_address': '客户地址',
            'f_orgname': '组织机构'
          },
          // 详情-导出Excel表头
          excelDetailHeaders: {
            'f_userinfo_code':'用户编号',
            'f_user_name':'用户姓名',
            'f_user_type':'用户类型',
            'f_address':'用户地址',
            'f_plan_name':'计划名称',
            'f_state':'是否已检',
            'f_entry_status':'安检状态',
            'f_offsite_time':'安检时间',
            'f_defect_content':'隐患状态',
            'f_check_number':'上报条数',
          }
        }
      }
    },
    props: ['checkrow'],
    ready () {
      this.search()
      this.getfield = this.config.excelHeaders
      this.getDetailfield = this.config.excelDetailHeaders
    },
    computed: {
      // 导出到Excel的条件构造
      exportParameter() {
        return {
          condition: this.$refs.paged.model.condition,
          startyear: this.$parent.$refs.list.model.params.startyear,
          startmon: this.$parent.$refs.list.model.params.startmon,
          endyear :this.$parent.$refs.list.model.params.endyear,
          endmon: this.$parent.$refs.list.model.params.endmon
        }
      }
    },
    methods: {
      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      selfSearch (args) {
        // args.condition = `${args.condition} and f_price_id = '${this.priceid}'`
        console.log(this.checkrow,this.$parent.$refs.list,'cew')
        var cc= this.$parent.$refs.list.model.condition
        console.log(cc)
        this.condition = args.condition
        args.condition=args.condition+' and '+ cc
        console.log( this.condition,args.condition)
        var self=this
        this.$parent.$refs.list.nameForSql.forEach(function (s) {
          if(s!=='f_user_number'&&s!=='f_year_number'&& self.checkrow[s]!==undefined&&self.checkrow[s]){
            console.log("打印checkrow:"+self.checkrow[s])
            var rowsname=self.checkrow[s].replace('*&','')
            args.condition=args.condition+" and  s."+s+"=\'"+rowsname+"\'"
          }
        })
        console.log('==============================')
        console.log(this.$refs.paged.model)
        console.log(this.$refs.paged.model.condition)
        console.log( this.condition,args.condition)
        this.model.search(args.condition, args.model)
      },
      dealmsg (val) {
        this.$parent.f_userinfo_id=val.f_userinfoid
        console.log("666666666666666666")
        console.log(this.$parent.f_userinfo_id)
        this.$parent.listpage=false
      }
    },
    watch: {
      'checkrow' () {
        this.search()
      }
    }
  }
</script>
