offer.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <view class="container">
  3. <scroll-view class="offer-scroll" scroll-y refresher-enabled @refresherrefresh="fetchOfferList">
  4. <!-- 加载状态 -->
  5. <view v-if="loading" class="loading-state">
  6. <text>加载中...</text>
  7. </view>
  8. <!-- 无数据提示 -->
  9. <view v-else-if="offers.length === 0" class="empty-state">
  10. <image src="/static/icons/empty.png" class="empty-icon" mode="aspectFit"></image>
  11. <text class="empty-text">暂无Offer记录</text>
  12. </view>
  13. <view v-else class="offer-list">
  14. <view v-for="(offer, index) in offers" :key="index" class="offer-card">
  15. <!-- 卡片头部:公司 + 状态标签 -->
  16. <view class="card-top">
  17. <view class="company-info">
  18. <text class="company-name">{{ offer.company }}</text>
  19. <text class="job-name">{{ offer.jobName }}</text>
  20. </view>
  21. <view :class="['status-badge', offer.enterpriseStatus === 'pending' ? 'pending' : (offer.enterpriseStatus === 'adopted' ? 'adopted' : 'rejected')]">
  22. <text>{{ getStatusBadge(offer) }}</text>
  23. </view>
  24. </view>
  25. <!-- 投递时间 -->
  26. <view class="card-meta">
  27. <text class="meta-time">投递时间:{{ offer.createTime }}</text>
  28. </view>
  29. <!-- 企业已处理 - 审核结果区域 -->
  30. <view v-if="offer.enterpriseStatus !== 'pending'" class="result-section">
  31. <view class="result-row">
  32. <view class="result-left">
  33. <image v-if="offer.enterpriseStatus === 'adopted'" src="/static/icons/success.svg" class="result-icon" mode="aspectFit"></image>
  34. <image v-else src="/static/icons/fail.svg" class="result-icon" mode="aspectFit"></image>
  35. <text :class="['result-text', offer.enterpriseStatus]">{{ getResultDesc(offer.enterpriseStatus) }}</text>
  36. </view>
  37. <!-- 操作按钮 -->
  38. <view class="action-btns" v-if="offer.enterpriseStatus === 'adopted' && offer.studentStatus === 'pending'">
  39. <button class="btn btn-outline" @click="handleReject(offer)">拒绝</button>
  40. <button class="btn btn-primary" @click="handleAccept(offer)">接受Offer</button>
  41. </view>
  42. <view :class="['student-status-tag', offer.studentStatus]" v-else-if="offer.studentStatus !== 'pending'">
  43. <text>{{ offer.statusText }}</text>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 签约文件 -->
  48. <view v-if="offer.enterpriseStatus === 'adopted' && offer.fileUrl" class="file-link" @click="openFile(offer.fileUrl)">
  49. <image src="/static/icons/pdf.svg" class="file-icon"></image>
  50. <text class="file-name">{{ offer.fileName }}</text>
  51. <text class="file-arrow">></text>
  52. </view>
  53. </view>
  54. </view>
  55. </scroll-view>
  56. <!-- 接受Offer确认协议弹窗 -->
  57. <view class="modal-mask" v-if="showAcceptModal">
  58. <view class="modal-content protocol-modal">
  59. <view class="modal-header">确认接受Offer?</view>
  60. <scroll-view class="protocol-body" scroll-y>
  61. <view class="rich-text-container">
  62. <rich-text :nodes="protocolHtml"></rich-text>
  63. </view>
  64. </scroll-view>
  65. <view class="modal-footer">
  66. <view class="btns-row">
  67. <button class="btn-cancel" @click="showAcceptModal = false">取消</button>
  68. <button class="btn-confirm" :disabled="countdown > 0" @click="confirmAccept">
  69. {{ countdown > 0 ? (countdown + 's后确认接受') : '已阅读,确认接受' }}
  70. </button>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 拒绝Offer确认弹窗 -->
  76. <view class="modal-mask" v-if="showRejectModal">
  77. <view class="modal-content confirm-modal">
  78. <view class="confirm-title">确认拒绝?</view>
  79. <view class="confirm-desc">拒绝后不可恢复</view>
  80. <view class="confirm-footer">
  81. <button class="btn-cancel" @click="showRejectModal = false">取消</button>
  82. <button class="btn-danger" @click="confirmReject">确认拒绝</button>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script setup>
  89. import { ref, onMounted } from 'vue';
  90. import { getOfferList, acceptOffer, rejectOffer } from '../../api/offer.js';
  91. import request from '../../utils/request.js';
  92. const showAcceptModal = ref(false);
  93. const showRejectModal = ref(false);
  94. const countdown = ref(10);
  95. let timer = null;
  96. const currentOffer = ref(null);
  97. const offers = ref([]);
  98. const loading = ref(false);
  99. // Offer协议内容(从 main_agreement 表 type=offer 读取,与总控页面共用)
  100. const protocolHtml = ref('');
  101. // 加载Offer协议
  102. const loadOfferConfig = async () => {
  103. try {
  104. const res = await request({ url: '/miniapp/auth/agreement?type=offer', method: 'GET' });
  105. if (res.code === 200 && res.data && res.data.content) {
  106. protocolHtml.value = res.data.content;
  107. }
  108. } catch (e) {
  109. console.error('获取Offer协议失败', e);
  110. }
  111. };
  112. // 获取Offer列表
  113. const fetchOfferList = async () => {
  114. loading.value = true;
  115. try {
  116. const res = await getOfferList();
  117. if (res.code === 200) {
  118. offers.value = res.data.map(item => ({
  119. id: item.id,
  120. jobName: item.postName || '未知岗位',
  121. company: item.companyName || '未知企业',
  122. fileName: item.offerFileName || 'offer.pdf',
  123. fileUrl: item.offerFileUrl,
  124. studentStatus: item.studentStatus || 'pending',
  125. enterpriseStatus: item.enterpriseStatus || 'pending',
  126. statusText: getStatusText(item.studentStatus, item.enterpriseStatus),
  127. status: item.studentStatus === 'pending' ? 'pending' : item.studentStatus,
  128. offerTime: item.offerTime,
  129. createTime: formatTime(item.createTime)
  130. }));
  131. }
  132. } catch (error) {
  133. uni.showToast({ title: '获取Offer列表失败', icon: 'none' });
  134. } finally {
  135. loading.value = false;
  136. }
  137. };
  138. const formatTime = (time) => {
  139. if (!time) return '--';
  140. const d = new Date(time);
  141. const year = d.getFullYear();
  142. const month = String(d.getMonth() + 1).padStart(2, '0');
  143. const day = String(d.getDate()).padStart(2, '0');
  144. const hour = String(d.getHours()).padStart(2, '0');
  145. const minute = String(d.getMinutes()).padStart(2, '0');
  146. return `${year}-${month}-${day} ${hour}:${minute}`;
  147. };
  148. const getStatusBadge = (offer) => {
  149. if (offer.enterpriseStatus === 'pending') return '审核中';
  150. if (offer.enterpriseStatus === 'adopted') return '已录用';
  151. if (offer.enterpriseStatus === 'rejected') return '未通过';
  152. return '未知';
  153. };
  154. const getResultDesc = (enterpriseStatus) => {
  155. switch (enterpriseStatus) {
  156. case 'adopted': return '企业已录用,请确认Offer';
  157. case 'rejected': return '很遗憾,该岗位暂不匹配';
  158. default: return '';
  159. }
  160. };
  161. const getStatusText = (studentStatus, enterpriseStatus) => {
  162. if (enterpriseStatus === 'rejected') return '已拒绝';
  163. if (studentStatus === 'accepted') return '已接受';
  164. if (studentStatus === 'rejected') return '已拒绝';
  165. return '待确认';
  166. };
  167. const handleAccept = (offer) => {
  168. currentOffer.value = offer;
  169. showAcceptModal.value = true;
  170. startCountdown();
  171. };
  172. const handleReject = (offer) => {
  173. currentOffer.value = offer;
  174. showRejectModal.value = true;
  175. };
  176. const startCountdown = () => {
  177. countdown.value = 10;
  178. if (timer) clearInterval(timer);
  179. timer = setInterval(() => {
  180. if (countdown.value > 0) {
  181. countdown.value--;
  182. } else {
  183. clearInterval(timer);
  184. }
  185. }, 1000);
  186. };
  187. const confirmAccept = async () => {
  188. if (!currentOffer.value) return;
  189. try {
  190. const res = await acceptOffer(currentOffer.value.id);
  191. if (res.code === 200) {
  192. uni.showToast({ title: '已接受Offer', icon: 'success' });
  193. fetchOfferList();
  194. } else {
  195. uni.showToast({ title: res.msg || '操作失败', icon: 'none' });
  196. }
  197. } catch (error) {
  198. uni.showToast({ title: '操作失败,请重试', icon: 'none' });
  199. } finally {
  200. showAcceptModal.value = false;
  201. }
  202. };
  203. const confirmReject = async () => {
  204. if (!currentOffer.value) return;
  205. try {
  206. const res = await rejectOffer(currentOffer.value.id);
  207. if (res.code === 200) {
  208. uni.showToast({ title: '已拒绝Offer', icon: 'none' });
  209. fetchOfferList();
  210. } else {
  211. uni.showToast({ title: res.msg || '操作失败', icon: 'none' });
  212. }
  213. } catch (error) {
  214. uni.showToast({ title: '操作失败,请重试', icon: 'none' });
  215. } finally {
  216. showRejectModal.value = false;
  217. }
  218. };
  219. onMounted(() => {
  220. loadOfferConfig();
  221. fetchOfferList();
  222. });
  223. const openFile = (url) => {
  224. if (!url) {
  225. uni.showToast({ title: '文件链接无效', icon: 'none' });
  226. return;
  227. }
  228. const getFileType = (fileUrl) => {
  229. const match = fileUrl.match(/\.(\w+)(\?|$)/);
  230. return match ? match[1].toLowerCase() : 'pdf';
  231. };
  232. const fileType = getFileType(url);
  233. uni.showLoading({ title: '加载中...' });
  234. uni.downloadFile({
  235. url: url,
  236. success: (res) => {
  237. if (res.statusCode === 200) {
  238. const filePath = res.tempFilePath;
  239. uni.openDocument({
  240. filePath: filePath,
  241. fileType: fileType,
  242. showMenu: true,
  243. success: () => { uni.hideLoading(); },
  244. fail: (err) => {
  245. uni.hideLoading();
  246. uni.showToast({ title: '预览失败', icon: 'none' });
  247. }
  248. });
  249. }
  250. },
  251. fail: (err) => {
  252. uni.hideLoading();
  253. uni.showToast({ title: '下载失败', icon: 'none' });
  254. }
  255. });
  256. };
  257. </script>
  258. <style lang="scss" scoped>
  259. .container {
  260. min-height: 100vh;
  261. background-color: #F5F6F8;
  262. }
  263. .offer-list {
  264. padding: 24rpx 30rpx;
  265. }
  266. .loading-state {
  267. text-align: center;
  268. padding: 100rpx 0;
  269. font-size: 28rpx;
  270. color: #999;
  271. }
  272. .empty-state {
  273. display: flex;
  274. flex-direction: column;
  275. align-items: center;
  276. padding: 150rpx 0;
  277. .empty-icon { width: 200rpx; height: 200rpx; margin-bottom: 30rpx; }
  278. .empty-text { font-size: 28rpx; color: #999; }
  279. }
  280. .offer-card {
  281. background: #FFF;
  282. border-radius: 24rpx;
  283. padding: 32rpx;
  284. margin-bottom: 24rpx;
  285. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
  286. .card-top {
  287. display: flex;
  288. justify-content: space-between;
  289. align-items: flex-start;
  290. margin-bottom: 16rpx;
  291. .company-info {
  292. flex: 1;
  293. min-width: 0;
  294. .company-name {
  295. font-size: 30rpx;
  296. font-weight: 600;
  297. color: #1A1A1A;
  298. display: block;
  299. margin-bottom: 6rpx;
  300. overflow: hidden;
  301. text-overflow: ellipsis;
  302. white-space: nowrap;
  303. }
  304. .job-name {
  305. font-size: 26rpx;
  306. color: #888;
  307. display: block;
  308. overflow: hidden;
  309. text-overflow: ellipsis;
  310. white-space: nowrap;
  311. }
  312. }
  313. .status-badge {
  314. flex-shrink: 0;
  315. padding: 6rpx 20rpx;
  316. border-radius: 20rpx;
  317. font-size: 22rpx;
  318. font-weight: 500;
  319. margin-left: 16rpx;
  320. &.pending {
  321. background: #FFF7E6;
  322. color: #FA8C16;
  323. }
  324. &.adopted {
  325. background: #F0FFF4;
  326. color: #52C41A;
  327. }
  328. &.rejected {
  329. background: #FFF1F0;
  330. color: #FF4D4F;
  331. }
  332. }
  333. }
  334. .card-meta {
  335. .meta-time {
  336. font-size: 24rpx;
  337. color: #BBB;
  338. }
  339. }
  340. .result-section {
  341. margin-top: 24rpx;
  342. padding-top: 24rpx;
  343. border-top: 1rpx solid #F0F2F5;
  344. .result-row {
  345. display: flex;
  346. justify-content: space-between;
  347. align-items: center;
  348. .result-left {
  349. display: flex;
  350. align-items: center;
  351. flex: 1;
  352. min-width: 0;
  353. .result-icon {
  354. width: 36rpx;
  355. height: 36rpx;
  356. margin-right: 12rpx;
  357. flex-shrink: 0;
  358. }
  359. .result-text {
  360. font-size: 28rpx;
  361. font-weight: 500;
  362. overflow: hidden;
  363. text-overflow: ellipsis;
  364. white-space: nowrap;
  365. &.adopted { color: #52C41A; }
  366. &.rejected { color: #FF4D4F; }
  367. }
  368. }
  369. .action-btns {
  370. display: flex;
  371. gap: 16rpx;
  372. flex-shrink: 0;
  373. margin-left: 16rpx;
  374. .btn {
  375. height: 60rpx;
  376. line-height: 58rpx;
  377. font-size: 24rpx;
  378. border-radius: 30rpx;
  379. padding: 0 28rpx;
  380. margin: 0;
  381. &::after { border: none; }
  382. &.btn-outline { background: #FFF; color: #666; border: 1rpx solid #DDD; }
  383. &.btn-primary { background: #1F6CFF; color: #FFF; }
  384. }
  385. }
  386. .student-status-tag {
  387. flex-shrink: 0;
  388. padding: 6rpx 20rpx;
  389. border-radius: 20rpx;
  390. font-size: 22rpx;
  391. font-weight: 500;
  392. margin-left: 16rpx;
  393. &.accepted {
  394. background: #F0FFF4;
  395. color: #52C41A;
  396. }
  397. &.rejected {
  398. background: #FFF1F0;
  399. color: #FF4D4F;
  400. }
  401. }
  402. }
  403. }
  404. .file-link {
  405. margin-top: 24rpx;
  406. padding: 20rpx 24rpx;
  407. background: #F8F9FB;
  408. border-radius: 16rpx;
  409. display: flex;
  410. align-items: center;
  411. .file-icon { width: 40rpx; height: 40rpx; margin-right: 12rpx; flex-shrink: 0; }
  412. .file-name { font-size: 26rpx; color: #1F6CFF; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  413. .file-arrow { font-size: 26rpx; color: #CCC; margin-left: 8rpx; flex-shrink: 0; }
  414. }
  415. }
  416. /* Modal */
  417. .modal-mask {
  418. position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  419. background: rgba(0,0,0,0.6); z-index: 1000;
  420. display: flex; align-items: center; justify-content: center;
  421. }
  422. .modal-content {
  423. background: #FFF; border-radius: 32rpx; overflow: hidden;
  424. &.protocol-modal { width: 620rpx; height: 1000rpx; display: flex; flex-direction: column; overflow: hidden; }
  425. &.confirm-modal { width: 540rpx; padding: 60rpx 40rpx; text-align: center; }
  426. }
  427. .modal-header { padding: 40rpx; text-align: center; font-size: 34rpx; font-weight: bold; flex-shrink: 0; }
  428. .protocol-body {
  429. flex: 1; height: 0; min-height: 0;
  430. .rich-text-container { padding: 0 40rpx 40rpx; box-sizing: border-box; }
  431. }
  432. .modal-footer {
  433. flex-shrink: 0;
  434. padding: 24rpx 40rpx calc(24rpx + env(safe-area-inset-bottom));
  435. border-top: 1rpx solid #F0F2F5;
  436. background: #FFF;
  437. .btns-row {
  438. display: flex; gap: 20rpx;
  439. button {
  440. height: 72rpx; line-height: 72rpx; border-radius: 36rpx; font-size: 26rpx;
  441. &::after { border: none; }
  442. &.btn-cancel { flex: 0 0 160rpx; background: #F5F5F7; color: #666; }
  443. &.btn-confirm { flex: 1; background: #1F6CFF; color: #FFF; &:disabled { opacity: 0.3; } }
  444. }
  445. }
  446. }
  447. .confirm-title { font-size: 36rpx; font-weight: bold; margin-bottom: 20rpx; }
  448. .confirm-desc { font-size: 28rpx; color: #888; margin-bottom: 60rpx; }
  449. .confirm-footer {
  450. display: flex; gap: 20rpx;
  451. button {
  452. flex: 1; height: 68rpx; line-height: 68rpx; border-radius: 34rpx; font-size: 26rpx;
  453. &::after { border: none; }
  454. &.btn-cancel { background: #F5F5F7; color: #666; }
  455. &.btn-danger { background: #1F6CFF; color: #FFF; }
  456. }
  457. }
  458. </style>