logic.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. export default {
  2. data() {
  3. return {
  4. formData: {
  5. mobile: '13612345678',
  6. code: '',
  7. name: '张三哥',
  8. gender: 1, // 1男 2女
  9. birthday: '2026-02-13',
  10. password: '',
  11. serviceType: ['宠物接送'],
  12. city: '',
  13. station: ''
  14. },
  15. showPwd: false,
  16. isAgreed: false,
  17. serviceTypes: ['宠物接送', '上门喂遛', '上门洗护'],
  18. // 日期选择器相关
  19. showPicker: false,
  20. years: [],
  21. months: [],
  22. days: [],
  23. pickerValue: [0, 0, 0], // 选中项索引
  24. tempYear: 0,
  25. tempMonth: 0,
  26. tempDay: 0,
  27. // 城市选择器相关
  28. showCityPicker: false,
  29. // 模拟级联数据
  30. cityData: [
  31. {
  32. id: 11, name: '北京市', children: [
  33. {
  34. id: 1101, name: '北京市', children: [
  35. { id: 110101, name: '东城区' },
  36. { id: 110105, name: '朝阳区' },
  37. { id: 110108, name: '海淀区' }
  38. ]
  39. }
  40. ]
  41. },
  42. {
  43. id: 44, name: '广东省', children: [
  44. {
  45. id: 4401, name: '广州市', children: [
  46. { id: 440106, name: '天河区' },
  47. { id: 440104, name: '越秀区' }
  48. ]
  49. },
  50. {
  51. id: 4403, name: '深圳市', children: [
  52. { id: 440304, name: '福田区' },
  53. { id: 440305, name: '南山区' },
  54. { id: 440306, name: '宝安区' },
  55. { id: 440309, name: '龙华区' }
  56. ]
  57. }
  58. ]
  59. }
  60. ],
  61. selectStep: 0, // 0:省, 1:市, 2:区
  62. selectedPathway: [], // 已选节点 [{id, name}, ...]
  63. currentList: [], // 当前可选列表
  64. // 站点选择器相关
  65. showStationPicker: false,
  66. stationList: ['民治街道第一站', '民治街道第二站', '龙华中心站', '福田区分站'],
  67. // 协议弹窗
  68. showPrivacy: false,
  69. privacyTitle: '',
  70. privacyContent: ''
  71. }
  72. },
  73. created() {
  74. this.initDateData();
  75. },
  76. methods: {
  77. initDateData() {
  78. const now = new Date();
  79. const currentYear = now.getFullYear();
  80. // 初始化年份 (1980 - 2030)
  81. for (let i = 1980; i <= currentYear + 5; i++) {
  82. this.years.push(i);
  83. }
  84. // 初始化月份
  85. for (let i = 1; i <= 12; i++) {
  86. this.months.push(i);
  87. }
  88. // 初始化日期 (默认31天, 实际应动态计算, 这里简化处理或在change中联动)
  89. for (let i = 1; i <= 31; i++) {
  90. this.days.push(i);
  91. }
  92. },
  93. // 打开选择器
  94. openPicker() {
  95. // 解析当前选中日期或默认日期
  96. const dateStr = this.formData.birthday || '2000-01-01';
  97. const [y, m, d] = dateStr.split('-').map(Number);
  98. // 查找索引
  99. const yIndex = this.years.indexOf(y);
  100. const mIndex = this.months.indexOf(m);
  101. const dIndex = this.days.indexOf(d);
  102. this.pickerValue = [
  103. yIndex > -1 ? yIndex : 0,
  104. mIndex > -1 ? mIndex : 0,
  105. dIndex > -1 ? dIndex : 0
  106. ];
  107. this.tempYear = this.years[this.pickerValue[0]];
  108. this.tempMonth = this.months[this.pickerValue[1]];
  109. this.tempDay = this.days[this.pickerValue[2]];
  110. this.showPicker = true;
  111. },
  112. closePicker() {
  113. this.showPicker = false;
  114. },
  115. onPickerChange(e) {
  116. const val = e.detail.value;
  117. this.tempYear = this.years[val[0]];
  118. this.tempMonth = this.months[val[1]];
  119. this.tempDay = this.days[val[2]];
  120. },
  121. confirmPicker() {
  122. // 格式化日期
  123. const mStr = this.tempMonth < 10 ? '0' + this.tempMonth : this.tempMonth;
  124. const dStr = this.tempDay < 10 ? '0' + this.tempDay : this.tempDay;
  125. this.formData.birthday = `${this.tempYear}-${mStr}-${dStr}`;
  126. this.closePicker();
  127. },
  128. toggleService(item) {
  129. const idx = this.formData.serviceType.indexOf(item);
  130. if (idx > -1) {
  131. this.formData.serviceType.splice(idx, 1);
  132. } else {
  133. this.formData.serviceType.push(item);
  134. }
  135. },
  136. // 城市选择器 logic
  137. openCityPicker() {
  138. this.showCityPicker = true;
  139. // 如果未选择过,初始化第一级
  140. if (this.selectedPathway.length === 0) {
  141. this.resetCityPicker();
  142. }
  143. },
  144. resetCityPicker() {
  145. this.selectStep = 0;
  146. this.selectedPathway = [];
  147. this.currentList = this.cityData;
  148. },
  149. closeCityPicker() {
  150. this.showCityPicker = false;
  151. },
  152. // 点击列表项
  153. selectCityItem(item) {
  154. // 记录当前选择
  155. this.selectedPathway[this.selectStep] = item;
  156. // 尝试获取下一级
  157. if (item.children && item.children.length > 0) {
  158. this.selectStep++;
  159. this.currentList = item.children;
  160. // 清理后续旧数据(如果是重新选择的情况)
  161. this.selectedPathway = this.selectedPathway.slice(0, this.selectStep);
  162. } else {
  163. // 没有下一级了,自动确认
  164. this.confirmCity();
  165. }
  166. },
  167. // 点击“已选路径”回溯
  168. jumpToStep(step) {
  169. this.selectStep = step;
  170. // 重新计算该级的列表
  171. if (step === 0) {
  172. this.currentList = this.cityData;
  173. } else {
  174. // 列表是上一级选择的 item 的 children
  175. const parent = this.selectedPathway[step - 1];
  176. this.currentList = parent ? parent.children : [];
  177. }
  178. },
  179. confirmCity() {
  180. // 拼接完整名称
  181. const fullPath = this.selectedPathway.map(i => i.name).join(' ');
  182. this.formData.city = fullPath;
  183. this.closeCityPicker();
  184. },
  185. // 站点选择器
  186. openStationPicker() {
  187. this.showStationPicker = true;
  188. },
  189. closeStationPicker() {
  190. this.showStationPicker = false;
  191. },
  192. selectStation(item) {
  193. this.formData.station = item;
  194. this.closeStationPicker();
  195. },
  196. openPrivacy() {
  197. this.privacyTitle = '宠宝履约者说明';
  198. this.privacyContent = '1. 履约职责\n作为宠宝履约者,您需要按照平台标准完成宠物接送、喂遛或洗护服务,确保宠物安全与健康。\n\n2. 结算方式\n服务费用将根据订单类型和距离计算,定期结算至您的账户。具体结算周期请查看钱包说明。\n\n3. 行为规范\n请在这个过程中保持专业,穿着整洁,礼貌待人。严禁虐待宠物,违反者将承担法律责任。';
  199. this.showPrivacy = true;
  200. },
  201. goToAuth() {
  202. if (!this.isAgreed) {
  203. uni.showToast({ title: '请勾选协议', icon: 'none' });
  204. return;
  205. }
  206. const services = JSON.stringify(this.formData.serviceType);
  207. uni.navigateTo({
  208. url: `/pages/recruit/auth?services=${services}`
  209. });
  210. }
  211. }
  212. }