<template>
  <div>
    <div ref="lxHeader">
      <lx-header icon="md-apps" style="margin-bottom: 10px; border: 0px; margin-top: 15px" text="第三方结算对象">
        <div slot="content"></div>
        <slot>
          <div>
            <Input v-model="select.keyword" placeholder="关键字搜索" style="width: 200px; margin-right: 10px"/>
            <Button style="margin-left: 10px" type="primary" @click="select.page = 1,getList()">查询</Button>
            <Button style="margin-left: 10px" type="primary" @click="$refs['addobjects'].type = 'add',$refs['addobjects'].isShow = true">新建</Button>
          </div>
        </slot>
      </lx-header>
    </div>

    <xy-table
      :total="total"
      :list="list"
      :table-item="table"
      @editor="editor"
      @delete="destroy"
      @pageSizeChange="e => select.page_size = e"
      @pageIndexChange="e => {select.page = e;getList()}"></xy-table>

    <add ref="addobjects" @refresh="getList" :types="types" :areas="areas"/>
  </div>
</template>

<script>
import {getList,destroy} from '@/api/payUnit'
import {getList as typeList} from '@/api/productType'
import {getparameter} from '@/api/system/dictionary'

import add from "./component/addobjects"

export default {
  components:{
    add
  },
  data() {
    return {
      select:{
        page:1,
        page_size:10,
        keyword:''
      },
      types:[],
      areas:[],

      total:0,
      list:[],
      table:[
        {
          prop:'name',
          label:'名称',
          minWidth: 200,
          align:'left'
        },
        {
          prop:'area_detail.value',
          label:'所属区域',
          width: 140
        },
        {
          prop:'product_type_id',
          label: '业务板块',
          width:160,
          formatter:(cell,data,value) => {
            return this.types.filter(item => {
              return item.id === value
            })[0]?.name || ''
          }
        }
      ]
    }
  },
  methods: {
    async getTypes(){
      const res = await typeList({page:1,page_size:9999},false)
      this.types = res.data
    },
    async getAreas(){
      const res = await getparameter({number:'serveArea'},false)
      this.areas = res.detail
    },

    async getList(){
      const res = await getList(this.select)
      this.total = res.total
      this.list = res.data
      console.log(this.list)
    },

    editor(row){
      this.$refs['addobjects'].type = 'editor'
      this.$refs['addobjects'].id = row.id
      this.$refs['addobjects'].isShow = true
    },
    destroy(row){
      destroy(row.id).then(res => {
        this.$successMessage('destroy','')
        this.getList()
      })
    }
  },
  mounted() {
    this.getTypes()
    this.getAreas()
    this.getList()
  }
}
</script>

<style scoped lang="scss">
</style>
