qualifications_logic.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. export default {
  2. data() {
  3. return {
  4. serviceTypes: [], // 从上一页传递过来的服务类型列表
  5. qualifications: {}, // 存储图片路径 { '宠物接送': 'path/to/img', ... }
  6. }
  7. },
  8. onLoad(options) {
  9. if (options.services) {
  10. try {
  11. this.serviceTypes = JSON.parse(options.services);
  12. // 初始化 qualifications 对象
  13. this.serviceTypes.forEach(type => {
  14. // 使用 Vue.set 或直接赋值
  15. this.qualifications[type] = [];
  16. });
  17. } catch (e) {
  18. console.error('Parse services failed', e);
  19. }
  20. }
  21. },
  22. methods: {
  23. chooseImage(serviceName) {
  24. uni.chooseImage({
  25. count: 9,
  26. sizeType: ['compressed'],
  27. sourceType: ['album', 'camera'],
  28. success: (res) => {
  29. if (!this.qualifications[serviceName]) {
  30. this.qualifications[serviceName] = [];
  31. }
  32. this.qualifications[serviceName] = this.qualifications[serviceName].concat(res.tempFilePaths);
  33. this.$forceUpdate();
  34. }
  35. });
  36. },
  37. deleteImage(serviceName, index) {
  38. this.qualifications[serviceName].splice(index, 1);
  39. this.$forceUpdate();
  40. },
  41. goBackToForm() {
  42. // 尝试返回填写页
  43. const pages = getCurrentPages();
  44. if (pages.length > 2) {
  45. uni.navigateBack({
  46. delta: 2
  47. });
  48. } else {
  49. // 如果页面栈不够(比如直接进入该页),则重定向
  50. uni.reLaunch({
  51. url: '/pages/recruit/form'
  52. });
  53. }
  54. },
  55. submit() {
  56. // 校验是否所有资质都已上传
  57. // const missing = this.serviceTypes.find(type => !this.qualifications[type]);
  58. // if (missing) {
  59. // uni.showToast({ title: `请上传${missing}服务资质`, icon: 'none' });
  60. // return;
  61. // }
  62. // 实际可能允许部分上传或者有后台逻辑,这里假设全部必填
  63. // 为了演示方便,暂时不强制校验,或者校验全部
  64. // 提交成功,跳转到成功页
  65. // 提交成功,跳转到成功页
  66. uni.reLaunch({
  67. url: '/pages/recruit/success'
  68. });
  69. }
  70. }
  71. }