<template>
  <div>
    <div class="normal-margin">
      <add v-if="tool.checkAuth($route.name,'finance')" class="inline-16"  :data="data" @onSuccess="queryfinancialinfo"></add>
      <el-input
          placeholder="请输入搜索内容"
          :suffix-icon="param.content.where.condition?param.content.where.condition.length > 0?'':'':'el-icon-search'"
          v-model="param.content.where.condition"
          style="width:200px"
          size="small"
          class="input-with-select inline-16"
          @keyup.native.enter="queryfinancialinfo(param.content.pageNumber = 1)"
          @clear="clearData"
          clearable>
      </el-input>
    </div>

    <el-table
        :header-cell-style="{background:'#EEEEEE',color:'#333'}"
        :data="tableData"
        stripe
        size="mini"
        style="width: 100%"
        border>

      <el-table-column
          prop="enterprisename"
          label="开票抬头">
      </el-table-column>
      <el-table-column
          prop="taxno"
          label="税号">
      </el-table-column>
      <el-table-column
          prop="bank"
          label="开户银行">
      </el-table-column>
      <el-table-column
          prop="bankcardno"
          label="开户账号">
      </el-table-column>
      <el-table-column
          prop="address"
          label="开票地址">
        <!--        <template slot-scope="scope">
                  {{scope.row.address}}&nbsp;<i style="color:red" v-if="scope.row.isdefault === 1" class="el-icon-place"></i>
                </template>-->
      </el-table-column>
      <el-table-column
          prop="phonenumber"
          label="电话">
      </el-table-column>
      <el-table-column
          prop="isdefault"
          label="是否默认">
        <template slot-scope="scope">
          <span>{{scope.row.isdefault === 1?'是':'否'}}</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="remarks"
          label="备注">
      </el-table-column>
      <el-table-column
          label="操作"
          width="100"
          fixed="right">
        <template slot-scope="scope">
          <edit :dataOld="data" :data="scope.row" class="inline-16" @onSuccess="onSuccess"></edit>
          <el-popconfirm
              confirm-button-text='确定'
              cancel-button-text='取消'
              icon="el-icon-info"
              title="确定删除该财务信息吗？"
              @confirm="delShow(scope.row.sys_enterprise_financeid)"
          >
            <el-button slot="reference" size="mini" type="text" :disabled="!tool.checkAuth($route.name,'finance')">删 除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div class="container normal-panel" style="text-align:right">
      <el-pagination
          background
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[20, 50, 100, 200]"
          layout="total,sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>

import add from './add'
import edit from './edit'
export default {
  name: "index",
  props:['data'],
  data () {
    return {
      search:'',
      tableData:[],
      param:{
        "id": 20221013160602,
        "content": {
          "sys_enterpriseid":0,
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": ""
          }
        },
      },
      total:0,
      currentPage:0
    }
  },
  components:{
    add,edit
  },
  methods:{
    async queryfinancialinfo () {
      this.param.content.sys_enterpriseid = this.$route.query.id
      const res = await this.$api.requested(this.param)
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.queryfinancialinfo()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.queryfinancialinfo()
    },
    async deleteRow (row) {
      const res = await this.$api.requested({
        "id": 20221013160502,
        "content": {
          "sys_enterprise_financeids": [row.sys_enterprise_financeid]
        },
      })
      this.tool.showMessage(res,()=>{
        this.queryfinancialinfo()
      })
    },
    clearData(){
      this.queryfinancialinfo(this.param.content.pageNumber = 1)
    },
    onSuccess(){
      this.queryfinancialinfo()
    },
    delShow(id){
      if (this.data.enterprisename === '' || this.data.abbreviation === '' || this.data.contact === ''){
        this.$message.error('请先将企业基础信息补充完整，再进行此操作');
      }else {
        this.onDel(id)
      }
    },
    async onDel(id){
      const res = await this.$api.requested({
        "id": 20221013160502,
        "content": {
          "sys_enterprise_financeids": [id]
        },
      })
      this.tool.showMessage(res,()=>{
        this.queryfinancialinfo()
      })
    }
  },
  mounted () {
    this.queryfinancialinfo()
  }
}
</script>

<style scoped>

</style>