<template>
  <div class="updates pagePadding" style="padding-top: 25px">
    <div v-if="powers.some((i) => i == '001')">
      <el-row style="padding: 0 0 10px 0">
        <el-col :span="3" class="fr" style="width: 66px; padding: 0 0 0 10px">
          <el-button type="primary" :size="searchSize" @click="searchList">
            刷新
          </el-button>
        </el-col>
        <el-col
          :span="3"
          class="fr"
          style="width: 66px; padding: 0 0 0 10px"
          v-if="powers.some((i) => i == '002')"
        >
          <el-button
            :size="searchSize"
            type="success"
            style="float: right"
            @click="showModel = true"
          >
            添加
          </el-button>
        </el-col>
      </el-row>

      <el-table
        :data="tableData"
        v-loading="loading"
        border
        :size="size"
        stripe
        style="width: 100%"
      >
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form :size="size" label-position="top" inline class="demo-table-expand">
              <el-form-item label="更新内容">
                <p v-html="props.row.system"></p>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="版本号" prop="version"> </el-table-column>
        <el-table-column label="更新模块" prop="module"> </el-table-column>
        <el-table-column label="更新时间" prop="addtime"> </el-table-column>
      </el-table>
      <div
        class="Pagination"
        style="text-align: right; margin-top: 10px"
        v-show="count > 0"
      >
        <el-pagination
          :size="searchSize"
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :current-page="parmValue.page"
          :page-sizes="[15, 50, 100]"
          :page-size="parmValue.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="count"
        ></el-pagination>
      </div>
    </div>
    <no-auth v-else></no-auth>
    <!-- 弹窗 新增/修改 -->
    <add-edit :show-model="showModel" @refresh="searchList" @cancel="showModel = false" />
  </div>
</template>

<script>
import asyncRequest from "@/apis/service/system/updates";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
import addEdit from "./addEdit";
export default {
  name: "updates",
  components: {
    addEdit
  },
  mixins: [resToken],
  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const { btnList } = this.$store.getters;
      const tran = btnList.find((item) => item.menu_route == "updates") || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      loading: true,
      showModel: false,
      parmValue: {
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      count: 0, // 总条数

      // 表格 - 数据
      tableData: [],
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    async handlePageChange(e) {
      this.parmValue.page = e;
      await this.searchList();
    },
    async handleSizeChange(e) {
      this.parmValue.size = e;
      this.parmValue.page = 1;
      await this.searchList();
    },
    // 刷新表格
    async searchList() {
      this.loading = true;
      const { code, data } = await asyncRequest.list(this.parmValue);
      if (code === 1) {
        const { list, count } = data;
        this.tableData = list;
        this.count = Number(count);
      } else {
        this.tableData = [];
        this.count = 0;
      }
      this.loading = false;
    },
  },
};
</script>

<style lang="scss" scoped></style>
