create.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="form-page">
  3. <LoadingSkeleton v-if="classLoading" :rows="4" />
  4. <ErrorState v-else-if="classError" message="可报班次加载失败" @retry="loadClasses" />
  5. <EmptyState
  6. v-else-if="classes.length === 0"
  7. icon="📭"
  8. title="暂无可报班次"
  9. desc="当前没有开放团体报名的班次,可联系机构确认"
  10. action-text="返回"
  11. @action="goBack"
  12. />
  13. <view v-else class="section-card">
  14. <text class="section-title">发起团报</text>
  15. <text class="card-desc">选择班次并填写成员名单(含开票信息,可选)</text>
  16. <view class="form-item">
  17. <text class="form-label">班次</text>
  18. <picker mode="selector" :range="classNames" @change="onClassChange">
  19. <view class="picker-value" :class="{ placeholder: !classId }">
  20. {{ classId ? className : '请选择班次' }}
  21. </view>
  22. </picker>
  23. <view v-if="classId && unitAmount !== null" class="unit-tip">
  24. 单价 ¥{{ fenToYuan(unitAmount) }},共 {{ members.length }} 人,合计 ¥{{ fenToYuan(unitAmount * members.length) }}
  25. </view>
  26. </view>
  27. <view class="form-item">
  28. <text class="form-label">成员名单</text>
  29. <view class="member-item" v-for="(m, idx) in members" :key="idx">
  30. <input class="member-name" v-model="m.name" placeholder="姓名" />
  31. <input class="member-phone" v-model="m.phone" type="number" maxlength="11" placeholder="手机号" />
  32. <text class="member-del" v-if="members.length > 1" @click="removeMember(idx)">删除</text>
  33. </view>
  34. <text class="add-member" @click="addMember">+ 添加成员</text>
  35. </view>
  36. <view class="form-item">
  37. <text class="form-label">发票抬头(企业名称,选填)</text>
  38. <input class="form-input" v-model="invoice.invoiceTitle" placeholder="不填则不开票" />
  39. </view>
  40. <view class="form-item" v-if="invoice.invoiceTitle">
  41. <text class="form-label">税号</text>
  42. <input class="form-input" v-model="invoice.invoiceTaxNo" placeholder="统一社会信用代码" />
  43. </view>
  44. <view class="form-item" v-if="invoice.invoiceTitle">
  45. <text class="form-label">开票类型</text>
  46. <view class="check-group">
  47. <view class="check-item" @click="invoice.invoiceType = '普票'">
  48. <text class="check-square" :class="{ checked: invoice.invoiceType === '普票' }">✓</text>
  49. <text class="check-text">普票</text>
  50. </view>
  51. <view class="check-item" @click="invoice.invoiceType = '专票'">
  52. <text class="check-square" :class="{ checked: invoice.invoiceType === '专票' }">✓</text>
  53. <text class="check-text">专票</text>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="form-item" v-if="invoice.invoiceTitle">
  58. <text class="form-label">接收邮箱(选填)</text>
  59. <input class="form-input" v-model="invoice.invoiceEmail" placeholder="电子发票接收邮箱" />
  60. </view>
  61. <view class="form-item" v-if="invoice.invoiceTitle">
  62. <text class="form-label">收票人电话(选填)</text>
  63. <input class="form-input" v-model="invoice.invoicePhone" type="number" maxlength="11" placeholder="收票联系电话" />
  64. </view>
  65. <button class="submit-btn" :loading="loading" :disabled="loading" @click="handleSubmit">提交团报</button>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import { getEnrollClasses, createGroupOrder } from '@/utils/api.js'
  71. import { fenToYuan } from '@/utils/format.js'
  72. import { guardPage } from '@/utils/guard.js'
  73. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  74. import ErrorState from '@/components/error-state.vue'
  75. import EmptyState from '@/components/empty-state.vue'
  76. export default {
  77. components: { LoadingSkeleton, ErrorState, EmptyState },
  78. data() {
  79. return {
  80. classes: [],
  81. classNames: [],
  82. classId: '',
  83. className: '',
  84. unitAmount: null,
  85. members: [{ name: '', phone: '' }],
  86. invoice: {
  87. invoiceTitle: '',
  88. invoiceTaxNo: '',
  89. invoiceEmail: '',
  90. invoicePhone: '',
  91. invoiceType: '普票'
  92. },
  93. loading: false,
  94. classLoading: false,
  95. classError: false
  96. }
  97. },
  98. onLoad() {
  99. if (!guardPage()) return
  100. this.loadClasses()
  101. },
  102. methods: {
  103. goBack() {
  104. var pages = getCurrentPages()
  105. if (pages.length > 1) {
  106. uni.navigateBack()
  107. } else {
  108. uni.redirectTo({ url: '/pages/group-order/index' })
  109. }
  110. },
  111. fenToYuan: fenToYuan,
  112. loadClasses() {
  113. var self = this
  114. self.classLoading = true
  115. self.classError = false
  116. getEnrollClasses().then(function(resp) {
  117. self.classes = resp.data || []
  118. var names = []
  119. for (var i = 0; i < self.classes.length; i++) {
  120. names.push(self.classes[i].name || ('班次' + self.classes[i].id))
  121. }
  122. self.classNames = names
  123. }).catch(function() {
  124. self.classError = true
  125. }).finally(function() {
  126. self.classLoading = false
  127. })
  128. },
  129. onClassChange(e) {
  130. var idx = Number(e.detail.value)
  131. var item = this.classes[idx]
  132. if (!item) return
  133. this.classId = item.id
  134. this.className = item.name
  135. // 团报按会员价计价(与后端 create 一致)
  136. var price = item.memberPrice > 0 && item.memberPrice < item.price ? item.memberPrice : item.price
  137. this.unitAmount = price
  138. },
  139. addMember() {
  140. this.members.push({ name: '', phone: '' })
  141. },
  142. removeMember(idx) {
  143. this.members.splice(idx, 1)
  144. },
  145. validatePhone(phone) {
  146. return /^1\d{10}$/.test(phone)
  147. },
  148. handleSubmit() {
  149. var self = this
  150. if (!self.classId) {
  151. uni.showToast({ title: '请选择班次', icon: 'none' })
  152. return
  153. }
  154. var memberList = []
  155. for (var i = 0; i < self.members.length; i++) {
  156. var name = (self.members[i].name || '').trim()
  157. var phone = (self.members[i].phone || '').trim()
  158. if (!name || !phone) {
  159. uni.showToast({ title: '请填写第 ' + (i + 1) + ' 位成员的姓名和手机号', icon: 'none' })
  160. return
  161. }
  162. if (!self.validatePhone(phone)) {
  163. uni.showToast({ title: '第 ' + (i + 1) + ' 位成员手机号格式不正确', icon: 'none' })
  164. return
  165. }
  166. memberList.push({ name: name, phone: phone })
  167. }
  168. if (self.invoice.invoiceTitle && (self.invoice.invoiceTitle || '').trim()) {
  169. if (!(self.invoice.invoiceTaxNo || '').trim()) {
  170. uni.showToast({ title: '填写发票抬头后请一并填写税号', icon: 'none' })
  171. return
  172. }
  173. }
  174. if (self.loading) return
  175. self.loading = true
  176. var payload = {
  177. classId: self.classId,
  178. members: memberList,
  179. invoiceTitle: (self.invoice.invoiceTitle || '').trim(),
  180. invoiceTaxNo: (self.invoice.invoiceTaxNo || '').trim(),
  181. invoiceEmail: (self.invoice.invoiceEmail || '').trim(),
  182. invoicePhone: (self.invoice.invoicePhone || '').trim(),
  183. invoiceType: self.invoice.invoiceType
  184. }
  185. createGroupOrder(payload).then(function(resp) {
  186. var id = resp.data && resp.data.id ? resp.data.id : ''
  187. uni.showToast({ title: '团报单已创建', icon: 'success' })
  188. setTimeout(function() {
  189. if (id) {
  190. uni.redirectTo({ url: '/pages/group-order/detail?id=' + id })
  191. } else {
  192. uni.redirectTo({ url: '/pages/group-order/index' })
  193. }
  194. }, 1200)
  195. }).catch(function(err) {
  196. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  197. }).finally(function() {
  198. self.loading = false
  199. })
  200. }
  201. }
  202. }
  203. </script>
  204. <style scoped>
  205. .form-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  206. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  207. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  208. .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 32rpx; }
  209. .form-item { margin-bottom: 24rpx; }
  210. .form-label { display: block; font-size: 26rpx; color: #3B5A78; font-weight: 500; margin-bottom: 12rpx; }
  211. .form-input { height: 72rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 16rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; }
  212. .picker-value { height: 72rpx; line-height: 72rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 16rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; }
  213. .picker-value.placeholder { color: #6B7B8C; }
  214. .unit-tip { font-size: 24rpx; color: #2E6FA8; margin-top: 12rpx; }
  215. .member-item { display: flex; align-items: center; margin-bottom: 16rpx; }
  216. .member-name { width: 200rpx; height: 64rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 12rpx; font-size: 26rpx; background: #F5FAFE; margin-right: 12rpx; }
  217. .member-phone { flex: 1; height: 64rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 12rpx; font-size: 26rpx; background: #F5FAFE; margin-right: 12rpx; }
  218. .member-del { font-size: 24rpx; color: #C0392B; padding: 8rpx; }
  219. .add-member { display: block; font-size: 26rpx; color: #2E6FA8; font-weight: 600; margin-top: 8rpx; }
  220. .check-group { display: flex; }
  221. .check-item { display: flex; align-items: center; margin-right: 40rpx; }
  222. .check-square { width: 36rpx; height: 36rpx; border: 2rpx solid #C3D2DF; border-radius: 6rpx; display: flex; align-items: center; justify-content: center; font-size: 24rpx; color: #FFF; margin-right: 12rpx; flex-shrink: 0; }
  223. .check-square.checked { background: #2E6FA8; border-color: #2E6FA8; }
  224. .check-text { font-size: 26rpx; color: #1E3A5F; }
  225. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-top: 24rpx; }
  226. .submit-btn:active { opacity: 0.85; }
  227. </style>