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

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

// pages/navigation/index/add/add.js
let app=getApp();
import Toast from './@vant/weapp/toast/toast';
Page({
/**
* 页面的初始数据
*/
 
data: {
name:"",
pattern:"",
kind:"",
style:"",
colour:"",
T:"",
thickness:"",
season:"" ,
url:""
},
cancel()
{
this.setData({ name:"",
pattern:"",
kind:"",
style:"",
colour:"",
T:"",
thickness:"",
season:"" ,
url:""});
},
//提交
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();
let clothes=this.data.clothes;
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();
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
 onShareAppMessage() {
  },
  
})