# form-create 生成表单

# 基本使用

<template>
		<bmx-form-create
			ref="formCreate"
		>
		</bmx-form-create>
		<button type="primary" @click="submit">校验</button>
		<button type="primary" @click="getData">不校验</button>
</template>
<script>

	export default {
		data() {
			return {
			}
		},
		onLoad() {
			const data = [{"type":"bmx-radio","field":"Ft8u5y3w4vkmz","title":"1+2咖啡30ct & 60ct 至少2个SKU上堆(是为1,否为0)","info":"","effect":{"fetch":"","inapplicableOption":{"to":"inapplicableOption","disabled":true},"material":{"to":"material","maxLimit":2,"minLimit":1,"gpsPosition":false,"size":1024,"type":"photo","sourceType":["camera"]},"dataset":{"to":"options","source":1,"value":73}},"props":{"disabled":false,"type":"default"},"options":[{"value":171,"label":"1"},{"value":172,"label":"0"}],"_fc_drag_tag":"bmx-radio","hidden":false,"display":true,"$required":"请输入"},{"type":"bmx-checkbox","field":"Ftek5y3w539j2","title":"货架陈列","info":"","effect":{"fetch":"","inapplicableOption":{"to":"inapplicableOption","disabled":true},"material":{"to":"material","minLimit":1,"gpsPosition":false,"size":1024,"type":"photo","sourceType":["camera","album"]},"dataset":{"to":"options","source":1,"value":74}},"props":{"type":"default","disabled":false,"min":1,"max":2},"options":[{"value":173,"label":"主货架 ≥1层 "},{"value":174,"label":"端架陈列 ≥1层"},{"value":175,"label":"冰柜陈列 ≥1层 "},{"value":176,"label":"每层≥1个面"},{"value":177,"label":"每层≥3个面"},{"value":178,"label":"每层≥6个面"}],"_fc_drag_tag":"bmx-checkbox","hidden":false,"display":true,"$required":"请输入"},{"type":"bmx-select","field":"Fmyy5y3w6ge2l","title":"雀巢咖啡1+2原味30ct(正常装&促销装均可 是为1,否为0)","info":"","effect":{"fetch":"","inapplicableOption":{"to":"inapplicableOption","disabled":true},"material":{"to":"material","minLimit":1,"gpsPosition":false,"size":1024,"type":"photo","sourceType":["camera"]},"dataset":{"to":"options","source":1,"value":75}},"props":{"placeholder":"请选择内容","clearable":true,"disabled":false,"defaultFirstOption":true},"options":[{"value":179,"label":"1"},{"value":180,"label":"0"}],"_fc_drag_tag":"bmx-select","hidden":false,"display":true,"$required":"请输入"},{"type":"bmx-multi-select","field":"Ffr85y3w6tk9q","title":"以下SKU任意2个上堆即可","info":"","effect":{"fetch":"","inapplicableOption":{"to":"inapplicableOption","disabled":true},"material":{"to":"material","minLimit":1,"gpsPosition":false,"size":1024,"type":"photo","sourceType":["form"]},"dataset":{"to":"options","source":1,"value":76}},"props":{"placeholder":"请选择内容","clearable":true,"disabled":false,"defaultFirstOption":true,"min":1,"max":2},"options":[{"value":181,"label":"雀巢怡养中老年配方奶粉400克*2礼盒"},{"value":182,"label":"雀巢怡养中老年配方奶粉 400克单袋"},{"value":183,"label":"脆脆鲨威化饼干138g"},{"value":184,"label":"雀巢咖啡1+2原味30ct(正常装)"},{"value":185,"label":"雀巢咖啡1+2特浓30条(促销装)"}],"_fc_drag_tag":"bmx-multi-select","hidden":false,"display":true},{"type":"bmx-input","field":"F9in5y3w7k6kn","title":"咖啡总拍数(数字)","info":"请输入数字","props":{"placeholder":"请输入","type":"text","minlength":1,"maxlength":200,"clearable":true,"disabled":false,"readonly":false,"showWordLimit":true,"rows":3},"remark":"备注","effect":{"inapplicableOption":{"to":"inapplicableOption","disabled":true},"material":{"to":"material","minLimit":1,"gpsPosition":false,"size":1024,"type":"photo","sourceType":["camera"]}},"_fc_drag_tag":"bmx-input","hidden":false,"display":true,"$required":"请输入"},{"type":"bmx-upload","field":"Fmsq5y3w7ww43","title":"货架位置照片","info":"","props":{"type":"photo","sourceType":["camera"],"minLimit":1,"size":1024,"maxLimit":3},"effect":{"inapplicableOption":{"to":"inapplicableOption","disabled":true}},"_fc_drag_tag":"bmx-upload","hidden":false,"display":true}]	
			this.$nextTick(() => {
				const formData = {
					data,
					model: '',
				  };
				//初始化表单
				this.$refs.formCreate.init(formData);
			})
			
		},
		methods: {
			// 图片上传方法
			ayonc imageUploadHandler(image){
				return image.url;
			},
			// 设置全局禁用状态(true,false)
			setFormDisabled(data) {
			  this.$nextTick(() => {
				this.$refs.formCreate.setGlobalDisabled(data);
			  });
			},
			// 校验表单
			submit() {
			  this.$refs.formCreate.submit().then((res) => {
				  uni.$u.toast('校验成功');
				  console.log(res)
			  }).catch((e) => {
			  });
			},
			// 不用校验获取填写数据
			getData() {
			  const data = this.$refs.formCreate.getData();
			  console.log("", data)
			},
		}
	}
</script>

# API

# Props

参数 说明 类型 默认值 可选值
imageUploadHandler 图片上传方法(需返回promise) Function - -

# Methods

此方法如要通过ref手动调用

名称 说明 参数 返回值
init 传递生成表单数据进行初始化 { data: [], model: ''} -
setGlobalDisabled 设置禁用 true|false -
submit 提交校验 - promise
getData 获取答案 - Array