123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import Service from "./common/service.js";
- import language from "./common/language.js";
- new Vue({
- el: "#app",
- data: {
- total: 0,
- params: {
- page: 1,
- page_num: 5,
- search: "",
- },
- list: [],
- current_info: null,
- create_params: null,
- file_name: "",
- pagination_list: [],
- },
- mounted() {
- this.getList();
- },
- methods: {
- text(val) {
- return language[val][localStorage.getItem("language")];
- },
- lan_key(val) {
- return `${val}${localStorage.getItem("language") == "en" ? "_en" : ""}`;
- },
- // 切换分页
- changeCurrent(val) {
- if (val == this.params.page || val == "...") return;
- if (val < 1 || val > Math.ceil(this.total / this.params.page_num)) return;
- this.params.page = val;
- this.getList();
- },
- setPaginationList() {
- const allNum = Math.ceil(this.total / this.params.page_num);
- this.pagination_list = new Array(allNum)
- .fill(null)
- .map((_, index) => {
- if (index == 0 || index == allNum - 1) return index + 1;
- return Math.abs(index + 1 - this.params.page) >= 2
- ? Math.abs(index + 1 - this.params.page) == 2
- ? "..."
- : ""
- : index + 1;
- })
- .filter((i) => i);
- },
- // 搜素
- search() {
- this.params.page = 1;
- this.getList();
- },
- // 获取数据
- getList() {
- Service.get_position(this.params)
- .then((res) => {
- this.list = res.data;
- // this.current_item = res.data[0] ? this.list[0].id : "";
- this.total = res.total;
- this.setPaginationList();
- })
- .catch((err) => {
- console.log(err);
- });
- },
- // 返回
- back() {
- if (this.create_params) return (this.create_params = null);
- if (this.current_info) return (this.current_info = null);
- },
- // 申请
- confirm() {
- this.create_params = {
- position: null, // 职位id
- realname: "", // 姓名
- tel: "", // 电话
- email: "", // 邮箱
- url: "", // 简历
- };
- this.file_name = "";
- this.create_params.position = this.current_info[this.lan_key("name")];
- },
- // 上传简历
- uploadFile({ target }) {
- const file = target.files[0];
- const formData = new FormData();
- formData.append("file", file);
- Service.upload(formData)
- .then((res) => {
- this.file_name = file.name;
- this.create_params.url = res.url;
- })
- .catch((err) => {
- console.log(err);
- });
- },
- // 提交
- submit() {
- if (!this.create_params.realname)
- return alert(this.text("请输入您的姓名"));
- if (!this.create_params.tel)
- return alert(this.text("请输入您的联系方式"));
- if (!this.create_params.email) return alert(this.text("请输入您的邮箱"));
- if (!this.create_params.url) return alert(this.text("请上传您的简历"));
- Service.create_position(this.create_params)
- .then((res) => {
- alert(this.text("提交成功"));
- this.create_params = null;
- this.current_info = null;
- })
- .catch((err) => {
- console.log(err);
- });
- },
- },
- });
|