<template>
  <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-3 form-group">
            <label class="font_normal_body">婚介所名称</label>
            <input type="text" style="width:60%" class="input_search" v-model="model.f_orgname"
                   condition="f_orgname like '%{}%'" placeholder="婚介所名称"/>
          </div>
<!--          <div class="col-sm-3 form-group">-->
<!--            <label class="font_normal_body">文章类型</label>-->
<!--            <v-select v-model="model.f_type" style="width:60%"-->
<!--                      placeholder='文章类型'-->
<!--                      :value.sync="model.f_type"-->
<!--                      :options='$parent.$parent.getType'-->
<!--                      condition= "f_type = '{}'"-->
<!--                      close-on-select value-single>-->
<!--            </v-select>-->
<!--          </div>-->

          <div class="col-sm-3 form-group">
            <label class="font_normal_body">详细地址</label>
            <input type="text" style="width:60%" class="input_search" v-model="model.f_org_site"
                   condition="f_org_site like '%{}%'" placeholder="详细地址"/>
          </div>
          <div class="col-sm-2 form-group button-range" style="float: right">
            <button class="button_search button_spacing" @click="search()" >查询</button>
            <button class="button_new button_spacing" @click="$parent.$parent.add()">新增</button>
            <button class="button_clear button_spacing" @click="clear">清空</button>
            <div style="float: right" class="button_spacing" :class="{'button_shrink_top': criteriaShow,'button_shrink_bottom': !criteriaShow}" @click="criteriaShow = !criteriaShow"></div>
          </div>
        </div>
        <div class="row" v-show="criteriaShow">
          <div class="col-sm-3 form-group">
            <label class="font_normal_body">文章状态</label>
            <v-select v-model="model.f_state" style="width:60%"
                      placeholder='状态'
                      :value.sync="model.f_state"
                      :options='$parent.$parent.getState'
                      condition= "f_state = '{}'"
                      close-on-select value-single>
            </v-select>
          </div>
          <div class="col-sm-3 form-group">
            <label class="font_normal_body">文章标题</label>
            <input type="text" style="width:60%" class="input_search" v-model="model.f_title"
                   condition="f_title like '%{}%'" placeholder="文章标题"/>
          </div>
          <div class="col-sm-3 form-group">
            <label class="font_normal_body">操作人员</label>
            <input type="text" style="width:60%" class="input_search" v-model="model.f_operator"
                   condition="f_operator like '%{}%'" placeholder="操&ensp;作&ensp;人"/>
          </div>
        </div>
      </div>
    </criteria>
    <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
      <template partial='head'>
        <tr>
          <th>序&emsp;&emsp;号</th>
          <th>文章标题</th>
          <th>文章类型</th>
          <th>文章图片</th>
          <th>权&emsp;&emsp;重</th>
          <th>状&emsp;&emsp;态</th>
          <th>操&ensp;作&ensp;人</th>
          <th>创建时间</th>
          <th>修改时间</th>
          <th>操&emsp;&emsp;作</th>
        </tr>
      </template>
      <template partial='body'>
        <tr>
          <td style="text-align:center">{{$index+1}}</td>
          <td style="text-align:center">{{row.f_title}}</td>
          <td style="text-align:center">{{row.f_type}}</td>
          <td style="text-align:center">
            <img-self :src="row.f_img" v-if="row.f_img" :width="100" :height="100"></img-self>
            <p v-else style="margin-top: 9px;">无图片</p>
          </td>
          <td style="text-align:center">{{row.f_weight}}</td>
          <td style="text-align:center">{{row.f_state}}</td>
          <td style="text-align:center">{{row.f_operator}}</td>
          <td style="text-align:center">{{row.f_date}}</td>
          <td style="text-align:center">{{row.f_edit_date}}</td>
          <td style="text-align:center">
            <button type="button" name="button" class="btn btn-link" @click.stop="$parent.$parent.$parent.preview(row.f_link)">预览</button>
          </td>
        </tr>
      </template>
      <template partial='foot'></template>
    </data-grid>
  </criteria-paged>
</template>

<script>
  import {PagedList} from 'vue-client'

  export default {
    data () {
      return {
        model: new PagedList('wx/rs/sql/singleTable_OrderBy', 20, {tablename: '`t_article`', items: '`*`', orderitem: '`f_weight,f_date desc`'},
          null, null, null, this.weixin_mmType, this.weixin_mm),
        f_orgids: this.$login.f.orgid,

        curorgid: [this.$login.f.orgid],
        f_orgid: '',
        f_filialeids: ''
      }
    },
    ready () {
      this.$refs.paged.$refs.cri.model.f_state = '有效'
      this.search()
    },
    methods: {
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeids = val[0]
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg(this.curorgid)
        }
        args.condition = `${args.condition} and f_orgid in ${this.f_orgid}`
        this.model.search(args.condition, args.model)
      },
      add () {
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.$dispatch('add')
      },
      preview (link) {
        window.open(link)
      }
    },
    computed: {
      getState () {
        return [{label: '全部', value: ''}, {label: '有效', value: '有效'}, {label: '无效', value: '无效'}]
      },
      getType () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('微信文章类型')]
      }
    }
  }
</script>
<style lang="less" >
</style>
