addProject.js 2.1 KB

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