<template>
  <div>
    <MOSTY.PageTree :pageTitle="'典型经验列表'" :searchType="'03'" @getDeptId="getdeptId">
      <template #serach>
        <el-divider />
        <MOSTY.Search :searchArr="searchArr" @submit="onSearch" />
        <el-divider />
        <div class="btnBox">
          <el-button type="primary" @click="addUserHander">
            <el-icon>
              <CirclePlus />
            </el-icon>
            <span>新增</span>
          </el-button>
        </div>
      </template>
      <template #table>
        <section class="eltab9">
          <MOSTY.Table :table-columns="tableColumn" :tableData="tableData" :tableloading="tableloading"
            :isSelect="false" :isSort="true" @SortChange="SortChange" style="width: 100%;">
            <template #level="{ row }">
              <dict-tag :options="D_BZ_LWJB" :value="row.level" :tag="false" />
            </template>
            <template #actions="{ row }">
              <span class="operedit" @click="editClick(row)"><el-icon>
                  <EditPen />
                </el-icon>修改</span>
              <span class="operesee" @click="seeClick(row)"><el-icon>
                  <Compass />
                </el-icon>查看</span>
              <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon-color="red" title="确定要删除?"
                @confirm="handledelete(row)">
                <template #reference>
                  <span class="operdel" size="small">
                    <el-icon>
                      <Delete />
                    </el-icon>删除</span>
                </template>
              </el-popconfirm>
            </template>
          </MOSTY.Table>
        </section>
        <div class="fenye">
          <MOSTY.Pages :pageConfiger="pageConfiger" @changeSize="handleSizeChange" @changeNo="handleCurrentChange" />

        </div>
      </template>
    </MOSTY.PageTree>

  </div>
  <!-- 修改 -->
  <div v-if="comprehensiveShow" class="dialog-box">
    <Editdxjy @close="close" :title="title" :orgcode="orgcode" :rowId="rowId" :saveBtnShow="saveBtnShow" />
  </div>

</template>

<script setup>
// 引入
import { onMounted, reactive, ref, watch, getCurrentInstance } from "vue";
import { filterYear } from "@/utils/auth.js";
import { ElMessage } from "element-plus";
import Editdxjy from "./commponents/Editdxjy.vue";
import * as MOSTY from "@/components/MyComponents/index";
import { getApi, deleteApi, putApi, postApi } from "@/api/tobAcco_api.js";
const { proxy } = getCurrentInstance();
const { D_BZ_LWJB } = proxy.$dict("D_BZ_LWJB");
const searchArr = reactive([
  {
    showType: "select",
    prop: "year",
    width: '250px',
    defaultVal: new Date().getFullYear(),
    options: filterYear(7),
  },
  {
    showType: "input",
    prop: "username",
    width: '250px',
    placeholder: '请输入人员姓名查询'
  }
]);
const tableColumn = ref([
  {
    title: "典型经验名称",
    prop: "titlename",
    sortable: true
  },
  {
    title: "主要内容",
    prop: "content",
    sortable: true
  },
  {
    title: "实施人员",
    prop: "username",
    sortable: true
  },
  {
    title: "级别",
    prop: "level",
    slot: true,
    sortable: true
  },
  {
    title: "提出时间",
    prop: "time",
    sortable: true
  },
  {
    title: "年度",
    prop: "year",
    sortable: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const pageConfiger = reactive({
  pageSize: 20,
  pageCurrent: 1,
  total: 0
})
const comprehensiveShow = ref(false);
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 20,
  type: '4',
  year: new Date().getFullYear(),
});
const rowId = ref(null);
const saveBtnShow = ref(true);
const title = ref("新增");
// 树的数据
const tableData = ref([
]);

function close() {
  rowId.value = null
  comprehensiveShow.value = false
  getListData()
}
function onSearch(obj) {
  listQuery.pageCurrent = 1
  pageConfiger.pageCurrent = 1
  listQuery.year = obj.year
  listQuery.username = obj.username
  getListData();
}
//获取列表数据
const tableloading = ref(false);
function getListData() {
  tableloading.value = true;
  postApi(listQuery, "/mosty-jcgl/safetypaperCommend/getPageList").then((res) => {
    if (res.records) {
      tableloading.value = false;
      tableData.value = res.records;
      pageConfiger.total = res.total;
    } else {
      tableData.value = [];
      tableloading.value = false;
    }
  }).finally(() => {
    tableloading.value = false;
  });
}

//分页
const handleSizeChange = (currentSize) => {
  listQuery.pageSize = currentSize;
  pageConfiger.pageSize = currentSize;
  getListData();
};
const handleCurrentChange = (currentPage) => {
  listQuery.pageCurrent = currentPage;
  pageConfiger.pageCurrent = currentPage;
  getListData();
};
//选择右侧部门
const getdeptId = (val) => {
  listQuery.orgcode = val.id;
  listQuery.pageCurrent = 1;
  pageConfiger.pageCurrent = 1;
  getListData();
};
// 方法

//新增
const addUserHander = () => {
  title.value = "典型经验新增";
  orgcode.value = listQuery.orgcode
  comprehensiveShow.value = true;
  rowId.value = null;
  saveBtnShow.value = true;
};

// 编辑
const orgcode = ref("")
const editClick = (row) => {
  title.value = "典型经验修改";
  orgcode.value = listQuery.orgcode
  comprehensiveShow.value = true;
  saveBtnShow.value = true;
  rowId.value = row.id
};
// 查看
const seeClick = (row) => {
  title.value = "典型经验详情";
  comprehensiveShow.value = true;
  rowId.value = row.id
  saveBtnShow.value = false;
};
//删除
const handledelete = (row) => {
  postApi({}, `/mosty-jcgl/safetypaperCommend/del/${row.id}`).then(
    (res) => {
      ElMessage.success("删除成功");
      getListData();
    }
  );
};


onMounted(() => {
});
</script>

<style lang="scss" scoped>
.bigBox {
  display: flex;

  .right {
    padding: 0 10px;
    margin: 0px 14px;
    background: #fff;
  }

  .btnBox {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 12px;
  }
}
</style>