You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

form-radio.js 1.3KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // components/form/form-radio/form-radio.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. label: {
  8. type: String,
  9. value: ''
  10. },
  11. list: {
  12. type: Array,
  13. value: []
  14. },
  15. value: {
  16. type: Number,
  17. value: 0
  18. }
  19. },
  20. observers: {
  21. list(val) {
  22. if(val.length > 0) {
  23. this.setData({
  24. radioList: val
  25. })
  26. }
  27. },
  28. value(val) {
  29. let self = this;
  30. if(val) {
  31. self.data.radioList.map((item, index) => {
  32. if (val == item.id) {
  33. item.check = 1;
  34. } else {
  35. item.check = 2;
  36. }
  37. })
  38. self.setData({
  39. radioList: self.data.radioList
  40. })
  41. }
  42. }
  43. },
  44. data: {
  45. styleCss: 'padding: 38rpx 0; line-height: 36rpx font-size: 28rpx; border-bottom: 1rpx dashed #f0f0f0;',
  46. radioList: []
  47. },
  48. methods: {
  49. choose(e) {
  50. let self = this;
  51. let idx = e.currentTarget.dataset.idx;
  52. self.data.radioList.map((item, index) => {
  53. if (index == idx) {
  54. item.check = 1;
  55. } else {
  56. item.check = 2;
  57. }
  58. })
  59. self.setData({
  60. radioList: self.data.radioList
  61. })
  62. self.triggerEvent('getvalue', {
  63. val: e.currentTarget.dataset.id
  64. })
  65. },
  66. }
  67. })