join-mobile.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import Service from "./common/service.js";
  2. import language from "./common/language.js";
  3. new Vue({
  4. el: "#app",
  5. data: {
  6. total: 0,
  7. params: {
  8. page: 1,
  9. page_num: 5,
  10. search: "",
  11. },
  12. list: [],
  13. current_info: null,
  14. create_params: null,
  15. file_name: "",
  16. pagination_list: [],
  17. },
  18. mounted() {
  19. this.getList();
  20. },
  21. methods: {
  22. text(val) {
  23. return language[val][localStorage.getItem("language")];
  24. },
  25. lan_key(val) {
  26. return `${val}${localStorage.getItem("language") == "en" ? "_en" : ""}`;
  27. },
  28. // 切换分页
  29. changeCurrent(val) {
  30. if (val == this.params.page || val == "...") return;
  31. if (val < 1 || val > Math.ceil(this.total / this.params.page_num)) return;
  32. this.params.page = val;
  33. this.getList();
  34. },
  35. setPaginationList() {
  36. const allNum = Math.ceil(this.total / this.params.page_num);
  37. this.pagination_list = new Array(allNum)
  38. .fill(null)
  39. .map((_, index) => {
  40. if (index == 0 || index == allNum - 1) return index + 1;
  41. return Math.abs(index + 1 - this.params.page) >= 2
  42. ? Math.abs(index + 1 - this.params.page) == 2
  43. ? "..."
  44. : ""
  45. : index + 1;
  46. })
  47. .filter((i) => i);
  48. },
  49. // 搜素
  50. search() {
  51. this.params.page = 1;
  52. this.getList();
  53. },
  54. // 获取数据
  55. getList() {
  56. Service.get_position(this.params)
  57. .then((res) => {
  58. this.list = res.data;
  59. // this.current_item = res.data[0] ? this.list[0].id : "";
  60. this.total = res.total;
  61. this.setPaginationList();
  62. })
  63. .catch((err) => {
  64. console.log(err);
  65. });
  66. },
  67. // 返回
  68. back() {
  69. if (this.create_params) return (this.create_params = null);
  70. if (this.current_info) return (this.current_info = null);
  71. },
  72. // 申请
  73. confirm() {
  74. this.create_params = {
  75. position: null, // 职位id
  76. realname: "", // 姓名
  77. tel: "", // 电话
  78. email: "", // 邮箱
  79. url: "", // 简历
  80. };
  81. this.file_name = "";
  82. this.create_params.position = this.current_info[this.lan_key("name")];
  83. },
  84. // 上传简历
  85. uploadFile({ target }) {
  86. const file = target.files[0];
  87. const formData = new FormData();
  88. formData.append("file", file);
  89. Service.upload(formData)
  90. .then((res) => {
  91. this.file_name = file.name;
  92. this.create_params.url = res.url;
  93. })
  94. .catch((err) => {
  95. console.log(err);
  96. });
  97. },
  98. // 提交
  99. submit() {
  100. if (!this.create_params.realname)
  101. return alert(this.text("请输入您的姓名"));
  102. if (!this.create_params.tel)
  103. return alert(this.text("请输入您的联系方式"));
  104. if (!this.create_params.email) return alert(this.text("请输入您的邮箱"));
  105. if (!this.create_params.url) return alert(this.text("请上传您的简历"));
  106. Service.create_position(this.create_params)
  107. .then((res) => {
  108. alert(this.text("提交成功"));
  109. this.create_params = null;
  110. this.current_info = null;
  111. })
  112. .catch((err) => {
  113. console.log(err);
  114. });
  115. },
  116. },
  117. });