enrolledForm.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="form" label-width="140">
  4. <u-form-item label="学生照片" prop="imageFileId" required label-position="top">
  5. <u-upload :max-count="1" :action="uploadUrl" :header="uploadHeader" @on-success="uploadSuccess" @on-error="uploadError"
  6. @on-remove="uploadRemove"></u-upload>
  7. </u-form-item>
  8. <u-form-item label="接收人" prop="coachName" required>
  9. <u-input v-model="form.coachName" placeholder="请输入接收人" disabled />
  10. </u-form-item>
  11. <u-form-item label="家长姓名" prop="parentsName" required>
  12. <u-input v-model="form.parentsName" placeholder="请输入家长姓名" />
  13. </u-form-item>
  14. <u-form-item label="学员姓名" prop="studentName" required>
  15. <u-input v-model="form.studentName" placeholder="请输入学员姓名" />
  16. </u-form-item>
  17. <u-form-item label="学员性别" prop="sex" required right-icon="arrow-right" @click.native="sexShow = true">
  18. <text>{{form.sex}}</text>
  19. </u-form-item>
  20. <u-form-item label="学员年龄" prop="age" required>
  21. <u-input v-model="form.age" type="number" placeholder="请输入学员年龄" />
  22. </u-form-item>
  23. <u-form-item label="学生生日" prop="birthday" required right-icon="arrow-right" @click.native="birthdayShow = true">
  24. <text>{{form.birthday}}</text>
  25. </u-form-item>
  26. <u-form-item label="手机号码" prop="phone" required>
  27. <u-input v-model="form.phone" type="number" placeholder="请输入手机号码" />
  28. </u-form-item>
  29. <u-form-item label="报名班级" prop="className" required right-icon="arrow-right" @click.native="classShow = true">
  30. <text>{{form.className}}</text>
  31. </u-form-item>
  32. <u-form-item label="课时数" prop="courseNumber" required>
  33. <u-input v-model="form.courseNumber" type="number" placeholder="请输入课时数" @blur="setSumPrice()" />
  34. </u-form-item>
  35. <u-form-item label="课时单价" prop="coursePrice" required>
  36. <u-input v-model="form.coursePrice" type="number" placeholder="请输入课时单价" @blur="setSumPrice()" />
  37. </u-form-item>
  38. <u-form-item label="课时总价" prop="sumPrice" required>
  39. <u-input v-model="form.sumPrice" type="number" placeholder="请输入课时总价" />
  40. </u-form-item>
  41. <u-form-item label="订单号" prop="orderNo" required>
  42. <u-input v-model="form.orderNo" placeholder="请输入订单号" />
  43. </u-form-item>
  44. <u-form-item label="赠课数量">
  45. <u-input v-model="form.lessonsGiveNumber" type="number" placeholder="请输入赠课数量" />
  46. </u-form-item>
  47. <u-form-item label="赠品" label-position="top"></u-form-item>
  48. <u-form-item :label="item.name" v-for="(item, index1) in giftList" :key="index1">
  49. <u-radio-group v-model="item.value" v-if="item.type == 1">
  50. <u-radio v-for="(site, index2) in item.itemList" :key="index2" :name="site.id">
  51. {{site.name}}
  52. </u-radio>
  53. </u-radio-group>
  54. <u-checkbox-group v-model="item.value" v-else>
  55. <u-checkbox v-model="site.checked" v-for="(site, index2) in item.itemList" :key="index2" :name="site.id">
  56. {{site.name}}
  57. </u-checkbox>
  58. </u-checkbox-group>
  59. </u-form-item>
  60. <u-form-item label="销售员" prop="saleName" required right-icon="arrow-right" @click.native="saleShow = true">
  61. <text>{{form.saleName}}</text>
  62. </u-form-item>
  63. <u-form-item label="谈单人" prop="talkerName" required right-icon="arrow-right" @click.native="talkerShow = true">
  64. <text>{{form.talkerName}}</text>
  65. </u-form-item>
  66. <u-form-item label="支付方式" prop="payTypeName" required right-icon="arrow-right" @click.native="payTypeShow = true">
  67. <text>{{form.payTypeName}}</text>
  68. </u-form-item>
  69. <u-form-item label="备注">
  70. <u-input v-model="form.remark" type="textarea" placeholder="请输入备注" auto-height :height="100" />
  71. </u-form-item>
  72. </u-form>
  73. <u-action-sheet :list="sexList" v-model="sexShow" @click="setSex"></u-action-sheet>
  74. <u-picker v-model="birthdayShow" mode="time" :params="birthdayParams" @confirm="setBirthday"></u-picker>
  75. <u-picker mode="selector" v-model="classShow" :range="classList" range-key="name" @confirm="setClass"></u-picker>
  76. <u-picker mode="selector" v-model="saleShow" :range="saleList" range-key="name" @confirm="setSale"></u-picker>
  77. <u-picker mode="selector" v-model="talkerShow" :range="talkerList" range-key="name" @confirm="setTalker"></u-picker>
  78. <u-picker mode="selector" v-model="payTypeShow" :range="payTypeList" range-key="name" @confirm="setPayType"></u-picker>
  79. <view class="handle-fix-box">
  80. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">提交</u-button>
  81. </view>
  82. <u-top-tips ref="uTips"></u-top-tips>
  83. </view>
  84. </template>
  85. <script>
  86. import {
  87. mapGetters
  88. } from 'vuex'
  89. const NET = require('@/utils/request')
  90. const API = require('@/config/api')
  91. export default {
  92. computed: {
  93. ...mapGetters([
  94. 'customStyle',
  95. ])
  96. },
  97. data() {
  98. return {
  99. uploadUrl: API.uploadFile,
  100. uploadHeader: {
  101. Authorization: uni.getStorageSync('token')
  102. },
  103. form: {
  104. imageFileId: '',
  105. coachName: '',
  106. parentsName: '',
  107. studentName: '',
  108. sex: '',
  109. age: '',
  110. birthday: '',
  111. phone: '',
  112. classId: '',
  113. className: '',
  114. courseNumber: '',
  115. coursePrice: '',
  116. sumPrice: '',
  117. orderNo: '',
  118. lessonsGiveNumber: '',
  119. giftId: [],
  120. saleId: '',
  121. saleName: '',
  122. talkerId: '',
  123. talkerName: '',
  124. payTypeId: '',
  125. payTypeName: '',
  126. remark: '',
  127. },
  128. rules: {
  129. coachName: [{
  130. required: true,
  131. message: '请输入接收人',
  132. trigger: 'change'
  133. }],
  134. parentsName: [{
  135. required: true,
  136. message: '请输入家长姓名',
  137. trigger: 'change'
  138. }],
  139. studentName: [{
  140. required: true,
  141. message: '请输入学员姓名',
  142. trigger: 'change'
  143. }],
  144. sex: [{
  145. required: true,
  146. message: '请选择学员性别',
  147. trigger: 'change'
  148. }],
  149. age: [{
  150. required: true,
  151. message: '请输入学员年龄',
  152. trigger: 'change'
  153. }],
  154. birthday: [{
  155. required: true,
  156. message: '请选择学生生日',
  157. trigger: 'change'
  158. }],
  159. phone: [{
  160. required: true,
  161. message: '请输入手机号码',
  162. trigger: 'change'
  163. },
  164. {
  165. pattern: /^1[0-9]{10}$/g,
  166. transform(value) {
  167. return String(value);
  168. },
  169. message: '请输入正确格式的手机号码'
  170. },
  171. ],
  172. className: [{
  173. required: true,
  174. message: '请选择报名班级',
  175. trigger: 'change'
  176. }],
  177. courseNumber: [{
  178. required: true,
  179. message: '请输入课时数',
  180. trigger: 'change'
  181. }],
  182. coursePrice: [{
  183. required: true,
  184. message: '请输入课时单价',
  185. trigger: 'change'
  186. }],
  187. sumPrice: [{
  188. required: true,
  189. message: '请输入课时总价',
  190. trigger: 'change'
  191. }],
  192. orderNo: [{
  193. required: true,
  194. message: '请输入订单号',
  195. trigger: 'change'
  196. }],
  197. saleName: [{
  198. required: true,
  199. message: '请选择销售员',
  200. trigger: 'change'
  201. }],
  202. talkerName: [{
  203. required: true,
  204. message: '请选择谈单人',
  205. trigger: 'change'
  206. }],
  207. payTypeName: [{
  208. required: true,
  209. message: '请选择支付方式',
  210. trigger: 'change'
  211. }],
  212. },
  213. sexShow: false,
  214. sexList: [{
  215. text: '男'
  216. },
  217. {
  218. text: '女'
  219. }
  220. ],
  221. birthdayShow: false,
  222. birthdayParams: {
  223. year: true,
  224. month: true,
  225. day: true,
  226. hour: false,
  227. minute: false,
  228. second: false
  229. },
  230. classShow: false,
  231. classList: [],
  232. giftList: [],
  233. saleShow: false,
  234. saleList: [],
  235. talkerShow: false,
  236. talkerList: [],
  237. payTypeShow: false,
  238. payTypeList: [],
  239. }
  240. },
  241. onLoad() {},
  242. onReady() {
  243. this.form.coachName = uni.getStorageSync('userData').nickName
  244. this.$refs.form.setRules(this.rules);
  245. NET.request(API.getClassList, {
  246. page: 1,
  247. size: 1000,
  248. }, 'POST').then(res => {
  249. this.classList = res.data.row
  250. }).catch(error => {
  251. this.$refs.uTips.show({
  252. title: error.message,
  253. type: 'warning',
  254. })
  255. })
  256. NET.request(API.getGiftList, {}, 'POST').then(res => {
  257. res.data.forEach(item => {
  258. if (item == 1) {
  259. item.value = ''
  260. } else {
  261. item.itemList.forEach(site => {
  262. site.checked = false
  263. })
  264. }
  265. })
  266. this.giftList = res.data
  267. }).catch(error => {
  268. this.$refs.uTips.show({
  269. title: error.message,
  270. type: 'warning',
  271. })
  272. })
  273. NET.request(API.getSaleList, {
  274. page: 1,
  275. size: 1000,
  276. }, 'POST').then(res => {
  277. this.saleList = res.data.row
  278. }).catch(error => {
  279. this.$refs.uTips.show({
  280. title: error.message,
  281. type: 'warning',
  282. })
  283. })
  284. NET.request(API.getTalkerList, {
  285. page: 1,
  286. size: 1000,
  287. }, 'POST').then(res => {
  288. this.talkerList = res.data.row
  289. }).catch(error => {
  290. this.$refs.uTips.show({
  291. title: error.message,
  292. type: 'warning',
  293. })
  294. })
  295. NET.request(API.getPayTypeList, {}, 'POST').then(res => {
  296. this.payTypeList = res.data
  297. }).catch(error => {
  298. this.$refs.uTips.show({
  299. title: error.message,
  300. type: 'warning',
  301. })
  302. })
  303. },
  304. methods: {
  305. // 文件上传成功回调
  306. uploadSuccess(res, index, lists, name) {
  307. this.form.imageFileId = res.data.id
  308. this.$refs.uTips.show({
  309. title: '文件上传成功',
  310. type: 'success',
  311. })
  312. return true
  313. },
  314. // 文件上传失败回调
  315. uploadError(res, index, lists, name) {
  316. this.$refs.uTips.show({
  317. title: error.message,
  318. type: 'warning',
  319. })
  320. },
  321. // 移除文件回调
  322. uploadRemove(index, lists, name) {
  323. this.form.imageFileId = ''
  324. },
  325. // 设置性别
  326. setSex(index) {
  327. this.form.sex = this.sexList[index].text
  328. },
  329. // 设置生日
  330. setBirthday(object) {
  331. this.form.birthday = object.year + '-' + object.month + '-' + object.day
  332. },
  333. // 设置报名班级
  334. setClass(object) {
  335. this.form.classId = this.classList[object[0]].id
  336. this.form.className = this.classList[object[0]].name
  337. },
  338. // 设置销售员
  339. setSale(object) {
  340. this.form.saleId = this.saleList[object[0]].id
  341. this.form.saleName = this.saleList[object[0]].name
  342. },
  343. // 设置谈单人
  344. setTalker(object) {
  345. this.form.talkerId = this.talkerList[object[0]].id
  346. this.form.talkerName = this.talkerList[object[0]].name
  347. },
  348. // 设置支付方式
  349. setPayType(object) {
  350. this.form.payTypeId = this.payTypeList[object[0]].id
  351. this.form.payTypeName = this.payTypeList[object[0]].name
  352. },
  353. // 设置总价
  354. setSumPrice() {
  355. if (this.form.courseNumber && this.form.coursePrice) {
  356. this.form.sumPrice = JSON.stringify(this.form.courseNumber * this.form.coursePrice)
  357. }
  358. },
  359. // 提交表单
  360. submitForm() {
  361. this.$refs.form.validate(valid => {
  362. if (valid) {
  363. let giftId = []
  364. this.giftList.forEach(item => {
  365. if (item.type == 1 && item.value) {
  366. giftId.push(item.value)
  367. } else if (item.type == 0) {
  368. giftId = giftId.concat(item.itemList.filter(site => site.checked).map(site => {
  369. return site.id
  370. }))
  371. }
  372. })
  373. NET.request(API.submitEnrolledForm, {
  374. ...this.form,
  375. giftId: giftId
  376. }, 'POST').then(res => {
  377. this.$refs.uTips.show({
  378. title: '提交成功',
  379. type: 'success',
  380. })
  381. setTimeout(() => {
  382. uni.navigateBack()
  383. }, 1000)
  384. }).catch(error => {
  385. this.$refs.uTips.show({
  386. title: error.message,
  387. type: 'warning',
  388. })
  389. })
  390. }
  391. });
  392. },
  393. },
  394. }
  395. </script>
  396. <style>
  397. page {
  398. width: 100%;
  399. height: 100%;
  400. position: relative;
  401. }
  402. </style>
  403. <style lang="scss" scoped>
  404. @import "@/static/css/themes.scss";
  405. .content {
  406. width: 100%;
  407. float: left;
  408. padding: 0 15px 60px 15px;
  409. box-sizing: border-box;
  410. }
  411. </style>