123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- // pages/upload/upload.js
- const app = getApp()
- const $api = require('../../utils/api.js').API;
- const baseURL = 'https://test.hunanwanzhu.com';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- open:true,
- stock_date:'',
- stock:[{name:'',fund:''}],
- stockList:[],
- today_stock_img:[],
- value:[-1],
- is_markt:0,
- today_fund:'',
- change:0,
- experience:'',
- cur:0,
- freshen:true,
- disable:false,
- id:0,
- images:[],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onShow(){
- if (!this.data.freshen) {
- return;
- }
- this.setData({
- disable: false
- })
- $api.initUser()
- wx.getStorage({
- key: 'user',
- complete: res => {
- this.setData({
- role: res.data.role,
- })
- }
- })
- $api.getCurrecord().then(res=>{
- if (!res.data.data.id){return}
- 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,
- experience: res.data.data.experience,
- id:res.data.data.id
- })
- })
- },
- 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
- })
-
- },
- /**添加持股 */
- 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
- })
- },
- delToday(e){
- this.setData({
- today_fund: '',
- })
- },
- bindPickerChange(e){
- var i=this.data.cur;
- var v = e.target.dataset.name
- var stock=this.data.stock;
- stock[i].name = v
- stock[i].code = e.target.dataset.id
- this.setData({
- stock: stock
- })
- setTimeout(()=>{
- this.setData({
- stockList: []
- },50)
- })
- return;
- },
- stockSearch(e){
- if (e.detail.value == ''){
- this.setData({
- stockList: []
- })
- return
- }
- var i = e.target.dataset.id;
- var v = e.detail.value
- var stock = this.data.stock;
- stock[i].name = v;
- this.setData({
- stock: stock
- })
- $api.searchStock({ name: e.detail.value}).then(res=>{
- this.setData({
- stockList:res.data.data,
- cur:e.target.dataset.id
- })
- })
- },
- blur(){
- // console.log(233)
- this.setData({
- stockList: []
- })
- },
- nameChange(e){
- console.log(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
- })
- },
- moneyChange(e){
- var i = e.target.dataset.id;
- var v = e.detail.value
- var stock = this.data.stock;
- if (v.split('.').length > 1 && v.split('.')[1].length > 4) {
- v = Math.floor(Number(v) * 10000) / 10000
- }
- stock[i].money = v;
- this.setData({
- stock: stock
- })
- },
- fundChange(e){
- var i = e.target.dataset.id;
- var v = e.detail.value
- var stock = this.data.stock;
- if (v.split('.').length > 1 && v.split('.')[1].length > 4) {
- v = Math.floor(Number(v) * 10000) / 10000
- }
- stock[i].fund = v;
- this.setData({
- stock: stock
- })
- },
- fundChange1(e) {
- var v = e.detail.value
- if (v.split('.').length > 1 && v.split('.')[1].length > 4){
- v = Math.floor(Number(v)*10000)/10000
- }
- this.setData({
- today_fund: v
- })
- },
- expChange(e){
- var v = e.detail.value
- this.setData({
- experience: v
- })
- },
- switch1Change(e){
- this.setData({
- is_markt: Number(e.detail.value)
- })
- },
- // oss验签上传图片
- upload() {
- const that = this
- var today_stock_img = that.data.today_stock_img;
- wx.chooseMedia({
- mediaType: ['image'], // 只能上传图片 还有个属性是可以上传视频
- success(res) {
- wx.showLoading({
- title: '上传中',
- mask: true
- })
- let imgs = []
- let valueArr = []
- // 需要oss 验签 此处是调取验签的接口
- $api.getOssSign(res).then((r) => {
- wx.hideLoading()
- const arr = res.tempFiles
- // arr 是为了获取上传图片反的数组
- arr.forEach((e) => {
- return imgs.push(e.tempFilePath)
- })
- for (var i = 0; i < imgs.length; i++) {
- let only = imgs[i].split('.')
- valueArr.push(
- only[only.length - 1]
- )
- let filename = parseInt(Math.random() * 1000000 + new Date().getTime()) + '.' + valueArr[valueArr.length - 1]
- let httpData = {
- Key: r.data.dir + filename,
- OSSAccessKeyId: r.data.AccessKeyID,
- Policy: r.data.policy_encode,
- Signature: r.data.signature,
- }
- wx.uploadFile({
- url: baseURL+'/api/wx/uploadfile',
- filePath: imgs[i],
- formData: httpData,
- fileType: 'image',
- name: 'file',
- timeout: 15000,
- header: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- success: (res) => {
- if (res.statusCode == 200) {
- var data=JSON.parse(res.data)
- today_stock_img.push(data.data.url)
- that.setData({
- today_stock_img: today_stock_img
- })
- that.loadOcr(imgs[0],data.data.url)
- } else {
- // 返回错误信息
- console.log('error')
- }
- },
- fail: function (res) {
- console.log(res);
- }
- })
- }
- })
- }
- })
- },
- loadOcr(path,url){
- var _this = this
- console.log(path,url)
- wx.getImageInfo({
- src:path,
- success:function(ires){
- _this.loadImageOcr(url,ires.width < ires.height ? 'phone':'pc')
- }
- })
- },
- loadImageOcr(img_url,source){
- var _this = this
- var param = {
- img_url:img_url.split('?')[0],
- source:source,
- }
- console.log('img_url',param['img_url'])
- console.log('source',param['source'])
- $api.imageOcr(param).then(res => {
- console.log('ocr',res)
- if(res.data.code == 0){
- _this.setData({
- today_fund:res.data.data.today,
- stock:res.data.data.list
- })
- }
- })
- },
- startOcr(e){
- var index = e.target.dataset.index;
- var img_url = this.data.today_stock_img[index]
-
- console.log('startocr',img_url)
- this.loadImageOcr(img_url,this.data.images[index].width < this.data.images[index].height ? 'phone':'pc')
- },
- imageLoad: function(e) {
- var width=e.detail.width; //获取图片真实宽度
- var height=e.detail.height;
-
- var image=this.data.images;
- //将图片的datadata-index作为image对象的key,然后存储图片的宽高值
- image[e.target.dataset.index]={
- width:width,
- height:height,
- }
- this.setData({
- images:image
- })
- },
- 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 stocks = []
- var slist = this.data.stock
- for(let i=0;i<slist.length;i++){
- if(slist[i].name.length <= 0){
- continue;
- }
- if(slist[i].fund > 5000){
- wx.showToast({
- icon: 'none',
- title: '持仓金额单位为万'
- })
- return;
- }
- stocks.push(slist[i])
- }
- var parm = {
- stock_date: this.data.stock_date,
- today_stock: stocks,
- is_markt: this.data.is_markt,
- today_stock_img: this.data.today_stock_img,
- today_fund: Number(this.data.today_fund),
- id:this.data.id,
- experience: this.data.experience
- }
- if (!parm.today_fund) {
- wx.showToast({
- icon: 'none',
- title: '请输入今日净资产'
- })
- return
- }
- if (parm.today_fund >= 10000) {
- 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 = []
- // }
- console.log(parm)
- if (parm.today_stock_img.length <= 0) {
- wx.showToast({
- icon: 'none',
- title: '请上传截图'
- })
- return
- }
- wx.showLoading({
- title: '正在提交',
- })
- this.setData({
- disable: true
- })
- $api.updateRecord(parm).then(res => {
- wx.hideLoading()
- wx.showToast({
- title: '提交成功',
- })
- this.setData({
- freshen: true,
- disable: false
- })
- setTimeout(() => {
- this.setData({
- stock: [{ label: '', name: '', code: '', fund: '' }],
- stockList: [],
- today_stock_img: [],
- value: [-1],
- is_markt: 0,
- today_fund: ''
-
- })
- wx.switchTab({
- url: '../user/user',
- })
- }, 200)
- })
- .catch(
- this.setData({
- disable:false
- })
- )
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|