<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="name">
              <template #label><span title="姓名">姓名</span></template>
              <j-input placeholder="请输入姓名" v-model:value="queryParam.name" allow-clear ></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <!-- <a-button type="primary" v-auth="'bizEmployeesInfo:biz_employees_info:add'"  @click="handleAdd" preIcon="ant-design:plus-outlined" style="margin-left: 8px"> 新增</a-button> -->
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-row>
      <a-col :span="6" v-for="(item,index) in dataList" :key="index" style="padding: 5px 10px 0 0;height: 240px;">
        <a-row style="padding: 5px;background-color: white;border-radius: 8px;height: 220px;">
          <a-col :span="4">
            <div class="bjclass">
              <img :src="handleHeadPath(item.headPath)" style="width: 40px;height:40px;margin-top: 10px;"  @error="setDefaultImage"/>
            </div>
          </a-col>
          <a-col :span="20" style="padding-left: 15px;">
            <div>
              <span class="titleOne">
                {{item.name}} / 
                {{item.sex_dictText?item.sex_dictText:'无'}}
              </span>
            </div>
            <div style="height: 130px">
              <div class="center-lines">入职日期: {{item.entryTime	}}</div>
              <div class="center-lines">身份证号: {{item.idCard	}}</div>
              <div class="center-lines">联系电话: {{item.tel	}}</div>
              <div class="center-lines">出生日期: {{item.dateOfBirth	}}</div>
            </div>
            <div style="color: #857f7f;">
              <span style="float:left;"><Icon icon="ant-design:user-add-outlined" :size="18" /><span style="margin-left:5px;">{{ item.createBy_dictText }}</span></span> 
              <span style="margin-left: 15px;float:left;"><Icon icon="ant-design:field-time-outlined" :size="20" /><span style="margin-left:5px;font-size:16px;">{{ item.createTime.substring(0,10) }}</span></span>
              <span style="margin-right: 15px;float:right;">
                <a-dropdown :trigger="['hover']" placement="topRight">
                <a-button type="link"><Icon icon="ant-design:more-outlined" :size="20" /></a-button>
                <template #overlay>
                  <a-menu>
                    <a-menu-item @click="handleEdit(item)">编辑</a-menu-item>
                    <a-menu-item @click="handleFwbq(item)">服务标签</a-menu-item>
                    <a-menu-item @click="handleFpzh(item)">分配账号</a-menu-item>
                  </a-menu>
                </template>
              </a-dropdown>
                </span>
            </div>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <div style="float:right;bottom: 20px;z-index: 999;padding: 8px 16px;border-radius: 4px;display: flex;align-items: center;">
      <span style="margin-right: 10px;">共 {{ total }} 条数据</span>
      <Pagination showLessItems v-model:current="current" :pageSize="pageSize" size="small"
        show-quick-jumper :total="total" @change="onPageChange" />
    </div>


    <!-- 表单区域 -->
    <BizEmployeesInfoModal ref="registerModal" @success="handleSuccess"></BizEmployeesInfoModal>
    <!-- 服务标签 -->
    <EmployeesServiceTagModal ref="registerServiceTagModal" @success="handleSuccess"></EmployeesServiceTagModal>
    <!--用户抽屉-->
    <UserDrawer @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>

<script lang="ts" name="bizEmployeesInfo-bizEmployeesInfo" setup>
  import { ref, reactive, onMounted } from 'vue';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './BizEmployeesInfo.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import BizEmployeesInfoModal from './components/BizEmployeesInfoModal.vue'
  import EmployeesServiceTagModal from '/@/views/biz/bizEmployeesInfo/employeesServiceTag/employeesServiceTagModal.vue'
  import { defHttp } from '/@/utils/http/axios';
  import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
  import { Pagination } from 'ant-design-vue';
  import { useDrawer } from '/@/components/Drawer';
  import UserDrawer from '/@/views/system/user/UserDrawer.vue';
import JInput from "/@/components/Form/src/jeecg/components/JInput.vue";


  const APagination = Pagination;
  //注册drawer
  const [registerDrawer, { openDrawer }] = useDrawer();

  const formRef = ref();
  const queryParam = reactive<any>({});
  const registerModal = ref();
  const registerServiceTagModal = ref();
  const dataList = ref<any[]>([]);
  const current = ref(1);
  const pageSize = ref(12);
  const total = ref(0);

  const labelCol = reactive({
    xs:24,
    sm:4,
    xl:6,
    xxl:4
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });

//当没有员工头像时，默认展示企业logo
  function handleHeadPath(headPath){
    console.log('headPath--->',headPath);
    if(headPath){
      return getFileAccessHttpUrl(headPath);
    }else{
      return '../resource/img/logo.png';
    }
  }

  // 分配账号
function handleFpzh(item){
  defHttp.get({url:'/sys/user/queryByEmployessId',params:{employessId:item.id}}).then(res=>{
    console.log("🚀 ~ handleFpzh ~ res:", res)
    if(res==null){
      var record = {employessId:item.id,phone:item.tel,realname:item.name,sex:item.sex?parseInt(item.sex):'' }
      console.log("🚀 ~ defHttp.get ~ record:", record)
      openDrawer(true, {
        record,
        isUpdate: false,
        showFooter: true,
        tenantSaas: false,
      });
    }else{
      openDrawer(true, {
        record:res,
        isUpdate: true,
        showFooter: true,
        tenantSaas: false,
      });
    }
  })
}

//分配服务标签
  function handleFwbq(info){
    registerServiceTagModal.value.disableSubmit = false;
    registerServiceTagModal.value.init(info);
  }

  /**
   * 新增事件
   */
  function handleAdd() {
    registerModal.value.disableSubmit = false;
    registerModal.value.add();
  }
  
  /**
   * 编辑事件
   */
  function handleEdit(record) {
    registerModal.value.disableSubmit = false;
    registerModal.value.edit(record);
  }
   
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }
   
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, handleSuccess);
  }
   
   
  /**
   * 成功回调
   */
  function handleSuccess() {
     reload()
  }
   

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    //刷新数据
    reload();
  }

function onPageChange(page,pageSize){
  console.log('onPageChange', page,pageSize);
  current.value = page;
  reload();
}

  function reload(){
    queryParam.pageSize = pageSize;
    queryParam.pageNo = current;
    console.log('queryParam',queryParam);
    defHttp.get({url:'/bizEmployeesInfo/bizEmployeesInfo/list',params:queryParam}).then(res=>{
      console.log(res);
      dataList.value = res.records;
      total.value = res.total;
    })
  }
  

  // 自动请求并暴露内部方法
  onMounted(() => {
   reload();
  });



</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
    .ant-form-item:not(.ant-form-item-with-help){
      margin-bottom: 16px;
      height: 32px;
    }
    :deep(.ant-picker),:deep(.ant-input-number){
      width: 100%;
    }
  }

  .cardClass{
    margin: 5px;
    // 添加向右下的阴影效果
    border-radius: 8px;
    transition: box-shadow 0.3s ease-in-out;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);

  }
  .buttonMargin{
    margin: 3px;
  }
  .bjclass{
  text-align: center;
  margin-top: 16px;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  background: linear-gradient(to bottom, #fff, #efe9e9);
}
.titleOne {
  font-size: 16px;
  font-weight: 600;
  height: 40px;
  line-height: 40px;
  margin-bottom: 10px;
}
.ellipsis-two-lines {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; /* 限制文本为2行 */
  overflow: hidden;
  text-overflow: ellipsis;
  line-height:24px;color: #5a5a5a;
}
.center-lines {
  line-height:24px;color: #5a5a5a;
}
</style>
