create.vue 8.9 KB

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