index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // components/sg-date-picker/index.js
  2. import http from '../../utils/http'
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. date: String
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. multiArray: [],
  15. multiIndex: []
  16. },
  17. lifetimes: {
  18. attached: function() {
  19. var that = this
  20. http({
  21. url: 'data/getYearsAndMonths',
  22. data: {},
  23. success: function(res) {
  24. if(res.code == 0) {
  25. that.setData({
  26. multiArray: res.data.array,
  27. multiIndex: res.data.index
  28. })
  29. that.updateDate()
  30. }
  31. }
  32. })
  33. },
  34. detached: function() {
  35. // 在组件实例被从页面节点树移除时执行
  36. },
  37. },
  38. /**
  39. * 组件的方法列表
  40. */
  41. methods: {
  42. updateDate: function() {
  43. var multiArray = this.data.multiArray
  44. var multiIndex = this.data.multiIndex
  45. if(multiArray[0][multiIndex[0]].id == '') {
  46. this.triggerEvent('update', {
  47. date: ''
  48. })
  49. } else {
  50. var date = multiArray[0][multiIndex[0]].id
  51. var month = multiArray[1][multiIndex[1]].id
  52. month = month <= 9 ? '0' + month : month
  53. this.triggerEvent('update', {
  54. date: date + '-' + month + '-' + '01'
  55. })
  56. }
  57. },
  58. bindColumnChange: function(e) {
  59. var multiIndex = this.data.multiIndex
  60. multiIndex[e.detail.column] = e.detail.value
  61. this.setData({
  62. multiIndex: multiIndex
  63. })
  64. this.updateDate()
  65. }
  66. }
  67. })