change.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. },
  16. uploadImg() {
  17. var today_stock_img = this.data.today_stock_img;
  18. wx.chooseImage({
  19. success: res => {
  20. wx.showLoading({
  21. title: '正在上传',
  22. })
  23. const tempFilePaths = res.tempFiles
  24. for (let i = 0; i < tempFilePaths.length; i++) {
  25. $api.upload(tempFilePaths[i].path, 'file').then(res => {
  26. wx.hideLoading()
  27. if (res.code == 0) {
  28. today_stock_img.push(res.data.url)
  29. this.setData({
  30. today_stock_img: today_stock_img
  31. })
  32. } else {
  33. wx.showToast({
  34. title: '上传失败',
  35. })
  36. }
  37. })
  38. .catch(err => {
  39. wx.hideLoading()
  40. })
  41. }
  42. }
  43. })
  44. },
  45. del(e) {
  46. var i = e.target.dataset.id;
  47. var today_stock_img = this.data.today_stock_img;
  48. today_stock_img.splice(i, 1)
  49. this.setData({
  50. today_stock_img: today_stock_img
  51. })
  52. },
  53. prview(e){
  54. var src = e.target.dataset.src;
  55. wx.previewImage({
  56. current: src, // 当前显示图片的http链接
  57. urls: [src] // 需要预览的图片http链接列表
  58. })
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. },
  80. /**
  81. * 页面相关事件处理函数--监听用户下拉动作
  82. */
  83. onPullDownRefresh: function () {
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function () {
  94. }
  95. })