addProject.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. year: null,
  5. arr: [],
  6. disabled: true,
  7. loading: false,
  8. range: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  9. },
  10. onLoad(options) {
  11. let project = JSON.parse(options.data);
  12. this.setData({
  13. project,
  14. year: options.year
  15. })
  16. project.forEach((v, i) => {
  17. this.isDisabled(i)
  18. })
  19. },
  20. submit() {
  21. if (this.data.disabled || this.data.loading) return;
  22. this.setData({
  23. loading: true
  24. })
  25. _Http.basic({
  26. "id": 20220905154102,
  27. "content": {
  28. "year": this.data.year,
  29. "hrid": wx.getStorageSync('userMsg').hrid,
  30. "project": this.data.project
  31. },
  32. }).then(res => {
  33. this.setData({
  34. loading: false
  35. });
  36. if (res.msg != '成功') return wx.showToast({
  37. title: res.msg,
  38. icon: "none"
  39. });
  40. this.setData({
  41. disabled: true
  42. })
  43. let pages = getCurrentPages();
  44. pages[pages.length - 2].getList(true);
  45. setTimeout(() => {
  46. wx.navigateBack({
  47. delta: 0,
  48. })
  49. }, 300)
  50. wx.showToast({
  51. title: '添加成功',
  52. icon: "none"
  53. });
  54. })
  55. },
  56. inputChange(e) {
  57. const {
  58. index,
  59. name
  60. } = e.target.dataset;
  61. this.setData({
  62. [`project[${index}].${name}`]: e.detail.value
  63. });
  64. this.isDisabled(index);
  65. },
  66. bindDateChange(e) {
  67. const {
  68. index
  69. } = e.target.dataset;
  70. this.setData({
  71. [`project[${index}].month`]: e.detail.value - 0 + 1
  72. });
  73. this.isDisabled(index);
  74. },
  75. isDisabled(i) {
  76. let data = this.data.project[i],
  77. arr = this.data.arr;
  78. arr[i] = data.target_h != '' && data.target_l != '' && data.month != '';
  79. this.setData({
  80. arr,
  81. disabled: !arr.every(v => v)
  82. })
  83. },
  84. onShareAppMessage() {}
  85. })