// pages/append/append.js const { getCategoryAPI, upLoadGoods } = require('../../API/appraise') const { upLoad, chooseImage } = require('../../utils/util') const baseURL = "http://192.168.31.30:8084"; Page({ /** * 页面的初始数据 */ data: { latitude: 0, longtitude: 0, mapName: "", columns: [], id: [], popShow: false, clssify: [], valueKeyName: "", index: 0, // 页面数据们 title: "", desc: "", price: Number, address: "", fileList: [], maxgoodsURL: 6 // clssify: Number }, popChange() { this.setData({ popShow: true }) this.getClassifyList() }, onConfirm(e) { const { value, index} = e.detail; this.setData({ popShow: false, valueKeyName: value, index: index }) }, onCancel() { this.setData({ popShow: false, valueKeyName: "" }) }, titleInput(e) { const {value, cursor, keyCode} = e.detail; this.setData({ title: value }) }, describeInput(e) { const {value, cursor, keyCode} = e.detail; this.setData({ desc: value }) }, numInput(e){ const {value, cursor, keyCode} = e.detail; this.setData({ price: value }) }, adressInput(e) { const { value, cursor, keyCode} = e.detail; this.setData({ address: value }) }, upData(){ // const price = this.data.price; // const address = this.data.address; // const classify = this.data.id[this.data.index]; // upLoadGoods(this.data).then((res) => { // console.log(res); // }).catch((err) => { // console.log(err); // }) wx.request({ url: baseURL + '/goods/create', method: "POST", header: { "content-type": "application/x-www-form-urlencoded" }, data: { "categories": [ this.data.id[this.data.index] ], "desc": this.data.desc, "ownerId": 0, "pic": this.data.fileList, "place": this.data.address, "price": this.data.price, "state": 0, "title": this.data.title }, success: function(res) { console.log(res); } }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, getClassifyList() { getCategoryAPI(this.data) .then((res) => { const { code, data, mesage } = res.data; const name = []; const id = []; for (let i = 0; i < data.length; i++) { name[i] = data[i].Name; id[i] = data[i].Id; } console.log(id); this.setData({ columns: name, id: id }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, afterRead(e) { const { file } = e.detail; upLoad(file.url).then((res) => { const { fileList = [] } = this.data; fileList.push({ ...file, url: res.data }); this.setData({ fileList, }) console.log(this.data.fileList); }) } })