<template>
  <div class="data-dictionary h100">
    <common-layout  ref="layoutRef" :table-attrs="{
     'has-operation':true
   }" :form-attrs="{
     'span-attrs':{
       span:4
     }
   }" :table-header="userManageHomeHeader" :get-table-list="getTableData" :filter-form="userManageHome">
      <template #plusBtn>
        <el-button  type="primary" :icon="Plus" @click="$emit('changeOperation','add')">新增</el-button>
      </template>
      <template #operation="{data}">
        <el-button  type="info" @click="$emit('changeOperation','detail',data)">查看</el-button>
        <el-button  type="info" @click="$emit('changeOperation','edit',data)">修改</el-button>
        <el-button  type="info" @click="deleteItem(data)">删除</el-button>
      </template>
    </common-layout>
  </div>
</template>

<script>
import {Base64} from "js-base64";
import {ref} from "vue";
import {Plus, Search} from "@element-plus/icons-vue"
import {useRootStore} from "@/pinia/useStore";
import CommonLayout from "@/components/CommonLayout.vue";
import {userManageHomeHeader} from "@/data/all-table-header";
import {userManageHome} from "@/data/all-form";

import {proXyxxDeleteSystemYhgl, proXyxxSelectYhgl} from "@/service/system-manage/user-manage/user-manage";
import {handleMes} from "@/units/element-ui/tip";
import {InsertSyslog} from "@/units/use-method/user-log";

export default {
  name: "UserManageHome",
  components:{CommonLayout},
  computed: {
    Plus(){
      return Plus
    }
  },
  setup(){
    const layoutRef = ref(null);
    const store =useRootStore();
    function getTableData (){
      proXyxxSelectYhgl({
        A_NAME:layoutRef.value.form.A_NAME,
        A_MANAGER:'true',
        A_USER_UNIT:'',
        END_TIME:layoutRef.value.form.END_DATE,
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize
      }).then(res =>{
        let originData = res.msg[0].Rows
        InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息查询", "用户管理查询成功", "用户管理", "")
        for(let i = 0;i<originData.length;i++){
          if(originData[i].MAIL){
            originData[i].MAIL = Base64.decode(originData[i].MAIL);
          }
          if(originData[i].TELPHONE){
            originData[i].TELPHONE = Base64.decode(originData[i].TELPHONE);
          }
          if(originData[i].CONTACT){
            originData[i].CONTACT = Base64.decode(originData[i].CONTACT);
          }
          if(originData[i].PASSWORD){
            originData[i].PASSWORD = Base64.decode(originData[i].PASSWORD);
            originData[i].CONFIRMPASSWORD = originData[i].PASSWORD ;
          }
        }

        layoutRef.value.getResData(originData,res.msg[0].TotalRowCount)
      })
    }
    function deleteItem (obj){
      proXyxxDeleteSystemYhgl({
        "A_USERID":obj.USERID
      }).then(res=>{
        handleMes(res,() => {
          InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息删除", "用户管理删除成功", "用户管理", "")
          getTableData();
        })
      })
    }
    return {
      userManageHome,
      userManageHomeHeader,
      getTableData,
      deleteItem,
      layoutRef
    }

  }

}
</script>

<style scoped lang="scss">
#policy-regulation-information{
  background-color: yellow;
  width: 100%;
  height: 100%;
}
</style>