<template>
  <div class="flex">
    <div class="row" style="height: auto">
      <div class="form-group col-sm-4 button-range" >
        <button class="button_search " @click="cancelmain()" >返回</button>
      </div>
    </div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial v-show="false" >
          <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 style = "float:right;margin-top:10px">
              <button class="button_search"  @click="search()" v-el:cba>查询</button>
            </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>
          </tr>
        </template>
        <template partial='body' >
          <tr >
            <td style="text-align:center;">{{$index+1}}</td>
            <td style="text-align: center;">
              <button class="btn btn-link" @click.stop="$parent.$parent.$parent.showchangedetail(row)">查看</button>
            </td>
            <td style="text-align: center;">
              <button class="btn btn-link" @click.stop="$parent.$parent.$parent.showupload(row)">查看</button>
            </td>
            <td style="text-align:center">{{row.f_oldversion}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_newversion}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_describe}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_operate_date}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_operator}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
    <modal  :show.sync="show" width="1000px" backdrop="true">
      <article slot="modal-body"  class="modal-body"  title="变更记录" >
        <price-change-detail :row="rows"  @select-changed="selectDoThing"  v-on:toggle="close"></price-change-detail>
      </article>
      <footer slot="modal-footer" class="modal-footer">

      </footer>
    </modal>
    <modal  :show.sync="uploadfile" width="1000px" backdrop="true">
      <article slot="modal-body"  class="modal-body"  title="变更附件" >
        <upload-files :blodid="blodid" cols="col-sm-6" fusetype="气价修改"></upload-files>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
  </div>
</template>

<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  export default {
    title: '气价操作记录',
    data () {
      return {
        show: false,
        uploadfile: false,
        blodid: '',
        rows: {},
        model: new PagedList('/rs/sql/singleTable_OrderBy', 5,
          {
            tablename: `'t_pricerecord'`,
            items: '`*`',
            orderitem: '`id desc`'
          })
      }
    },
    props: ['row'],
    ready () {
      this.search()
    },
    methods: {
      showchangedetail (row) {
        this.show = true
        this.rows = row
      },
      async showupload (row) {
        this.uploadfile = true
        console.log('================')
        console.log(row)
        let condition = 'f_price_id=' + row.f_price_id + ' and f_version=' + row.f_oldversion + " and f_state='有效'"
        let res = await this.$resetpost('rs/sql/singleTable_OrderBy', {
          data: {
            items: '*',
            tablename: 't_stairprice',
            orderitem: 'id DESC',
            condition: condition
          }
        }, {resolveMsg: null, rejectMsg: '获取记录出错'})
        this.blodid = res.data[0].id
      },
      search () {
        if (this.row) {
          this.condition = `f_price_id = '${this.row.f_price_id}'`
          if (this.$refs.paged.$refs.criteria.condition) {
            this.condition += `and ${this.$refs.paged.$refs.criteria.condition}`
          }
          this.model.search(this.condition, this.model)
        }
      },
      cancelmain () {
        this.$parent.changeView = false
      },
      selectDoThing () {

      }
    },
    watch: {
      'row' () {
        this.search()
      }
    }
  }
</script>

