weixin_45835034 2020-11-04 15:51
浏览 231

如何将picker的值同input的值一同上传到云数据库?

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()
    })
  },

})
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办