<template >
  <div id="stand-work-list" class="flex bg-white p-10">
    <div class="span">
      <textarea name="name" rows="8"  v-model="sqlstr" class="form-control" style="resize: vertical;"></textarea>
      <button  type="button" class="btn btn-default" @click='search'>查询</button>
      <table class="table table-bordered">
        <thead class="text-left">
          <th v-for="oneth in dataname">
            <nobr>{{oneth.thname}}</nobr></th>
        </thead>
        <tbody>
        <tr v-for="onedata in datamodel">
          <td v-for="oneth in dataname">{{getprop(onedata,oneth.thname)}}</td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
  import co from 'co'
  import { PagedList, HttpResetClass } from 'vue-client'
  import * as Util from '../Util'
  export default {
    title: 'SQL查询',
    props: {
      datamodel: [],
      sqlstr:'',
      dataname: [],
    },
    data () {
      return {
        datamodel: [],
        sqlstr:'',
        dataname: [],
      }
    },
    ready () {

    },
    watch: {

    },
    methods: {
      search(){
        let http1 = new HttpResetClass()
        this.datamodel=[],
          this.dataname=[],
        http1.load('POST', 'rs/sql/sqlsearch', {data:
      {
        condition: this.sqlstr
      }
      }, {resolveMsg: null, rejectMsg: null}).then((req) => {
          for (var pname in req.data[0]) {
            console.log(pname)
            this.dataname.push({"thname":pname})
          }
          this.datamodel=req.data;
        })
      },
      getprop(obj,name){
        var str=''
        for (var item in obj){
          if(item.toString()==name.toString()){
            str +=obj[item]
          }
        }
        console.log(str)
        return str
      },
    },
    components: {

    }
  }
</script>
