intention.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_dict = require("../../api/dict.js");
  4. const api_student = require("../../api/student.js");
  5. const common_assets = require("../../common/assets.js");
  6. const StepLayout = () => "../../components/step-layout/step-layout.js";
  7. const _sfc_main = {
  8. components: {
  9. StepLayout
  10. },
  11. setup() {
  12. const intentions = common_vendor.ref([]);
  13. const arrivalTime = common_vendor.ref("");
  14. const internDuration = common_vendor.ref("");
  15. const arrivalTimeList = common_vendor.ref([]);
  16. const durationList = common_vendor.ref([]);
  17. const isIntern = common_vendor.computed(() => {
  18. var _a;
  19. return ((_a = intentions.value.find((item) => item.name === "实习")) == null ? void 0 : _a.selected) || false;
  20. });
  21. const arrivalTimeLabel = common_vendor.computed(() => {
  22. if (!arrivalTime.value)
  23. return "";
  24. const found = arrivalTimeList.value.find((d) => d.dictValue === arrivalTime.value);
  25. return found ? found.dictLabel : arrivalTime.value;
  26. });
  27. const internDurationLabel = common_vendor.computed(() => {
  28. if (!internDuration.value)
  29. return "";
  30. const found = durationList.value.find((d) => d.dictValue === internDuration.value);
  31. return found ? found.dictLabel : internDuration.value;
  32. });
  33. const jobTypes = common_vendor.ref([]);
  34. const targetCompanies = common_vendor.ref([]);
  35. const showModal = common_vendor.ref(false);
  36. const modalContent = common_vendor.ref("");
  37. let currentDeleteIndex = -1;
  38. const isEditMode = common_vendor.ref(false);
  39. const loadDicts = async () => {
  40. var _a, _b, _c;
  41. common_vendor.index.showLoading({ title: "加载中..." });
  42. try {
  43. const [arrRes, posTypeRes, posIntentionRes, durRes] = await Promise.all([
  44. api_dict.getDicts("main_arrival_time"),
  45. api_dict.getDicts("main_position_type"),
  46. api_dict.getDicts("main_position_intention"),
  47. api_dict.getDicts("main_internship_duration")
  48. ]);
  49. if (arrRes.code === 200) {
  50. arrivalTimeList.value = arrRes.data || arrRes.rows || [];
  51. if (arrivalTimeList.value.length > 0) {
  52. arrivalTime.value = ((_a = arrivalTimeList.value[1]) == null ? void 0 : _a.dictValue) || ((_b = arrivalTimeList.value[0]) == null ? void 0 : _b.dictValue) || "";
  53. }
  54. }
  55. if (durRes && durRes.code === 200) {
  56. durationList.value = durRes.data || durRes.rows || [];
  57. if (durationList.value.length > 0) {
  58. internDuration.value = ((_c = durationList.value[0]) == null ? void 0 : _c.dictValue) || "";
  59. }
  60. }
  61. if (posTypeRes.code === 200) {
  62. intentions.value = (posTypeRes.data || posTypeRes.rows || []).map((dict, idx) => ({
  63. name: dict.dictLabel,
  64. value: dict.dictValue,
  65. selected: idx === 0
  66. }));
  67. }
  68. if (posIntentionRes.code === 200) {
  69. jobTypes.value = (posIntentionRes.data || posIntentionRes.rows || []).map((dict, idx) => ({
  70. name: dict.dictLabel,
  71. value: dict.dictValue,
  72. selected: idx < 2
  73. // 默认随便选一两个
  74. }));
  75. }
  76. } catch (e) {
  77. common_vendor.index.__f__("error", "at pages/intention/intention.js:82", e);
  78. } finally {
  79. common_vendor.index.hideLoading();
  80. }
  81. };
  82. const loadStudentData = async () => {
  83. const userInfo = common_vendor.index.getStorageSync("userInfo");
  84. if (!userInfo || !userInfo.studentId)
  85. return;
  86. try {
  87. const res = await api_student.getStudent(userInfo.studentId);
  88. if (res.code === 200 && res.data) {
  89. const data = res.data;
  90. if (data.availability) {
  91. const found = arrivalTimeList.value.find((d) => d.dictValue === data.availability || d.dictLabel === data.availability);
  92. if (found)
  93. arrivalTime.value = found.dictValue;
  94. }
  95. if (data.internshipDuration) {
  96. const found = durationList.value.find((d) => d.dictValue === data.internshipDuration || d.dictLabel === data.internshipDuration);
  97. if (found)
  98. internDuration.value = found.dictValue;
  99. }
  100. if (data.jobType) {
  101. intentions.value.forEach((item) => {
  102. item.selected = item.value === data.jobType || item.name === data.jobType;
  103. });
  104. }
  105. if (data.jobIntention) {
  106. const selectedIntentions = data.jobIntention.split(",").map((s) => s.trim()).filter((s) => s);
  107. jobTypes.value.forEach((item) => {
  108. item.selected = selectedIntentions.includes(item.value) || selectedIntentions.includes(item.name);
  109. });
  110. }
  111. if (data.intentionCompanies) {
  112. const companyNames = data.intentionCompanies.split(",").map((s) => s.trim()).filter((s) => s);
  113. targetCompanies.value = companyNames.map((name) => ({ name }));
  114. }
  115. }
  116. } catch (err) {
  117. common_vendor.index.__f__("error", "at pages/intention/intention.js:132", "加载学员数据失败", err);
  118. }
  119. };
  120. common_vendor.onMounted(async () => {
  121. const options = getCurrentPages()[getCurrentPages().length - 1].options;
  122. if (options && options.editMode === "1") {
  123. isEditMode.value = true;
  124. }
  125. common_vendor.index.$on("submit_companies", (selectedCompanies) => {
  126. targetCompanies.value = [...selectedCompanies];
  127. });
  128. await loadDicts();
  129. if (isEditMode.value) {
  130. await loadStudentData();
  131. }
  132. });
  133. common_vendor.onUnmounted(() => {
  134. common_vendor.index.$off("submit_companies");
  135. });
  136. const openModal = (content, index) => {
  137. modalContent.value = content;
  138. currentDeleteIndex = index;
  139. showModal.value = true;
  140. };
  141. const closeModal = () => {
  142. showModal.value = false;
  143. };
  144. const confirmDelete = () => {
  145. if (currentDeleteIndex !== -1) {
  146. targetCompanies.value.splice(currentDeleteIndex, 1);
  147. }
  148. closeModal();
  149. };
  150. const toggleIntention = (index) => {
  151. intentions.value.forEach((item, i) => {
  152. item.selected = i === index;
  153. });
  154. };
  155. const selectInternDuration = () => {
  156. if (durationList.value.length === 0)
  157. return;
  158. common_vendor.index.showActionSheet({
  159. itemList: durationList.value.map((d) => d.dictLabel),
  160. success: (res) => {
  161. internDuration.value = durationList.value[res.tapIndex].dictValue;
  162. }
  163. });
  164. };
  165. const selectTime = () => {
  166. if (arrivalTimeList.value.length === 0)
  167. return;
  168. common_vendor.index.showActionSheet({
  169. itemList: arrivalTimeList.value.map((d) => d.dictLabel),
  170. success: (res) => {
  171. arrivalTime.value = arrivalTimeList.value[res.tapIndex].dictValue;
  172. }
  173. });
  174. };
  175. const toggleType = (index) => {
  176. jobTypes.value[index].selected = !jobTypes.value[index].selected;
  177. };
  178. const addCompany = () => {
  179. const selectedNames = targetCompanies.value.map((c) => c.name);
  180. common_vendor.index.setStorageSync("selected_companies", JSON.stringify(selectedNames));
  181. common_vendor.index.navigateTo({ url: "/pages/intention/company-select" });
  182. };
  183. const deleteCompany = (index) => {
  184. openModal("确定要删除这家意向公司吗?", index);
  185. };
  186. const onSubmit = async () => {
  187. var _a;
  188. common_vendor.index.__f__("log", "at pages/intention/intention.js:215", "intention.js: onSubmit called");
  189. common_vendor.index.showLoading({ title: "提交中..." });
  190. try {
  191. const userInfo = common_vendor.index.getStorageSync("userInfo");
  192. common_vendor.index.__f__("log", "at pages/intention/intention.js:219", "intention.js: userInfo from storage:", userInfo);
  193. const studentId = userInfo ? userInfo.studentId || userInfo.id : null;
  194. common_vendor.index.__f__("log", "at pages/intention/intention.js:221", "intention.js: studentId identified:", studentId);
  195. if (!studentId) {
  196. common_vendor.index.hideLoading();
  197. common_vendor.index.showToast({ title: "登录状态失效", icon: "none" });
  198. return;
  199. }
  200. const selectedJobIntention = ((_a = intentions.value.find((i) => i.selected)) == null ? void 0 : _a.value) || "";
  201. const selectedJobType = jobTypes.value.filter((i) => i.selected).map((i) => i.value).join(",");
  202. const companies = targetCompanies.value.map((c) => c.name).join(",");
  203. const reqData = {
  204. id: studentId,
  205. jobIntention: selectedJobType,
  206. // 求职意向类型(审计、咨询、税务等),传 dictValue
  207. intentionCompanies: companies,
  208. // 意向公司列表
  209. jobType: selectedJobIntention,
  210. // 求职类型(全职、实习、兼职),传 dictValue
  211. availability: arrivalTime.value,
  212. internshipDuration: isIntern.value ? internDuration.value : ""
  213. };
  214. common_vendor.index.__f__("log", "at pages/intention/intention.js:242", "intention.js: sending updateStudent request with data:", reqData);
  215. const res = await api_student.updateStudent(reqData);
  216. common_vendor.index.__f__("log", "at pages/intention/intention.js:245", "intention.js: updateStudent response:", res);
  217. common_vendor.index.hideLoading();
  218. if (res.code === 200) {
  219. common_vendor.index.showToast({
  220. title: isEditMode.value ? "保存成功" : "提交成功",
  221. icon: "success"
  222. });
  223. setTimeout(() => {
  224. common_vendor.index.reLaunch({
  225. url: "/pages/my/my",
  226. success: () => {
  227. setTimeout(() => {
  228. common_vendor.index.navigateTo({ url: "/pages/my/resume_view" });
  229. }, 100);
  230. }
  231. });
  232. }, 1e3);
  233. } else {
  234. common_vendor.index.showToast({ title: res.msg || "保存失败", icon: "none" });
  235. }
  236. } catch (e) {
  237. common_vendor.index.__f__("error", "at pages/intention/intention.js:268", e);
  238. common_vendor.index.hideLoading();
  239. common_vendor.index.showToast({ title: "网络异常", icon: "none" });
  240. }
  241. };
  242. const onSkip = () => {
  243. common_vendor.index.reLaunch({
  244. url: "/pages/my/my",
  245. success: () => {
  246. setTimeout(() => {
  247. common_vendor.index.navigateTo({ url: "/pages/my/resume_view" });
  248. }, 100);
  249. }
  250. });
  251. };
  252. return {
  253. intentions,
  254. arrivalTime,
  255. arrivalTimeLabel,
  256. internDuration,
  257. internDurationLabel,
  258. isIntern,
  259. jobTypes,
  260. targetCompanies,
  261. showModal,
  262. modalContent,
  263. closeModal,
  264. confirmDelete,
  265. toggleIntention,
  266. selectTime,
  267. selectInternDuration,
  268. toggleType,
  269. addCompany,
  270. deleteCompany,
  271. onSubmit,
  272. onSkip,
  273. isEditMode
  274. };
  275. }
  276. };
  277. if (!Array) {
  278. const _easycom_step_layout2 = common_vendor.resolveComponent("step-layout");
  279. _easycom_step_layout2();
  280. }
  281. const _easycom_step_layout = () => "../../components/step-layout/step-layout.js";
  282. if (!Math) {
  283. _easycom_step_layout();
  284. }
  285. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  286. return common_vendor.e({
  287. a: common_vendor.f(_ctx.intentions, (item, index, i0) => {
  288. return {
  289. a: common_vendor.t(item.name),
  290. b: index,
  291. c: common_vendor.n(item.selected ? "active" : ""),
  292. d: common_vendor.o(($event) => _ctx.toggleIntention(index), index)
  293. };
  294. }),
  295. b: _ctx.isIntern
  296. }, _ctx.isIntern ? {
  297. c: common_vendor.t(_ctx.internDurationLabel || "请选择"),
  298. d: common_vendor.n(!_ctx.internDuration ? "is-empty" : ""),
  299. e: common_vendor.o((...args) => _ctx.selectInternDuration && _ctx.selectInternDuration(...args))
  300. } : {}, {
  301. f: common_vendor.t(_ctx.arrivalTimeLabel || "1周内"),
  302. g: common_vendor.n(!_ctx.arrivalTime ? "is-empty" : ""),
  303. h: common_vendor.o((...args) => _ctx.selectTime && _ctx.selectTime(...args)),
  304. i: common_vendor.f(_ctx.jobTypes, (type, index, i0) => {
  305. return {
  306. a: common_vendor.t(type.name),
  307. b: index,
  308. c: common_vendor.n(type.selected ? "active" : ""),
  309. d: common_vendor.o(($event) => _ctx.toggleType(index), index)
  310. };
  311. }),
  312. j: common_vendor.o((...args) => _ctx.addCompany && _ctx.addCompany(...args)),
  313. k: _ctx.targetCompanies.length === 0
  314. }, _ctx.targetCompanies.length === 0 ? {
  315. l: common_assets._imports_0$1
  316. } : {}, {
  317. m: common_vendor.f(_ctx.targetCompanies, (comp, index, i0) => {
  318. return {
  319. a: common_vendor.o(($event) => _ctx.deleteCompany(index), index),
  320. b: common_vendor.t(comp.name),
  321. c: index
  322. };
  323. }),
  324. n: common_vendor.o((...args) => _ctx.closeModal && _ctx.closeModal(...args)),
  325. o: common_vendor.t(_ctx.modalContent),
  326. p: common_vendor.o((...args) => _ctx.closeModal && _ctx.closeModal(...args)),
  327. q: common_vendor.o((...args) => _ctx.confirmDelete && _ctx.confirmDelete(...args)),
  328. r: _ctx.showModal ? 1 : "",
  329. s: common_vendor.o(_ctx.onSubmit),
  330. t: common_vendor.o(_ctx.onSkip),
  331. v: common_vendor.p({
  332. title: "填写工作意向",
  333. nextText: "提交",
  334. showSkip: !_ctx.isEditMode,
  335. subtitle: "我们会妥善保护你的隐私,后续你也可以在设置中将简历隐藏"
  336. })
  337. });
  338. }
  339. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-6e833e70"]]);
  340. wx.createPage(MiniProgramPage);
  341. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/intention/intention.js.map