提交 17f0bef1 编写于 作者: W weixin_47563380

Tue Sep 24 08:14:00 CST 2024 inscode

上级 2b91a63c
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
\ No newline at end of file
/* pages/MDmaterial/MDmaterial.wxss */
.menu {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10rpx 10rpx;
background-color: #feffff;
}
.menu-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.menu-item image {
width: 80rpx;
height: 80rpx;
}
.menu-item text {
margin-top: 10rpx;
font-size: 28rpx;
color: #000000;
}
.shop-item{
display: flex;
padding: 15rpx;
border: 1px solid #efefef;
margin: 15rpx;
border-radius: 8rpx;
box-shadow: 1rpx 1rpx 15rpx #ddd;
}
.thumb image{
width: 250rpx;
height: 250rpx;
display: block;
margin-right: 15rpx;
}
.info{
display: flex;
flex-direction: column;
justify-content: space-around;
font-size: 24rpx;
}
.shop-title{
font-weight: bold;
}
\ No newline at end of file
// pages/MDmaterial/MDmaterial.ts
Page({
/**
* 页面的初始数据
*/
data: {
isShow:true,
searchInput: '', // 用户输入的查询条件
searchResults: [], // 查询结果
imagePath: '', // 用于存储图片的路径
MText: '',//物料描述
MCode: '',//批次编码
MLocation: '',//存放地点
src: '',// 存储拍摄的照片路径
item: {
MText: '',//物料描述
MCode: '',//批次编码
MLocation: '',//存放地点
src: '',// 存储拍摄的照片路径
},
// 初始时,stkmat数组为空
itmes: []
},
// 处理输入事件
handleInput: function (e) {
this.setData({
searchInput: e.detail.value
});
},
// 执行查询
searchData: function () {
let searchInput = this.data.searchInput.trim();
let searchResults = [];
// 这里我们进行简单的模糊查询,即检查name或info字段是否包含搜索条件
this.data.items.forEach(item => {
if (item.MText.includes(searchInput) || item.MCode.includes(searchInput) || item.MLocation.includes(searchInput)) {
searchResults.push(item);
this.setData({
isShow: false
});
}
});
// 更新查询结果到页面上
this.setData({
searchResults: searchResults
});
},
selectImage: function () {
wx.chooseImage({
count: 1,
success: function (res) {
const tempFilePath = res.tempFilePaths[0]; // 用户选择的图片临时文件路径
// 将图片路径保存到本地缓存
wx.setStorageSync('imagePath', tempFilePath);
// 同时更新页面的数据,以便立即显示图片
this.setData({
imagePath: tempFilePath
});
}.bind(this) // 注意这里需要绑定this
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
// 页面加载时,尝试从缓存中读取图片路径
const cachedImagePath = wx.getStorageSync('imagePath') || '';
if (cachedImagePath) {
this.setData({
imagePath: cachedImagePath
});
} else {
this.setData({
imagePath: "/images/banner1.jpg" //初始图片
});
}
// 尝试从本地存储中获取'items'
const storedItems = wx.getStorageSync('stkmats');
//console.log('storedItems:'+storedItems);
// 检查storedItems是否为null(或undefined,但wx.getStorageSync不会返回undefined)
// 如果是null,则默认为空数组;否则,尝试解析JSON字符串为数组
const itemslist = storedItems ? JSON.parse(storedItems) : [];
//if(itemslist)
//console.log('itemslist:'+itemslist);
// 更新页面的items数据
this.setData({
items: itemslist
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
wx.setNavigationBarTitle({
title: '物料管理',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<view>
<input type="text" bindinput="handleInput" placeholder="请输入查询条件" />
<button bindtap="searchData">查询</button>
<view wx:for="{{searchResults}}" wx:key="id">
{{item.MText}} - {{item.MCode}} - {{item.MLocation}}
</view>
</view>
<view class="shop-item" wx:for="{{searchResults}}" wx:key="id">
<!-- 图片资源 -->
<view class="thumb">
<image src="{{item.src}}" mode="aspectFit" bindtap="selectImage"></image>
</view>
<!-- 文字信息 -->
<view class="info">
<text class="shop-title">物料描述: {{item.MText}}</text>
<text>批次编码:{{item.MCode}}</text>
<text>存放地点: {{item.MLocation}}</text>
</view>
</view>
<view class="shop-item" wx:if="{{isShow}}" wx:for="{{items}}" wx:key="index">
<!-- 图片资源 -->
<view class="thumb">
<image src="{{item.src}}" mode="aspectFit" bindtap="selectImage"></image>
</view>
<!-- 文字信息 -->
<view class="info">
<text class="shop-title">物料描述: {{item.MText}}</text>
<text>批次编码:{{item.MCode}}</text>
<text>存放地点: {{item.MLocation}}</text>
</view>
</view>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册