<template>
  <div>
    <template v-if="operateType == 'detail'">
      <!-- 搜索栏 -->
      <search-bar :conditionForm="conditionForm" @submitSearch="receiveSearch"></search-bar>
      <!-- 操作栏 -->
      <operate-bar :pageOptList="pageOptList" @submitPageOpt="receviceOpt"></operate-bar>
      <!-- 表格 -->
      <new-table
        ref="table"
        :tableUrl="tableUrl[attrBelongType]"
        :tableHeader="tableHeader"
        :condition="condition"
        :tableOptList="tableOptList"
        @submitTableOpt="receviceOpt"
        lazyl
      >
      </new-table>
    </template>
    <p v-else>请选择属性值</p>
  </div>
</template>

<script>
import newTable from '@/components/new-table';
import { ObjRelAppTableUrl, ObjRelServiceTableUrl, delAttrRelResource } from '@/api/data-auth';
import { relateSourceTableHeader, relateSourceCondition } from '../../auth-subject-manage/DataConfig';
import addDialog from './add-appser-dialog';
import operateBar from '@/components/operate-bar';
import searchBar from '@/components/search-bar';
import { searchOpt } from '@/mixins/page-opt';

export default {
  name: 'personnelList', // 组件名称
  props: {
    parentNode: Object,
    operateType: String,
    attrBelongType: String
  },
  components: { newTable, operateBar, searchBar },
  mixins: [searchOpt],
  data() {
    const vm = this;
    return {
      tableHeader: relateSourceTableHeader[vm.attrBelongType],
      tableUrl: {
        APP: ObjRelAppTableUrl,
        SER: ObjRelServiceTableUrl
      },
      condition: {
        attrId: {
          op: '=',
          value: this.parentNode.id
        }
      },
      conditionForm: [
        ...relateSourceCondition[vm.attrBelongType],
        {
          name: 'attrId',
          op: '=',
          value: this.parentNode.id
        }
      ],
      pageOptList: ['新增'],
      tableOptList: ['删除']
    };
  },
  computed: {},
  watch: {},
  methods: {
    receviceOpt(opt, row) {
      if (opt == '新增') {
        this.handleAdd();
      } else if (opt == '删除') {
        this.handleDelete(row);
      }
    },
    /**
     * @description: 添加
     */
    handleAdd() {
      const vm = this;
      const layer = this.$dgLayer({
        title: '添加',
        shade: [0.4, '#FFF'],
        content: addDialog,
        props: {
          attrBelongType: vm.attrBelongType,
          parentNode: vm.parentNode
        },
        on: {
          success() {
            layer.close(layer.dialogIndex);
            vm.handleSearch();
          }
        },
        area: ['1200px', '760px']
      });
    },
    handleDelete(row) {
      this.$dgConfirm(`是否确定删除这条数据！`, '提示', {}).then(() => {
        delAttrRelResource(row.attrRelId).then((res) => {
          this.$message.success('删除成功');
          this.handleSearch();
        });
      });
    }
  },
  created() {},
  mounted() {}
};
</script>
<style lang="scss" scoped>
.add-btn {
  margin-bottom: 10px;
}
</style>
