picker.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {getEventParam} from "../../utils/utils";
  2. import {logicStatus} from "../../model/enum";
  3. Component({
  4. properties: {
  5. label: String,
  6. pickData: {
  7. type: Array,
  8. value: [
  9. {dictLabel: '是', dictValue: logicStatus.YES + ""},
  10. {dictLabel: '否', dictValue: logicStatus.NO + ""}
  11. ]
  12. },
  13. key: {
  14. type: String,
  15. value: 'dictLabel'
  16. },
  17. value: {
  18. type: String,
  19. value: 'dictValue'
  20. },
  21. emitKey: String,
  22. index: String,
  23. placeholder: String,
  24. required: {
  25. type: Boolean,
  26. value: true
  27. }
  28. },
  29. observers: {
  30. index: function (index) {
  31. this.setData({
  32. position: this.findIndex(this.data.pickData, index)
  33. })
  34. }
  35. },
  36. data: {
  37. position: -1
  38. },
  39. methods: {
  40. findIndex(arr, value) {
  41. return arr.findIndex(item => item.dictValue === value);
  42. },
  43. bindChange(e) {
  44. this.setData({
  45. position: getEventParam(e, 'value')
  46. }, () => {
  47. this.triggerEvent('change', {
  48. [this.data.emitKey]: this.data.pickData[this.data.position][this.data.value]
  49. })
  50. })
  51. },
  52. }
  53. });