116 lines
2.5 KiB
JavaScript
116 lines
2.5 KiB
JavaScript
// pages/add/index.js
|
|
const { api } = require("../../utils/api")
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
key:'',
|
|
timer:null,
|
|
list:[],
|
|
hotList:[
|
|
{url:'https://res.catter.cn/pub/2025/09/30/20250930143920286.png',name:'金鱼吊兰'},
|
|
{url:'https://res.catter.cn/pub/2025/09/30/20250930145312611.png',name:'月季'},
|
|
{url:'https://res.catter.cn/pub/2025/09/30/20250930150006852.png',name:'多肉'}
|
|
]
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.fetchHotList()
|
|
},
|
|
|
|
fetchHotList(){
|
|
const data ={ current:1,pageSize:20,isHot:1}
|
|
api('/library/list','POST',data,'json').then(res => {
|
|
if (res.code === 200){
|
|
const list = res.data.list
|
|
this.setData({hotList:list})
|
|
}
|
|
})
|
|
},
|
|
|
|
search(e){
|
|
if (this.data.timer) {
|
|
clearTimeout(this.data.timer)
|
|
this.data.timer = null;
|
|
}
|
|
const key = e.detail.value
|
|
this.data.timer = setTimeout(() => {
|
|
if (key.length === 0){
|
|
this.setData({list:[],key:''})
|
|
return
|
|
}
|
|
this.setData({key:key})
|
|
this.fetchList(key)
|
|
|
|
}, 500)
|
|
},
|
|
|
|
fetchList(key){
|
|
console.log(key);
|
|
const data ={ current:1,pageSize:20,name:key}
|
|
api('/library/list','POST',data,'json').then(res => {
|
|
if (res.code === 200){
|
|
const list = res.data.list
|
|
this.setData({list:list})
|
|
}
|
|
})
|
|
},
|
|
|
|
addPlant(){
|
|
var data = {
|
|
"aliases": "",
|
|
"farms": [
|
|
{
|
|
"cycleDays": 0,
|
|
"desc": "",
|
|
"name": ""
|
|
}
|
|
],
|
|
"flowerDiameter": 0,
|
|
"floweringColor": "",
|
|
"floweringPeriod": "",
|
|
"floweringShape": "",
|
|
"foliageColor": "",
|
|
"foliageShape": "",
|
|
"foliageType": "",
|
|
"genus": "",
|
|
"GrowthHabit": "",
|
|
"hardyTempMax": 0,
|
|
"hardyTempMin": 0,
|
|
"height": 0,
|
|
"latinName": "",
|
|
"lifeCycle": "",
|
|
"lightIntensity": "",
|
|
"lightType": "",
|
|
"name": "",
|
|
"optimalTempMax": 0,
|
|
"optimalTempMin": 0,
|
|
"ossIds": [
|
|
"9b8efb93-af19-11f0-997e-bc2411e64a23"
|
|
],
|
|
"pestsDiseases": "",
|
|
"tag": ""
|
|
}
|
|
data.name = this.data.key
|
|
api('/plant/plant','POST',data,'json').then(res => {
|
|
if(res.code === 200){
|
|
console.log(res.data);
|
|
}else {
|
|
wx.showModal({
|
|
content: res.msg})
|
|
}
|
|
})
|
|
},
|
|
|
|
goInfo(e){
|
|
const id = e.currentTarget.dataset.id
|
|
wx.navigateTo({
|
|
url: '../add/info?id=' + id,
|
|
})
|
|
}
|
|
}) |