app-submit-checkbox.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="app-submit-checkbox"
  3. :class="[{'round' : round}, iValue === activeValue ? 'active' : 'inactive', iValue === activeValue ? themeBgClass : '']"
  4. :style="{'width': `${width}rpx`, 'height': `${height}rpx`, borderColor: borderColor}"
  5. @click.stop="handleClick">
  6. </view>
  7. </template>
  8. <script>
  9. import {mapGetters} from 'vuex';
  10. export default {
  11. name: "app-submit-checkbox",
  12. props: {
  13. value: {
  14. default: true,
  15. },
  16. activeValue: {
  17. default: true,
  18. },
  19. inactiveValue: {
  20. default: false,
  21. },
  22. width: {
  23. default: 40
  24. },
  25. height: {
  26. default: 40
  27. },
  28. sign: {
  29. default: null,
  30. },
  31. borderColor: {
  32. default: '#cccccc',
  33. },
  34. round: {
  35. default: false,
  36. },
  37. theme: {
  38. default: null,
  39. },
  40. },
  41. data() {
  42. return {
  43. iValue: this.value,
  44. iTheme: this.theme,
  45. };
  46. },
  47. computed: {
  48. ...mapGetters('mallConfig', {
  49. defaultTheme: 'getTheme',
  50. }),
  51. cTheme() {
  52. return this.iTheme ? this.iTheme : this.defaultTheme;
  53. },
  54. themeBgClass() {
  55. if (this.cTheme.indexOf('gift') >= 0) {
  56. return `${this.cTheme} ${this.cTheme}-background`;
  57. } else {
  58. return `${this.cTheme} ${this.cTheme}-m-back`;
  59. }
  60. },
  61. themeBorderClass() {
  62. if (this.cTheme.indexOf('gift') >= 0) {
  63. return `${this.cTheme} ${this.cTheme}-background`;
  64. } else {
  65. return `${this.cTheme} ${this.cTheme}-m-back`;
  66. }
  67. },
  68. },
  69. watch: {
  70. value(v) {
  71. this.iValue = v;
  72. },
  73. theme(v) {
  74. this.iTheme = v;
  75. },
  76. },
  77. methods: {
  78. handleClick() {
  79. this.iValue = this.iValue === this.activeValue ? this.inactiveValue : this.activeValue;
  80. this.$emit('input', this.iValue, this.sign);
  81. this.$emit('change', this.iValue, this.sign);
  82. },
  83. },
  84. }
  85. </script>
  86. <style scoped lang="scss">
  87. .app-submit-checkbox {
  88. border: #{1rpx} solid;
  89. display: inline-block;
  90. }
  91. .app-submit-checkbox.inactive {
  92. background: #fff;
  93. }
  94. .app-submit-checkbox.round {
  95. border-radius: #{10000rpx};
  96. }
  97. .app-submit-checkbox.active {
  98. border: none;
  99. background-image: url("../../static/image/icon/yes-radio.png");
  100. background-size: 100% 100%;
  101. }
  102. </style>