wxml:
<form bindsubmit="sp_fabu">
<view class="leixing">
<picker bindchange="bindPickerChange" value="{{lx_index}}" range="{{lx_array}}">
<view class="leixing_1" name = "lx_index">
商品类型:{{lx_array[lx_index]}}
</view>
</picker>
</view>
<view class="biaoti">
<input name="sp_biaoti" class="biaoti_1" maxlength="15" placeholder="商品标题(限定字数15以内~)" />
</view>
<view class="jieshao">
<textarea name="sp_jieshao" class="jieshao_1" maxlength="100" placeholder="商品介绍(限定字数100以内~)" />
</view>
<view class="jiage">
价格:<input name="sp_jiage" type="number" class="jiage_1" maxlength="15" placeholder="商品价格" />
</view>
<view class="lianxi">
联系方式: <input name="sp_phone" type="number" class="lianxi_1" maxlength="11" placeholder="手机号码" />
</view>
<button bindtap="tofabu" class="btn" size="large" form-type="submit">确认发布</button>
</form>
js:
const db = wx.cloud.database()
Page({
/**
* 页面的初始数据
*/
data: {
lx_array: ['数码', '日化', '虚拟', '资料','服装'],
objectArray: [
{
id: 0,
name: '数码'
},
{
id: 1,
name: '日化'
},
{
id: 2,
name: '虚拟'
},
{
id: 3,
name: '资料'},
{
id: 4,
name: '服装'},
],
lx_index: 0,
"lx_index":"",
"sp_biaoti":"",
"sp_jieshao":"",
"sp_jiage":"",
"sp_phone":"",
"sp_time":"",
},
//改变商品类型
bindPickerChange: function(res) {
console.log('picker发送选择改变,携带值为', res.detail.value)
this.setData({
lx_index: res.detail.value
})
},
//向sp_fabu发送数据
sp_fabu:function(res){
console.log(res)
var lx_index = res.detail.value.lx_index
var sp_biaoti = res.detail.value.sp_biaoti
var sp_jieshao = res.detail.value.sp_jieshao
var sp_jiage = res.detail.value.sp_jiage
var sp_phone = res.detail.value.sp_phone
var sp_time = Date()
wx.showLoading({
title: '数据正在提交中......',
mask:"true"
})
db.collection("cs").add({
data:{
"lx_index": lx_index,
"sp_biaoti": sp_biaoti,
"sp_jieshao": sp_jieshao,
"sp_jiage": sp_jiage,
"sp_phone": sp_phone,
"sp_time": Date()
}
}).then(res=>{
console.log(res)
wx.hideLoading()
})
},
})