<template>
  <div>
    <base-layout
      ref="baseLayout"
      :buttonList="buttonList"
      @onFuncBtn="onFuncBtn"
      :querySwitch="true"
      :searchList="requirementList"
      @search="handleSearchEvent"
      :isPage="true"
      @pageChange="handlePageChange"
    >
      <div slot="main" slot-scope="{ tableHeight }">
        <base-table
          ref="baseTable"
          :showIndex="true"
          :funWidth="120"
          :funData="funData"
          @onFunc="onFunc"
          :tabLoading.sync="tabLoading"
          :tableHeight="tableHeight"
          :tableData="tableData"
          :tableColumn="tableColumnData"
        >
          <template #type="{ row }">
            {{ taskStatusDist[row.type] }}
          </template>
        </base-table>
      </div>
    </base-layout>
    <right-dialog ref="rightDialog" @resetTable="resetTable"></right-dialog>
  </div>
</template>

<script>
import baseLayout from "@/components/base/baseLayout";
import baseTable from "@/components/base/baseTable";
import rightDialog from "./rightDialog.vue";
import { getApiModuleApi } from "@/api/apiChunks/index.js";

export default {
  components: {
    baseLayout,
    baseTable,
    rightDialog,
  },
  data() {
    return {
      buttonList: [
        {
          menuName: "刷新",
          icon: "el-icon-refresh",
          btnFunction: "resetLoad",
        },
      ], //按钮组
      requirementList: [
        {
          placeholder: "消息内容",
          prop: "sendCount",
          tag: "elInput",
        },
        {
          placeholder: "发送时间",
          prop: "sendDatetime",
          tag: "elDatePicker",
        },
      ], //查询模板list
      tabLoading: false,
      tableColumnData: [
        {
          prop: "type",
          label: "消息类型",
          tooltip: true,
          width: 100,
        },
        {
          prop: "recipientsPersonName",
          label: "接收人",
          tooltip: true,
          width: 120,
        },
        {
          prop: "sendDatetime",
          label: "发送时间",
          tooltip: true,
          width: 170,
        },
        {
          prop: "sendCount",
          label: "消息内容",
          tooltip: true,
        },
        {
          prop: "sendPersonName",
          label: "发送人",
          width: 120,
        },
        {
          prop: "resultMessage",
          label: "三方系统消息结果",
          tooltip: true,
        },
        // {
        //   prop: "create_user_name",
        //   label: "创建人",
        //    width:120
        // },
        {
          prop: "create_time",
          label: "创建时间",
          width: 170,
        },
      ], //表头数据
      funData: [
        {
          color: "#6a9af1",
          text: "查看",
        },
      ],
      tableData: [], //表格数据
      pageModel: {
        pageNum: 1,
        pageSize: 100,
      },
      queryModel: {
        send_count: "",
        send_datetime: "",
      },
      taskStatusDist: {
        1: "系统消息",
        2: "单据消息",
        3: "钉钉消息",
        4: "企业微信消息",
      },
    };
  },
  mounted() {
    this.GetProductionTableData();
  },
  methods: {
    onCellClick(row) {
      this.openLoading("detail");
      this.$refs.rightDialog.openDialog("show", row);
    },
    // 表格数据
    async GetProductionTableData() {
      this.tabLoading = true;
      let param = {
        ...this.pageModel,
        ...this.queryModel,
      };
      const res = await getApiModuleApi(
        {
          tl: "sysSendMessageLogService",
          as: "",
          dj: "queryEntityPage",
        },
        {
          ...param,
        }
      );
      this.tabLoading = false;
      if (res.status == "200") {
        this.tableData = res.attribute.list;
        this.$refs.baseLayout.setPageTotal(res.attribute.total);
      }
    },
    // 分页变化
    handlePageChange(val) {
      this.pageModel.pageNum = val.pageIndex;
      this.pageModel.pageSize = val.pageSize;
      this.GetProductionTableData();
    },
    // 按钮组
    onFuncBtn(btn) {
      this.onCellClick();
    },
    // 表格操作事件 查看 编辑 删除
    onFunc(index, row, item) {
      // 查看
      if (item.text === "查看") {
        this.openLoading("detail");
        this.$refs.rightDialog.openDialog("show", row);
      }
    },
    // 重置表格
    resetTable() {
      this.pageModel.pageNum = 1;
      this.$refs.baseLayout.pageClear();
      this.GetProductionTableData();
    },
    // 搜索
    handleSearchEvent() {
      let data = this.$refs.baseLayout.ruleForm;
      this.queryModel = data;
      this.resetTable();
    },
  },
};
</script>

<style scoped>
.clickTitle {
  color: #409eff;
  cursor: pointer;
}
</style>
