change.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // pages/change/change.js
  2. const app = getApp()
  3. const $api = require('../../utils/api.js').API;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. today_stock_img:'',
  10. init_fund:'',
  11. yesterday_fund:'',
  12. today_fund:'',
  13. today_income:'',
  14. total_income:'',
  15. stock_date:'',
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. var y=new Date().getFullYear()
  22. var m=Number(new Date().getMonth() + 1)
  23. var d = new Date().getDate()
  24. m=m>9?m:'0'+m;
  25. d=d>9?d:'0'+d
  26. this.setData({
  27. stock_date:y+'-'+m+'-'+d
  28. })
  29. },
  30. uploadImg() {
  31. var today_stock_img = this.data.today_stock_img;
  32. wx.chooseImage({
  33. success: res => {
  34. wx.showLoading({
  35. title: '正在上传',
  36. })
  37. const tempFilePaths = res.tempFiles
  38. for (let i = 0; i < tempFilePaths.length; i++) {
  39. $api.upload(tempFilePaths[i].path, 'file').then(res => {
  40. wx.hideLoading()
  41. if (res.code == 0) {
  42. // today_stock_img.push(res.data.url)
  43. this.setData({
  44. today_stock_img: res.data.url
  45. })
  46. } else {
  47. wx.showToast({
  48. title: '上传失败',
  49. })
  50. }
  51. })
  52. .catch(err => {
  53. wx.hideLoading()
  54. })
  55. }
  56. }
  57. })
  58. },
  59. del(e) {
  60. // var i = e.target.dataset.id;
  61. // var today_stock_img = this.data.today_stock_img;
  62. // today_stock_img.splice(i, 1)
  63. this.setData({
  64. today_stock_img: ''
  65. })
  66. },
  67. prview(e){
  68. var src = e.target.dataset.src;
  69. wx.previewImage({
  70. current: src, // 当前显示图片的http链接
  71. urls: [src] // 需要预览的图片http链接列表
  72. })
  73. },
  74. todaychange(e){
  75. this.setData({
  76. today_fund: e.detail.value
  77. })
  78. },
  79. outchange(e){
  80. this.setData({
  81. out_fund: e.detail.value
  82. })
  83. },
  84. inchange(e){
  85. this.setData({
  86. in_fund: e.detail.value
  87. })
  88. },
  89. trypost(){
  90. var data={
  91. today_fund:this.data.today_fund,
  92. out_fund:this.data.out_fund,
  93. in_fund:this.data.in_fund,
  94. account_img:this.data.today_stock_img,
  95. trycalc:1
  96. }
  97. if (!data.today_fund){
  98. wx.showToast({
  99. icon: 'none',
  100. title: '请输入今日净资产'
  101. })
  102. return
  103. }
  104. if (data.today_fund >= 10000){
  105. wx.showToast({
  106. icon: 'none',
  107. title: '今日净资产单位为万'
  108. })
  109. return
  110. }
  111. if (data.out_fund >= 2000){
  112. wx.showToast({
  113. icon: 'none',
  114. title: '今日转出资金单位为万'
  115. })
  116. return
  117. }
  118. if (data.in_fund >= 2000){
  119. wx.showToast({
  120. icon: 'none',
  121. title: '今日转入资金单位为万'
  122. })
  123. return
  124. }
  125. if (!data.out_fund && !data.in_fund){
  126. wx.showToast({
  127. icon: 'none',
  128. title: '请输入今转出资金或今转入资金'
  129. })
  130. return
  131. }
  132. if (!data.account_img){
  133. wx.showToast({
  134. icon: 'none',
  135. title: '请上传账户截图'
  136. })
  137. return
  138. }
  139. $api.update(data).then(res=>{
  140. if(res.data.code == 0){
  141. this.setData({
  142. init_fund:res.data.data.init_fund,
  143. yesterday_fund:res.data.data.yesterday_fund,
  144. total_income:res.data.data.total_income,
  145. today_income:res.data.data.today_income
  146. })
  147. }else{
  148. wx.showToast({
  149. title: '提交失败',
  150. })
  151. }
  152. })
  153. },
  154. post(){
  155. var data={
  156. out_fund:this.data.out_fund,
  157. in_fund:this.data.in_fund,
  158. account_img:this.data.today_stock_img
  159. }
  160. if (!data.out_fund && !data.in_fund){
  161. wx.showToast({
  162. icon: 'none',
  163. title: '请输入今转出资金或今转入资金'
  164. })
  165. return
  166. }
  167. if (!data.account_img){
  168. wx.showToast({
  169. icon: 'none',
  170. title: '请上传账户截图'
  171. })
  172. return
  173. }
  174. $api.update(data).then(res=>{
  175. if(res.data.code == 0){
  176. let key = 'change' + this.data.stock_date
  177. wx.setStorage({
  178. key: key,
  179. data: '1',
  180. })
  181. wx.showToast({
  182. title: '提交成功',
  183. success:function(){
  184. setTimeout(() => {
  185. wx.navigateBack({
  186. delta: 0,
  187. })
  188. }, 1500);
  189. }
  190. })
  191. }else{
  192. wx.showToast({
  193. title: '提交失败',
  194. })
  195. }
  196. })
  197. },
  198. /**
  199. * 生命周期函数--监听页面初次渲染完成
  200. */
  201. onReady: function () {
  202. },
  203. /**
  204. * 生命周期函数--监听页面显示
  205. */
  206. onShow: function () {
  207. },
  208. /**
  209. * 生命周期函数--监听页面隐藏
  210. */
  211. onHide: function () {
  212. },
  213. /**
  214. * 生命周期函数--监听页面卸载
  215. */
  216. onUnload: function () {
  217. },
  218. /**
  219. * 页面相关事件处理函数--监听用户下拉动作
  220. */
  221. onPullDownRefresh: function () {
  222. },
  223. /**
  224. * 页面上拉触底事件的处理函数
  225. */
  226. onReachBottom: function () {
  227. },
  228. /**
  229. * 用户点击右上角分享
  230. */
  231. onShareAppMessage: function () {
  232. }
  233. })