<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-col-gutter-md">
        <div class="col-3">
          <q-input @input="resetSearch" filled clearable v-model="msg.EnterpriseName" label="企业名称" maxlength="20" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat
        class="sticky-right-column-table sticky-column-table" separator="none" :data="dataList" :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="addObj(null)" />
          </div>
        </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>
        <template v-slot:body-cell-Id="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
              @click="addObj(props.row)" />
            <q-btn flat size="xs" icon="delete" color="negative" class="q-mr-xs" label="删除"
              @click="delEnterprise(props.row.Id)" />
          </q-td>
        </template>
      </q-table>
      <enterprise-form v-if="isShowEnter" :save-obj="objOption" @close="closeSaveForm" @success="RefreshPage">
      </enterprise-form>
    </div>
  </div>
</template>
<script>
  import {
    GetEnterprisePage,
    RemoveEnterprise
  } from '../../api/users/user'
  import enterpriseForm from '../../components/sale/enterprise-form'
  export default {
    meta: {
      title: "企业管理"
    },
    components: {
      enterpriseForm
    },
    data() {
      return {
        columns: [{
            name: 'EnterpriseName',
            required: true,
            label: '企业名称',
            align: 'left',
            field: row => row.EnterpriseName
          },
          {
            name: 'CreateByName',
            required: true,
            label: '创建人',
            align: 'left',
            field: 'CreateByName'
          },
          {
            name: 'CreateTime',
            required: true,
            label: '创建时间',
            align: 'left',
            field: 'CreateTime'
          },
          {
            name: 'Id',
            label: '操作',
            field: 'Id'
          }
        ],
        dataList: [],
        loading: true,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          EnterpriseName: ""
        },
        pageCount: 0,
        isShowEnter: false,
        objOption: null,
        EnterpriseNameList: [],
      }
    },
    created() {},
    mounted() {
      this.getList()
    },
    methods: {
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },

      RefreshPage() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      deleteUser(id) {
        let that = this
        this.$q.dialog({
          title: "删除教师",
          message: "你正在进行删除教师行为，一旦执行无法找回，是否确认执行？",
          persistent: true,
          cancel: {
            label: "取消",
            flat: true
          },
          ok: {
            label: "确认",
            flat: true,
            focus: true
          }
        }).onOk(() => {
          that.resetLoading = true
          deleteTeacher({
            TId: id
          }).then(res => {
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '数据删除成功！',
              position: 'top'
            })
            this.getList()
          })
        });
      },
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      getList() {
        this.loading = true;
        GetEnterprisePage(this.msg).then(res => {
          this.loading = false;
          if (res.Code == 1) {
            this.dataList = res.Data.PageData;
            this.pageCount = res.Data.PageCount;
          }
        }).catch(() => {
          this.loading = false
        })
      },
      addObj(obj) {
        if (obj) {
          this.objOption = obj;
        } else {
          this.objOption = null
        }
        this.isShowEnter = true
      },
      //删除企业
      delEnterprise(Id) {
        let delMsg = {
          Id: Id
        };
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定该企业？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          RemoveEnterprise(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '删除成功！',
                position: 'top'
              })
              this.getList();
            }
          })
        }).onCancel(() => {

        });
      },
      closeSaveForm() {
        this.isShowEnter = false
      }
    },
  }

</script>

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

</style>
