<!--
服务资源管理
@Author: linqian
@Date: 2021-05-17 13:53
-->
<template>
  <div>
    <!-- 搜索栏 -->
    <search-bar :conditionForm="conditionForm" @submitSearch="receiveSearch"></search-bar>
    <!-- 操作栏 -->
    <operate-bar :pageOptList="pageOptList" @submitPageOpt="receviceOpt"></operate-bar>
    <!-- 表格 -->
    <new-table
      ref="table"
      :tableHeader="tableHeader"
      :tableUrl="tableUrl"
      :condition="condition"
      :tableOptList="tableOptList"
      @submitTableOpt="receviceOpt"
    >
    </new-table>
  </div>
</template>

<script>
import searchBar from '@/components/search-bar';
import operateBar from '@/components/operate-bar';
import newTable from '@/components/new-table';
import { conditionForm, pageOptList, tableOptList, tableHeader } from './DataConfig';
import { searchOpt, importOpt, syncOpt } from '@/mixins/page-opt';
import * as Api from '@/api/ser-resource-manage';
import { serviceImportUrl } from '@/api/import';
import { authSerSyncUrl } from '@/api/sync';
import addForm from './add-form';
export default {
  components: {
    searchBar,
    operateBar,
    newTable
  },
  mixins: [searchOpt, importOpt, syncOpt],
  data() {
    return {
      conditionForm,
      pageOptList,
      tableOptList,
      tableHeader,
      tableUrl: Api.tableUrl
    };
  },
  computed: {},
  methods: {
    /**
     * 接收操作事件
     */
    receviceOpt(type, row) {
      if (type == '修改') {
        this.handleEdit(row);
      } else if (type == '新增') {
        this.handleAdd();
      } else if (type == '详情') {
        this.handleViewDetail(row);
      } else if (type == '删除') {
        this.handleDelete(row);
      } else if (type == '导入') {
        this.handleImport(serviceImportUrl, 'serviceResource');
      } else if (type == '同步') {
        this.handleSync(authSerSyncUrl);
      }
    },
    /**
     * 编辑
     */
    handleEdit(row) {
      this.handleOpenForm(row.id, '修改');
    },
    /**
     * 查看详情
     */
    handleViewDetail(row) {
      this.handleOpenForm(row.id, '详情', true);
    },
    /**
     * 新增
     */
    handleAdd() {
      this.handleOpenForm(void 0, '新增');
    },
    handleOpenForm(id, title, isDetail = false) {
      const vm = this;
      const layer = this.$dgLayer({
        title,
        content: addForm,
        props: {
          id,
          isDetail
        },
        on: {
          success() {
            vm.handleSearch();
            layer.close(layer.dialogIndex);
          }
        },

        area: ['800px', '550px']
      });
    },
    /**
     * 删除
     */
    handleDelete(row) {
      this.$dgConfirm(`是否确定删除这条数据！`, '提示', {}).then(() => {
        Api.del(row.id).then((res) => {
          this.$message.success("删除成功！");
          this.handleSearch();
        });
      });
    }
  },
  created() {},
  mounted() {}
};
</script>

<style lang='scss'>
</style>