QYF-GitLab1
14 小时以前 e1f87494b737169c412ca723baf3085cb0c5706e
src/views/personalCenter/course.vue
@@ -3,20 +3,13 @@
    <div class="personalPage-title">我的课程</div>
    <div class="headerBox">
      <div class="searchBox">
        <el-input
          v-model="searchKey"
          clearable
          @clear="getData"
          placeholder="请输入关键字"
        >
        <el-input v-model="searchKey" clearable @clear="getData" placeholder="请输入关键字">
          <template #append>
            <el-button type="primary" class="searchBtn" :icon="Search" @click="getData" />
          </template>
        </el-input>
      </div>
      <el-button type="primary" class="applyStartClasses" @click="applyCourse"
        >申请开课</el-button
      >
      <el-button type="primary" class="applyStartClasses" @click="applyCourse">申请开课</el-button>
    </div>
    <div class="courseListBox" v-loading="pages.loading">
      <div
@@ -34,7 +27,7 @@
              <div style="width: 300px" v-html="item.reason"></div>
            </template>
            <span v-if="item.applyState == 'Reject'" style="color: red">
              拒绝原因:{{ item.reason != "" ? item.reason : "-" }}
              拒绝原因:{{ item.reason != '' ? item.reason : '-' }}
            </span>
          </el-tooltip>
          <el-button
@@ -63,11 +56,7 @@
            >
              审核中
            </div>
            <div
              class="stateIcon"
              v-if="item.applyState == 'Reject'"
              style="background-color: red"
            >
            <div class="stateIcon" v-if="item.applyState == 'Reject'" style="background-color: red">
              未通过
            </div>
            <img v-if="item.icon" :src="item.icon" />
@@ -97,13 +86,8 @@
    </div>
    <!-- 申请开课弹框 -->
    <el-dialog v-model="applyCourseDialog" width="750" align-center>
      <template #title>{{ editData ? "重新申请" : "申请开课" }}</template>
      <el-form
        :model="formData"
        label-position="left"
        ref="dialogFormRef"
        label-width="80px"
      >
      <template #title>{{ editData ? '重新申请' : '申请开课' }}</template>
      <el-form :model="formData" label-position="left" ref="dialogFormRef" label-width="80px">
        <el-form-item
          label="课程名称"
          prop="name"
@@ -137,9 +121,7 @@
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="applyCourseDialog = false">取消</el-button>
          <el-button type="primary" @click="submit" :loading="submitLoading"
            >提交</el-button
          >
          <el-button type="primary" @click="submit" :loading="submitLoading">提交</el-button>
        </div>
      </template>
    </el-dialog>
@@ -156,37 +138,21 @@
              placeholder="请输入关键字"
            >
              <template #append>
                <el-button
                  type="primary"
                  class="searchBtn"
                  :icon="Search"
                  @click="getTextBook"
                />
                <el-button type="primary" class="searchBtn" :icon="Search" @click="getTextBook" />
              </template>
            </el-input>
          </div>
        </div>
        <div style="min-height: 370px" v-if="textBookListData.length > 0">
          <div
            v-for="(item, index) in textBookListData"
            :key="index"
            class="textBookItem"
          >
            <el-checkbox
              class="checkBox"
              v-model="item.check"
              @change="selectChange(item)"
            />
          <div v-for="(item, index) in textBookListData" :key="index" class="textBookItem">
            <el-checkbox class="checkBox" v-model="item.check" @change="selectChange(item)" />
            <div class="imgBox autoImgBox">
              <img :src="item.img" />
            </div>
            <p>{{ item.product.name }}</p>
          </div>
        </div>
        <div
          class="nullBox"
          v-if="!textBookPages.loading && textBookListData.length == 0"
        >
        <div class="nullBox" v-if="!textBookPages.loading && textBookListData.length == 0">
          <el-empty />
        </div>
      </div>
@@ -211,137 +177,137 @@
</template>
<script setup lang="ts">
import { reactive, ref, onMounted, inject, watch } from "vue";
import { Search } from "@element-plus/icons-vue";
import { useRouter, useRoute } from "vue-router";
import { ElMessage } from "element-plus";
import { reactive, ref, onMounted, inject, watch } from 'vue'
import { Search } from '@element-plus/icons-vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
// eslint-disable-next-line
import { getPublicImage } from "@/assets/js/middleGround/tool.js";
import { getPublicImage } from '@/assets/js/middleGround/tool.js'
// eslint-disable-next-line
import defaultImg from "@/assets/images/default-book-img.png";
import defaultImg from '@/assets/images/default-book-img.png'
const router: any = useRouter();
const route: any = useRoute();
const MG: any = inject("MG");
const selectName = ref("");
const router: any = useRouter()
const route: any = useRoute()
const MG: any = inject('MG')
const selectName = ref('')
// 申请开课防抖loading
const submitLoading = ref(false);
const submitLoading = ref(false)
const courseList: any = ref([]);
const courseList: any = ref([])
onMounted(() => {
  getData();
});
  getData()
})
const searchKey = ref("");
const searchKey = ref('')
const pages = reactive({
  page: 1,
  pageSize: 6,
  count: 0,
  loading: true,
});
})
// 获取课程
const getData = () => {
  pages.loading = true;
  pages.loading = true
  MG.edu
    .getAppCourseList({
      size: pages.pageSize,
      start: pages.pageSize * pages.page - pages.pageSize,
      sort: {
        type: "Desc",
        field: "CreateDate",
        type: 'Desc',
        field: 'CreateDate',
      },
      filterList: [],
      searchList: searchKey.value
        ? [
            {
              keywords: searchKey.value,
              field: "Name",
              compareType: "Contains",
              field: 'Name',
              compareType: 'Contains',
            },
          ]
        : [],
    })
    .then((res: any) => {
      pages.loading = false;
      pages.count = res.totalSize;
      pages.loading = false
      pages.count = res.totalSize
      courseList.value = res.datas.map((item: any) => {
        return {
          ...item,
          name: item.name,
          id: item.id,
          icon: item.icon != "default" ? getPublicImage(item.icon, 80) : defaultImg,
          icon: item.icon != 'default' ? getPublicImage(item.icon, 80) : defaultImg,
          introduction: item.description,
          reason: item.applyReturnMsg ? JSON.parse(item.applyReturnMsg).reason : "",
        };
      });
    });
};
          reason: item.applyReturnMsg ? JSON.parse(item.applyReturnMsg).reason : '',
        }
      })
    })
}
// 申请开课
const applyCourse = () => {
  editData.value = null;
  editData.value = null
  formData.value = {
    name: "",
    bookName: "",
    bookId: "",
    selectData: "",
    desc: "",
  };
  applyCourseDialog.value = true;
};
    name: '',
    bookName: '',
    bookId: '',
    selectData: '',
    desc: '',
  }
  applyCourseDialog.value = true
}
const editData: any = ref(null);
const editData: any = ref(null)
const reapplyCourse = (data: any) => {
  editData.value = data;
  editData.value = data
  formData.value = {
    name: data.name,
    bookName: data.linkProduct.name,
    bookId: data.linkProduct.id,
    selectData: "",
    selectData: '',
    desc: data.description,
  };
  applyCourseDialog.value = true;
};
  }
  applyCourseDialog.value = true
}
// 申请教材弹框
const applyCourseDialog = ref(false);
const selectTextBookDialog = ref(false);
const applyCourseDialog = ref(false)
const selectTextBookDialog = ref(false)
const formData = ref({
  name: "",
  bookName: "",
  bookId: "",
  selectData: "",
  desc: "",
});
  name: '',
  bookName: '',
  bookId: '',
  selectData: '',
  desc: '',
})
const selectChange = (select: any) => {
  for (let i = 0; i < textBookListData.value.length; i++) {
    const item: any = textBookListData.value[i];
    const item: any = textBookListData.value[i]
    if (item.id == select.id) {
      item.check = true;
      item.check = true
    } else {
      item.check = false;
      item.check = false
    }
  }
};
}
const selectTextBookSubmit = () => {
  const selectData: any = textBookListData.value.filter((item: any) => item.check)[0];
  const selectData: any = textBookListData.value.filter((item: any) => item.check)[0]
  if (!selectData?.product?.id) {
    ElMessage.warning("请选择开课教材!");
    return false;
    ElMessage.warning('请选择开课教材!')
    return false
  }
  formData.value.bookId = selectData.product.id;
  formData.value.bookName = selectData.product.name;
  formData.value.selectData = selectData;
  selectTextBookDialog.value = false;
};
  formData.value.bookId = selectData.product.id
  formData.value.bookName = selectData.product.name
  formData.value.selectData = selectData
  selectTextBookDialog.value = false
}
const submit = () => {
  submitLoading.value = true;
  submitLoading.value = true
  if (editData.value) {
    MG.edu
      .updateCourse({
@@ -359,36 +325,36 @@
            }),
          })
          .then((ares: any) => {
            ElMessage.success("课程已重新申请,等待管理员审核。");
            applyCourseDialog.value = false;
            getData();
          });
      });
            ElMessage.success('课程已重新申请,等待管理员审核。')
            applyCourseDialog.value = false
            getData()
          })
      })
  } else {
    if (formData.value.name == "") {
    if (formData.value.name == '') {
      ElMessage({
        type: "warning",
        message: "请填写课程名称",
      });
      submitLoading.value = false;
      return false;
        type: 'warning',
        message: '请填写课程名称',
      })
      submitLoading.value = false
      return false
    }
    if (!formData.value.bookId) {
      ElMessage({
        type: "warning",
        message: "请选择关联教材",
      });
      submitLoading.value = false;
      return false;
        type: 'warning',
        message: '请选择关联教材',
      })
      submitLoading.value = false
      return false
    }
    MG.edu
      .applyNewCourse({
        name: formData.value.name,
        description: formData.value.desc,
        content: "",
        icon: formData.value.selectData.product.icon ?? "default",
        type: "course",
        config: "",
        content: '',
        icon: formData.value.selectData.product.icon ?? 'default',
        type: 'course',
        config: '',
        applyData: JSON.stringify({
          textBookId: formData.value.bookId,
          textBookName: formData.value.bookName,
@@ -399,17 +365,17 @@
      })
      .then((res: any) => {
        if (res) {
          ElMessage.success("课程已申请,等待管理员审核。");
          applyCourseDialog.value = false;
          getData();
          ElMessage.success('课程已申请,等待管理员审核。')
          applyCourseDialog.value = false
          getData()
        }
      });
      })
  }
  formData.value.selectData = "";
  formData.value.selectData = ''
  setTimeout(() => {
    submitLoading.value = false;
  }, 1000);
};
    submitLoading.value = false
  }, 1000)
}
// 获取已购买的教材列表
const textBookPages = reactive({
@@ -417,77 +383,77 @@
  pageSize: 12,
  count: 0,
  loading: false,
});
const textBookListData = ref([]);
})
const textBookListData = ref([])
const getTextBook = () => {
  textBookPages.loading = true;
  textBookPages.loading = true
  const searchData = [
    {
      keywords: "digitalTextbooks",
      field: "ProductType",
      keywords: 'digitalTextbooks',
      field: 'ProductType',
    },
    {
      keywords: "mediaBook",
      field: "ProductType",
      keywords: 'mediaBook',
      field: 'ProductType',
    },
    {
      keywords: selectName.value,
      field: "ProductName",
      field: 'ProductName',
    },
  ];
  ]
  const data = {
    Size: textBookPages.pageSize,
    Start: textBookPages.pageSize * textBookPages.page - textBookPages.pageSize,
    sort: {
      type: "Desc",
      field: "CreateDate",
      type: 'Desc',
      field: 'CreateDate',
    },
    searchList: searchData,
  };
  }
  MG.store
    .getPurchasedProductList(data)
    .then((res: any) => {
      textBookPages.count = res.totalSize;
      textBookPages.count = res.totalSize
      textBookListData.value = res.datas.map((item: any) => {
        return {
          ...item,
          img: item.product.icon ? getPublicImage(item.product.icon, 80) : defaultImg,
        };
      });
      textBookPages.loading = false;
        }
      })
      textBookPages.loading = false
    })
    .catch(() => {
      textBookPages.loading = false;
    });
};
      textBookPages.loading = false
    })
}
// 选择教材
const selectBook = () => {
  selectTextBookDialog.value = true;
  textBookListData.value = [];
  getTextBook();
};
  selectTextBookDialog.value = true
  textBookListData.value = []
  getTextBook()
}
const pageChange = (val: any) => {
  pages.page = val;
  getData();
};
  pages.page = val
  getData()
}
const handleCurrentChange = (val: any) => {
  textBookPages.page = val;
  getTextBook();
};
  textBookPages.page = val
  getTextBook()
}
const gotoDetail = (data: any) => {
  if (data.applyState == "Normal") {
  if (data.applyState == 'Normal') {
    router.push({
      name: "courseDetail",
      name: 'courseDetail',
      query: {
        courseId: data.id,
      },
    });
    })
  }
};
}
</script>
<style lang="less" scoped>
@@ -520,7 +486,7 @@
    .courseItem {
      float: left;
      width: 46%;
      width: 45%;
      height: 210px;
      margin: 0 2% 20px;
      border-radius: 8px;
@@ -561,6 +527,7 @@
      .itemInfo {
        padding: 10px 20px;
        box-sizing: border-box;
        flex: 1;
        display: flex;
        .imgBox {