index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <QStemplate :title="title" :titleHide="titleHide" :fontSize="fontSize" :width="width" :titleFlex="titleFlex"
  3. :contentFlex="contentFlex" :titleStyle="titleStyle" :contentStyle="contentStyle" :required="required" :requiredSign="requiredSign"
  4. :layout="layout" :titleLayout="titleLayout" :itemDisabled="itemDisabled" :titleColor="titleColor">
  5. <view class="flex_row_none_c width100 padding_10rpx_15rpx">
  6. <checkbox-group @change="checkboxChange" class="width100 wrap" :class="itemLayout_computed">
  7. <label class="fontColor666666 flex_row_none_c marginRight_15rpx padding_10rpx" v-for="(checkboxItem, checkboxIndex) in itemArray||[]"
  8. :key="checkboxIndex">
  9. <checkbox :value="checkboxItem.value" :checked="getStatus[checkboxIndex]" :disabled="disabled" :color="checkboxItem.color||color"
  10. :style="'transform: scale(' + (scale||'.8') + ');'" />
  11. <view class="flex_row_none_c">{{checkboxItem.name}}</view>
  12. </label>
  13. </checkbox-group>
  14. </view>
  15. </QStemplate>
  16. </template>
  17. <script>
  18. import _app from '../../js/app.js';
  19. import QStemplate from '../../template/template.vue';
  20. import QSInputsMixin from '../../js/QSInputsMixin.js';
  21. export default {
  22. components: {
  23. QStemplate
  24. },
  25. props: {
  26. itemArray: {
  27. type: Array,
  28. default () {
  29. return []
  30. }
  31. },
  32. color: {
  33. type: String,
  34. default: '#33cc33'
  35. },
  36. scale: {
  37. type: String,
  38. default: '.8'
  39. },
  40. disabled: {
  41. type: Boolean,
  42. default: false
  43. }
  44. },
  45. computed:{
  46. getStatus() {
  47. const status = [];
  48. const value = this.value;
  49. const itemArray = this.itemArray;
  50. if(value instanceof Array && value.length > 0) {
  51. for(let i = 0; i < itemArray.length; i++) {
  52. const j = value.findIndex(item=>item === itemArray[i].value)
  53. if(j >= 0) {
  54. status.push(true);
  55. }else{
  56. status.push(false);
  57. }
  58. }
  59. }else{
  60. itemArray.forEach(()=>{
  61. status.push(false);
  62. })
  63. }
  64. return status;
  65. }
  66. },
  67. methods: {
  68. checkboxChange({
  69. detail: {
  70. value
  71. }
  72. }) {
  73. this.setValue(value);
  74. }
  75. },
  76. mixins: [QSInputsMixin({
  77. QSInputsType: _app.typeObj.checkbox
  78. })]
  79. };
  80. </script>
  81. <style scoped>
  82. @import url("../../css/inputs.css");
  83. </style>