picker.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. },
  25. observers: {
  26. index: function (index) {
  27. this.setData({
  28. position: this.findIndex(this.data.pickData, index)
  29. })
  30. }
  31. },
  32. data: {
  33. position: -1
  34. },
  35. methods: {
  36. findIndex(arr, value) {
  37. return arr.findIndex(item => item.dictValue === value);
  38. },
  39. bindChange(e) {
  40. this.setData({
  41. position: getEventParam(e, 'value')
  42. }, () => {
  43. this.triggerEvent('change', {
  44. [this.data.emitKey]: this.data.pickData[this.data.position][this.data.value]
  45. })
  46. })
  47. },
  48. }
  49. });