<style>
  .site_ListDiv {
    margin-bottom: 10px;
  }

</style>
<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
      </div>
      <div class="page-option">
        <q-btn color="accent" class="q-mr-md" icon="add" label="新增站点" @click="addSite(null)" />
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-tow-column-table"
        separator="none" title="文件站点配置" :data="data" :columns="columns" row-key="name">
        <template v-slot:body-cell-StoreType="props">
          <q-td :props="props" style="position:relative;">
            <template v-if="props.row.StoreType==1">
              <img src="../../assets/images/myimg/tencent.png" alt="" />
            </template>
            <template v-if="props.row.StoreType==2">
              <img src="../../assets/images/myimg/ali.png" alt="" />
            </template>
            <div style="position:absolute;top:0;left:0;">
              <img v-if="props.row.IsDefault==1" style="width:50px;" src="../../assets/images/myimg/default.png" />
            </div>
          </q-td>
        </template>
        <template v-slot:body-cell-Using="props">
          <q-td :props="props">
            <div class="site_ListDiv">空间名称（Bucket）：{{props.row.Bucket}}</div>
            <div class="site_ListDiv">所属地域：{{props.row.Region}}</div>
            <div class="site_ListDiv">自定义域名：{{props.row.CustomDomain}}</div>
            <div class="site_ListDiv">SecretId：{{props.row.SecretId}}</div>
            <div>SecretKey：{{props.row.SecretKey}}</div>
          </q-td>
        </template>
        <template v-slot:bottom>
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
              @click="addSite(props.row)" />
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="设为默认"
              @click="setMoren(props.row)" />
          </q-td>
        </template>
      </q-table>
      <site-form v-if="isShowSiteForm" :save-obj="roleObjOption" @close="closeSiteSaveForm" @success="refreshPage">
      </site-form>
    </div>
  </div>
</template>

<script>
  import {
    getSiteConfig,
    setSiteConfig
  } from '../../api/system/sitecfg'
  import siteForm from '../../components/system/site-form'
  export default {
    meta: {
      title: "站点配置"
    },
    components: {
      siteForm,
    },
    data() {
      return {
        isShowSiteForm: false,
        columns: [{
            name: 'StoreType',
            label: '类型',
            field: 'StoreType',
            align: 'left'
          },
          {
            name: 'Bucket',
            label: '存储位置',
            field: 'Bucket',
            align: 'left'
          },
          {
            name: 'Using',
            label: '使用中',
            field: 'Using',
            align: 'left'
          },
          {
            name: 'UploadDomain',
            label: '上传自定义域名',
            field: 'UploadDomain',
            align: 'left'
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'StoreType'
          }
        ],
        data: [],
        // loading: true,
        loading: false,
        msg: {
          pageIndex: 1,
          pageSize: 20,
        },
        roleObjOption: null,
      }
    },
    mounted() {
      this.getList();
    },
    methods: {
      getList() {
        getSiteConfig(this.msg).then(res => {
          if (res.Code == 1) {
            this.data = res.Data;
          }
        }).catch(() => {

        })
      },
      //新增站点
      addSite(obj) {
        if (obj) {
          this.roleObjOption = obj
        } else {
          this.roleObjOption = null
        }
        this.isShowSiteForm = true;
      },
      //设为默认
      setMoren(obj) {
        let newMsg = obj;
        newMsg.IsDefault = 1;
        setSiteConfig(newMsg).then(res => {
          this.$q.notify({
            icon: 'iconfont icon-chenggong',
            color: 'accent',
            timeout: 2000,
            message: '设置默认成功！',
            position: 'top'
          })
          this.getList();
        }).catch(() => {

        })
      },
      //关闭弹窗
      closeSiteSaveForm() {
        this.isShowSiteForm = false
      },
      //刷新页面
      refreshPage() {
        this.getList()
      },
    }
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass');

</style>
