my-cate.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view>
  3. <view class="card-view">
  4. <image src="../../static/img/train-banner2.png" mode="aspectFill" style="width: 100%;"></image>
  5. </view>
  6. <view class="card-view">
  7. <!-- <tui-divider width="80%" gradual>选择要常用的题库</tui-divider> -->
  8. <!-- <view class="margin">
  9. <tn-radio-group activeColor="#5677fc" v-model="kind" @change="changeKind">
  10. <tn-radio name="QUESTION">试题题库</tn-radio>
  11. <tn-radio name="PAPER">试卷题库</tn-radio>
  12. </tn-radio-group>
  13. </view> -->
  14. <tui-cascade-selection height="200px" :itemList="cateList" @complete="complete" text="请选择题库" :defaultItemList="defaultCateList"></tui-cascade-selection>
  15. </view>
  16. <view style="width:90%; margin: 10rpx auto;" class="padding-bottom-xl">
  17. <tui-button shape="circle" shadow bold preventClick @click="save">保存</tui-button>
  18. </view>
  19. <login ref="login" v-on:succ="getCate"></login>
  20. </view>
  21. </template>
  22. <script>
  23. import userApi from "@/common/api/user.js"
  24. export default {
  25. data() {
  26. return {
  27. page: '',
  28. cateList: [],
  29. cateId: 0,
  30. cateName: '',
  31. // questionCount: 0,
  32. kind: 'QUESTION',
  33. defaultCateList: [],
  34. selectItem: {},
  35. }
  36. },
  37. onLoad(e) {
  38. this.page = e?.page
  39. this.getCate('init')
  40. },
  41. methods: {
  42. // 获取题库
  43. getCate(type = '') {
  44. this.http('cate/getThree', {
  45. kind: this.kind
  46. }).then(res => {
  47. this.cateList = res.data
  48. // 模拟题库点击事件
  49. if (this.cateId) {
  50. this.complete({
  51. value: this.cateId,
  52. result: [
  53. {
  54. text: this.cateName
  55. }
  56. ]
  57. })
  58. }
  59. if (type == 'init') {
  60. let defaultCate = this.utils.getData('default_cate-' + this.kind)
  61. console.log('defaultCate', defaultCate)
  62. if (defaultCate) {
  63. let lastCate = [...defaultCate.result].pop()
  64. console.log('lastCate', lastCate)
  65. let defaultCateList = []
  66. for (var i = 0; i < defaultCate.result.length; i++) {
  67. defaultCateList.push(defaultCate.result[i].text)
  68. }
  69. this.defaultCateList = defaultCateList
  70. this.cateId = lastCate.value
  71. this.cateName = lastCate.text
  72. this.complete({
  73. value: this.cateId,
  74. result: [
  75. {
  76. text: this.cateName
  77. }
  78. ]
  79. })
  80. }
  81. }
  82. })
  83. },
  84. changeKind(e) {
  85. console.log('changeKind', e, this.kind)
  86. this.getCate('init')
  87. },
  88. // 选择题库
  89. complete(e) {
  90. console.log(e);
  91. console.log('您选择的数据为:', e);
  92. this.cateId = e.value
  93. this.cateName = e.result[e.result.length - 1].text
  94. this.selectItem = e
  95. },
  96. // 保存我常用的题库
  97. save() {
  98. if (!this.cateId) {
  99. this.utils.toast('请先选择题库')
  100. return
  101. }
  102. this.utils.setData('default_cate-' + this.kind, this.selectItem)
  103. this.utils.alert('保存成功', () => {
  104. this.utils.goback()
  105. })
  106. // userApi.saveMyCate(this, {cate_id: this.cateId}).then(res => {
  107. // console.log('saveMyCate res', res)
  108. // if (res.code == 1) {
  109. // this.utils.alert('保存成功')
  110. // setTimeout(() => {
  111. // this.utils.goback()
  112. // }, 1000)
  113. // } else {
  114. // this.utils.alert(res.msg)
  115. // }
  116. // })
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. .tn-radio__label {
  123. color: #333 !important;
  124. font-size: 15px !important;
  125. }
  126. </style>