<template>
  <!-- <a-list item-layout="horizontal" :data-source="list" :grid="{ gutter: 16, xs: 1, sm: 2, md: 4, lg: 4, xl: 6, xxl: 3, xxxl: 2 }"> -->
  <a-list item-layout="horizontal" :data-source="list" :loading="loadingList" >
    <template #renderItem="{ item }">
      <a-list-item>
        <a-list-item-meta>
          <template #title>
            <div class="wenZiJiaCu fs1d1r">
              听了&nbsp;{{ item.kkdw }}&nbsp;{{item.skjs}}&nbsp;主讲的&nbsp;《{{ item.kcmc }}》
            </div>
          </template>
          <template #description>
            <!-- -{{ item }}- -->
            <div class="wenZiJiaCu">
              <span v-if="item.score" class="hand" style="color: #337ab7;" @click="viewModal.view(item)">已评分：{{ item.score }}分</span>
              <span v-else  class="hand" style="color: #b77633;" @click="txpjFun(item)"><FormOutlined/>填写评价</span>

              <span v-if="item.source != null" class="hand" style="padding-left: .5rem;color: #337ab7;">【</span>
              <span v-if="item.source=='0'" class="hand" style="padding-left: .5rem;color: #337ab7;">课程中心</span>
              <span v-else-if="item.source=='1'" class="hand" style="padding-left: .5rem;color: #337ab7;">老系统</span>
              <span v-else-if="item.source=='2'" class="hand" style="padding-left: .5rem;color: #337ab7;">政务大厅</span>
              <span v-else-if="item.source=='3'" class="hand" style="padding-left: .5rem;color: #337ab7;">纸质评价</span>
              <span v-if="item.source != null" class="hand" style="padding-left: .5rem;color: #337ab7;">--</span>
              <span v-if="item.evaluationver=='1'" class="hand" style="padding-left: .5rem;color: #337ab7;">原始数据</span>
              <span v-else-if="item.evaluationver=='2'" class="hand" style="padding-left: .5rem;color: #337ab7;">线上听课</span>
              <span v-else-if="item.evaluationver=='3'" class="hand" style="padding-left: .5rem;color: #337ab7;">听课记录</span>
              <span v-else-if="item.evaluationver=='4'" class="hand" style="padding-left: .5rem;color: #337ab7;">同行专家</span>
              <span v-if="item.source != null" class="hand" style="padding-left: .5rem;color: #337ab7;">】</span>

              <span v-if="item.suibiNotes"  class="hand" style="padding-left: .5rem;color: #337ab7;">
                <a-popover title="听课笔记">
                  <template #content>
                    {{ item.suibiNotes }}
                  </template>
                  查看听课笔记
                </a-popover>
              </span>
              <span v-if="item.bh" style="color: #337ab7;margin-left: 30px;" @click="fwdtModal.view(item)"><FormOutlined/>服务大厅</span>
            </div>
          </template>
          <template #avatar>
            <div class="wenZiJuZhong dateAndTime">
              <!-- <TeamOutlined/> -->
              <i class="fas fa-users" />
              <div>{{ item.shijian }}</div>
              <div style="color: #1ab394;">{{ item.tkrq }}</div>
            </div>
          </template>
        </a-list-item-meta>
      </a-list-item>
    </template>
  </a-list>
  <a-pagination v-model="current" :total="total" show-less-items @change="handlePageChange" v-if="props.flagPage" style="text-align: right;" :hideOnSinglePage="true"/>
  <addModalPage ref="tingKeZuJiAddModal"/>
  <viewModalPage ref="viewModal"/>
  <fwdtModalPage ref="fwdtModal"/>
</template>
<script setup lang="ts">
import { ref, onMounted, watch, createVNode,h } from 'vue';
import { TeamOutlined, FormOutlined } from '@ant-design/icons-vue';
import { getUserId,getSysConfig } from '/@/views/site/utils/index';
  import { Input, Popover, Pagination, Empty } from 'ant-design-vue';

import addModalPage from '/@/views/site/tingKeZuJi/components/addModal.vue';
import viewModalPage from '/@/views/site/tingKeZuJi/components/viewModal.vue';
import fwdtModalPage from '/@/views/site/tingKeZuJi/components/fwdtModal.vue';
import { defHttp } from '/@/utils/http/axios';
  import { Modal } from 'ant-design-vue';
  import { ExclamationCircleOutlined,CheckOutlined,CloseOutlined } from '@ant-design/icons-vue';
enum Api {
  list = '/kcTingke/kcTingke/indexListPage',
  listTkjl = '/kcTingke/kcTingke/findTingKeZuJiBytingketimeAndUserId'
}

const tingKeZuJiAddModal = ref();
const viewModal = ref();
const fwdtModal = ref();
const current = ref<number>(0);
const total = ref<number>(2);
const loadingList = ref<boolean>(false);

const APagination = Pagination;
const emit = defineEmits(['changeParam']);

const props = defineProps({
  queryParam: { type: Object, default: () => ({}) },
  flagPage: { type:Boolean,default:false}
});

/**
 * 列表接口
 * @param params
 */
const listApi = (params) => defHttp.get({ url: Api.list, params });
const listTkjlApi = (params) => defHttp.get({ url: Api.listTkjl, params });

const list = ref<any>([]);
onMounted(() => {
  init();
});

watch(
  () => props.queryParam,
  (v) => init(),
  {
    deep:true,
    immediate:true,
  }
);


function txpjFun(item){

  let ketangbiaoid = item.ketangbiaoid;
  let userid = item.userid;
  listTkjlApi({ userid: userid, ketangbiaoid:ketangbiaoid}).then(res => {
    var list = res
    console.log(`🚀 ~ file: list.vue:106 ~ listTkjlApi ~ list:`, list)
    if(list.length>0){
      var score = list[0].score
      if(score){
        Modal.error({
            icon: createVNode({}),
            content:  h('div', {style:'height:200px;text-align:center;'}, [
              h('icon', {style:'font-size:80px;font-weight:600;color:red;'}, createVNode(CloseOutlined)),
              h('p',{style:'font-size:22px;font-weight:600;color:black;'}, '已经对此课程进行评价，不可重复评价，请点击刷新按钮！'),
            ]),
            okText: 'OK',
            width:'500px',
          });
      }else{
        tingKeZuJiAddModal.value.view(item)
      }
    }else{
      tingKeZuJiAddModal.value.view(item)
    }

  });

}

function init() {
  loadData()
}
function loadData(){
  loadingList.value = true
  console.log(`🚀 ~ file: list.vue:139 ~ listApi ~ props.queryParam:`, props.queryParam)
  listApi({ userid: getUserId(),  ...props.queryParam }).then(res => {
    total.value = res.total;
    current.value = res.current;
    list.value = res.records
    loadingList.value = false
    // props.queryParam.value = res.total;
  });
}

function handlePageChange(record){
  console.log(`🚀 ~ file: list.vue:150 ~ handlePageChange ~ record:`, record)
  // props.queryParam.pageNo=record
  emit('changeParam',record);
  // loadData();
}


function onSearch() {
  loadData();
}

defineExpose({
  onSearch
});

</script>
<style lang="less" scoped>
.wenZiJuZhong {
  text-align: center;
}
.wenZiJiaCu {
  font-weight: 700;
}
.fs1d1r {
  font-size: 16px;
  min-height: 55.281px;
}
.hand {
  cursor:pointer;
}
.dateAndTime {
  padding-top: 10px;
}

</style>