<template>
  <div>
    <div class="titleBox">
      <!-- 头部 -->
      <PageTitle title="下发任务">
        <el-button type="primary" @click="addEditForm('add', '')">
          <el-icon style="vertical-align: middle">
            <CirclePlus />
          </el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>

      </PageTitle>
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" />
    </div>
    <!-- 表格 -->
    <div class="tabBox">
      <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
        :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth" @chooseData="chooseData">
        <template #fgrwzt="{ row }">
          <!-- <el-table-column prop="wlq" label="未领取"/>
          <el-table-column prop="ylq" label="已领取"/>
          <el-table-column prop="ywc" label="已完成"/> -->
          <dict-tag :options="D_BZ_QWRWZT" :value="row.fgrwzt" :tag="false" />
        </template>
        <template #controls="{ row }">
          <!-- 领取后不可再编辑，领取后不可再删除 -->
          <el-button @click="addEditForm('detail', row)" size="small">详情</el-button>
          <el-button @click="addEditForm('eidt', row)" size="small">编辑</el-button>
          <el-button @click="deletList(row.id)" type="danger" size="small">删除</el-button>
        </template>
      </MyTable>
      <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
        ...pageData.pageConfiger,
        total: pageData.total
      }"></Pages>
    </div>
    <!-- 编辑-新增 -->
    <EditAddForm ref="editInfo" @updateDate="getDataList" :dic="{ D_BZ_QWRWZT }"></EditAddForm>
  </div>
</template>

<script setup>
import { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";
import EditAddForm from "./components/editAddForm.vue";
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import Search from "@/components/aboutTable/Search.vue";
import { reactive, ref, onMounted, getCurrentInstance, nextTick } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_QWRWZT } = proxy.$dict("D_BZ_QWRWZT");
const ids = ref([]); //多选
const searchBox = ref(); //搜索框
const listQuery = ref({});
const editInfo = ref();
const searchConfiger = reactive([
  {
    showType: "input",
    prop: "sbmc",
    placeholder: "请输入任务名称",
    label: "任务名称"
  },
  {
    showType: "select",
    prop: "rwLqZt",
    placeholder: "请选择任务领取状态",
    label: "任务领取状态",
    options: D_BZ_QWRWZT
  }
]);
const pageData = reactive({
  tableData: [], //表格数据
  tableConfiger: {
    loading: false,
    rowHieght: 61,
    showSelectType: "checkBox"
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageNum: 1
  }, //分页
  controlsWidth: 210, //操作栏宽度
  tableColumn: [
    { label: "任务名称", prop: "fgRwmc" },
    { label: "方格编号", prop: "fgmc" },
    { label: "下发日期", prop: "xfrq" },
    { label: "下发部门", prop: "xfbm" },
    { label: "任务领取人", prop: "fgrwlqr" },
    { label: "任务领取状态", prop: "fgrwzt", showSolt: true },
  ]
});
onMounted(() => {
  tabHeightFn();
  getDataList();
});
// 搜索
const onSearch = (val) => {
  listQuery.value = { ...listQuery.value, ...val };
  getDataList();
};

// 获取数据
const getDataList = () => {
  let pramas = {
    pageSize: pageData.pageConfiger.pageSize,
    pageCurrent: pageData.pageConfiger.pageNum,
    ...listQuery.value
  };
  pageData.tableConfiger.loading = true;
  qcckGet(pramas, "/mosty-yjzl/tbZdyrw/selectList")
    .then((res) => {
      pageData.tableData = res.records || [];
      pageData.tableConfiger.loading = false;
      pageData.total = res.total;
    })
    .catch(() => {
      pageData.tableConfiger.loading = false;
    });
};
const changeNo = (val) => {
  pageData.pageConfiger.pageNum = val;
  getDataList();
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
  getDataList();
};

// 多选
const chooseData = (val) => {
  if (Array.isArray(val)) ids.value = val.map((v) => v.id);
};
//批量删除
const deletList = (id) => {
  proxy.$confirm("确定要删除", "警告", { type: "warning" }).then(() => {
    qcckPost({ id }, "/mosty-yjzl/tbZdxlFgxlrw/delZdyxlFgxlrw").then(() => {
      proxy.$message({ type: "success", message: "删除成功" });
      getDataList();
    });
  }).catch(() => {
    proxy.$message.info("已取消");
  });
};

// 新增编辑表单
const addEditForm = (type, row) => {
  nextTick(() => {
    editInfo.value.init(type, row);
  });
};

// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight = window.innerHeight - searchBox.value.offsetHeight - 240;
  window.onresize = function () { tabHeightFn(); };
};
</script>

<style lang="scss" scoped>
::v-deep .el-table thead.is-group th.el-table__cell {
  background: rgba(6, 42, 72, 0.8);
}
</style>
<style>
.el-loading-mask {
  background: rgba(0, 0, 0, 0.3);
}
</style>
