123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <template>
- <view class="content">
- <view class="one">
- <view class="one_1">
- <input type="text" v-model="name" @input="toInput" placeholder="搜索课程名称">
- </view>
- <view class="one_2">
- <button size="mini" class="button" type="primary" @click="toAdd">添加</button>
- </view>
- </view>
- <view class="two" v-if="total>0">
- <up-list @scrolltolower="scrolltolower">
- <up-list-item v-for="(item, index) in list" :key="index">
- <view class="list">
- <view class="name textOne">{{item.name||'暂无'}}</view>
- <view class="other_1">
- <view class="value">
- <view class="title">类型:</view>
- <view class="label">{{getDict(item.type,'type')}}</view>
- </view>
- <view class="value">
- <view class="title">学科:</view>
- <view class="label">{{getDict(item.subject,'subject')}}</view>
- </view>
- <view class="value">
- <view class="title">年级:</view>
- <view class="label">{{getDict(item.grade,'grade')}}</view>
- </view>
- </view>
- <view class="other_2">
- <view class="other_2_1">金额(元):</view>
- <view class="other_2_2 red">{{item.money||'免费'}}</view>
- </view>
- <view class="other_2">
- <view class="other_2_1">时间:</view>
- <view class="other_2_2 ">{{item.start_time}} - {{item.end_time}}</view>
- </view>
- <view class="other_2">
- <view class="other_2_1">状态:</view>
- <view class="other_2_2" :class="[item.status=='0'?'red':'']">
- {{getDict(item.status,'status')}}
- </view>
- </view>
- <view class="bottom">
- <button class="button button_1" type="default" size="mini" @click="toEdit(item)">修改</button>
- <button v-if="item.status=='0'" class="button button_2" type="default" size="mini" @click="toDelete(item)">删除</button>
- </view>
- </view>
- </up-list-item>
- </up-list>
- </view>
- <up-empty v-else mode="list" icon="/static/list.png">
- </up-empty>
- <view class="is_bottom" v-if="is_bottom">
- <text>{{config.bottom_title||'没有更多了!'}}</text>
- </view>
- </view>
- </template>
- <script setup lang="ts">
- import { inject, computed, ref } from 'vue';
- //该依赖已内置不需要单独安装
- import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
- // 请求接口
- const $api = inject('$api');
- // 基本信息
- const config = ref({ logo: [], file: [] });
- // 列表
- const list = ref([]);
- const total = ref(0);
- const skip = ref(0);
- const limit = ref(5);
- const page = ref(0);
- // 数据是否触底
- const is_bottom = ref(false);
- const name = ref('');
- // 字典表
- const subjectList = ref([])
- const gradeList = ref([])
- const showList = ref([])
- const typeList = ref([])
- const statusList = ref([])
- // user
- const user = computed(() => {
- return uni.getStorageSync('user');
- })
- onShow(async () => {
- await searchConfig();
- await searchOther();
- await clearPage();
- await search();
- })
- onPullDownRefresh(async () => {
- await clearPage();
- await search();
- uni.stopPullDownRefresh();
- })
- // config信息
- const searchConfig = async () => {
- config.value = uni.getStorageSync('config');
- };
- // 其他查询信息
- const searchOther = async () => {
- let res;
- // 学科
- res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
- if (res.errcode === 0) subjectList.value = res.data;
- // 年级
- res = await $api(`dictData`, 'GET', { code: 'grade', is_use: '0' });
- if (res.errcode === 0) gradeList.value = res.data;
- // 类型
- res = await $api(`dictData`, 'GET', { code: 'courseType', is_use: '0' });
- if (res.errcode === 0) typeList.value = res.data;
- // 状态
- res = await $api(`dictData`, 'GET', { code: 'courseStatus', is_use: '0' });
- if (res.errcode === 0) statusList.value = res.data;
- // 是否公开
- res = await $api(`dictData`, 'GET', { code: 'show', is_use: '0' });
- if (res.errcode === 0) showList.value = res.data;
- };
- // 查询
- const search = async () => {
- const info : any = {
- skip: skip.value,
- limit: limit.value,
- teacher: user.value._id,
- is_show: '0'
- }
- if (name.value) info.name = name.value
- const res = await $api('course', 'GET', info);
- if (res.errcode === 0) {
- list.value = list.value.concat(res.data)
- total.value = res.total
- } else {
- uni.showToast({
- title: res.errmsg || '',
- icon: 'error',
- });
- }
- };
- const getDict = (data, model) => {
- let res
- if (model == 'subject') res = subjectList.value.find((f) => f.value == data)
- else if (model == 'grade') res = gradeList.value.find((f) => f.value == data)
- else if (model == 'type') res = typeList.value.find((f) => f.value == data)
- else if (model == 'status') res = statusList.value.find((f) => f.value == data)
- return res.label || '暂无'
- }
- // 搜索课程
- const toInput = async (e) => {
- await clearPage();
- await search();
- };
- // 新增课程
- const toAdd = async () => {
- uni.navigateTo({
- url: `/pagesMy/course/add`
- })
- };
- // 修改
- const toEdit = async (item) => {
- uni.navigateTo({
- url: `/pagesMy/course/add?id=${item.id || item._id}`
- })
- };
- // 删除
- const toDelete = async () => {
- uni.showModal({
- title: '提示',
- content: '确定删除该课程吗?',
- success: async function (res) {
- if (res.confirm) {
- const arr = await $api(`course/${e._id}`, 'DELETE');
- if (arr.errcode == '0') {
- uni.showToast({
- title: '删除信息成功',
- icon: 'none'
- })
- await clearPage()
- await search()
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'none'
- })
- }
- }
- }
- });
- };
- const scrolltolower = () => {
- if (total.value > list.value.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- page.value = page.value + 1;
- skip.value = page.value * limit.value;
- search();
- uni.hideLoading();
- } else is_bottom.value = true
- };
- // 清空列表
- const clearPage = () => {
- list.value = []
- skip.value = 0
- limit.value = 6
- page.value = 0
- };
- </script>
- <style lang="scss" scoped>
- .content {
- display: flex;
- flex-direction: column;
- min-height: 100vh;
- background-color: var(--f1Color);
- .one {
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 2vw;
- background-color: var(--mainColor);
- .one_1 {
- padding: 0 2vw;
- width: 75vw;
- input {
- padding: 2vw;
- background-color: var(--f1Color);
- font-size: var(--font14Size);
- border-radius: 5px;
- }
- }
- .button {
- background-color: var(--3c9Color);
- color: var(--mainColor);
- }
- }
- .two {
- margin: 0 2vw;
- .list {
- background-color: var(--mainColor);
- border-bottom: 1px solid var(--f5Color);
- margin: 2vw 0 0 0;
- border-radius: 4px;
- padding: 2vw;
- .name {
- font-size: var(--font16Size);
- font-weight: bold;
- margin: 0 2vw 2vw 2vw;
- }
- .other_1 {
- display: flex;
- justify-content: space-between;
- padding: 1vw 2vw;
- .value {
- display: flex;
- align-items: center;
- .title {
- font-size: var(--font14Size);
- font-weight: bold;
- }
- .label {
- font-size: var(--font12Size);
- color: var(--f85Color);
- }
- }
- }
- .other_2 {
- display: flex;
- align-items: center;
- padding: 1vw 2vw;
- .other_2_1 {
- font-size: var(--font14Size);
- font-weight: bold;
- }
- .other_2_2 {
- width: 70%;
- font-size: var(--font12Size);
- color: var(--f85Color);
- }
- .red {
- color: var(--ff0Color);
- }
- }
- .bottom {
- margin: 2vw 0 0 0;
- text-align: center;
- .button {
- color: var(--mainColor);
- font-size: var(--font14Size);
- border-radius: 2vw;
- }
- .button_1 {
- margin: 0 2vw 0 0;
- background-color: var(--3c9Color);
- }
- .button_2 {
- background-color: var(--ff0Color);
- }
- }
- }
- }
- }
- </style>
|