<template>
  <div>
    <div class="i-layout-page-header">
      <PageHeader :title="$route.meta.title" :content="$route.meta.description" hidden-breadcrumb />
    </div>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <view-table
        ref="table"
        view-code="CustomPage"
        :select-enable="allow('export')"
        :create-enable="allow('create')"
        :remove-enable="allow('remove')"
        @create="$refs.form.open()"
        @edit="({ row, index }) => $refs.form.open(row.customPage)"
      >
        <template #filterCommand>
          <Button v-if="allow('export')" size="small" type="info" custom-icon="fa fa-cloud-download-alt" @click="exportFile()">{{ $t('Front_Btn_Export') }}</Button>
          <file-upload v-if="allow('import')" url="api/CustomPage/importFile" accept=".cp" @on-success="importFileSuccess">
            <template #>
              <Button type="primary" custom-icon="fa fa-cloud-upload-alt" size="small">{{ $t('Front_Btn_Import') }}</Button>
            </template>
          </file-upload>
        </template>
        <template #command="{}">
          <!-- <Button size="small"
                  title="页面组件"
                  type="info"
                  custom-icon="fa fa-window-maximize"
                  @click="$refs.componentTable.open({customPageID: row.id})"></Button>
              <Button size="small"
                  title="页面控件"
                  type="info"
                  custom-icon="fa fa-clone"
                  @click="$refs.controlTable.open({customPageID: row.id})"></Button> -->
        </template>
      </view-table>
    </Card>
    <modal-form ref="form" view-code="CustomPageEdit" :create-enable="allow('create')" :edit-enable="allow('edit')" @on-after-save="$refs.table.loadData()" />
    <!-- <modal-table ref="componentTable"
            view-code="CustomPageComponent"
            @create="(param)=>$refs.componentForm.openDefault(param)"
            @edit="({row, index})=>$refs.componentForm.open(row)">
            <template slot-scope="{ row }"
                slot="command">
                <Button size="small"
                    title="页面控件"
                    type="info"
                    custom-icon="fa fa-clone"
                    @click="$refs.controlTable.open({customPageID: row.customPageID, customPageComponentID: row.id})"></Button>
            </template>
        </modal-table>
        <modal-form ref="componentForm"
            view-code="CustomPageComponentEdit"
            @on-after-save="$refs.componentTable.loadData()" />
        <modal-table ref="controlTable"
            view-code="CustomPageControl"
            @create="(param)=>$refs.controlForm.openDefault(param)"
            @edit="({row, index})=>$refs.controlForm.open(row)" />
        <modal-form ref="controlForm"
            view-code="CustomPageControlEdit"
            @on-after-save="$refs.controlTable.loadData()" /> -->
  </div>
</template>
<script>
  import mixinPage from '../../mixins/page';
  import customPageApi from '../../api/customPage';

  export default {
    name: 'system-page',
    mixins: [mixinPage],
    components: {},
    data() {
      return {};
    },
    computed: {},
    created() {},
    methods: {
      // 导出文件
      exportFile() {
        let ids = this.$refs.table.getSelected().map(x => {
          return x.id;
        });
        if (ids.length > 0) {
          customPageApi.exportFile(ids);
        } else {
          this.error('Front_Msg_Please_Select_Export_Item');
        }
      },
      // 导入成功
      importFileSuccess(res) {
        if (res.code == 0) {
          this.success('Front_Msg_Success', () => {
            this.$refs.table.loadData();
          });
        } else {
          this.error(res.message);
        }
      }
    }
  };
</script>
