app-submit-checkbox.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, 'background-color': iValue === activeValue && !is_gift ? cTheme.background : ''}"
  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. is_gift: false
  46. };
  47. },
  48. mounted() {
  49. this.is_gift = typeof(this.cTheme) == 'string' && this.cTheme.indexOf('gift') >= 0 ? true : false;
  50. },
  51. computed: {
  52. ...mapGetters('mallConfig', {
  53. defaultTheme: 'getTheme',
  54. }),
  55. cTheme() {
  56. return this.iTheme ? this.iTheme : this.defaultTheme;
  57. },
  58. themeBgClass() {
  59. if (typeof(this.cTheme) == 'string' && this.cTheme.indexOf('gift') >= 0) {
  60. return `${this.cTheme} ${this.cTheme}-background`;
  61. }
  62. },
  63. },
  64. watch: {
  65. value(v) {
  66. this.iValue = v;
  67. },
  68. theme(v) {
  69. this.iTheme = v;
  70. },
  71. },
  72. methods: {
  73. handleClick() {
  74. this.iValue = this.iValue === this.activeValue ? this.inactiveValue : this.activeValue;
  75. this.$emit('input', {
  76. v: this.iValue, index: this.sign
  77. });
  78. this.$emit('change', this.iValue, this.sign);
  79. },
  80. },
  81. }
  82. </script>
  83. <style scoped lang="scss">
  84. .app-submit-checkbox {
  85. border: #{1rpx} solid;
  86. display: inline-block;
  87. }
  88. .app-submit-checkbox.inactive {
  89. background: #fff;
  90. }
  91. .app-submit-checkbox.round {
  92. border-radius: #{10000rpx};
  93. }
  94. .app-submit-checkbox.active {
  95. border: none;
  96. background-image: url("../../static/image/icon/yes-radio.png");
  97. background-size: 100% 100%;
  98. }
  99. </style>