<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <!-- <el-button
          type="primary"
          size="medium"
          @click="exportAll"
          :disabled="multipleSelection.length == 0"
        >
          <span class="d-in-block v-mid font-size-16">导出</span>
        </el-button> -->
      </div>
      <el-form label-width="100px" :inline="true">
        <el-form-item prop="state_value">
          <el-select
            class="mr10"
            v-model="state_value"
            placeholder="请选择类别"
          >
            <el-option
              v-for="item in type_list"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="keyword">
          <el-input
            placeholder="请输入搜索关键字"
            v-model="keyword"
            clearable
            @clear="getListData"
          ></el-input>
        </el-form-item>
        <el-button type="primary" class="ml5" @click="getListData"
          >搜索</el-button
        >
      </el-form>
    </div>
    <el-table
      :data="tableData"
      tooltip-effect="dark"
      v-loading="loading"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        align="center"
        width="55"
      ></el-table-column>
      <el-table-column
        label="序号"
        align="center"
        type="index"
        width="50"
      ></el-table-column>
      <el-table-column
        label="类型"
        prop="lb_name"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="标题"
        prop="gw_title"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column label="发文字号" prop="gw_zh"></el-table-column>
      <el-table-column label="发起人" prop="gw_fqr_name"></el-table-column>
      <el-table-column label="发起科室" prop="gw_fqks_name"  show-overflow-tooltip></el-table-column>
      <el-table-column
        label="发起时间"
        prop="create_dateline"
      ></el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="text" @click="handleDetail(scope.row)"
            >详情</el-button
          >
          <el-button type="text" @click="exportsingle(scope.row)">导出</el-button>
        </template>
        
      </el-table-column>
    </el-table>
    <footer
      class="flex-item-none"
      style="display: flex; justify-content: flex-end; margin-top: 30px"
    >
      <el-pagination
        background
        layout="total,prev, pager, next"
        :page-size="limit"
        :total="total"
        :current-page.sync="cur_page"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </footer>
  </div>
</template>

<script>
import {
  gwk_list,
  exportWord_api,
  export_api,
  gwk_add,
  gwk_edit,
  gwk_detail,
  gwk_del,
  org_users,
  getDownloadAPI
} from "./itemApi";
import { useUserStore } from "@/stores/user";
const { real_name, dept_ids } = useUserStore();
export default {
  name: "bbtj",
  data() {
    return {
      state_value: "",
      keyword: "",
      type_list: [
        {
          label: "全部",
          value: "0",
        },
      ],
      tableData: [],
      type_value: "",
      multipleSelection: [],
      limit: 10,
      total: 0,
      cur_page: 1,
      dialogFormVisible: false,
      showType: [],
      dialogForm: {
        year: "",
      },
      rules_check: {
        year: [{ required: true, message: "请选择年份", trigger: "change" }],
      },
      title: "",
      isEdit: false,
      id: "",
      loading: false,
      userList: [],

      mineStatus: "",
      mineStatusValue: [],
    };
  },
  mounted() {
    // this.getUserList();
    this.getListData();
  },
  methods: {
    getUserList() {
      let data = {
        dept_id: dept_ids[0],
        page: 1,
        limit: 9999,
      };
      org_users(data).then((res) => {
        if (res.code == 1) {
          this.userList = res.data.page_data;
        }
      });
    },
    //初始化列表数据
    getListData() {
      this.loading = true;
      let transObj = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        gw_fb: 1,
      };
      gwk_list(transObj).then((res) => {
        this.loading = false;
        this.tableData = res.data.page_data;
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
      });
    },
    //多选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //导出所有
    exportAll() {
      let Token = JSON.parse(window.localStorage.getItem("userInfo")).token;
      let expId = [];
      this.multipleSelection.forEach((item) => {
        expId.push(item.lb_id);
      });
      let transString = expId.join();
      let link =
        window.globalVariables.api +
        "/jdbg/gwgl_gw/index?api=xls&page=1&limit=10000&site=jnmf&token=" +
        Token +
        "&ids=" +
        transString;
      window.open(link, "_blank");
    },
    //导出单个
    exportsingle(item) {
      
      let onlineUrl = item.gw_ylfj_pdf;
      let fullpath = window.globalVariables.api + '/' + item.gw_ylfj_pdf;
      window.open(fullpath, "_blank");
      return

      let link = window.globalVariables.api + "/jdbg/gwgl_gw/export_word";
      let data = {
        site: "jnmf",
        gw_id: item.gw_id,
        type:1,//带公章
      };
      exportWord_api(data).then((res) => {
        if (res.code == "1") {
          let zipLink = res.data.file_url;
          window.open(zipLink, "_blank");
        }
      });

      // let Token = JSON.parse(window.localStorage.getItem("userInfo")).token;
      //  let link =
      //   window.globalVariables.api +"/jdbg/gwgl_gw/export_word?api=xls&page=1&limit=10000&site=jnmf&token=" +Token +
      //   "&type=1"+
      //   "&gw_id=" +
      //   item.gw_id;
      // this.downLoadPDF(link)
    },
    //下载PDF
    downLoadPDF(link) {
      getDownloadAPI(link).then(res => {
        console.log(res,"00000")
        return
          if(res.size > 0){
            const content = res
            const blob = new Blob([content])
            const fileName = '发票.pdf'
            if ('download' in document.createElement('a')) { // 非IE下载
              const elink = document.createElement('a')
              elink.download = fileName
              elink.style.display = 'none'
              elink.href = URL.createObjectURL(blob)
              document.body.appendChild(elink)
              elink.click()
              URL.revokeObjectURL(elink.href) // 释放URL 对象
              document.body.removeChild(elink)
            } else { // IE10+下载
              navigator.msSaveBlob(blob, fileName)
            }
            /* this.$message.success("导出成功")*/
          }
        })
    },
    //详情
    handleDetail(item) {
      // 预览显示
      let chooseID = item.gw_id;
      this.$router.push({ name: "gwglxt_dbfw_gwxq", params: { id: chooseID } });
    },

    //翻页
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
  },
};
</script>

<style lang="scss" scoped>
@import url("../../../styles/documentOnlineRev.scss");
.time-type-list {
  width: 100%;
  border-bottom: 1px solid #f3f3f3;
  margin-bottom: 20px;
  display: flex;

  li {
    position: relative;
    top: 2px;
    cursor: pointer;
    width: 50px;
    font-size: 14px;
    line-height: 30px;
    text-align: center;

    & + li {
      margin-left: 20px;
    }

    &.selected {
      color: #265cd4;
      border-bottom: 2px solid #265cd4;
    }
  }
}
.posiR {
  position: relative;
}
.zhang {
  position: absolute;
  right: 10%;
  bottom: 10%;
  z-index: 13;
}
</style>
