enrolledForm.vue 15 KB

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