addProject.js 2.2 KB

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