upload.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. // pages/upload/upload.js
  2. const app = getApp()
  3. const $api = require('../../utils/api.js').API;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. open:true,
  10. stock_date:'',
  11. stock:[{name:'',fund:''}],
  12. stockList:[],
  13. today_stock_img:[],
  14. value:[-1],
  15. is_markt:0,
  16. today_fund:'',
  17. change:0,
  18. experience:'',
  19. cur:0,
  20. freshen:true,
  21. disable:false
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onShow(){
  27. if (!this.data.freshen) {
  28. return;
  29. }
  30. $api.getCurrecord().then(res=>{
  31. if (!res.data.data.id){return}
  32. let stock = res.data.data.today_stock
  33. this.setData({
  34. stock: stock.length > 0 ? stock : [{ name: '', fund: '' }],
  35. today_stock_img: res.data.data.today_stock_img,
  36. today_fund: res.data.data.today_fund,
  37. is_markt: res.data.data.is_markt,
  38. change: 1,
  39. experience: res.data.data.experience
  40. })
  41. })
  42. },
  43. onLoad: function (options) {
  44. var y=new Date().getFullYear()
  45. var m=Number(new Date().getMonth() + 1)
  46. var d = new Date().getDate()
  47. m=m>9?m:'0'+m;
  48. d=d>9?d:'0'+d
  49. this.setData({
  50. stock_date:y+'-'+m+'-'+d
  51. })
  52. $api.getAuthinfo().then(res=>{
  53. this.setData({
  54. role: res.data.data.role
  55. })
  56. })
  57. },
  58. /**添加持股 */
  59. add(){
  60. var stock = this.data.stock;
  61. var value=this.data.value;
  62. stock.push({ name: '', fund: '' })
  63. value.push(-1)
  64. this.setData({
  65. stock: stock,
  66. value: value
  67. })
  68. },
  69. del(e){
  70. var i = e.target.dataset.id;
  71. var stock = this.data.stock;
  72. var value = this.data.value;
  73. stock.splice(i,1)
  74. value.splice(i,1)
  75. this.setData({
  76. stock: stock,
  77. value: value
  78. })
  79. },
  80. bindPickerChange(e){
  81. var i=this.data.cur;
  82. var v = e.target.dataset.name
  83. var stock=this.data.stock;
  84. stock[i].name = v
  85. this.setData({
  86. stock: stock
  87. })
  88. setTimeout(()=>{
  89. this.setData({
  90. stockList: []
  91. },50)
  92. })
  93. return;
  94. },
  95. stockSearch(e){
  96. if (e.detail.value == ''){
  97. this.setData({
  98. stockList: []
  99. })
  100. return
  101. }
  102. var i = e.target.dataset.id;
  103. var v = e.detail.value
  104. var stock = this.data.stock;
  105. stock[i].name = v;
  106. this.setData({
  107. stock: stock
  108. })
  109. $api.searchStock({ name: e.detail.value}).then(res=>{
  110. this.setData({
  111. stockList:res.data.data,
  112. cur:e.target.dataset.id
  113. })
  114. })
  115. },
  116. blur(){
  117. // console.log(233)
  118. this.setData({
  119. stockList: []
  120. })
  121. },
  122. nameChange(e){
  123. console.log(e)
  124. var i = e.target.dataset.id;
  125. var v = e.detail.value
  126. var stock = this.data.stock;
  127. stock[i].name = v;
  128. this.setData({
  129. stock: stock
  130. })
  131. },
  132. fundChange(e){
  133. var i = e.target.dataset.id;
  134. var v = e.detail.value
  135. var stock = this.data.stock;
  136. if (v.split('.').length > 1 && v.split('.')[1].length > 4) {
  137. v = Math.floor(Number(v) * 10000) / 10000
  138. }
  139. stock[i].fund = v;
  140. this.setData({
  141. stock: stock
  142. })
  143. },
  144. fundChange1(e) {
  145. var v = e.detail.value
  146. if (v.split('.').length > 1 && v.split('.')[1].length > 4){
  147. v = Math.floor(Number(v)*10000)/10000
  148. }
  149. this.setData({
  150. today_fund: v
  151. })
  152. },
  153. expChange(e){
  154. var v = e.detail.value
  155. this.setData({
  156. experience: v
  157. })
  158. },
  159. switch1Change(e){
  160. this.setData({
  161. is_markt: Number(e.detail.value)
  162. })
  163. },
  164. uploadImg() {
  165. var today_stock_img = this.data.today_stock_img;
  166. wx.chooseImage({
  167. success: res => {
  168. wx.showLoading({
  169. title: '正在上传',
  170. })
  171. const tempFilePaths = res.tempFiles
  172. for (let i = 0; i < tempFilePaths.length; i++) {
  173. $api.upload(tempFilePaths[i].path, 'file').then(res => {
  174. wx.hideLoading()
  175. if (res.code == 0) {
  176. today_stock_img.push(res.data.url)
  177. this.setData({
  178. today_stock_img: today_stock_img
  179. })
  180. } else {
  181. wx.showToast({
  182. title: '上传失败',
  183. })
  184. }
  185. })
  186. .catch(err => {
  187. wx.hideLoading()
  188. })
  189. }
  190. }
  191. })
  192. },
  193. del1(e) {
  194. var i = e.target.dataset.id;
  195. var today_stock_img = this.data.today_stock_img;
  196. today_stock_img.splice(i, 1)
  197. this.setData({
  198. today_stock_img: today_stock_img
  199. })
  200. },
  201. prview(e){
  202. var src = e.target.dataset.src;
  203. wx.previewImage({
  204. current: src, // 当前显示图片的http链接
  205. urls: [src] // 需要预览的图片http链接列表
  206. })
  207. },
  208. post(){
  209. $api.getAuthinfo().then(res => {
  210. this.setData({
  211. need_fill: res.data.data.need_fill,
  212. })
  213. if (!this.data.need_fill){
  214. var parm = {
  215. stock_date: this.data.stock_date,
  216. today_stock: this.data.stock,
  217. is_markt: this.data.is_markt,
  218. today_stock_img: this.data.today_stock_img,
  219. today_fund: Number(this.data.today_fund),
  220. experience: this.data.experience
  221. }
  222. if (!parm.today_fund) {
  223. wx.showToast({
  224. icon: 'none',
  225. title: '请输入今日净资产'
  226. })
  227. return
  228. }
  229. if (!parm.is_markt) {
  230. // for (let i = 0; i < parm.today_stock.length;i++){
  231. // if (!parm.today_stock[i].name || !parm.today_stock[i].fund) {
  232. // wx.showToast({
  233. // icon: 'none',
  234. // title: '请选择股票并输入资金额'
  235. // })
  236. // return;
  237. // break;
  238. // }
  239. // }
  240. } else {
  241. parm.today_stock = []
  242. }
  243. if (parm.today_stock_img.length <= 0) {
  244. wx.showToast({
  245. icon: 'none',
  246. title: '请上传截图'
  247. })
  248. return
  249. }
  250. wx.showLoading({
  251. title: '正在提交',
  252. })
  253. this.setData({
  254. disable: true
  255. })
  256. $api.updateRecord(parm).then(res => {
  257. wx.hideLoading()
  258. wx.showToast({
  259. title: '提交成功',
  260. })
  261. this.setData({
  262. freshen: true,
  263. })
  264. setTimeout(() => {
  265. this.setData({
  266. stock: [{ label: '', name: '', code: '', fund: '' }],
  267. stockList: [],
  268. today_stock_img: [],
  269. value: [-1],
  270. is_markt: 0,
  271. today_fund: '',
  272. disable: false
  273. })
  274. wx.switchTab({
  275. url: '../index/index',
  276. })
  277. }, 200)
  278. })
  279. }
  280. })
  281. },
  282. fundchange(e) {
  283. this.setData({
  284. init_fund: e.detail.value
  285. })
  286. },
  287. save() {
  288. if (!this.data.init_fund) {
  289. wx.showToast({
  290. icon: 'none',
  291. title: '请输入初始资金',
  292. })
  293. return;
  294. }
  295. $api.initfund({ init_fund: this.data.init_fund }).then(res => {
  296. wx.showToast({
  297. title: '提交成功',
  298. })
  299. this.getUserData()
  300. })
  301. },
  302. /**
  303. * 生命周期函数--监听页面初次渲染完成
  304. */
  305. onReady: function () {
  306. },
  307. /**
  308. * 生命周期函数--监听页面隐藏
  309. */
  310. onHide: function () {
  311. },
  312. /**
  313. * 生命周期函数--监听页面卸载
  314. */
  315. onUnload: function () {
  316. },
  317. /**
  318. * 页面相关事件处理函数--监听用户下拉动作
  319. */
  320. onPullDownRefresh: function () {
  321. },
  322. /**
  323. * 页面上拉触底事件的处理函数
  324. */
  325. onReachBottom: function () {
  326. },
  327. /**
  328. * 用户点击右上角分享
  329. */
  330. onShareAppMessage: function () {
  331. }
  332. })