<!--components/form/form.wxml-->
<wxs module="format">
  // wxs中不能写ES6的语法: 例如箭头函数
  function isHide(hide, arr) {
    var rs = true
    arr.forEach(function (e) {
      hide.forEach(function (h) {
        if (e.id === h.id) {
          e.force = false
          h.value.forEach(function (v) {
            if (e.inputValue === v) {
              rs = false
            }
          })
        }
      })
    })
    return rs
  }

  // 需要导出函数, 导出只能使用CommonJs规范
  module.exports = {
    // 对象中也不能使用对象的增强写法
    isHide: isHide
  }
</wxs>

<view>
  <view wx:for="{{formLayoutData.formInfo}}" wx:key="{{index}}">
    <t-cell required="{{item.force}}" wx:if="{{item.type == 'cell'}}" title="{{item.label}}" note="{{item.inputValue}}" url="{{item.url}}" hover>

    </t-cell>
    <!-- 输入 -->
    <t-input wx:if="{{item.type == 'text'}}" value="{{item.inputValue}}" data-value="{{item.id}}" data-index="{{index}}" layout="horizontal" status="error" data-item="{{item}}" tips="{{item.errorMsg}}" placeholder="{{item.placeholder}}" align="right" bind:blur="onBlur" bind:clear="onClear" clearable>
      <view slot="label">
        {{item.label}} <text wx:if="{{item.force}}" style="color:#e34d59">*</text>
      </view>
    </t-input>
    <!-- 选择 -->
    <t-cell wx:if="{{item.type == 'picker'}}" required="{{item.force}}" note="{{item.inputValue >= 1?'是':item.inputValue >= 0? '否' :(item.inputValue||'请选择')}}" class="block" title="{{item.label}}" data-index="{{index}}" data-item="{{item}}" arrow hover bind:click="onPicker">
      <text slot="description" class="t-class-description">{{item.errorMsg?item.errorMsg:''}}</text>
    </t-cell>
    <!-- 上传 -->
    <view wx:if="{{item.type == 'upload'}}" style="padding:10px">
      <view class="uploadPanel">
        附件上传
      </view>
      <slot style="flex:1" name="attinfos"></slot>
      <upload id="upload" originFiles='{{item.originFiles||[]}}' />
    </view>
    <!-- 时间选择 -->
    <t-cell wx:if="{{item.type == 'datepicker'}}" title="{{item.label}}" hover note="{{item.inputValue}}" arrow data-item="{{item}}" data-index="{{index}}" data-mode="date" bindtap="showDatePicker" t-class="pannel-item" />
    <!-- 选择省市县 -->
    <t-cell required="{{item.force}}" wx:if="{{item.type == 'cascader'}}" title="{{item.label}}" data-index="{{index}}" note="{{item.inputValue}}" bind:click="showCascader">
      <text slot="description" class="t-class-description">{{item.errorMsg?item.errorMsg:''}}</text>
    </t-cell>

    <!-- 跳转链接 -->
    <t-cell required="{{item.force}}" wx:if="{{item.type == 'link' && format.isHide(item.hide,formLayoutData.formInfo)}}" title="{{item.label}}" note="{{item.inputValue}}" url="{{item.url}}" hover arrow>
      <text slot="description" class="t-class-description">{{item.errorMsg?item.errorMsg:''}}</text>
    </t-cell>

  </view>
  <view wx:if="{{!hideBtn}}" style="padding:30px">
    <t-button theme="primary" size="medium" disabled="{{disabledStatus}}" bind:tap="formSubmit" block>提 交</t-button>
  </view>
  <t-picker visible="{{pickerVisible}}" data-key="id" title="选择{{actPicker.label}}" cancelBtn="取消" confirmBtn="确认" bindconfirm="onPickerConfirm" bindchange="onPickerChange">
    <t-picker-item options="{{actPicker.data}}"></t-picker-item>
  </t-picker>
  <t-date-time-picker title="选择日期" visible="{{dateVisible}}" mode="date" value="{{timePickerValue}}" format="YYYY-MM-DD" bindchange="onTimePickerConfirm" />
  <t-cascader visible="{{cascaderVisible}}" theme="step" options="{{options}}" value='' title="请选择地址" bind:change="onChange"></t-cascader>
</view>