join.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. current_item: 0,
  13. list: [],
  14. current_info: {
  15. name: "",
  16. time: "",
  17. },
  18. create_params: {
  19. position: null, // 职位id
  20. realname: "", // 姓名
  21. tel: "", // 电话
  22. email: "", // 邮箱
  23. url: "", // 简历
  24. },
  25. file_name: "",
  26. pagination_list: [],
  27. },
  28. computed: {
  29. use_submit() {
  30. return Object.keys(this.create_params).every(
  31. (item) => this.create_params[item]
  32. );
  33. },
  34. },
  35. mounted() {
  36. this.getList();
  37. },
  38. methods: {
  39. text(val) {
  40. return language[val][localStorage.getItem("language")];
  41. },
  42. lan_key(val) {
  43. return `${val}${localStorage.getItem("language") == "en" ? "_en" : ""}`;
  44. },
  45. // 切换分页
  46. changeCurrent(val) {
  47. if (val == this.params.page || val == "...") return;
  48. if (val < 1 || val > Math.ceil(this.total / this.params.page_num)) return;
  49. this.params.page = val;
  50. this.getList();
  51. },
  52. setPaginationList() {
  53. const allNum = Math.ceil(this.total / this.params.page_num);
  54. this.pagination_list = new Array(allNum)
  55. .fill(null)
  56. .map((_, index) => {
  57. if (index == 0 || index == allNum - 1) return index + 1;
  58. return Math.abs(index + 1 - this.params.page) >= 2
  59. ? Math.abs(index + 1 - this.params.page) == 2
  60. ? "..."
  61. : ""
  62. : index + 1;
  63. })
  64. .filter((i) => i);
  65. },
  66. // 搜素
  67. search() {
  68. this.params.page = 1;
  69. this.getList();
  70. },
  71. // 获取数据
  72. getList() {
  73. Service.get_position(this.params)
  74. .then((res) => {
  75. this.list = res.data;
  76. // this.current_item = res.data[0] ? this.list[0].id : "";
  77. this.total = res.total;
  78. this.setPaginationList();
  79. })
  80. .catch((err) => {
  81. console.log(err);
  82. });
  83. },
  84. // 申请
  85. setSubmitInfo(item) {
  86. if (!item) {
  87. this.current_info = {
  88. name: "",
  89. time: "",
  90. };
  91. this.create_params = {
  92. position: null, // 职位id
  93. realname: "", // 姓名
  94. tel: "", // 电话
  95. email: "", // 邮箱
  96. url: "", // 简历
  97. };
  98. this.file_name = "";
  99. return;
  100. }
  101. this.create_params.position = this.current_info.name =
  102. item[this.lan_key("name")];
  103. this.current_info.name = item[this.lan_key("name")];
  104. this.current_info.time = item.time;
  105. },
  106. // 上传简历
  107. uploadFile({ target }) {
  108. const file = target.files[0];
  109. const formData = new FormData();
  110. formData.append("file", file);
  111. Service.upload(formData)
  112. .then((res) => {
  113. this.file_name = file.name;
  114. this.create_params.url = res.url;
  115. })
  116. .catch((err) => {
  117. console.log(err);
  118. });
  119. },
  120. // 提交
  121. submit() {
  122. if (!this.use_submit) return;
  123. Service.create_position(this.create_params)
  124. .then((res) => {
  125. Object.keys(this.create_params).forEach(
  126. (key) => (this.create_params[key] = "")
  127. );
  128. alert(this.text("提交成功"));
  129. })
  130. .catch((err) => {
  131. console.log(err);
  132. });
  133. },
  134. },
  135. });