<template>
  <div 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-4 form-group">
              <label class="font_normal_body">地址信息</label>
              <input  type="text" class="input_search" style="width:60%" v-model="model.f_address"
                      condition="f_address like '%{}%'" placeholder="地址信息"
                      :size="model.f_address ? model.f_address.length*2 : 8"/>
            </div>
            <div class="col-sm-4 form-group button-range" >
              <button class="button_search button_spacing" @click="search()" >查询</button>
              <button class="button_new button_spacing"  style="width: max-content" @click="$parent.$parent.add('民用')">添加民用</button>
              <button class="button_new button_spacing" style="width: max-content" @click="$parent.$parent.add('非民用')">添加特殊地址</button>
              <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid  :model="model" partial='list' style="overflow: auto" class="list_area table_sy"  v-ref:grid>
        <template partial='head'>
          <tr>
            <th><nobr>地址信息</nobr></th>
            <th><nobr>选择</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center"><nobr>{{row.f_address}}</nobr></td>
            <td style="text-align:center">
              <button type="button" name="button" class="button_export"
                      @click.stop="$parent.$parent.$parent.confirmaddress(row)">确认选择</button>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
  <modal :show.sync="showFile" v-ref:modal backdrop="true">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="closeFile"><span>&times;</span></button>
      <h4 class="modal-title">选择文件</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="form-group">
        <file-upload class="my-file-uploader" name="useraddressUploadFile" action="rs/file/uploadFile" tagname="确定" multiple v-ref:file></file-upload>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer"></footer>
  </modal>
</template>

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

  export default {
    data () {
      return {
        criteriaShow: false,
        model: new PagedList('rs/sql/address_getAddress', 20, {}),
        addflag: false,
        addtitle: '',

        // 公司下拉
        curorgid: [this.$login.f.orgid],
        f_orgid: '',

        // 文件上传弹框
        showFile: false
      }
    },
    title: '地址列表',
    props: {
      f_filialeid: {
        type: String
      }
    },
    ready () {
      console.log('f_filialeid8888:',this.f_filialeid)
      this.search()
    },
    methods: {
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      // 添加方法
      add (val) {
        if (this.f_filialeid) {
          this.$refs.paged.$refs.grid.selectStore.selected = null
          this.$dispatch('add', val)
        } else {
          this.$showAlert('请先选择左上角的所在分公司', 'warning', 2000)
        }
      },
      // 修改
      modify (val) {
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.$dispatch('modify', val)
      },
      confirmaddress (row) {
        console.log('------------------------', row)
        this.$refs.paged.$refs.cri.search()
        this.$dispatch('confirmaddress', row)
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },

      selfSearch (args) {
        if (!this.f_filialeid) {
          this.getorg([this.$login.f.orgid])
        }
        args.condition = `${args.condition} and a.f_userinfo_id is null and a.f_filialeid = '${this.f_filialeid}'`
        this.model.search(args.condition, args.model)
      },

      // 清空
      clear () {
        this.$refs.paged.$refs.cri.model = {}
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeid = val[0]
      }
    },
    watch: {
      // 'company' (val) {
      //   this.f_orgid = val
      //   this.f_filialeids = val
      // }
    }

  }
</script>
