change.js 5.0 KB

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