加入了搜索功能
This commit is contained in:
@ -1,13 +1,45 @@
|
||||
// pages/course/searchCourses/searchCourses.js
|
||||
import { baseUrl, globalImgUrl } from "../../../request";
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
courseList: [],
|
||||
searchKeyword: '',
|
||||
globalImgUrl,
|
||||
},
|
||||
|
||||
// 每次用户输入都会进这里
|
||||
onSearchInput(e) {
|
||||
this.setData({
|
||||
searchKeyword: e.detail.value
|
||||
});
|
||||
},
|
||||
gotoCourseDetail(e) {
|
||||
const courseId = e.currentTarget.dataset.id;
|
||||
wx.navigateTo({
|
||||
url: `/pages/course/courseDetail/courseDetail?id=${courseId}`,
|
||||
});
|
||||
},
|
||||
onSearch() {
|
||||
const token = wx.getStorageSync('token')
|
||||
const { searchKeyword } = this.data
|
||||
wx.request({
|
||||
url: baseUrl + '/course/query/keyword',
|
||||
header: {
|
||||
Authorization: token
|
||||
},
|
||||
method: 'POST',
|
||||
data: {
|
||||
templateString: searchKeyword
|
||||
},
|
||||
success: res => {
|
||||
let result = res.data.data
|
||||
this.setData({courseList: result})
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
|
@ -5,20 +5,20 @@
|
||||
class="image"
|
||||
src="./images/sousuo.png"
|
||||
/>
|
||||
<input class="text ml-3" placeholder="搜索更多好课" />
|
||||
<input class="text ml-3" placeholder="搜索更多好课" bindinput="onSearchInput" confirm-type="search" bindconfirm="onSearch"/>
|
||||
</view>
|
||||
<view class="flex-col list mt-17">
|
||||
<view class="flex-row relative list-item" wx:for="{{items}}" wx:for-item="item" wx:for-index="index" wx:key="index">
|
||||
<view bind:tap="gotoCourseDetail" data-id="{{item.id}}" class="flex-row relative list-item" wx:for="{{courseList}}" wx:for-item="item" wx:for-index="index" wx:key="index">
|
||||
<view class="list-divider pos_3"></view>
|
||||
<image
|
||||
class="image_2 pos"
|
||||
src="https://ide.code.fun/api/image?token=6854f3c94ae84d0012332367&name=9c2a22f14e2bd768cbd40d939693e4a8.png"
|
||||
src="{{globalImgUrl + item.image}}"
|
||||
/>
|
||||
<view class="flex-col group_2 pos_2">
|
||||
<text class="font">区块链和加密数字货币(随报随学认证班)</text>
|
||||
<text class="font">{{item.name}}</text>
|
||||
<view class="flex-row justify-between items-baseline mt-17">
|
||||
<text class="font_2">券后99元起</text>
|
||||
<text class="font_3">18523人学习</text>
|
||||
<text class="font_2">券后{{item.discountPrice}}元起</text>
|
||||
<text class="font_3">{{item.orderCount}}人学习</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
Reference in New Issue
Block a user