change.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.today_fund >= 10000){
  96. wx.showToast({
  97. icon: 'none',
  98. title: '今日净资产单位为万'
  99. })
  100. return
  101. }
  102. if (data.out_fund >= 2000){
  103. wx.showToast({
  104. icon: 'none',
  105. title: '今日转出资金单位为万'
  106. })
  107. return
  108. }
  109. if (data.in_fund >= 2000){
  110. wx.showToast({
  111. icon: 'none',
  112. title: '今日转入资金单位为万'
  113. })
  114. return
  115. }
  116. if (!data.out_fund && !data.in_fund){
  117. wx.showToast({
  118. icon: 'none',
  119. title: '请输入今转出资金或今转入资金'
  120. })
  121. return
  122. }
  123. if (!data.account_img){
  124. wx.showToast({
  125. icon: 'none',
  126. title: '请上传账户截图'
  127. })
  128. return
  129. }
  130. $api.update(data).then(res=>{
  131. if(res.data.code == 0){
  132. this.setData({
  133. init_fund:res.data.data.init_fund,
  134. yesterday_fund:res.data.data.yesterday_fund,
  135. total_income:res.data.data.total_income,
  136. today_income:res.data.data.today_income
  137. })
  138. }else{
  139. wx.showToast({
  140. title: '提交失败',
  141. })
  142. }
  143. })
  144. },
  145. post(){
  146. var data={
  147. out_fund:this.data.out_fund,
  148. in_fund:this.data.in_fund,
  149. account_img:this.data.today_stock_img
  150. }
  151. if (!data.out_fund && !data.in_fund){
  152. wx.showToast({
  153. icon: 'none',
  154. title: '请输入今转出资金或今转入资金'
  155. })
  156. return
  157. }
  158. if (!data.account_img){
  159. wx.showToast({
  160. icon: 'none',
  161. title: '请上传账户截图'
  162. })
  163. return
  164. }
  165. $api.update(data).then(res=>{
  166. if(res.data.code == 0){
  167. wx.showToast({
  168. title: '提交成功',
  169. success:function(){
  170. setTimeout(() => {
  171. wx.navigateBack({
  172. delta: 0,
  173. })
  174. }, 1500);
  175. }
  176. })
  177. }else{
  178. wx.showToast({
  179. title: '提交失败',
  180. })
  181. }
  182. })
  183. },
  184. /**
  185. * 生命周期函数--监听页面初次渲染完成
  186. */
  187. onReady: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面显示
  191. */
  192. onShow: function () {
  193. },
  194. /**
  195. * 生命周期函数--监听页面隐藏
  196. */
  197. onHide: function () {
  198. },
  199. /**
  200. * 生命周期函数--监听页面卸载
  201. */
  202. onUnload: function () {
  203. },
  204. /**
  205. * 页面相关事件处理函数--监听用户下拉动作
  206. */
  207. onPullDownRefresh: function () {
  208. },
  209. /**
  210. * 页面上拉触底事件的处理函数
  211. */
  212. onReachBottom: function () {
  213. },
  214. /**
  215. * 用户点击右上角分享
  216. */
  217. onShareAppMessage: function () {
  218. }
  219. })