// pages/article/publish.js import request from '../../utils/request' Page({ /** * 页面的初始数据 */ data: { categoryList:[], layerHide:false, getListImg: [], radioItems: [ {name: '包邮', value: '美国',checked: 'true'}, {name: '按距离估算', value: '中国'} ], currentTab: 0, typeName:'', countPic:9,//上传图片最大数量 showImgUrl: "https://api.fireflysg.com", //路径拼接,一般上传返回的都是文件名, uploadImgUrl:'https://api.fireflysg.com/firefly/media-room/photo/upload',//图片的上传的路径 switch: false, content:'', title:'', point:'', stockCount:'', goodsPhoto:'', imgList:[], categoryId:1 }, submit(){ let datas={ goodsName:this.data.title, categoryId:this.data.categoryId, desc:this.data.content, point:this.data.point, stockCount:this.data.stockCount, goodsPhoto:this.data.goodsPhoto, mediaList:this.data.imgList } console.log(datas) request._post('/firefly/goods/add/new',datas, res=>{ if(res.retCode == 0){ wx.hideLoading(); setTimeout(() => { wx.showToast({ title: '发布成功,获得'+res.body.points+'积分!', icon: 'none', duration:2000 }) }, 100); wx.switchTab({ url: '/pages/shopList/index', }) } } ) }, getcategory(){ request._post('/firefly/category/list',{type:3}, res=>{ if(res.retCode == 0){ this.setData({ categoryList:res.body }) } }) }, currentTab: function (e) { var categoryItem = e.currentTarget.dataset.item if (this.data.categoryId == categoryItem.id){ return; } this.setData({ categoryId: categoryItem.id, typeName: categoryItem.name, layerHide: false }) }, getInputTitle(e){ this.setData({ title: e.detail.value }) }, getInputContent(e){ this.setData({ content: e.detail.value }) }, getInputPoint(e){ this.setData({ point: e.detail.value }) }, getInputStockCount(e){ this.setData({ stockCount: e.detail.value }) }, //监听组件事件,返回的结果 myEventListener:function(e){ console.log("上传的图片结果集合") console.log(e.detail.picsList) this.setData({ imgList:e.detail.picsList }) }, myEventListener1:function(e){ console.log("上传的图片结果集合") console.log(e.detail.picsList) this.setData({ goodsPhoto:e.detail.picsList[0].mediaPath }) }, getDetail(id){ let that = this let datas={ goodsId: id } request._post('/firefly/goods/detail',datas, res=>{ if(res.retCode == 0){ // goodsName:this.data.title, // categoryId:this.data.categoryId, // desc:this.data.content, // point:this.data.point, // stockCount:this.data.stockCount, // goodsPhoto:this.data.goodsPhoto, // mediaList:this.data.imgList let arr = [] that.data.getListImg.push(res.body.goodsPhoto) that.setData({ title: res.body.goodsName, categoryId: res.body.categoryId, content: res.body.desc, point: res.body.points, stockCount: res.body.stockCount, goodsPhoto: res.body.goodsPhoto, getListImg: that.data.getListImg, mediaList: [] }) } } ) }, typeEvent(){ this.setData({layerHide:true}) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getcategory() console.log(options.id) if(options.id){ this.getDetail(options.id) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })