<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 class="col-3">
          <q-input @change="resetSearch" clearable standout="bg-primary text-white" v-model="msg.SName" label="校区名称"
            @clear="resetSearch" maxlength="20" />
        </div>
        <div class="col-3">
          <q-select @input="resetSearch" standout="bg-primary text-white" v-model="StatusTemp" :options="StatusOpts"
            option-value="value" option-label="label" label="校区状态" />
        </div>
      </div>
      
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table"
        separator="none" :data="data" :columns="columns" row-key="name">
        <template v-slot:top="props">
          <div class="col-2 q-table__title">校区信息</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" size="sm" icon="add" label="新增校区" @click="EditSchool(null)" />
          </div>
        </template>
        <template v-slot:body-cell-Status="props">
          <q-td :props="props">
            <q-badge :color="props.value==1?'negative':'primary'" :label="props.value==1?'关闭':'正常'" />
          </q-td>
        </template>
        <template v-slot:body-cell-Remark="props">
          <q-td :props="props">
            <q-badge color="grey-3 text-grey-10" :label="props.value" />
          </q-td>
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-family:perfectFont" label="编辑"
              @click="EditSchool(props.row)" />
          </q-td>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
      </q-table>
      <school-form v-if="isShowSchoolForm" :save-obj="objOption" @close="closeSchoolForm" @success="refreshPage">
      </school-form>
    </div>
  </div>
</template>

<script>
  import {
    getSchoolPage,
  } from '../../api/school/index'
  //校区管理
  import schoolForm from '../../components/school/schoolarea/school-form'
  export default {
    meta: {
      title: "校区管理"
    },
    components: {
      schoolForm
    },
    data() {
      return {
        currentUrl: "",
        columns: [{
            name: 'SName',
            required: true,
            label: '学校名称',
            align: 'left',
            field: row => row.SName,
            format: val => `${val}`,
            sortable: true
          },
          {
            name: 'ManagerName',
            label: '负责人',
            field: 'ManagerName',
            align: 'left',
            sortable: true
          },
          {
            name: 'SLinkTel',
            label: '负责人电话',
            align: 'left',
            field: 'SLinkTel'
          },
          {
            name: 'Status',
            label: '状态',
            align: 'left',
            field: 'Status'
          },
          {
            name: 'CreateByName',
            label: '创建人',
            align: 'left',
            field: 'CreateByName'
          },
          {
            name: 'CreateTimeStr',
            label: '建立时间',
            align: 'left',
            field: 'CreateTimeStr'
          },
          {
            name: 'Remark',
            label: '备注',
            align: 'left',
            field: 'Remark'
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'SId'
          },
        ],
        data: [],
        loading: true,
        StatusOpts: [{
            label: '全部',
            value: '-1'
          },
          {
            label: '正常',
            value: '0'
          },
          {
            label: '关闭',
            value: '1'
          }
        ],
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          SName: "",
          Status: '-1'
        },
        StatusTemp: "",
        pageCount: 0,
        persistent: false,
        objOption: {
          SId: 0,
          SName: "",
          SAddress: "",
          SLinkTel: "",
          SDomain: "",
          SLogo: "",
          Remark: "",
          Status: '0',
          Dept_Id: 0, //管理部门
          ManagerId: 0, //负责人编号
        },
        isShowSchoolForm: false, //是否显示校区弹窗
      }
    },
    created() {
      this.StatusTemp = this.StatusOpts[0]
    },
    mounted() {
      this.currentUrl = this.$route.path
      this.getSchool();
    },
    methods: {
      //更多按钮点击事件
      onItemClick() {},
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getSchool();
      },
      //分页改变
      changePage(val) {
        this.msg.pageIndex = val;
        this.getSchool()
      },
      //获取学校分页列表
      getSchool() {
        this.loading = true;
        this.msg.Status = this.StatusTemp ? this.StatusTemp.value : '-1'
        getSchoolPage(this.msg).then(res => {
          this.loading = false
          this.data = res.Data.PageData;
          this.pageCount = res.Data.PageCount;
        }).catch(() => {
          this.loading = false;
        })
      },
      //关闭校区弹窗
      closeSchoolForm() {
        this.isShowSchoolForm = false;
      },
      //刷新页面
      refreshPage() {
        this.getSchool();
      },
      //新增、修改校区
      EditSchool(obj) {
        if (obj) {
          this.objOption = obj;
        } else {
          this.objOption = null;
        }
        this.isShowSchoolForm = true;
      },
    }
  }

</script>

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

</style>
