<!--
 * @Author: Liugh
 * @Date: 2021-05-19 16:09:07
 * @LastEditTime: 2021-05-20 11:13:49
 * @LastEditors: Do not edit
 * @FilePath: \auth-web\src\pages\data-auth-module\auth-object-manage\object-prop-manage\add-dialog.vue
 * @Description: 
-->

<template>
  <main class="add-dialog">
    <dg-row class="property-wapper">
      <!-- 搜索栏 -->
      <search-bar :conditionForm="appConditonForm2" @submitSearch="receiveSearch"></search-bar>
      <!-- 表格 -->
      <new-table
        ref="table"
        :selection="true"
        :tableHeader="cardAgencylist"
        :tableUrl="tableUrl"
        :condition="condition"
        v-if="type !== 'service'"
      >
      </new-table>
    </dg-row>
    <div v-footer>
      <dg-button @click="handleClose">取消</dg-button>
      <dg-button type="primary" @click="handleSave">保存</dg-button>
    </div>
  </main>
</template>

<script>
import { appRestApi } from '@/api/application';
import { cardAgencylist, cardFunctionList, appConditonForm2 } from '../../auth-subject-manage/DataConfig';
import { addRelateApp, getRelateIds } from '@/api/data-auth';
import searchBar from '@/components/search-bar';
import { searchOpt } from '@/mixins/page-opt';
import newTable from '@/components/new-table';
import _ from 'lodash';
export default {
  name: 'add-dialog', // 组件名称
  props: {
    // 接收父组件的数据
    type: {
      type: String,
      default: 'application'
    },
    parentNode: Object
  },
  components: { searchBar, newTable }, // 注册局部组件
  mixins: [searchOpt],
  data() {
    // 组件内部参数
    return {
      // 参数名称及默认值
      cardFunctionList,
      cardAgencylist,
      tableUrl: appRestApi.table,
      otherParams: {
        attrBelongType: this.parentNode.attrBelongType,
        attrId: this.parentNode.id,
        attrType: 'OBJ'
      },
      appConditonForm2
    };
  },
  computed: {}, // 计算属性
  watch: {}, // 侦听器（扩展的计算属性）
  methods: {
    /**
     * 关闭
     */
    handleClose() {
      this.$emit('close');
    },
    /**
     * 添加
     */
    handleSave() {
      const params = {
        ...this.otherParams,
        relIds: this.$refs.table.newChooseArr.map((item) => item.id || item)
      };
      addRelateApp(params).then((res) => {
        this.$message.success('保存成功');
        this.$emit('success');
      });
    }
  },
  created() {
  },
  mounted() {
     getRelateIds(this.otherParams).then((res) => {
       this.$nextTick(() => {
         this.$refs.table.newChooseArr = res.data.content;
       })
    });

  }
};
</script>
<style lang="scss" scoped></style>
