| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- <template>
- <view class="container" :style="[showEdit ? 'padding-bottom:180rpx' : '', showPage ? 'overflow:hidden' : 'overflow:visible']">
- <!-- 背景图片区域 -->
- <img class="img_bg" src="../../static/images/center-bg.png" />
- <!-- 输入框和设置按钮区域 -->
- <view class="header">
- <view class="header_input">
- <uni-icons type="search" size="28" color="#808080" @click="changeInputValue"></uni-icons>
- <input v-model="keyWord" class="input" type="text" placeholder="请输入学生姓名" />
- </view>
- <view class="header_set" @click="handleClickSet">
- <uni-icons type="gear" size="28" color="#383838"></uni-icons>
- </view>
- </view>
- <!-- 功能按钮区域 -->
- <view class="school" v-if="list.length">
- <!-- 邀请家长按钮区域 -->
- <view v-if="!showEdit" class="invite" @click="handleInvitation">
- <uni-icons type="personadd" size="22" color="#0061FF"></uni-icons>
- 邀请家长
- </view>
- <!-- 批量修改按钮区域 -->
- <view v-if="!showEdit" class="school_edit" @click="handleEdit('修改')">
- <img class="img" src="@/static/images/edit2.png" />
- 批量修改
- </view>
- <!-- 添加按钮区域 -->
- <view v-if="!showEdit" class="add" @click="handleAdd">
- <uni-icons type="plus" size="22" color="#0061FF"></uni-icons>
- 添加
- </view>
- <!-- 删除按钮区域 -->
- <view v-if="!showEdit" class="delete" @click="handleDelete('删除')">
- <uni-icons type="trash" size="22" color="#D43030"></uni-icons>
- 批量删除
- </view>
- <!-- 全选按钮区域 -->
- <view v-if="showEdit" class="school_btn">
- <view class="cancel" @click="handleCancel">取消</view>
- <radio color="#0061FF" style="transform: scale(0.7)" :checked="allChecked" @click="handleAllCheck" />
- <view class="all">全选</view>
- </view>
- </view>
- <!-- 学生列表区域 -->
- <view class="list_box" v-if="list.length">
- <uni-swipe-action>
- <view v-for="(item, index) in list" :key="index">
- <uni-swipe-action-item :right-options="options" @click="onClickItem(item)">
- <!-- 每一个学生区域 -->
- <view class="item_box" @click="handleClickItem(item)">
- <view class="box_info">
- <image class="info_img" src="/static/images/header.png" mode="aspectFill"></image>
- <view class="info_msg">
- <view class="msg_name">
- {{ item.name }}
- </view>
- <view class="msg_no">
- {{ item.cardNo }}
- </view>
- </view>
- </view>
- <view class="box_time">{{ item.timeGroup }}</view>
- <radio v-if="showEdit" color="#0061FF" style="transform: scale(0.7)" :checked="item.isChecked" />
- </view>
- </uni-swipe-action-item>
- <view style="height: 20rpx"></view>
- </view>
- </uni-swipe-action>
- </view>
- <!-- 关联时间组按钮区域 -->
- <view class="btn" v-if="showEdit && currentType == '修改'">
- <view class="btn_box" @click="handleBind">
- <uni-icons color="#fff" type="link" size="28"></uni-icons>
- <text class="text">关联时间组</text>
- </view>
- </view>
- <!-- 批量删除区域 -->
- <view class="btn" v-if="showEdit && currentType == '删除'">
- <view class="btn_box delete" @click="handleDeleteBatch">
- <uni-icons color="#fff" type="trash" size="28"></uni-icons>
- <text class="text">批量删除</text>
- </view>
- </view>
- <!-- 没有数据时展示的页面 -->
- <NoData v-if="!list.length" style="margin-top: 140rpx" />
- <!-- 弹窗区域 -->
- <uni-popup ref="popupDom">
- <view class="pop_up">
- <!-- 头部标题区域 -->
- <view class="popup_top">{{ headerName }} - 关联时间组</view>
- <!-- 时间组区域 -->
- <view class="popup_body">
- <!-- 每一个时间组区域 -->
- <view class="time_item" v-for="item in timeGroups" :key="item.id" @click="handleClickItemPop(item)">
- <view class="item_left">
- <view class="top">{{ item.name }}</view>
- <view class="bottom">{{ item.remark }}</view>
- </view>
- <radio color="#0061FF" style="transform: scale(0.9)" :checked="item.isChecked" />
- </view>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script setup>
- import { ref } from 'vue'
- import { onLoad } from '@dcloudio/uni-app'
- import HeaderInput from '@/components/headerInput.vue'
- import NoData from '@/components/noData.vue'
- import { myRequest } from '@/utils/api.js'
- import { decryptDes } from '@/utils/des.js'
- // 当前所处班级
- const classInfo = ref()
- // 搜索框绑定数据
- const keyWord = ref('')
- // 学生列表数据
- const list = ref([])
- // 缓存数据
- const copyList = ref([])
- // 是否显示全选radio
- const showEdit = ref(false)
- // 是否全选
- const allChecked = ref(false)
- // 弹窗DOM
- const popupDom = ref()
- // 时间组列表
- const timeGroups = ref([])
- // 弹窗标题
- const headerName = ref('')
- // 当前学生id
- const studentId = ref()
- // 滚动穿透控制
- const showPage = ref(false)
- const options = [
- {
- text: '删除',
- style: {
- backgroundColor: '#D43030'
- }
- }
- ]
- const currentType = ref('')
- onLoad(() => {
- getData()
- })
- // 获取学生列表数据
- const getData = async () => {
- const res = await myRequest({
- url: '/wanzai/api/smartUser/queryClassUser',
- data: {
- userId: uni.getStorageSync('userInfo').id,
- keyWord: keyWord.value
- }
- })
- // console.log(res)
- const result = JSON.parse(decryptDes(res.data))
- // console.log(result)
- list.value = result.userDetails
- list.value.forEach((ele) => {
- ele.isChecked = false
- })
- classInfo.value = result.name
- uni.setNavigationBarTitle({
- title: result.name
- })
- }
- // 点击邀请家长按钮回调
- const handleInvitation = () => {
- uni.navigateTo({
- url: '/pages/invitation/invitation'
- })
- }
- // 点击批量按钮回调
- const handleEdit = (type) => {
- currentType.value = type
- showEdit.value = true
- copyList.value = JSON.parse(JSON.stringify(list.value))
- }
- // 点击添加按钮回调
- const handleAdd = () => {
- uni.navigateTo({
- url: '/pages/addStudent/addStudent'
- })
- }
- // 批量删除按钮回调
- const handleDelete = (type) => {
- currentType.value = type
- showEdit.value = true
- copyList.value = JSON.parse(JSON.stringify(list.value))
- }
- // 点击取消按钮回调
- const handleCancel = () => {
- currentType.value = ''
- showEdit.value = false
- allChecked.value = false
- list.value = copyList.value
- }
- // 点击全选按钮回调
- const handleAllCheck = () => {
- if (!allChecked.value) {
- list.value.forEach((ele) => {
- ele.isChecked = true
- })
- } else {
- list.value.forEach((ele) => {
- ele.isChecked = false
- })
- }
- allChecked.value = !allChecked.value
- }
- // 点击每一项删除回调
- const onClickItem = (item) => {
- uni.showModal({
- title: '提示',
- content: `确定把${item.name}移除吗?`,
- success: (res) => {
- if (res.confirm) {
- handleDeleteReq([item.id])
- }
- }
- })
- }
- // 删除请求
- const handleDeleteReq = async (ids) => {
- const res = await myRequest({
- url: '/wanzai/api/smartUser/appRemoveClass',
- method: 'post',
- data: {
- ids: ids
- }
- })
- // console.log(res)
- if (res.code == 200) {
- uni.showToast({
- title: res.message,
- icon: 'success'
- })
- setTimeout(() => {
- currentType.value = ''
- showEdit.value = false
- allChecked.value = false
- getData()
- }, 1500)
- }
- }
- // 点击每一个学生时的回调
- const handleClickItem = (item) => {
- if (showEdit.value) {
- item.isChecked = !item.isChecked
- // 判断全选按钮的状态
- allChecked.value = list.value.every((ele) => ele.isChecked)
- } else {
- // 编辑单个学生
- showPage.value = true
- headerName.value = item.name
- studentId.value = item.id
- getTimeGroups()
- popupDom.value.open('center')
- }
- }
- // 获取时间组列表数据
- const getTimeGroups = async () => {
- const res = await myRequest({
- url: '/wanzai/api/smartUser/timeGroups'
- })
- // console.log(res)
- const result = JSON.parse(decryptDes(res.data))
- // console.log(result)
- timeGroups.value = result
- timeGroups.value.forEach((ele) => {
- ele.isChecked = false
- })
- }
- // 点击弹窗每一个时间组的回调
- const handleClickItemPop = (item) => {
- timeGroups.value.forEach((ele) => {
- ele.isChecked = false
- })
- item.isChecked = !item.isChecked
- uni.showModal({
- title: '提示',
- content: '确定修改时间组吗?',
- success: async (res) => {
- if (res.confirm) {
- handleConfirm(item.id)
- }
- }
- })
- }
- const handleConfirm = async (timeGroupId) => {
- const res = await myRequest({
- url: '/wanzai/api/smartUser/setUserTimeGroup',
- method: 'post',
- data: {
- ids: [studentId.value],
- timeGroupId
- }
- })
- // console.log(res)
- uni.showToast({
- title: res.message,
- icon: 'none',
- mask: true
- })
- if (res.code == 200) {
- setTimeout(() => {
- uni.reLaunch({
- url: '/pages/studentManage/studentManage'
- })
- }, 1500)
- }
- }
- // 点击关联时间组按钮回调
- const handleBind = () => {
- // 判断是否选择了学生
- const flag = list.value.find((ele) => ele.isChecked)
- if (!flag) {
- uni.showToast({
- title: '请至少选择一名学生',
- icon: 'none',
- mask: true
- })
- } else {
- let arr = []
- list.value.forEach((ele) => {
- if (ele.isChecked) {
- arr.push(ele.id)
- }
- })
- uni.navigateTo({
- url: `/pages/timeGroup/timeGroup?ids=${JSON.stringify(arr)}`
- })
- }
- }
- // 批量删除按钮回调
- const handleDeleteBatch = () => {
- // 判断是否选择了学生
- const flag = list.value.find((ele) => ele.isChecked)
- if (!flag) {
- uni.showToast({
- title: '请至少选择一名学生',
- icon: 'none',
- mask: true
- })
- } else {
- uni.showModal({
- title: '提示',
- content: '确定批量移除吗?',
- success: (res) => {
- if (res.confirm) {
- let arr = []
- list.value.forEach((ele) => {
- if (ele.isChecked) {
- arr.push(ele.id)
- }
- })
- handleDeleteReq(arr)
- }
- }
- })
- }
- }
- // 输入框组件自定义事件
- const changeInputValue = () => {
- getData()
- }
- // 设置图标点击回调
- const handleClickSet = () => {
- uni.navigateTo({
- url: '/pages/set/set'
- })
- }
- </script>
- <style lang="scss" scoped>
- .container {
- display: flex;
- flex-direction: column;
- padding: 0 20rpx;
- min-height: 100vh;
- background-color: #f1f6fe;
- // 背景图片区域样式
- .img_bg {
- position: absolute;
- top: -70rpx;
- right: 0;
- width: 589rpx;
- height: 320rpx;
- pointer-events: none;
- }
- .header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding-top: 30rpx;
- .header_input {
- display: flex;
- align-items: center;
- box-sizing: border-box;
- padding-left: 40rpx;
- width: 589rpx;
- height: 100rpx;
- font-size: 28rpx;
- border-radius: 13rpx;
- border: 2rpx solid #cccccc;
- background-color: #fff;
- .input {
- padding: 0 20rpx;
- width: 425rpx;
- }
- }
- .header_set {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 100rpx;
- height: 100rpx;
- border-radius: 13rpx;
- border: 2rpx solid #cccccc;
- background-color: #fff;
- }
- }
- // 学校名称区域样式
- .school {
- display: flex;
- // justify-content: space-between;
- align-items: center;
- margin-top: 38rpx;
- color: #808080;
- font-size: 28rpx;
- .invite {
- display: flex;
- align-items: center;
- margin-right: 30rpx;
- color: #0061ff;
- }
- .school_edit {
- display: flex;
- align-items: center;
- margin-right: 80rpx;
- color: #00baad;
- .img {
- width: 45rpx;
- height: 45rpx;
- }
- }
- .add {
- display: flex;
- align-items: center;
- color: #0061ff;
- }
- .delete {
- display: flex;
- align-items: center;
- margin-left: auto;
- color: #d43030;
- }
- .school_btn {
- display: flex;
- align-items: center;
- .cancel {
- margin-right: 20rpx;
- color: #d43030;
- }
- .all {
- margin-left: -10rpx;
- }
- }
- }
- .list_box {
- padding-bottom: 30rpx;
- margin-top: 22rpx;
- background-color: #f1f6fe;
- .item_box {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 20rpx;
- height: 167rpx;
- font-size: 28rpx;
- border-radius: 8rpx;
- background-color: #fff;
- .box_info {
- display: flex;
- .info_img {
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- }
- .info_msg {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- margin-left: 28rpx;
- .msg_name {
- font-size: 32rpx;
- }
- .msg_no {
- color: #808080;
- }
- }
- }
- .box_time {
- }
- }
- }
- .btn {
- position: fixed;
- bottom: 0;
- padding: 0 30rpx 30rpx;
- background-color: #fff;
- .btn_box {
- display: flex;
- justify-content: center;
- align-items: center;
- margin-top: 28rpx;
- width: 650rpx;
- height: 100rpx;
- color: #fff;
- font-size: 32rpx;
- border-radius: 8rpx;
- background-color: #0061ff;
- .text {
- margin-left: 10rpx;
- }
- }
- .delete {
- background-color: #d43030;
- }
- }
- .pop_up {
- width: 710rpx;
- height: 855rpx;
- border-radius: 22rpx;
- background-color: #fff;
- .popup_top {
- height: 94rpx;
- line-height: 94rpx;
- text-align: center;
- font-size: 28rpx;
- border-bottom: 1rpx solid #e6e6e6;
- }
- .popup_body {
- height: 760rpx;
- overflow-y: auto;
- .time_item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 40rpx;
- height: 130rpx;
- border-bottom: 1rpx solid #e6e6e6;
- .item_left {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- height: 80rpx;
- .top {
- font-size: 28rpx;
- }
- .bottom {
- font-size: 24rpx;
- color: #b3b3b3;
- }
- }
- }
- }
- }
- }
- </style>
|