index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="one_1">
  5. <input type="text" v-model="name" @input="toInput" placeholder="搜索课程名称">
  6. </view>
  7. <view class="one_2">
  8. <button size="mini" class="button" type="primary" @click="toAdd">添加</button>
  9. </view>
  10. </view>
  11. <view class="two" v-if="total>0">
  12. <up-list @scrolltolower="scrolltolower">
  13. <up-list-item v-for="(item, index) in list" :key="index">
  14. <view class="list">
  15. <view class="name textOne">{{item.name||'暂无'}}</view>
  16. <view class="other_1">
  17. <view class="value">
  18. <view class="title">类型:</view>
  19. <view class="label">{{getDict(item.type,'type')}}</view>
  20. </view>
  21. <view class="value">
  22. <view class="title">学科:</view>
  23. <view class="label">{{getDict(item.subject,'subject')}}</view>
  24. </view>
  25. <view class="value">
  26. <view class="title">年级:</view>
  27. <view class="label">{{getDict(item.grade,'grade')}}</view>
  28. </view>
  29. </view>
  30. <view class="other_2">
  31. <view class="other_2_1">金额(元):</view>
  32. <view class="other_2_2 red">¥{{item.money||'免费'}}</view>
  33. </view>
  34. <view class="other_2">
  35. <view class="other_2_1">时间:</view>
  36. <view class="other_2_2 ">{{item.start_time}} - {{item.end_time}}</view>
  37. </view>
  38. <view class="other_2">
  39. <view class="other_2_1">状态:</view>
  40. <view class="other_2_2" :class="[item.status=='0'?'red':'']">
  41. {{getDict(item.status,'status')}}
  42. </view>
  43. </view>
  44. <view class="bottom">
  45. <button class="button button_1" type="default" size="mini" @click="toEdit(item)">修改</button>
  46. <button v-if="item.status=='0'" class="button button_2" type="default" size="mini"
  47. @click="toDelete(item)">删除</button>
  48. </view>
  49. </view>
  50. </up-list-item>
  51. </up-list>
  52. </view>
  53. <up-empty v-else mode="list" icon="/static/list.png">
  54. </up-empty>
  55. <view class="is_bottom" v-if="is_bottom">
  56. <text>{{config.bottom_title||'没有更多了!'}}</text>
  57. </view>
  58. </view>
  59. </template>
  60. <script setup lang="ts">
  61. import { inject, computed, ref } from 'vue';
  62. //该依赖已内置不需要单独安装
  63. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  64. // 请求接口
  65. const $api = inject('$api');
  66. // 基本信息
  67. const config = ref({ logo: [], file: [] });
  68. // 列表
  69. const list = ref([]);
  70. const total = ref(0);
  71. const skip = ref(0);
  72. const limit = ref(5);
  73. const page = ref(0);
  74. // 数据是否触底
  75. const is_bottom = ref(false);
  76. const name = ref('');
  77. // 字典表
  78. const subjectList = ref([])
  79. const gradeList = ref([])
  80. const showList = ref([])
  81. const typeList = ref([])
  82. const statusList = ref([])
  83. // user
  84. const user = computed(() => {
  85. return uni.getStorageSync('user');
  86. })
  87. onShow(async () => {
  88. await searchConfig();
  89. await searchOther();
  90. await clearPage();
  91. await search();
  92. })
  93. onPullDownRefresh(async () => {
  94. await clearPage();
  95. await search();
  96. uni.stopPullDownRefresh();
  97. })
  98. // config信息
  99. const searchConfig = async () => {
  100. config.value = uni.getStorageSync('config');
  101. };
  102. // 其他查询信息
  103. const searchOther = async () => {
  104. let res;
  105. // 学科
  106. res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
  107. if (res.errcode === 0) subjectList.value = res.data;
  108. // 年级
  109. res = await $api(`dictData`, 'GET', { code: 'grade', is_use: '0' });
  110. if (res.errcode === 0) gradeList.value = res.data;
  111. // 类型
  112. res = await $api(`dictData`, 'GET', { code: 'courseType', is_use: '0' });
  113. if (res.errcode === 0) typeList.value = res.data;
  114. // 状态
  115. res = await $api(`dictData`, 'GET', { code: 'courseStatus', is_use: '0' });
  116. if (res.errcode === 0) statusList.value = res.data;
  117. // 是否公开
  118. res = await $api(`dictData`, 'GET', { code: 'show', is_use: '0' });
  119. if (res.errcode === 0) showList.value = res.data;
  120. };
  121. // 查询
  122. const search = async () => {
  123. const info : any = {
  124. skip: skip.value,
  125. limit: limit.value,
  126. teacher: user.value._id,
  127. is_show: '0'
  128. }
  129. if (name.value) info.name = name.value
  130. const res = await $api('course', 'GET', info);
  131. if (res.errcode === 0) {
  132. list.value = list.value.concat(res.data)
  133. total.value = res.total
  134. } else {
  135. uni.showToast({
  136. title: res.errmsg || '',
  137. icon: 'error',
  138. });
  139. }
  140. };
  141. const getDict = (data, model) => {
  142. let res
  143. if (model == 'subject') res = subjectList.value.find((f) => f.value == data)
  144. else if (model == 'grade') res = gradeList.value.find((f) => f.value == data)
  145. else if (model == 'type') res = typeList.value.find((f) => f.value == data)
  146. else if (model == 'status') res = statusList.value.find((f) => f.value == data)
  147. return res.label || '暂无'
  148. }
  149. // 搜索课程
  150. const toInput = async (e) => {
  151. await clearPage();
  152. await search();
  153. };
  154. // 新增课程
  155. const toAdd = async () => {
  156. uni.navigateTo({
  157. url: `/pagesMy/course/add`
  158. })
  159. };
  160. // 修改
  161. const toEdit = async (item) => {
  162. uni.navigateTo({
  163. url: `/pagesMy/course/add?id=${item.id || item._id}`
  164. })
  165. };
  166. // 删除
  167. const toDelete = async () => {
  168. uni.showModal({
  169. title: '提示',
  170. content: '确定删除该课程吗?',
  171. success: async function (res) {
  172. if (res.confirm) {
  173. const arr = await $api(`course/${e._id}`, 'DELETE');
  174. if (arr.errcode == '0') {
  175. uni.showToast({
  176. title: '删除信息成功',
  177. icon: 'none'
  178. })
  179. await clearPage()
  180. await search()
  181. } else {
  182. uni.showToast({
  183. title: arr.errmsg,
  184. icon: 'none'
  185. })
  186. }
  187. }
  188. }
  189. });
  190. };
  191. const scrolltolower = () => {
  192. if (total.value > list.value.length) {
  193. uni.showLoading({
  194. title: '加载中',
  195. mask: true
  196. })
  197. page.value = page.value + 1;
  198. skip.value = page.value * limit.value;
  199. search();
  200. uni.hideLoading();
  201. } else is_bottom.value = true
  202. };
  203. // 清空列表
  204. const clearPage = () => {
  205. list.value = []
  206. skip.value = 0
  207. limit.value = 6
  208. page.value = 0
  209. };
  210. </script>
  211. <style lang="scss" scoped>
  212. .content {
  213. display: flex;
  214. flex-direction: column;
  215. min-height: 100vh;
  216. background-color: var(--f1Color);
  217. .one {
  218. display: flex;
  219. justify-content: center;
  220. align-items: center;
  221. padding: 2vw;
  222. background-color: var(--mainColor);
  223. .one_1 {
  224. padding: 0 2vw;
  225. width: 75vw;
  226. input {
  227. padding: 2vw;
  228. background-color: var(--f1Color);
  229. font-size: var(--font14Size);
  230. border-radius: 5px;
  231. }
  232. }
  233. .button {
  234. background-color: var(--3c9Color);
  235. color: var(--mainColor);
  236. }
  237. }
  238. .two {
  239. margin: 0 2vw;
  240. .list {
  241. background-color: var(--mainColor);
  242. border-bottom: 1px solid var(--f5Color);
  243. margin: 2vw 0 0 0;
  244. border-radius: 4px;
  245. padding: 2vw;
  246. .name {
  247. font-size: var(--font16Size);
  248. font-weight: bold;
  249. margin: 0 2vw 2vw 2vw;
  250. }
  251. .other_1 {
  252. display: flex;
  253. justify-content: space-between;
  254. padding: 1vw 2vw;
  255. .value {
  256. display: flex;
  257. align-items: center;
  258. .title {
  259. font-size: var(--font14Size);
  260. font-weight: bold;
  261. }
  262. .label {
  263. font-size: var(--font12Size);
  264. color: var(--f85Color);
  265. }
  266. }
  267. }
  268. .other_2 {
  269. display: flex;
  270. align-items: center;
  271. padding: 1vw 2vw;
  272. .other_2_1 {
  273. font-size: var(--font14Size);
  274. font-weight: bold;
  275. }
  276. .other_2_2 {
  277. width: 70%;
  278. font-size: var(--font12Size);
  279. color: var(--f85Color);
  280. }
  281. .red {
  282. color: var(--ff0Color);
  283. }
  284. }
  285. .bottom {
  286. margin: 2vw 0 0 0;
  287. text-align: center;
  288. .button {
  289. color: var(--mainColor);
  290. font-size: var(--font14Size);
  291. border-radius: 2vw;
  292. }
  293. .button_1 {
  294. margin: 0 2vw 0 0;
  295. background-color: var(--3c9Color);
  296. }
  297. .button_2 {
  298. background-color: var(--ff0Color);
  299. }
  300. }
  301. }
  302. }
  303. .is_bottom {
  304. width: 100%;
  305. text-align: center;
  306. text {
  307. padding: 2vw 0;
  308. display: inline-block;
  309. color: var(--f85Color);
  310. font-size: var(--font12Size);
  311. }
  312. }
  313. }
  314. </style>