<template>
  <div class="entry-manager">
    <bread-crumb :curmbFirst="curmbFirst"></bread-crumb>
    <div class="component-content screenSet" id="screenSet">
      <el-form :model="formInline" ref="formInline" label-width="75px" class="form-inline">
        <el-col :span="6">
          <el-form-item label="入口名称：">
            <el-input size="small" v-model="formInline.name" placeholder="请输入名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2"></el-col>
        <el-col :span="12">
          <el-button type="primary" size="small">查询</el-button>
        </el-col>
        <el-col :span="4" style="padding:0;text-align:right;padding-right:10px;">
          <el-button type="primary" size="small" @click="toPage()">新建入口</el-button>
        </el-col>
      </el-form>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID编号" align="center"></el-table-column>
        <el-table-column prop="project" label="入口名称" align="center"></el-table-column>
        <el-table-column prop="name" label="创建人" align="center"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column prop="desc" label="入口介绍" align="center"></el-table-column>
        <el-table-column prop="startTime" label="开始时间" align="center"></el-table-column>
        <el-table-column prop="endTime" label="介绍时间" align="center"></el-table-column>
        <el-table-column prop="status" label="状态" align="center">
          <template slot-scope="scope">{{ scope.row.status | shieldStatus }}</template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="350" align="center">
          <template slot-scope="scope">
            <el-button type="primary" @click="toPage(scope.row.id)" size="small">编辑</el-button>
            <el-button type="primary" @click="openDialog('up',scope.row)" size="small">上架</el-button>
            <el-button type="primary" size="small">下架</el-button>
            <el-button type="primary" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="formInline.pageNo"
          :page-sizes="[10, 20, 30, 100]"
          :page-size="formInline.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalRows"
        ></el-pagination>
      </div>
      <el-dialog title="确认上架" :visible.sync="dialogUp" width="30%" center>
        <p v-if="childrenNum > 0" class="dialog_p">该项目已关联{{ childrenNum }}个子项目</p>
        <p v-if="childrenNum > 0" class="dialog_p">确认要继续上架吗？</p>
        <p v-if="childrenNum == 0" class="dialog_p">该项目已关联0个子项目</p>
        <p v-if="childrenNum == 0" class="dialog_p">继续上架，将在APP端无法显示该项目</p>
        <span v-if="childrenNum > 0" slot="footer" class="dialog-footer">
          <el-button @click="dialogUp = false">确认上架</el-button>
          <el-button type="primary" @click="dialogUp = false">取消</el-button>
        </span>
        <span v-if="childrenNum == 0" slot="footer" class="dialog-footer">
          <el-button @click="dialogUp = false">取消</el-button>
          <el-button type="primary" @click="dialogUp = false">确定上架</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import BreadCrumb from "../../components/breadcrumb.vue";
import { mapGetters } from "vuex";
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
import * as operationData from "../../utils/operation";
let vm = null;
export default {
  components: {
    BreadCrumb
  },
  data() {
    return {
      curmbFirst: "入口管理",
      totalRows: 0,
      formInline: {
        name: "",
        pageNo: 1,
        pageSize: 10
      },
      tableData: [
        {
          id: 123,
          project: "小何同学的项目",
          name: "小王同学",
          createTime: "2019-09-09",
          desc: "小王同学",
          startTime: "2019-10-10",
          endTime: "2019-12-10",
          status: 1
        }
      ],
      dialogUp: false,
      childrenNum: 1,
      scopeRow: {},
    };
  },
  computed: {
    ...mapGetters(["_token"])
  },
  created() {
    vm = this;
  },
  mounted: function() {
    commonUtil.resizeHeight();
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pageNo = val;
    },
    toPage(id) {
      console.log(id);
      if (id === undefined) {
        this.$router.push("edit-entry");
      } else {
        this.$router.push("edit-entry?projectId=" + id);
      }
    },
    openDialog(type,row) {
      vm.scopeRow = row;
      vm.dialogUp = true;
    }
  }
};
</script>
<style lang="scss">
.entry-manager {
  .component-content {
    padding: 10px;
    background: #fff;
    .dialog_p {
      text-align: center;
    }
  }
}
</style>