<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <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="学习主题">
              <j-dict-select-tag placeholder="请输入学习主题" v-model="queryParam.mreLearningId"
                                 dictCode="mr_e_learning,subject,id"></j-dict-select-tag>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="考察人员">
              <a-input placeholder="请输入考察人员" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="类型">
                <a-input placeholder="请输入类型" v-model="queryParam.type"></a-input>
              </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>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        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">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" 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="handleDetail(record)">详情</a>
          <!--          <a-divider type="vertical" />-->
          <!--          <a-dropdown>-->
          <!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
          <!--            <a-menu slot="overlay">-->
          <!--              <a-menu-item>-->
          <!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
          <!--                  <a>删除</a>-->
          <!--                </a-popconfirm>-->
          <!--              </a-menu-item>-->
          <!--            </a-menu>-->
          <!--          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <mr-learning-modal ref="modalForm" @ok="modalFormOk"></mr-learning-modal>
    <mr-learning-audit-modal ref="auditForm"></mr-learning-audit-modal>

    <j-modal
      :okButtonProps="{ }"
      :title='modelDetail.title'
      :visible.sync='modelDetail.visible'
      :width='800'
      switchFullscreen
    >
      <template>
        <a-descriptions title="" :column="1" bordered>
          <a-descriptions-item label="姓名">

          </a-descriptions-item>
          <a-descriptions-item label="身份">

          </a-descriptions-item>
          <a-descriptions-item label="手机号码">

          </a-descriptions-item>
          <a-descriptions-item label="身份证号">

          </a-descriptions-item>
        </a-descriptions>
      </template>
    </j-modal>
  </a-card>
</template>

<script>

    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import MrLearningModal from '../modules/mrLearning/MrLearningModal'
    import { Base64 } from 'js-base64'
    import MrLearningAuditModal from '../modules/mrLearning/MrLearningAuditModal'
    import { getAction } from '@/api/manage'

    export default {
        name: 'MrLearningList',
        mixins: [JeecgListMixin, mixinDevice],
        components: {
            MrLearningAuditModal,
            MrLearningModal
        },
        data() {
            return {
                queryParamTwo: {},
                description: '未成年学习表管理页面',
                // 表头
                columns: [
                    {
                        title: '#',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '网络学习主题',
                        align: 'center',
                        dataIndex: 'mreLearningId_dictText'
                    },
                    {
                        title: '考察人员',
                        align: 'center',
                        dataIndex: 'mrIncarceratedUser.name',
                    },
                    {
                        title: '微信名',
                        align: 'center',
                        dataIndex: 'wxUserId_dictText',
                        customRender: (text) => {
                            //字典值翻译通用方法
                            return Base64.decode(text)
                        }
                    },
                  // {
                  //   title: '类型',
                  //   align: 'center',
                  //   dataIndex: 'type_dictText'
                  // },
                    {
                        title: '创建日期',
                        align: 'center',
                        dataIndex: 'createTime'
                    },
                    // {
                    //     title:'视频时长（分钟）',
                    //     align:"center",
                    //     dataIndex: 'learningTime'
                    // },
                    // {
                    //     title:'审核',
                    //     align:"center",
                    //     dataIndex: 'status_dictText'
                    // },
                    // {
                    //     title: '操作',
                    //     dataIndex: 'action',
                    //     align: 'center',
                    //     fixed: 'right',
                    //     width: 147,
                    //     scopedSlots: { customRender: 'action' }
                    // }
                ],
                url: {
                    list: '/MrLearning/mrLearning/list',
                    delete: '/MrLearning/mrLearning/delete',
                    deleteBatch: '/MrLearning/mrLearning/deleteBatch',
                    exportXlsUrl: '/MrLearning/mrLearning/exportXls',
                    importExcelUrl: 'MrLearning/mrLearning/importExcel',

                },
                dictOptions: {},
                score: 0,
                modelDetail: {
                    title: '详情',
                    visible: false
                },
                info: {},
                disableSubmit: true,
                superFieldList: [],
            }
        },
        created() {
            this.getSuperFieldList()
            this.getDefaultCredits()
        },
        computed: {
            importExcelUrl: function () {
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
            },
        },
        methods: {
            handleDetail: function (record) {
                console.log(1111)
                this.modelDetail.visible = true
                this.info = record
            },
            initDictConfig() {
            },
            getDefaultCredits() {
                let that = this
                let score = 0
                getAction(`/sys/dict/getDictItems/${'default_credits'}`, {}).then((res) => {
                    console.log(res)
                    if (res.success) {
                        score = res.result[0].value
                        that.score = score
                        //that.$message.success(res.message)
                    } else {
                        that.$message.warning(res.message)
                    }
                })
            },
            handleAudit(record) {
                record.status = '1'
                record.score = this.score
                console.log(record)
                this.$refs.auditForm.edit(record)
            },
            handleAuditRefuse(record) {
                record.status = '-1'
                this.audit(record)
            },
            audit: function (record) {
                var that = this
                that.model={}
                let formData = Object.assign(that.model, record)
                putAction(that.url.audit, formData).then((res) => {
                    if (res.success) {
                        //that.$message.success(res.message)
                    } else {
                        that.$message.warning(res.message)
                    }
                })
            },
            getSuperFieldList() {
                let fieldList = []
                fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
                fieldList.push({ type: 'string', value: 'mreLearningId', text: '网络学习id', dictCode: '' })
                fieldList.push({ type: 'string', value: 'wxUserId', text: '微信userid', dictCode: '' })
                fieldList.push({ type: 'string', value: 'type', text: '类型', dictCode: '' })
                fieldList.push({ type: 'int', value: 'learningTime', text: '若是视频有时长（分钟）', dictCode: '' })
                this.superFieldList = fieldList
            }
        }
    }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>