<template>
  <div class="flex-row">
    <div class="basic-main">
      <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-2  form-group">
                <label class="font_normal_body">组织机构</label>
                <res-select restype='organization'
                            @res-select="$parent.$parent.getorg"
                            is-mul="false"
                            :initresid='$parent.$parent.curorgid'>
                </res-select>
              </div>
              <div class="col-sm-2  form-group">
                <label class="font_normal_body">销货方名称</label>
                <input  type="text" class="input_search" style="width:60%" v-model="model.f_saler_name" style="width:60%"
                        condition="f_saler_name like '%{}%'" placeholder="销货方名称"
                />
              </div>
              <div style="float: right">
                <button class="button_search button_spacing" @click="search()" >查询</button>
                <button class="button_new button_spacing" @click="$parent.$parent.addCompany()" >新增</button>
              </div>
            </div>

          </div>
        </criteria>
        <data-grid  :model="model" partial='list' class="list_area table_sy" 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>
            </tr>
          </template>
          <template partial='body'>
            <tr>
              <td style="text-align:center"><nobr>{{row.f_saler_name}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_saler_address_phone}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_bank_account}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_taxpayer_number}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_kpr}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_fhr}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_skr}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_input_date}}</nobr></td>
              <td style="text-align:center">
                <a style="text-decoration: none" @click="$parent.$parent.$parent.modify(row)">修改&nbsp;</a> <span>|</span> <a style="text-decoration: none" @click="$parent.$parent.$parent.deleteInfo(row)">&nbsp;删除</a>
              </td>
            </tr>
          </template>
          <template partial='foot'></template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>


  <modal :show.sync="show" backdrop="false" v-if="show">
    <article slot="modal-body" class="modal-body">
      <company-title-input :row='row'></company-title-input>
    </article>
    <footer slot="modal-footer">
    </footer>
  </modal>

</template>

<script>
  import { PagedList } from 'vue-client'
  import CompanyTitleInput from './CompanyTitleInput'
  import {HttpResetClass} from 'vue-client'

  export default {
    components: {CompanyTitleInput},
    data () {
      return {
        model: new PagedList('rs/sql/sale_getCompanyTitle', 20),
        show: false,
        row: null,
        curorgid: [this.$login.f.orgid],
      }
    },
    title: '抬头管理',
    ready () {
      this.search()
    },
    computed: {
    },
    events: {
      'company-title-input-close' () {
        this.show = false
        this.search()
      }
    },
    methods: {
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
        }
        args.condition = `${args.condition} and f_orgid = '${this.f_filialeids}'`
        await this.model.search(args.condition, args.model)
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeids = val[0]
      },
      modify (val) {
        this.row = val
        this.show = true
      },
      deleteInfo (row) {
        let deleteInfo = {
          id: row.id,
          f_orgid: this.$login.f.orgid
        }
        new HttpResetClass().load('POST','/rs/logic/deleteCompanyTitle', {data: deleteInfo}, {
          resolveMsg: '删除成功',
          rejectMsg: '删除失败'
        }).then((res) => {
          console.log(res)
        })
        this.search()
      },
      addCompany () {
        this.row = null
        this.show = true
      }
    }

  }
</script>
