<template>
  <div class="page-body">
    <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>
          <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:body-cell-IsRequired="props">
          <q-td :props="props">
            <span v-if="props.row.IsRequired==0">否</span>
            <span v-if="props.row.IsRequired==1">是</span>
          </q-td>
        </template>
        <template v-slot:body-cell-IsShow="props">
          <q-td :props="props">
            <span v-if="props.row.IsShow==0">是</span>
            <span v-if="props.row.IsShow==1">否</span>
          </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>
        <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="addObj(props.row)" />
            <q-btn flat size="xs" icon="delete" color="negative" style="font-weight:400" label="删除"
              @click="delQuestion(props.row)" />
          </q-td>
        </template>
      </q-table>
      <student-form v-if="isShowWenjuan" :save-obj="objOption" :ID="msg.SurveyId" @close="closeSaveForm"
        @success="resetSearch"></student-form>
    </div>
  </div>
</template>
<script>
  import studentForm from '../../components/activity/student-from'
  import {
    getActivitySurveyGuestPage,
    removeActivitySurveyGuest
  } from '../../api/studentmsg/index'
  export default {
    meta: {
      title: "意见调查表"
    },
    components: {
      studentForm
    },
    data() {
      return {
        columns: [{
            name: 'Id',
            label: 'ID',
            align: 'left',
            field: 'Id'
          }, {
            name: 'GuestName',
            label: '学员名称',
            field: 'GuestName',
            align: 'left'
          }, {
            name: 'StartTime',
            label: '开始时间',
            field: 'StartTime',
            align: 'left'
          }, {
            name: 'EndTime',
            label: '结束时间',
            field: 'EndTime',
            align: 'left'
          },

          {
            name: 'optioned',
            label: '操作',
            field: 'TId'
          }
        ],
        dataList: [],
        loading: true,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          SurveyId: 0,
        },
        pageCount: 0,
        isShowWenjuan: false,
        objOption: null,
      }
    },
    created() {
      if (this.$route.query && this.$route.query.ID) {
        this.msg.SurveyId = this.$route.query.ID;
      }
    },
    mounted() {
      this.getList();
    },
    methods: {
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      getList() {
        this.loading = true;
        getActivitySurveyGuestPage(this.msg).then(res => {
          this.loading = false;
          if (res.Code == 1) {
            this.dataList = res.Data.PageData;
            this.pageCount = res.Data.PageCount;
          }
        });
      },
      addObj(obj) {
        if (obj) {
          this.objOption = obj
        } else {
          this.objOption = null
        }
        this.isShowWenjuan = true;
      },
      //删除当前行信息
      delQuestion(row) {
        let that = this;
        this.$q.dialog({
          title: "提示",
          message: '是否删除该活动信息？',
          cancel: {
            label: "取消",
            flat: true
          },
          ok: {
            label: "确认",
            flat: true,
            focus: true
          }
        }).onOk(() => {
          removeActivitySurveyGuest({
            Id: row.Id
          }).then(res => {
            if (res.Code == 1) {
              that.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '数据删除成功！',
                position: 'top'
              })
              that.getList();
            } else {
              that.$q.notify({
                type: 'negative',
                position: "top",
                message: res.data.message,
              })
            }
          })
        })
      },
      closeSaveForm() {
        this.isShowWenjuan = false;
      },
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
    },
  }
</script>

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