create.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view class="header">
  4. <text class="title">创建成长记录</text>
  5. <text class="subtitle">选择创建方式</text>
  6. </view>
  7. <view class="source-type-section">
  8. <view class="source-card" :class="sourceType === 'manual' ? 'source-active' : ''" @click="sourceType = 'manual'">
  9. <text class="source-icon">📝</text>
  10. <text class="source-name">手动创建</text>
  11. <text class="source-desc">填写成员基本信息</text>
  12. </view>
  13. <view class="source-card" :class="sourceType === 'upload' ? 'source-active' : ''" @click="sourceType = 'upload'">
  14. <text class="source-icon">📄</text>
  15. <text class="source-name">上传报告</text>
  16. <text class="source-desc">上传PDF测评报告</text>
  17. </view>
  18. <view class="source-card" :class="sourceType === 'assessment' ? 'source-active' : ''" @click="sourceType = 'assessment'">
  19. <text class="source-icon">🎓</text>
  20. <text class="source-name">购买测评</text>
  21. <text class="source-desc">购买DAN测评服务</text>
  22. </view>
  23. </view>
  24. <view class="form" v-if="sourceType === 'manual'">
  25. <view class="form-item">
  26. <text class="label">成员</text>
  27. <view class="child-select" @click="selectChild">
  28. <text class="select-text" v-if="selectedChild">{{ selectedChild.nickname || selectedChild.name }}</text>
  29. <text class="select-placeholder" v-else>请选择成员</text>
  30. <text class="select-arrow">›</text>
  31. </view>
  32. </view>
  33. <view class="form-item">
  34. <text class="label">档案标题</text>
  35. <input class="input" v-model="formData.recordTitle" placeholder="例如:2026年5月成长记录" />
  36. </view>
  37. <view class="form-row">
  38. <view class="form-item half">
  39. <text class="label">身高(cm)</text>
  40. <input class="input" v-model="formData.height" type="number" placeholder="选填" />
  41. </view>
  42. <view class="form-item half">
  43. <text class="label">体重(kg)</text>
  44. <input class="input" v-model="formData.weight" type="number" placeholder="选填" />
  45. </view>
  46. </view>
  47. <view class="form-item">
  48. <text class="label">学校名称</text>
  49. <input class="input" v-model="formData.school" placeholder="选填" />
  50. </view>
  51. <view class="form-row">
  52. <view class="form-item half">
  53. <text class="label">年级</text>
  54. <picker mode="selector" :range="gradeOptions" :value="formData.grade ? (formData.grade - 1) : -1" @change="onGradeChange">
  55. <view class="picker-input">{{ formData.grade ? gradeOptions[formData.grade - 1] : '请选择年级' }}</view>
  56. </picker>
  57. </view>
  58. <view class="form-item half">
  59. <text class="label">成绩表现</text>
  60. <input class="input" v-model="formData.academicPerformance" placeholder="选填" />
  61. </view>
  62. </view>
  63. <view class="form-item">
  64. <text class="label">学校所在省</text>
  65. <input class="input" v-model="formData.schoolProvince" placeholder="选填" />
  66. </view>
  67. <view class="form-item">
  68. <text class="label">学校所在市</text>
  69. <input class="input" v-model="formData.schoolCity" placeholder="选填" />
  70. </view>
  71. <view class="form-item">
  72. <text class="label">学校所在区</text>
  73. <input class="input" v-model="formData.schoolDistrict" placeholder="选填" />
  74. </view>
  75. <view class="form-item">
  76. <text class="label">学校所在街道</text>
  77. <input class="input" v-model="formData.schoolStreet" placeholder="选填" />
  78. </view>
  79. <button class="btn-submit" @click="submitManual">创建档案</button>
  80. </view>
  81. <view class="redirect-section" v-if="sourceType === 'upload'">
  82. <view class="redirect-card">
  83. <text class="redirect-desc">上传PDF格式的DAN测评报告,系统将自动解析报告内容并创建成长记录。</text>
  84. <button class="btn-submit" @click="goUpload">上传测评报告</button>
  85. </view>
  86. </view>
  87. <view class="redirect-section" v-if="sourceType === 'assessment'">
  88. <view class="redirect-card">
  89. <text class="redirect-desc">购买DAN测评服务后,规划师完成测评录入将自动创建成长记录,无需手动填写。</text>
  90. <button class="btn-submit" @click="goPurchase">购买测评服务</button>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. import { getChildren, createGrowthRecord } from '../../utils/api.js'
  98. import fontScaleMixin from '@/mixins/font-scale.js'
  99. export default {
  100. mixins: [fontScaleMixin],
  101. data() {
  102. return {
  103. sourceType: 'manual',
  104. children: [],
  105. selectedChild: null,
  106. targetChildId: '',
  107. gradeOptions: ['一年级','二年级','三年级','四年级','五年级','六年级','初一','初二','初三','高一','高二','高三'],
  108. formData: {
  109. memberId: null,
  110. recordTitle: '',
  111. height: '',
  112. weight: '',
  113. school: '',
  114. grade: null,
  115. academicPerformance: '',
  116. schoolProvince: '',
  117. schoolCity: '',
  118. schoolDistrict: '',
  119. schoolStreet: ''
  120. }
  121. }
  122. },
  123. onLoad(options) {
  124. this.targetChildId = options.memberId || ''
  125. if (options.sourceType) {
  126. this.sourceType = options.sourceType
  127. }
  128. this.loadChildren()
  129. if (this.targetChildId) {
  130. this.formData.recordTitle = '成长记录 - ' + this.getCurrentDate()
  131. }
  132. },
  133. computed: {},
  134. methods: {
  135. getCurrentDate() {
  136. var d = new Date()
  137. return d.getFullYear() + '年' + (d.getMonth() + 1) + '月'
  138. },
  139. async loadChildren() {
  140. try {
  141. var res = await getChildren()
  142. if (res.code === 200) {
  143. this.children = res.data || []
  144. var target = null
  145. if (this.targetChildId) {
  146. target = this.children.find(function(c) { return String(c.id) === String(this.targetChildId) }.bind(this))
  147. }
  148. if (!target && this.children.length > 0) {
  149. target = this.children[0]
  150. }
  151. if (target) {
  152. this.selectedChild = target
  153. this.formData.memberId = target.id
  154. }
  155. }
  156. } catch (e) {
  157. console.error(e)
  158. }
  159. },
  160. selectChild() {
  161. var items = this.children.map(function(c) { return c.nickname || c.name })
  162. var self = this
  163. uni.showActionSheet({
  164. itemList: items,
  165. success: function(res) {
  166. var idx = res.tapIndex
  167. if (idx >= 0 && idx < self.children.length) {
  168. self.selectedChild = self.children[idx]
  169. self.formData.memberId = self.selectedChild.id
  170. }
  171. }
  172. })
  173. },
  174. onGradeChange(e) {
  175. this.formData.grade = e.detail.value + 1
  176. },
  177. async submitManual() {
  178. if (!this.formData.memberId) {
  179. uni.showToast({ title: '请选择成员', icon: 'none' })
  180. return
  181. }
  182. uni.showLoading({ title: '创建中...' })
  183. try {
  184. var submitData = {
  185. memberId: this.formData.memberId,
  186. recordTitle: this.formData.recordTitle || '成长记录',
  187. height: this.formData.height || null,
  188. weight: this.formData.weight || null,
  189. school: this.formData.school || null,
  190. grade: this.formData.grade,
  191. academicPerformance: this.formData.academicPerformance || null,
  192. schoolProvince: this.formData.schoolProvince || null,
  193. schoolCity: this.formData.schoolCity || null,
  194. schoolDistrict: this.formData.schoolDistrict || null,
  195. schoolStreet: this.formData.schoolStreet || null
  196. }
  197. var res = await createGrowthRecord(submitData)
  198. uni.hideLoading()
  199. if (res.code === 200) {
  200. uni.showToast({ title: '创建成功', icon: 'success' })
  201. setTimeout(function() {
  202. uni.navigateTo({
  203. url: '/pages/growth/detail?recordId=' + res.data.id
  204. })
  205. }, 500)
  206. } else {
  207. uni.showToast({ title: res.message || '创建失败', icon: 'none' })
  208. }
  209. } catch (e) {
  210. uni.hideLoading()
  211. uni.showToast({ title: e.message || '创建失败', icon: 'none' })
  212. }
  213. },
  214. goUpload() {
  215. var url = '/pages/growth/upload'
  216. if (this.targetChildId) {
  217. url += '?memberId=' + this.targetChildId
  218. }
  219. uni.navigateTo({ url: url })
  220. },
  221. goPurchase() {
  222. uni.navigateTo({
  223. url: '/pages/assessment/purchase'
  224. })
  225. }
  226. }
  227. }
  228. </script>
  229. <style scoped lang="scss">
  230. .container {
  231. padding: $uni-space-page;
  232. background: $facade-fill-page;
  233. min-height: 100vh;
  234. }
  235. .header {
  236. text-align: center;
  237. padding: 40rpx 0 $uni-space-lg;
  238. }
  239. .title {
  240. font-size: calc(40rpx * var(--font-scale, 1));
  241. font-weight: bold;
  242. color: $facade-text-strong;
  243. display: block;
  244. margin-bottom: 10rpx;
  245. }
  246. .subtitle {
  247. font-size: calc(26rpx * var(--font-scale, 1));
  248. color: $facade-text-muted;
  249. }
  250. .source-type-section {
  251. display: flex;
  252. gap: 16rpx;
  253. margin-bottom: $uni-space-lg;
  254. }
  255. .source-card {
  256. flex: 1;
  257. background: $app-surface;
  258. border-radius: 16rpx;
  259. padding: 24rpx 16rpx;
  260. text-align: center;
  261. border: 2rpx solid $facade-hairline;
  262. }
  263. .source-active {
  264. border-color: $accent-indigo;
  265. background: $facade-violet-tint-2;
  266. }
  267. .source-icon {
  268. font-size: calc(48rpx * var(--font-scale, 1));
  269. display: block;
  270. margin-bottom: 8rpx;
  271. }
  272. .source-name {
  273. font-size: calc(26rpx * var(--font-scale, 1));
  274. font-weight: bold;
  275. color: $facade-text-strong;
  276. display: block;
  277. margin-bottom: 4rpx;
  278. }
  279. .source-desc {
  280. font-size: calc(20rpx * var(--font-scale, 1));
  281. color: $facade-text-muted;
  282. display: block;
  283. }
  284. .form {
  285. background: $app-surface;
  286. border-radius: 24rpx;
  287. padding: $uni-space-lg;
  288. }
  289. .form-item {
  290. margin-bottom: $uni-space-lg;
  291. }
  292. .form-row {
  293. display: flex;
  294. gap: 20rpx;
  295. }
  296. .half {
  297. flex: 1;
  298. }
  299. .label {
  300. font-size: calc(28rpx * var(--font-scale, 1));
  301. color: $facade-text-strong;
  302. display: block;
  303. margin-bottom: 16rpx;
  304. font-weight: bold;
  305. }
  306. .input {
  307. width: 100%;
  308. height: 76rpx;
  309. border: 1rpx solid $facade-hairline;
  310. border-radius: 8rpx;
  311. padding: 0 20rpx;
  312. font-size: calc(28rpx * var(--font-scale, 1));
  313. box-sizing: border-box;
  314. }
  315. .child-select {
  316. display: flex;
  317. align-items: center;
  318. height: 76rpx;
  319. border: 1rpx solid $facade-hairline;
  320. border-radius: 8rpx;
  321. padding: 0 20rpx;
  322. }
  323. .select-text {
  324. flex: 1;
  325. font-size: calc(28rpx * var(--font-scale, 1));
  326. color: $facade-text-strong;
  327. }
  328. .select-placeholder {
  329. flex: 1;
  330. font-size: calc(28rpx * var(--font-scale, 1));
  331. color: $facade-text-ghost;
  332. }
  333. .select-arrow {
  334. font-size: calc(32rpx * var(--font-scale, 1));
  335. color: $facade-text-ghost;
  336. }
  337. .picker-input {
  338. height: 76rpx;
  339. line-height: 76rpx;
  340. border: 1rpx solid $facade-hairline;
  341. border-radius: 8rpx;
  342. padding: 0 20rpx;
  343. font-size: calc(28rpx * var(--font-scale, 1));
  344. color: $facade-text-strong;
  345. }
  346. .btn-submit {
  347. width: 100%;
  348. height: 88rpx;
  349. line-height: 88rpx;
  350. background: linear-gradient(135deg, $accent-indigo 0%, $accent-indigo-deep 100%);
  351. color: $app-surface;
  352. border-radius: 24rpx;
  353. font-size: calc(32rpx * var(--font-scale, 1));
  354. font-weight: bold;
  355. text-align: center;
  356. }
  357. .redirect-section {
  358. margin-top: 20rpx;
  359. }
  360. .redirect-card {
  361. background: $app-surface;
  362. border-radius: 24rpx;
  363. padding: 40rpx $uni-space-page;
  364. }
  365. .redirect-desc {
  366. font-size: calc(28rpx * var(--font-scale, 1));
  367. color: $facade-text-body;
  368. line-height: 1.6;
  369. display: block;
  370. margin-bottom: $uni-space-lg;
  371. }
  372. </style>