index.vue 8.1 KB

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