<template>
  <a-card :bordered="false" :body-style="{ padding: '0px 0px 8px' }">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="录入日期">
              <a-range-picker v-model="queryParam.dateQ"
                format="YYYY-MM-DD"
                :placeholder="['开始日期', '结束日期']"
                @change="onCreateTimeChange" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="状态">
              <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="education_schedule_status"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="课程">
              <j-dict-select-tag placeholder="请选择课程" v-model="queryParam.courseId" dictCode="education_course,name,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="老师">
              <j-dict-select-tag placeholder="请选择老师" v-model="queryParam.lecturerId" dictCode="sys_user,realname,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="创建人">
              <j-dict-select-tag placeholder="请选择创建人" v-model="queryParam.createBy" dictCode="sys_user,realname,id"/>
            </a-form-item>
          </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" @click="handleAdd" icon="bars" style="margin-left: 8px">安排试听课</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleCallRoll(record)" v-if="record.status == '2'">点名</a>
          <a-divider type="vertical" v-if="record.status == '2'"/>
          <a @click="handleEditRoll(record)" v-if="record.status == '1'">编辑点名</a>
          <a-divider type="vertical" v-if="record.status == '1'"/>
          <a @click="handleEdit(record)" v-if="record.status == '2'">排课变更</a>
          <a-divider type="vertical" v-if="record.status == '2'"/>
          <a @click="handleDel(record)">删除</a>
        </span>
        <span slot="curriculaDate" slot-scope="text, record">
          <a href="javascript:;" @click="handleDetail(record)">{{record.curriculaDate + getWeek(record.curriculaDate) + record.curriculaTime}}</a>
        </span>
      </a-table>
    </div>
    <CallRoll @child-event='callRollReturn' :para="dataPara" :childShow="callRollShow" :update="updateTag"></CallRoll>
    <AuditionClassAdd  @child-event='auditionClassAddReturn' :auditionClassShow="auditionClassShow" 
    :classType="'classAdd'"></AuditionClassAdd>
    <customer-audition-modal ref="modalForm" @ok="modalFormOk"></customer-audition-modal>
    <AuditionClassEdit  @child-event='editReturn' :childShow="editShow" :para="editPara"></AuditionClassEdit>
    <EducationDetails @info-event='infoReturn' :infoShow="infoShow" :dataPara="infoRow" activeKey = "tab1"></EducationDetails>
    <a-modal :visible="deleteVisible" title="确认信息" @ok="deleteOk"  @cancel="deleteCancel" :width="600">
      <span style="text-align: center;">删除试听课会同时将课上的学员试听状态修改为已取消，是否确认删除?</span>
    </a-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import {postAction} from '@/api/manage'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CustomerAuditionModal from './CustomerAuditionModal'
  import AuditionClassAdd from '../../education/modules/AuditionClassAdd.vue'
  import CallRoll from '../../education/modules/CallRoll.vue'
  import AuditionClassEdit from '../../education/modules/AuditionClassEdit.vue'
  import EducationDetails from '../../modules/EducationDetails.vue'
  export default {
    name: 'CustomerAuditionList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CustomerAuditionModal,AuditionClassAdd,CallRoll,AuditionClassEdit,EducationDetails
    },
    data () {
      return {
        description: '试听管理管理页面',
        auditionClassShow: false,
        callRollShow: false,
        editPara: {},
        editShow: false,
        dataPara: {},
        updateTag: false,
        deleteVisible: false,
        deletePara: {},
        infoShow: false,
        infoRow: {},
        queryParam: {
          type: 2
        },
        // 表头
        columns: [
          {
            title:'上课时间',
            align:"center",
            dataIndex: 'curriculaDate',
            scopedSlots: { customRender: 'curriculaDate' }
          },
          {
            title:'课程',
            align:"center",
            dataIndex: 'courseId_dictText'
          },
          {
            title:'老师',
            align:"center",
            dataIndex: 'lecturerId_dictText'
          },
          {
            title:'教室',
            align:"center",
            dataIndex: 'classRoomId_dictText'
          },
          {
            title:'实到/应到',
            align:"center",
            dataIndex: 'maximum'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createBy_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/education/educationSchedule/list",
          delete: "/customer/customerAudition/delete",
          deleteBatch: "/customer/customerAudition/deleteBatch",
          exportXlsUrl: "/customer/customerAudition/exportXls",
          importExcelUrl: "customer/customerAudition/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'schoolDistrictId',text:'校区ID',dictCode:"school_organization,name,id"})
        fieldList.push({type:'string',value:'cpName',text:'潜客姓名',dictCode:"customer_public,name,name"})
        fieldList.push({type:'string',value:'cpPhone',text:'潜客手机',dictCode:''})
        fieldList.push({type:'datetime',value:'auditionTime',text:'试听日期'})
        fieldList.push({type:'string',value:'salesCode',text:'顾问',dictCode:''})
        fieldList.push({type:'string',value:'auditionStatus',text:'试听状态',dictCode:''})
        fieldList.push({type:'datetime',value:'realAuditionTime',text:'到听日期'})
        fieldList.push({type:'Blob',value:'mark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'scheduleId',text:'课表ID',dictCode:''})
        this.superFieldList = fieldList
      },
      onCreateTimeChange: function (value, dateString) {
        this.queryParam.beginTime=dateString[0];
        this.queryParam.endTime=dateString[1];
      },
      auditionClassAddReturn() {
        this.auditionClassShow = false;
        this.loadData();
      },
      handleAdd() {
        this.auditionClassShow = true;
      },
      handleCallRoll(record) {
        this.dataPara = record;
        this.callRollShow = true;
      },
      callRollReturn() {
        this.callRollShow = false;
        this.updateTag = false;
        this.loadData();
      },
      handleEdit(row) {
        this.editPara = row;
        this.editShow = true;
      },
      editReturn() {
        this.editShow = false;
        this.updateTag = false;
        this.loadData();  
      },
      handleEditRoll(record) {
        this.dataPara = record;
        this.callRollShow = true;
        this.updateTag = true;
      },
      getWeek(text) {
        if (text !== undefined) {
          var dateArray = text.split("-");
          let date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
          return "【星期" + "日一二三四五六".charAt(date.getDay()) +"】" ;
        } else {
          return null;
        }
      },
      handleDel(record) {
        this.deletePara = record
        this.deleteVisible = true;
      },
      deleteOk() {
        postAction("/education/educationSchedule/callRollDelete", this.deletePara).then((res) => {
          if(res.success) {
              this.$message.success('删除成功');
          } else {
              this.$message.warn(res.message);
          }
          this.deletePara = {};
          this.deleteVisible = false;
          this.loadData();
        });
      },
      deleteCancel() {
        this.deletePara = {};
        this.deleteVisible = false;
      },
      handleDetail(record) {
        this.infoShow = true;
        this.infoRow = record;
      },
      infoReturn() {
        this.loadData();
        this.infoShow = false;
        this.infoRow = {};
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>