You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
clothesProject/pages/navigation/index/add/add.js

133 lines
2.1 KiB

2 years ago
// pages/navigation/index/add/add.js
let app=getApp();
import Toast from './@vant/weapp/toast/toast';
Page({
/**
* 页面的初始数据
*/
2 years ago
 
2 years ago
data: {
2 years ago
name:"",
pattern:"",
kind:"",
style:"",
colour:"",
T:"",
thickness:"",
season:"" ,
2 years ago
url:""
2 years ago
},
2 years ago
cancel()
{
this.setData({ name:"",
pattern:"",
kind:"",
style:"",
colour:"",
T:"",
thickness:"",
2 years ago
season:"" ,
url:""});
2 years ago
},
//提交
submit()
{
console.log("名称",this.data.name)
for(let n in app.globalData.clothes)
{
if(this.data.name==app.globalData.clothes[n].name)
{
Toast.fail('名称重复');
//返回0
return 0;
}
}
//初始化云
wx.cloud.init({
env:'cloud1-5ggzbo3kcd4ea4e2'
});
//初始化数据库
const db=wx.cloud.database();
2 years ago
let clothes=this.data.clothes;
2 years ago
db.collection('cloth').add({
data: {
name:this.data.name,
pattern:this.data.pattern,
kind:this.data.kind,
style:this.data.style,
colour:this.data.colour,
T:this.data.T,
thickness:this.data.thickness,
season:this.data.season,
url:app.globalData.url
},
sucess:function(res){
console.log(res);
}
})
let s=JSON.stringify(this.data);
app.globalData.clothes.push(JSON.parse(s))
console.log("数据123",this.data,app.globalData.clothes)
this.cancel();
2 years ago
},
2 years ago
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
2 years ago
 onShareAppMessage() {
2 years ago
2 years ago
  },
  
})