const uploadJS = require('../../mixin/upload.js') Page({ /** * 页面的初始数据 */ data: { // * 商品品牌:下拉选择 // * 单位:下拉选择 // * 商品货号:系统自动生成(只读) // * 批发价 // * 零售价 // * 库存 // * 状态:现售产品有上架、下架状态 // * 发售时间:不能低于当前创建时间 form: { 'product_img_url': [], // 商品主图 'product_rotation_img_list': [], // 商品轮播图 'product_detail_img_list': [], // 详情图 'product_title': '测试商品', // 商品标题 'product_category_id': 1, // 分类ID 'product_brand_id': 1, // 品牌ID 'product_spec': 'xl', // 规格 'product_unit': '个', // 单位 'product_all_price': 10000, // 批发价 'product_price': 9000, // 零售价 'product_count': 1000, // 库存 'product_sale_at': 0 // 预售时间(0代表预售) }, product_img_url_max: 1, product_rotation_img_list_max: 5, product_detail_img_list_max: 5 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, ...uploadJS, uploadCallBack(res) { const temp = res.map(item => { return { 'url': item.url, 'formkey': item.formkey } }) let tempForm = {} let formkey = '' if (temp.length > 0) { formkey = temp[0].formkey } switch (formkey) { case 'product_img_url': tempForm[`form.${formkey}`] = temp break case 'product_rotation_img_list': case 'product_detail_img_list': tempForm[`form.${formkey}`] = this.data.form[formkey].concat(...temp) break default: } console.log(tempForm) if (Object.keys(tempForm).length > 0) { this.setData(tempForm) } }, onSubmit(e) { console.log(e.detail) } })