低代码第二篇 组件封装【表单组件】 单选组件

 输入框属性
序号属性值默认值描述
1title文本字段标题
2canedittrue该表单是否可编辑,默认为true,即可编辑
3defvalue“”字段默认值,默认为空
4isshowtrue该字段可见性,默认为可见

页面代码

<view class="{{formitem.border?'cu-form-group border-top':'cu-form-group' }}  ">
  <view class="title">{{formitem.title}}:</view>
  <view class="text-left {{!formitem.canedit?'cannotedit':''}} "  bindtap="openselect">{{formitem.deftext?formitem.deftext:'请选择'+formitem.title}}</view>
  <view class="cuIcon-right lg text-gray" wx:if="{{formitem.canedit}}"></view>
  <!-- <input disabled="{{!formitem.canedit}}" value="{{formitem.defvalue}}"></input> -->
</view>
 
<view class="cu-modal {{showoption?'show':''}}" bindtap="hideModal">
  <view class="cu-dialog option-window" catchtap>
 
    <view class="margin-xs padding-sm solids-bottom " wx:for="{{formitem.options}}" wx:key="id" 
    data-id="{{item.id}}" data-text="{{item.text}}" bindtap="selectchange">
      <view class="flex flex-wrap ">
        <view class="basis-xl text-left">{{item.text}}</view>
        <view class="basis-xs {{item.id==formitem.defvalue?'cuIcon-roundcheck':'cuIcon-round'}} lg text-blue  text-right">
        </view>
      </view>
    </view>
 
  </view>
</view>

js代码

// component/wxe/simpleselectsingle.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    formitem: {
      type: Object,
      value: {title:'普通单选',defvalue:'001',deftext:null,canedit:false,options:[{id:'001',text:'选项1'},{id:'002',text:'选项2'},,{id:'003',text:'选项3'}]}
    }
 
  },
 
  /**
   * 组件的初始数据
   */
  data: {
    showoption:false
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    selectchange:function(e){
      var id_=e.currentTarget.dataset.id;
      var text_=e.currentTarget.dataset.text;
      this.setData({
        ['formitem.defvalue']: id_,
        ['formitem.deftext']:text_,
        showoption: false
      });
      var parma={};
      parma.defvalue=id_;
      parma.fieldname=this.data.formitem.fieldname
      parma.deftext=text_;
      this.triggerEvent("itemchange", parma, {})
    },
    openselect:function(e){
      console.log("openselect");
      this.setData({
        showoption: true
      })
    }
  }
  
})

css代码

/* component/wxe/MultiText.wxss */
@import "/colorui/main.wxss";
@import "/colorui/icon.wxss";
.border-top{
  border-top: 1rpx solid #eee;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值