<template>
  <div>
    <addContact v-if="tool.checkAuth($route.name,'contactMag')" @onAddSuccess="listData" :mainData="mainData"></addContact>
    <tableLayout :layout="tablecols" :data="list" :custom="true" height="calc(100vh - 455px)" fixedName="operation">
      <template v-slot:customcol="scope">
        <p v-if="scope.column.columnname === 'province'">
          {{scope.column.data['province']}}-{{scope.column.data['city']}}-{{scope.column.data['county']}}
        </p>
        <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
       <template v-slot:opreation="scope">
        <edit-contact v-if="tool.checkAuth($route.name,'contactMag')" class="inline-16" :mainData="mainData" :row="scope.data" @onAddSuccess="listData"></edit-contact>
        <el-popconfirm
          title="确定删除吗？"
          @confirm="deleteContacts(scope.data)">
          <el-button size="small" v-if="tool.checkAuth($route.name,'contactMag')" type="text" slot="reference">删 除</el-button>
        </el-popconfirm>
      </template>
    </tableLayout>
  </div>
</template>

<script>
import editContact from './edit.vue'
import addContact from './add.vue'
export default {
  props:['mainData'],
  data () {
    return {
      list:[],
      param:{}
    }
  },
  components:{
    addContact,
    editContact
  },
  methods:{
    async listData () {
      const res = await this.$api.requested({
        "id": "20221009155803",
        "content": {
        "sys_enterpriseid":this.mainData.sys_enterpriseid,
          "where":{
            "condition":"",
            "workaddress":0
          }
        }
      })
      this.list = res.data
    },
    async deleteContacts (row) {
      console.log(row)
      const res = await this.$api.requested({
        "id": "20221009155903",
        "version":1,
        "content": {
          "contactsid":row.contactsid
        }
      })
      this.tool.showMessage(res,()=>{
        this.listData()
      })
    }
  },
  mounted () {
   this.listData()
  },
  watch:{
    mainData (val) {
      this.param = val
      // this.listData()
    }
  },
  created () {
    // 获取角色表结构
    this.tablecols = this.tool.tabelCol(this.$route.name)['addressAndContact'].tablecols
  }
}

</script>
<style>
</style>