<template>
	<view>
		<view class="content-box">
			<label class="content-label">
				<view class="label-name">
					<text>市场名称</text>
				</view >
				<view class="label-data">
					<input type="text" v-model="msgform.marketName"  class="label-input"/>
				</view>
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>市场地址</text>
				</view >
				<view class="label-data">
					<input type="text" v-model="msgform.address"  class="label-input"/>
				</view>
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>竞争对手数量</text>
				</view >
				<view class="label-data">
					<input type="text" v-model="msgform.competitorNumber"  class="label-input"/>
				</view>
				
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>潜在客户数量</text>
				</view >
				<view class="label-data">
					<input type="text" v-model="msgform.customerNumber"  class="label-input"/>
				</view>
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>平均消费</text>
				</view >
				<view class="label-data">
					<input type="text" v-model="msgform.avgPrice"  class="label-input"/>
				</view>
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>调研时间</text>
				</view >
				<view class="label-data">
					<!-- <input @click="open()" type="text" v-model="msgform.researchTime"  class="label-input"/> -->
					<!-- <uni-calendar
					ref="calendar"
					:insert="false"
					@confirm="confirm"
					 /> -->
					 <picker mode="date" :value="date" start="2015-09-01" end="2024-09-01" @change="DateChange" class="common-picker">
					 	<view class="picker">
					 		{{date}}
					 	</view>
					 </picker>
				</view>
			</label>
		</view>
		<button @click="addF()" style="width: 80%; background-color:cornflowerblue;color: white">保存</button>
	</view>
</template>

<script>
	import {addResearch,updateResearch,getResearch} from "../../api/marketmini/index"
	export default {
		data() {
			return {
				msgform:{
					researchId: null,
					marketName: null, 
					address: null,
					competitorNumber: null,
					customerNumber: null,
					avgPrice: null,
					researchTime: null,
					createUserId: null,
					updateUserId: null,
					createTime: null,
					updateTime: null
				},
				flag:'msg',
				id:'',
				date: '请选择',
			}
		},	
		methods: {
			DateChange(e) {
				this.date = e.detail.value
				// console.log(this.date)
				this.msgform.researchTime = this.date
			},
			open(){
				this.$refs.calendar.open();
			},
			confirm(e) {
				// console.log(e);
				this.msgform.researchTime = e.fulldate
			},
			addF(){
				const form = {
					address: this.msgform.address,
					avgPrice: this.msgform.avgPrice,
					competitorNumber: this.msgform.competitorNumber,
					createTime: this.msgform.createTime,
					createUserId: this.msgform.createUserId,
					customerNumber: this.msgform.customerNumber,
					marketName: this.msgform.marketName,
					researchId: this.msgform.researchId,
					researchTime:this.msgform.researchTime,
					updateTime: this.msgform.updateTime,
					updateUserId: this.msgform.updateUserId
				}
				if(this.id !== ""){
					updateResearch(form).then(()=>{
						uni.navigateBack({
							delta: 1
						});
					})
				}else{
					addResearch(form).then(data=>{
						uni.switchTab({
							url:"/pages/index/index"
						})
					})
				}
				
			}
		},
		onLoad:function(option){
			if(option.id!=null){
				console.log(option.id)
				this.id = option.id
				getResearch(option.id).then(data=>{
					this.msgform = data.data
					this.date = data.data.researchTime
				})
			}
		}
	}
</script>

<style>
@import url("@/common/scss/core.scss");
</style>
