<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>
              <a-input placeholder="请输入姓名" v-model:value="queryParam.name" allow-clear ></a-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">
        <a-card :title="item.name +'/'+item.sex_dictText" class="cardClass">
          <template #extra><a title="操作">
            
            <a-popover title="功能" style="width: 300px;">
              <template #content>
                <div>
                  <span class="buttonMargin">
                    <a-button type="primary" @click="handleEdit(item)">编辑</a-button>
                  </span>
                  <span class="buttonMargin">
                    <a-button type="primary" @click="handleFwbq(item)">服务标签</a-button>
                  </span>
                  <span class="buttonMargin">
                    <a-button type="primary" @click="handleFpzh(item)">分配账号</a-button>
                  </span>
                </div>
              </template>
              <icon icon="ant-design:setting-outlined" />
            </a-popover>
            
            </a></template>
            <!-- 人员信息 -->
            <a-row>
              <a-col :span="8" style="padding: 0 8px;">
                <img
                  width="100%"
                  :src="handleHeadPath(item.headPath)"
                  @error="setDefaultImage"
                />
              </a-col>
              <a-col :span="16">
                <p>入职日期: {{item.entryTime}}</p>
                <p>身份证号: {{item.idCard}}</p>
                <p>联系电话: {{item.tel}}</p>
                <p>出生日期: {{item.dateOfBirth}}</p>
              </a-col>
            </a-row>
        </a-card>
      </a-col>
      <a-col :span="24" style="text-align: right;">
        <a-pagination v-model:current="current" v-model:page-size="pageSize" :total="total" show-less-items @change="onPageChange" />
      </a-col>
    </a-row>



    <!-- 表单区域 -->
    <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';


  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(8);
  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 '../../../../../public/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: 5px;
    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;
  }
</style>
