dealOrder.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: '40%' }">
  53. <van-picker
  54. title="选择课程"
  55. show-toolbar
  56. :columns="columnsOptions"
  57. @confirm="onConfirm"
  58. @cancel="popupShow = false"
  59. />
  60. </van-popup>
  61. <van-number-keyboard
  62. :show="numberShow"
  63. @blur="numberShow = false"
  64. @input="onInput"
  65. @delete="onDelete"
  66. />
  67. </div>
  68. </template>
  69. <script>
  70. import {getDealerCourseList,dealCourse} from '../api'
  71. import Vue from "vue";
  72. import { NumberKeyboard } from "vant";
  73. Vue.use(NumberKeyboard);
  74. export default {
  75. name: "dealOrder",
  76. components: {},
  77. data() {
  78. return {
  79. numberShow: false,
  80. popupShow: false,
  81. form: {
  82. name: "",
  83. id: 0,
  84. number: 0,
  85. content: ""
  86. },
  87. coursesUsable: 0,
  88. courseList:[],
  89. columnsOptions:[]
  90. };
  91. },
  92. created() {
  93. this.getCourseList();
  94. },
  95. methods: {
  96. //获取可交易的课程
  97. getCourseList(){
  98. getDealerCourseList().then(res=>{
  99. this.courseList = res.list;
  100. let list = [];
  101. res.list.forEach(item=>{
  102. list.push(item.subjectName)
  103. })
  104. this.columnsOptions = list
  105. })
  106. },
  107. //交易
  108. postDeal(){
  109. let data = {
  110. subjectId:this.form.id,
  111. amount:this.form.number,
  112. content:this.form.content
  113. }
  114. dealCourse(this.$route.params.id,data).then(res=>{
  115. this.$toast.success('交易成功')
  116. this.form.id = 0;
  117. this.form.number = 0;
  118. this.form.content = "";
  119. this.form.name = "";
  120. this.$router.go(-1)
  121. })
  122. },
  123. //交易提示
  124. comfirm(){
  125. this.$dialog.confirm({
  126. title: '提示',
  127. message: '确认要提交当前名额交易吗?',
  128. }).then(() => {
  129. if(this.form.id != 0 && this.form.number != 0){
  130. this.postDeal();
  131. }else{
  132. this.$toast.fail('请填写正确的交易信息后提交')
  133. }
  134. })
  135. },
  136. //数字输入框加
  137. onInput(key) {
  138. this.form.number = Number(`${this.form.number}${key}`)
  139. },
  140. //数字输入框减
  141. onDelete() {
  142. this.form.number = Number(this.form.number.toString().slice(0,this.form.number.toString().length - 1))
  143. },
  144. //返回
  145. onClickLeft() {
  146. this.$router.go(-1);
  147. },
  148. //显示课程选择
  149. showPop() {
  150. this.popupShow = true;
  151. },
  152. //课程选择确认
  153. onConfirm(e, index) {
  154. this.form.name = this.courseList[index].subjectName;
  155. this.form.id = this.courseList[index].subjectId;
  156. this.coursesUsable = this.courseList[index].amount;
  157. this.popupShow = false;
  158. }
  159. }
  160. };
  161. </script>
  162. <style scoped lang="scss">
  163. .page {
  164. background: #F3F2EE;
  165. background: linear-gradient(90deg, #F3F2EE, #E7EFF9);
  166. .orderContent {
  167. .form {
  168. .desc {
  169. padding: 0 0.2rem;
  170. font-size: 0.24rem;
  171. color: #888;
  172. line-height: 2;
  173. }
  174. .submit {
  175. margin-top: 0.5rem;
  176. display: flex;
  177. justify-content: space-around;
  178. align-items: center;
  179. }
  180. }
  181. }
  182. }
  183. </style>