wk-field-bool.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view class="wk-field wk-field-bool" @click.stop>
  3. <view v-if="_label" class="wk-field__label">
  4. <view v-if="field.isNull === 1" class="line" />
  5. {{ _label }}
  6. </view>
  7. <view class="wk-field__body">
  8. <switch
  9. :checked="checkedStatus"
  10. :disabled="field.disabled"
  11. color="#007AFF"
  12. class="switch-core"
  13. @change="handleChange" />
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import mixins from './mixins'
  19. export default {
  20. name: 'WkFieldBool',
  21. mixins: [mixins],
  22. data() {
  23. return {
  24. checkedStatus: false
  25. }
  26. },
  27. watch: {
  28. formValue: {
  29. handler() {
  30. this.checkedStatus = Boolean(Number(this.formValue))
  31. },
  32. immediate: true,
  33. deep: true
  34. }
  35. },
  36. methods: {
  37. handleChange() {
  38. console.log('bool change', this.checkedStatus)
  39. this.checkedStatus = !this.checkedStatus
  40. const val = this.checkedStatus ? '1' : '0'
  41. this.$emit('input', val)
  42. this.$emit('change', {
  43. index: this.index,
  44. field: this.field,
  45. value: val
  46. })
  47. }
  48. }
  49. }
  50. </script>
  51. <style scoped lang="scss">
  52. @import './wkField.scss';
  53. .wk-field-bool {
  54. @include left;
  55. .wk-field__body {
  56. min-height: unset;
  57. border: unset;
  58. padding: 10rpx 0;
  59. @include right;
  60. .switch-core {
  61. transform: translateX(10%) scale(0.8);
  62. }
  63. }
  64. }
  65. </style>