<?php

/* ========================================================================
 * $Id: form2.php 2425 2020-07-06 17:07:24Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# 新表单
# form2
#请求数据
if($MODE=='$post'){
  $action=onez()->gp('action');
  if($action=='data'){
    $ac=onez()->gp('ac');
    if($ac=='upload'){
      $data=$_REQUEST['base64'];
      $data=base64_decode($data);
      $file='/cache/plugins/vue/'.date('Y/m/d').'/'.uniqid().'.jpg';
      onez()->mkdirs(dirname(ONEZ_CACHE_PATH.$file));
      $im=imagecreatefromstring($data);
      imagejpeg($im,ONEZ_CACHE_PATH.$file);
      imagedestroy($im);
      @unlink($temp_file);
      if(file_exists(ONEZ_CACHE_PATH.$file)){
        onez()->write(ONEZ_CACHE_PATH.$file,$data);
        $A['url']=ONEZ_CACHE_URL.$file;
      }else{
        return $this->error('文件无效');
      }
      return;
    }
  }
  return;
}
?>
<template v-if="data && data.ready">
<van-form @submit="submit">
  <template v-for="item in fields">
  
    <van-cell :title="item.label" v-if="item.type=='number'" class="toLeft">
      <template #default>
        <van-stepper v-model="data.data[item.key]" :min="0" :name="item.key" />
      </template>
    </van-cell>
    <van-cell :title="item.label" v-else-if="item.type=='switch'" center class="toLeft">
      <template #default>
        <van-switch v-model="data.data[item.key]" :name="item.key" />
      </template>
    </van-cell>
    <van-cell :title="item.label" v-else-if="item.type=='file'" center class="toLeft">
      <template #default>
        <van-uploader v-model="data.data[item.key]" image-fit="contain" :after-read="afterRead" multiple />
      </template>
    </van-cell>
    <van-field v-else-if="item.type=='textarea'" :name="item.key" :label="item.label" :readonly="item.readonly" v-model="data.data[item.key]" :rows="item.rows||3" type="textarea" :placeholder="item.hint" @click="fieldClick(item)" />
    <van-field v-else :name="item.key" :label="item.label" :readonly="item.readonly" v-model="data.data[item.key]" :placeholder="item.hint" @click="fieldClick(item)" />
  </template>
  <van-calendar v-model="calendar_show" @confirm="calendar_confirm" />
  <van-popup v-model="picker_show" position="bottom">
    <van-picker show-toolbar :columns="picker_columns" @cancel="picker_show = false" @confirm="picker_confirm" />
  </van-popup>
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">
      {{data.btnname||'立即提交'}}
    </van-button>
  </div>
</van-form>
</template>