 <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="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
      class="print_table"
      width="100%"
      cellpadding="0"
      cellspacing="0"
      :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="820px">
      <div class="w-210mm mx-auto">
        <div
          class="py-4 px-18 w-210mm relative min-h-40 text-black"
          id="printBox"
        >
          <el-form ref="form" :model="dialogForm">
            <table
              class="print_table"
              width="100%"
              cellpadding="0"
              cellspacing="0"
            >
              <thead>
                <tr>
                  <td colspan="14">{{ school_name }}学生学籍卡</td>
                </tr>
              </thead>
              <!-- <tr>
                <td colspan="14">景宁畲族自治县教育局</td>
              </tr> -->
              <tbody>
                <tr>
                  <td colspan="2">学生姓名</td>
                  <td colspan="4">{{ detailInfo.xdx_xsxm }}</td>
                  <td colspan="2">性别</td>
                  <td colspan="4">
                    {{ detailInfo.xdx_xb_option_n }}
                  </td>
                  <td
                    rowspan="4"
                    style="width: 114px; height: 156px; padding: 0 0 0 1px"
                  >
                    <img
                      v-if="detailInfo.xdx_sczp"
                      style="width: 114px; height: 156px"
                      :src="detailInfo.xdx_sczp"
                      alt=""
                    />
                  </td>
                </tr>
                <tr>
                  <td colspan="2">民族</td>
                  <td colspan="4">{{ detailInfo.xdx_mz }}</td>
                  <td colspan="2">出生年月</td>
                  <td colspan="4" class="ignore">{{ detailInfo.xdx_csrq }}</td>
                </tr>
                <tr>
                  <td colspan="2">身份证号</td>
                  <td colspan="4">{{ detailInfo.xdx_zjhm }}</td>
                  <td colspan="2">政治面貌</td>
                  <td colspan="4" class="ignore">{{ detailInfo.xdx_zzmm }}</td>
                </tr>
                <tr>
                  <td colspan="2">籍贯</td>
                  <td colspan="4">{{ detailInfo.xdx_jg }}</td>
                  <td colspan="2"></td>
                  <td colspan="4" class="ignore"></td>
                </tr>
                <tr>
                  <td colspan="2">家庭住址</td>
                  <td colspan="12">{{ detailInfo.xdx_jtzz }}</td>
                </tr>
                <tr>
                  <td colspan="2">爱好</td>
                  <td colspan="12">{{ detailInfo.xdx_ahtc }}</td>
                </tr>
                <tr v-if="jtcyDetailInfo.length > 0">
                  <td
                    class="last"
                    colspan="2"
                    :rowspan="jtcyDetailInfo.length + 1"
                  >
                    家庭主要
                  </td>
                  <td colspan="2">称谓</td>
                  <td colspan="2">姓名</td>
                  <td colspan="2">政治面貌</td>
                  <td colspan="2">工作单位</td>
                  <td colspan="2">职务</td>
                  <td colspan="2">手机号码</td>
                </tr>

                <tr v-for="(item, index) in jtcyDetailInfo" :key="index">
                  <td colspan="2" class="ignore">{{ item.xdxj_cw }}</td>
                  <td colspan="2">{{ item.xdxj_xm }}</td>
                  <td colspan="2">{{ item.xdxj_zzmm }}</td>
                  <td colspan="2">{{ item.xdxj_gzdw }}</td>
                  <td colspan="2">{{ item.xdxj_zw }}</td>
                  <td colspan="2">{{ item.xdxj_sjhm }}</td>
                </tr>
              </tbody>
            </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>
      </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, user_org } = 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: "",
      school_name: "",
      dept_id: "",
    };
  },
  methods: {
    addData() {
      this.loading = true;
      request({
        url: "xddy/dygl_xsrstjlb/recreate_data",
        data: {
          token: token,
          site: "jnmf",
          client: "web",
          api: "json",
          page: "1",
          limit: "10000",
          issubmit: 1,
          dept_id: this.dept_id,
        },
      }).then((res) => {
        if (res.code == "1") {
          this.loading = false;
          this.getListData();
        }
      });
    },
    printHTML() {
      this.$print({
        printable: "printBox",
        type: "html",
        header: "",
        targetStyles: ["*"], // 打印内容使用所有HTML样式，没有设置这个属性/值，设置分页打印没有效果
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    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 =
            window.globalVariables.api +
            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.detailInfo = {};
      this.jtcyDetailInfo = {};
      this.dialogFormVisible = false;
      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();
    if (user_org) {
      user_org.map((item) => {
        if (item.uo_type === "2") {
          this.school_name = item.uo_name;
          this.dept_id = item.uo_id;
        }
      });
    }
  },
};
</script>


<style lang="scss" scoped>
@import "/public/print.css";
::v-deep .el-input {
  width: 160px;
}
</style>
