| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <template>
- <view class="box">
- <view class="input-box">
- <view class="input-box-left">
- {{ label }}
- </view>
- <view class="input-box-right">
- <checkbox-group @change="checkboxChange">
- <label class="checkbox-item" v-for="(checkboxItem,index) in checkboxArr">
- <checkbox :id="name+index" :value="checkboxItem.id" />
- <text class="iconfont icon-ok" v-if="checkboxItem.isChecked"> </text>
- <text class="iconfont icon-no" v-else> </text>
- {{checkboxItem.name}}
- </label>
- </checkbox-group>
- </view>
- </view>
- <view class="box-solid"></view>
- </view>
- </template>
- <script>
- export default {
- name: 'en-checkbox',
- props: {
- type: {
- type: String,
- default: 'text'
- },
- label: {
- type: String,
- default: '标题'
- },
- checkboxData: {
- type: Array,
- default: []
- },
- checkboxKey:{
- type:String,
- default:'id'
- },
- checkboxValue:{
- type:String,
- default:'name'
- },
- disabled: {
- default: false
- },
- name: {
- type: String,
- default: 'text'
- },
- valueType: {
- default: '1'
- },
- value: {
- default: []
- }
- },
- data() {
- return {
- inputValue: [],
- checkboxArr:[],
- }
- },
- components: {},
- mounted() {
- this.setValue()
- this.setCheckboxData()
- },
- watch: {
- 'value': function () {
- if (this.inputValue !== this.value) {
- this.setValue()
- }
- },
- 'inputValue': function () {
- if(this.valueType==='1'){
- this.$emit('input', this.inputValue.join(','))
- }else {
- this.$emit('input', this.inputValue)
- }
- }
- },
- methods: {
- checkboxChange(e){
- this.inputValue=e.detail.value
- console.log(this.inputValue)
- this.setIsCheckbox()
- },
- setCheckboxData(){
- if(this.checkboxData.length<=0){
- return ;
- }
- this.checkboxData.forEach((item)=>{
- if(item[this.checkboxKey] && item[this.checkboxValue]){
- this.checkboxArr.push({
- 'id':item[this.checkboxKey]+'',
- 'name':item[this.checkboxValue],
- 'isChecked':false,
- })
- }
- })
- this.setIsCheckbox()
- },
- setValue(){
- let newValue=this.value
- if(typeof newValue ==='string'){
- newValue=newValue.split(',')
- }
- this.inputValue = []
- newValue.forEach((item)=>{
- this.inputValue.push(item+'')
- })
- this.setIsCheckbox()
- },
- setIsCheckbox(){
- this.checkboxArr.forEach((item)=>{
- item.isChecked=this.inputValue.indexOf(item.id) >= 0
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @font-face {
- font-family: 'iconfont';
- src: url('iconfont.ttf?t=1662432727120') format('truetype');
- }
- .iconfont {
- font-family: "iconfont" !important;
- font-size: 36rpx;
- color: #3169FA;
- font-style: normal;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- }
- .box{
- background-color: #ffffff;
- padding: 34rpx 0 12rpx 0;
- .input-box {
- display: flex;
- align-items: center;
- .input-box-left {
- width: 210rpx;
- min-width: 210rpx;
- font-size: 32rpx;
- color: #333333;
- }
- .input-box-right{
- display: flex;
- align-items: center;
- .checkbox-item{
- padding-right: 20rpx;
- margin-bottom: 20rpx;
- checkbox{
- display: none;
- }
- }
- }
- }
- .box-solid{
- border-bottom: 1px solid #F0F0F0;
- margin-top:22rpx;
- }
- }
- </style>
|