 <template>
  <div>
    <div class="d-flex flex-between pt7">
      <div>
        <el-button type="primary" @click="exportAll">导出</el-button>
        <!-- <el-button type="primary" @click="addData">添加</el-button>
      <el-button
        type="danger"
        @click="delData"
        :disabled="multipleSelection.length == 0"
        >删除</el-button
      > -->
      </div>
      <el-form :inline="true">
        <el-form-item class="mr10" prop="keyword" label="">
          <el-input
            placeholder="请输入学生姓名"
            v-model="keyword"
            clearable
            @clear="getListData"
          ></el-input>
        </el-form-item>
        <el-form-item class="mr10" prop="xdx_xsxh" label="">
          <el-input
            v-model="xdx_xsxh"
            placeholder="请输入学籍号"
            clearable
            @clear="getListData"
          ></el-input>
        </el-form-item>
        <el-form-item class="mr10" prop="xdx_lxfs" label="">
          <el-input
            v-model="xdx_lxfs"
            clearable
            @clear="getListData"
            placeholder="请输入手机号码"
          ></el-input>
        </el-form-item>
        <el-form-item class="mr10" prop="class_name" label="">
          <el-input
            v-model="class_name"
            clearable
            @clear="getListData"
            placeholder="请输入班级"
          ></el-input>
        </el-form-item>

        <el-button type="primary" class="ml5" @click="getListData"
          >搜索</el-button
        >
        <!-- <el-button type="primary" class="ml5" @click="clearData"
          >清空</el-button
        > -->
      </el-form>
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      v-loading="loading"
      ref="multipleTable"
      @selection-change="handleSelectionChange"
      style="width: 100%"
    >
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>
      <el-table-column label="学生姓名" prop="xdx_xsxm" width="100">
      </el-table-column>
      <el-table-column
        label="学籍号"
        prop="xdx_xsxh"
        align="center"
        width="250"
      >
      </el-table-column>
      <el-table-column label="性别" prop="xdx_xb" width="80"> </el-table-column>
      <el-table-column label="年龄" prop="xdx_nl" align="center" width="80">
      </el-table-column>
      <el-table-column
        label="联系方式"
        prop="xdx_lxfs"
        align="center"
        width="180"
      >
      </el-table-column>
      <el-table-column
        label="备注"
        prop="xdx_bz"
        width="auto"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column label="班级" prop="class_name" width="150">
      </el-table-column>
      <el-table-column label="学籍卡" width="150">
        <template slot-scope="scope">
          <el-button type="text" @click="detailData(scope.row)"
            >查看
          </el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="editData(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>

    <el-dialog :visible.sync="detailDialogFormVisible" width="700px">
      <div id="printBox">
        <h3 class="text-center mb45">XXX学校高等教育学生学籍卡</h3>
        <el-form ref="form" :model="dialogForm" label-width="0px">
          <table class="form-table" cellpadding="0" cellspacing="0">
            <tr>
              <td>
                <h3 class="font-size-14">学生姓名</h3>
              </td>
              <td>
                <div class="font-size-14">
                  {{ detailInfo.xdx_xsxm }}
                </div>
              </td>
              <td>
                <h3 class="font-size-14">性别</h3>
              </td>
              <td>
                <div class="font-size-14">{{ detailInfo.xdx_xb_option_n }}</div>
              </td>

              <td rowspan="5" class="text-center">
                <img
                  v-if="detailInfo.xdx_sczp"
                  style="width: 120px; height: 160px"
                  :src="detailInfo.xdx_sczp"
                  alt=""
                />
              </td>
            </tr>
            <tr>
              <td>
                <h3 class="font-size-14">民族</h3>
              </td>
              <td>
                <div class="font-size-14">{{ detailInfo.xdx_mz }}</div>
              </td>
              <td>
                <h3 class="font-size-14">出生年月</h3>
              </td>
              <td>
                <div class="font-size-14">{{ detailInfo.xdx_csrq }}</div>
              </td>
            </tr>
            <tr>
              <td>
                <h3 class="font-size-14">身份证号</h3>
              </td>
              <td>
                <div class="font-size-14">{{ detailInfo.xdx_zjhm }}</div>
              </td>
              <td>
                <h3 class="font-size-14">政治面貌</h3>
              </td>
              <td>
                <div class="font-size-14">{{ detailInfo.xdx_zzmm }}</div>
              </td>
            </tr>
            <tr>
              <td>
                <h3 class="font-size-14">籍贯</h3>
              </td>
              <td>
                <div class="font-size-14">{{ detailInfo.xdx_jg }}</div>
              </td>
              <td>
                <h3 class="font-size-14">家庭住址</h3>
              </td>
              <td>
                <div class="font-size-14">{{ detailInfo.xdx_jtzz }}</div>
              </td>
            </tr>
            <tr>
              <td>
                <h3 class="font-size-14" style="height: 53px">爱好</h3>
              </td>
              <td colspan="3">
                <div class="font-size-14" style="height: 53px">
                  {{ detailInfo.xdx_ahtc }}
                </div>
              </td>
            </tr>
          </table>
          <table class="form-table-two" cellpadding="0" cellspacing="0">
            <tr v-if="jtcyDetailInfo.length > 0">
              <td rowspan="3" class="w20">
                <h3 class="font-size-14">家庭主要</h3>
              </td>
              <td class="w10">
                <h3 class="font-size-14">称谓</h3>
              </td>
              <td class="w10">
                <h3 class="font-size-14">姓名</h3>
              </td>
              <td class="w15">
                <h3 class="font-size-14">政治面貌</h3>
              </td>
              <td class="w20">
                <h3 class="font-size-14">工作单位</h3>
              </td>
              <td class="w10">
                <h3 class="font-size-14">职务</h3>
              </td>
              <td class="w20">
                <h3 class="font-size-14">手机号码</h3>
              </td>
            </tr>

            <tr v-for="(item, index) in jtcyDetailInfo" :key="index">
              <td>
                <div class="font-size-14">{{ item.xdxj_cw }}</div>
              </td>
              <td>
                <div class="font-size-14">{{ item.xdxj_xm }}</div>
              </td>
              <td>
                <div class="font-size-14">{{ item.xdxj_zzmm }}</div>
              </td>
              <td>
                <div class="font-size-14">{{ item.xdxj_gzdw }}</div>
              </td>
              <td>
                <div class="font-size-14">{{ item.xdxj_zw }}</div>
              </td>
              <td>
                <div class="font-size-14">{{ item.xdxj_sjhm }}</div>
              </td>
            </tr>
          </table>
        </el-form>
      </div>
      <div slot="footer" class="text-center">
        <el-button @click="formCancel">取 消</el-button>
        <el-button type="primary" @click="printHTML">打印</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { xjk_list, xjk_detail, family_list, xqgl_list } from "./api";
import { request } from "@/utils/request";
import { useUserStore } from "@/stores/user";
const { token } = useUserStore();
export default {
  name: "index",
  data() {
    return {
      limit: 10,
      total: 12,
      cur_page: 1,
      keyword: "",
      xdx_xsxh: "",
      xdx_lxfs: "",
      class_name: "",
      dialogForm: {
        xsxm: "",
        xsxh: "",
        xb: "",
        nl: "",
        lxfs: "",
        bz: "",
        bj: "",
        yybz: "",
        yddqzt: "",
        jg: "",
        zzmm: "",
        jtzz: "",
        zjhm: "",
        mz: "",
        jcw: "",
        jxm: "",
        jzzmm: "",
        jzw: "",
        jgzdw: "",
        jsjhm: "",
      },

      tableData: [],
      teamList: [],
      gradeList: [],
      detailInfo: {},
      detailInfo1: {},
      dynamicTags: ["全国先进工作者", "优秀党务工作者"],
      inputVisible: false,
      inputValue: "",
      title: "",
      multipleSelection: [],
      id: "",
      loading: false,
      isEdit: false,
      dialogImageUrl: "",
      dialogVisible: false,
      dialogFormVisible: false,
      detailDialogFormVisible: false,
      jtcyDetailInfo: [],
      team_id: "",
    };
  },
  methods: {
    printHTML() {
      this.$print({
        printable: "printBox",
        type: "html",
        header: "",
        targetStyles: ["*"], // 打印内容使用所有HTML样式，没有设置这个属性/值，设置分页打印没有效果
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    async getListData() {
      this.loading = true;
      xqgl_list({ limit: 999 }).then((res) => {
        if (res.code == 1) {
          this.teamList = res.data.page_data;
          this.teamList.map((item) => {
            if (item.team_current_option_k == "1") {
              this.team_id = item.team_id;
              let data = {
                page: this.cur_page,
                limit: this.limit,
                keyword: this.keyword,
                xdx_xsxh: this.xdx_xsxh,
                xdx_lxfs: this.xdx_lxfs,
                class_name: this.class_name,
                team_id: this.team_id,
              };
              xjk_list(data).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 = [];
      for (let i in val) {
        this.multipleSelection.push(val[i].xdx_id);
      }
    },

    detailData(item) {
      this.title = "信息详情";
      this.detailDialogFormVisible = true;
      let data = {
        xdx_id: item.xdx_id,
        xdx_xsxh: item.xdx_xsxh,
      };
      xjk_detail(data).then((res) => {
        if (res.code == 1) {
          this.detailInfo = res.data.one_info;
          let a = this.detailInfo.xdx_sczp.indexOf("|");
          this.detailInfo.xdx_sczp = this.detailInfo.xdx_sczp.substring(0, a);
          console.log(this.detailInfo.xdx_sczp, 123);
        }
      });
      let data1 = {
        xdx_id: item.xdx_id,
      };
      family_list(data1).then((res) => {
        if (res.code == 1) {
          this.jtcyDetailInfo = res.data.page_data;
        }
      });
    },

    formCancel() {
      this.detailDialogFormVisible = false;
    },

    clearData() {
      this.keyword = "";
      this.xdx_xsxh = "";
      this.xdx_lxfs = "";
      this.class_name = "";
    },
    exportAll() {
      let ids = this.multipleSelection.join(",");
      let link =
        window.globalVariables.api +
        "/xddy/dygl_xsxjk/index?api=xls&page=1&limit=10000&token=" +
        token +
        "&xdx_id=" +
        ids;
      console.log(link);
      window.open(link, "_blank");
    },
  },
  mounted() {
    this.getListData();
  },
};
</script>



<style lang="scss" scoped>
::v-deep .el-input {
  width: 160px;
}
.form-table {
  width: 100%;
  border-collapse: collapse;
  padding: auto;
  td {
    width: 20%;
    height: 30px;
    line-height: 30px;
    padding: 4px 4px 5px 5px;
    border: 1px solid #dbdbdb;
  }
  td:nth-child(odd) {
    background-color: #f0f3f8;
  }
  td:nth-child(5) {
    background-color: #fff;
  }
}
.form-table-two {
  width: 100%;
  border-collapse: collapse;
  padding: auto;
  td {
    height: 30px;
    line-height: 30px;
    padding: 4px 4px 5px 5px;
    border: 1px solid #dbdbdb;
    border-top: none;
  }
  tr:first-child {
    background-color: #f0f3f8;
  }
}
</style>