123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- // pages/upload/upload.js
- const app = getApp()
- var host = app.globalData.host;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- open:true,
- stock_date:'',
- stock:[{name:'',fund:''}],
- stockList:[],
- today_stock_img:[],
- value:[-1],
- is_markt:0,
- today_fund:'',
- change:0,
- freshen:true,
- disable:false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onShow(){
- setTimeout(()=>{
- if (!this.data.userInfo.token || !this.data.freshen) {
- return;
- }
- wx.request({
- url: host + '/api/wx/player/currecord',
- header: {
- 'Authorization': this.data.userInfo.token
- },
- success: res => {
- console.log(res)
- if (res.data.data) {
- let stock = res.data.data.today_stock
- this.setData({
- stock: stock.length > 0 ? stock : [{ name: '', fund: '' }],
- today_stock_img: res.data.data.today_stock_img,
- today_fund: res.data.data.today_fund,
- is_markt: res.data.data.is_markt,
- change:1
- })
- }
- }
- })
- this.getuser()
- },500)
- },
- onLoad: function (options) {
- var y=new Date().getFullYear()
- var m=Number(new Date().getMonth() + 1)
- var d = new Date().getDate()
- m=m>9?m:'0'+m;
- d=d>9?d:'0'+d
- this.setData({
- stock_date:y+'-'+m+'-'+d
- })
- wx.getStorage({
- key: 'userInfo',
- success: res => {
- if (res.data) {
- this.setData({
- userInfo: res.data
- })
- this.getData();
- } else {
- wx.switchTab({
- url: '../user/user',
- })
- }
- },
- fail:error=>{
- wx.switchTab({
- url: '../user/user',
- })
- }
- })
- },
- getuser() {
- wx.request({
- url: host + '/api/wx/authinfo',
- header: {
- 'Authorization': this.data.userInfo.token
- },
- success: res => {
- if (res.data.data.need_fill) {
- wx.switchTab({
- url: '../user/user',
- })
- }
- }
- })
- },
- getData() {
- wx.request({
- url: host + '/api/wx/stock/search',
- header: {
- 'Authorization': this.data.userInfo.token
- },
- success: res => {
- this.setData({
- stockList:res.data.data
- })
- },
- fail: error => {
- //失败重新登陆
- wx.switchTab({
- url: '../user/user',
- })
- }
- })
- },
- /**添加持股 */
- add(){
- var stock = this.data.stock;
- var value=this.data.value;
- stock.push({ name: '', fund: '' })
- value.push(-1)
- this.setData({
- stock: stock,
- value: value
- })
- },
- del(e){
- var i = e.target.dataset.id;
- var stock = this.data.stock;
- var value = this.data.value;
- stock.splice(i,1)
- value.splice(i,1)
- this.setData({
- stock: stock,
- value: value
- })
- },
- bindPickerChange(e){
- var i=e.target.dataset.id;
- var v = e.detail.value
- var stock=this.data.stock;
- var list=this.data.stockList;
- var value=this.data.value;
- value[i] =v;
- stock[i]={
- name: list[v].name,
- code:list[v].code,
- label: list[v].label
- }
- this.setData({
- stock: stock,
- value: value
- })
- },
- nameChange(e){
- var i = e.target.dataset.id;
- var v = e.detail.value
- var stock = this.data.stock;
- stock[i].name = v;
- this.setData({
- stock: stock
- })
- },
- fundChange(e){
- var i = e.target.dataset.id;
- var v = e.detail.value
- var stock = this.data.stock;
- stock[i].fund = v;
- this.setData({
- stock: stock
- })
- },
- fundChange1(e) {
- var v = e.detail.value
- this.setData({
- today_fund: v
- })
- },
- switch1Change(e){
- this.setData({
- is_markt: Number(e.detail.value)
- })
- },
- upload(){
- this.setData({
- freshen:false
- })
- var today_stock_img = this.data.today_stock_img;
- wx.chooseImage({
- success: res=> {
- console.log(res)
- const tempFilePaths = res.tempFiles
- for (let i = 0; i < tempFilePaths.length;i++){
- // if(tempFilePaths[i].size > 1024){
- // wx.showToast({
- // icon: 'none',
- // title: '图片大小不能超过1M'
- // })
- // }else{
- wx.uploadFile({
- url: host + '/api/wx/uploadfile',
- filePath: tempFilePaths[i].path,
- name: 'file',
- header: {
- 'Authorization': this.data.userInfo.token
- },
- success: res => {
- const data = JSON.parse(res.data)
- today_stock_img.push(data.data.url)
- this.setData({
- today_stock_img: today_stock_img
- })
- }
- })
- // }
-
- }
-
- }
- })
- },
- del1(e) {
- var i = e.target.dataset.id;
- var today_stock_img = this.data.today_stock_img;
- today_stock_img.splice(i, 1)
- this.setData({
- today_stock_img: today_stock_img
- })
- },
- prview(e){
- var src = e.target.dataset.src;
- wx.previewImage({
- current: src, // 当前显示图片的http链接
- urls: [src] // 需要预览的图片http链接列表
- })
- },
- post(){
- var parm={
- stock_date: this.data.stock_date,
- today_stock:this.data.stock,
- is_markt: this.data.is_markt,
- today_stock_img: this.data.today_stock_img,
- today_fund: Number(this.data.today_fund)
- }
- if (!parm.today_fund){
- wx.showToast({
- icon: 'none',
- title: '请输入今日净资产'
- })
- return
- }
- if (!parm.is_markt){
- // for (let i = 0; i < parm.today_stock.length;i++){
- // if (!parm.today_stock[i].name || !parm.today_stock[i].fund) {
- // wx.showToast({
- // icon: 'none',
- // title: '请选择股票并输入资金额'
- // })
- // return;
- // break;
- // }
- // }
-
- }else{
- parm.today_stock = []
- }
- // if (parm.today_stock_img.length<=0) {
- // wx.showToast({
- // icon: 'none',
- // title: '请上传截图'
- // })
- // return
- // }
- wx.showLoading({
- title: '正在提交',
- })
- this.setData({
- disable:true
- })
- wx.request({
- url: host + '/api/wx/player/record',
- data:parm,
- header: {
- 'Authorization': this.data.userInfo.token
- },
- method:'POST',
- success: res => {
- wx.hideLoading()
- if (res.data.code != 0) {
- wx.showToast({
- icon: 'none',
- title: res.data.message,
- })
- return;
- }
- wx.showToast({
- title: '提交成功',
- })
- this.setData({
- freshen: true,
- })
- setTimeout(()=>{
- this.setData({
- stock: [{ label: '', name: '', code: '', fund: '' }],
- stockList: [],
- today_stock_img: [],
- value: [-1],
- is_markt: 0,
- today_fund: '',
- disable:false
- })
- wx.switchTab({
- url: '../index/index',
- })
- },200)
- },
- fail: error => {
- wx.hideLoading()
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|