<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection" >
     <!--插槽:table标题-->
      <template #tableTitle>
           
      </template>
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{text}">
         <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->
      <template #pcaSlot="{text}">
         {{ getAreaTextByCode(text) }}
      </template>
      <template #fileSlot="{text}">
         <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
         <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <RateTaskModal @register="registerModal" @success="handleSuccess"></RateTaskModal>
  </div>
</template>

<script lang="ts" name="rate-rateTask" setup>
  import {ref, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import RateTaskModal from './components/RateTaskModal.vue'
  import {columns, searchFormSchema} from './RateTaskRate.data';
  import {ratelist} from './RateTask.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import { useMessage } from '/@/hooks/web/useMessage';
  const { createMessage } = useMessage();
  import { useRouter } from 'vue-router';
  import { useUserStore } from '/@/store/modules/user';
  const router = useRouter();
  const userStore = useUserStore();
  const checkedKeys = ref<Array<string | number>>([]);
  //注册model
  const [registerModal, {openModal}] = useModal();
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '评估打分',
           api: ratelist,
           columns,
           canResize:false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
      },
          
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext


   /**
    * 详情
   */
  function handleDetail(record: Recordable) {
     router.push({path: '/rate/rateRateView',query:{id:record.id}})
   }


   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }

   /**
    * 评分 rate
   */
   function handleRateContent(record: Recordable) {
   
    router.push({path: '/rate/rateRate',query:{id:record.id}})
   }


   /**
      * 操作栏
      */
  function getTableAction(record){
       return [

        {
           label: '评分',
           onClick: handleRateContent.bind(null, record),
           ifShow: ()=> { 
            if(getIsRateUser(userStore.getUserInfo.username,record['rateUser'])&(record['rateTaskstatus']=='11'||record['rateTaskstatus']=='12'))
            return true
            else return false
            }
         },
       
         {
           label: '查看',
           onClick: handleDetail.bind(null, record),
           ifShow: ()=> { 
            if(record['rateTaskstatus']=='13')
            return  true
            else return false
            }
         },
        
       ]
   }
     /**
        * 下拉操作栏
        */
  function getDropDownAction(record){
       return [ /**
         {
           label: '详情',
           onClick: handleDetail.bind(null, record),
         },  */
       ]
   }

function getIsRateUser(username,rateTaskstatus){
var flag =false;
 var valueArray = rateTaskstatus.split(',');
  for(var i=0;i<valueArray.length;i++){
    if(username==valueArray[i])
    flag=true;
  }
return flag
}



</script>

<style scoped>

</style>