dealOrder.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="page">
  3. <van-nav-bar
  4. title="课程交易"
  5. left-text="返回"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. ></van-nav-bar>
  9. <div class="orderContent">
  10. <div class="form">
  11. <van-field
  12. readonly
  13. clickable
  14. label="选择课程"
  15. :value="form.name"
  16. placeholder="选择课程"
  17. @click="showPop"
  18. />
  19. <div class="desc" v-if="form.id != 0">
  20. <span>该课程名额剩余{{ coursesUsable }}套</span>
  21. </div>
  22. <van-field
  23. readonly
  24. label="选择交易数量"
  25. :value="form.number"
  26. placeholder="选择交易数量"
  27. @touchstart.native.stop="numberShow = true"
  28. />
  29. <van-field
  30. v-model="form.content"
  31. rows="3"
  32. autosize
  33. label="备注"
  34. type="textarea"
  35. maxlength="100"
  36. placeholder="备注留言"
  37. show-word-limit
  38. />
  39. <div class="submit">
  40. <van-button
  41. color="#999"
  42. style="padding: 0 .8rem;border-radius: 0.15rem;"
  43. @click="$router.go(-1)"
  44. >取消</van-button
  45. >
  46. <van-button style="background-color: #26A2FF;padding: 0 .8rem;color: #FFF;border-radius: 0.15rem;" @click="comfirm"
  47. >确认</van-button
  48. >
  49. </div>
  50. </div>
  51. </div>
  52. <van-popup v-model="popupShow" position="bottom" :style="{ height: '30%' }">
  53. <van-picker
  54. title="选择课程"
  55. show-toolbar
  56. :columns="columnsOptions"
  57. @confirm="onConfirm"
  58. />
  59. </van-popup>
  60. <van-number-keyboard
  61. :show="numberShow"
  62. @blur="numberShow = false"
  63. @input="onInput"
  64. @delete="onDelete"
  65. />
  66. </div>
  67. </template>
  68. <script>
  69. import {getDealerCourseList,dealCourse} from '../api'
  70. import Vue from "vue";
  71. import { NumberKeyboard } from "vant";
  72. Vue.use(NumberKeyboard);
  73. export default {
  74. name: "dealOrder",
  75. components: {},
  76. data() {
  77. return {
  78. numberShow: false,
  79. popupShow: false,
  80. form: {
  81. name: "",
  82. id: 0,
  83. number: 0,
  84. content: ""
  85. },
  86. coursesUsable: 0,
  87. courseList:[],
  88. columnsOptions:[]
  89. };
  90. },
  91. created() {
  92. this.getCourseList();
  93. },
  94. methods: {
  95. getCourseList(){
  96. getDealerCourseList().then(res=>{
  97. this.courseList = res.list;
  98. let list = [];
  99. res.list.forEach(item=>{
  100. list.push(item.subjectName)
  101. })
  102. this.columnsOptions = list
  103. })
  104. },
  105. postDeal(){
  106. let data = {
  107. subjectId:this.form.id,
  108. amount:this.form.number,
  109. content:this.form.content
  110. }
  111. dealCourse(this.$route.params.id,data).then(res=>{
  112. this.$toast.success('交易成功')
  113. this.form.id = 0;
  114. this.form.number = 0;
  115. this.form.content = "";
  116. this.form.name = "";
  117. this.$router.go(-1)
  118. })
  119. },
  120. comfirm(){
  121. this.$dialog.confirm({
  122. title: '提示',
  123. message: '确认要提交当前名额交易吗?',
  124. }).then(() => {
  125. if(this.form.id != 0 && this.form.number != 0){
  126. this.postDeal();
  127. }else{
  128. this.$toast.fail('请填写正确的交易信息后提交')
  129. }
  130. })
  131. },
  132. onInput(key) {
  133. this.form.number = Number(`${this.form.number}${key}`)
  134. },
  135. onDelete() {
  136. this.form.number = Number(this.form.number.toString().slice(0,this.form.number.toString().length - 1))
  137. },
  138. onClickLeft() {
  139. this.$router.go(-1);
  140. },
  141. showPop() {
  142. this.popupShow = true;
  143. },
  144. onConfirm(e, index) {
  145. this.form.name = this.courseList[index].subjectName;
  146. this.form.id = this.courseList[index].subjectId;
  147. this.coursesUsable = this.courseList[index].amount;
  148. this.popupShow = false;
  149. }
  150. }
  151. };
  152. </script>
  153. <style scoped lang="scss">
  154. .page {
  155. background: #F3F2EE;
  156. background: linear-gradient(90deg, #F3F2EE, #E7EFF9);
  157. .orderContent {
  158. .form {
  159. .desc {
  160. padding: 0 0.2rem;
  161. font-size: 0.24rem;
  162. color: #888;
  163. line-height: 2;
  164. }
  165. .submit {
  166. margin-top: 0.5rem;
  167. display: flex;
  168. justify-content: space-around;
  169. align-items: center;
  170. }
  171. }
  172. }
  173. }
  174. </style>