<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="customerName"  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="company"  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="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="phone"  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="age"  class="label-input"/>
				</view>
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>性别</text>
				</view >
				<view class="label-data">
					<picker @change="PickerChange" :value="index" :range="picker" class="common-picker">
						<view class="picker">
							{{index>-1?picker[index]:' 请选择 '}}
						</view>
					</picker>
					<!-- <input type="text" v-model="sex"  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="position"  class="label-input"/>
				</view>
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>是否内部客户</text>
				</view >
				<view class="label-data">
					<picker @change="PickerChangeIn" :value="indexIn" :range="pickerIn" class="common-picker">
						<view class="picker">
							{{indexIn>-1?pickerIn[indexIn]:' 请选择 '}}
						</view>
					</picker>
					<!-- <input type="text" v-model="isIn"  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="remark"  class="label-input"/>
				</view>
			</label>
			<label class="content-label">
				<view class="label-name">
					<text>登记年份</text>
				</view >
				<view class="label-data">
					<picker @change="PickerChangeYear" :value="indexYear" :range="pickerYear" class="common-picker">
						<view class="picker">
							{{indexYear>-1?pickerYear[indexYear]:' 请选择 '}}
						</view>
					</picker>
					<!-- <input type="text" v-model="year"  class="label-input"/> -->
				</view>
			</label>
		</view>
		<button @click="addF()" style="width: 80%; background-color:cornflowerblue;color: white">保存</button>
	</view>
</template>

<script>
	import { addCustomerInfo,getCustomerInfo,updateCustomerInfo } from "../../api/marketmini/index"
	export default {
		data() {
			return {
				customerId: null,
				customerName: null,
				company: null,
				age: null,
				address: null,
				isIn: null,
				sex: null,
				position: null,
				remark: null,
				year: null,
				phone: null,
				createUserId: null,
				createTime: null,
				updateUserId: null,
				updateTime: null,
				search:null,
				flag:'msg',
				id:'',
				sexnum:1,
				isInnum:1,
				picker: ['男', '女', '未知'],
				index: -1,
				pickerIn: ['是', '否'],
				indexIn: -1,
				pickerYear: ['2021', '2022','2023','2024'],
				indexYear: -1,
			}
		},
		methods: {
			PickerChange(e) {
				this.index = e.detail.value
				// console.log(this.picker[this.index])
				this.sex = this.index
				console.log(this.sex)
			},
			PickerChangeIn(e) {
				this.indexIn = e.detail.value
				// console.log(this.pickerIn[this.indexIn])
				this.isIn = this.indexIn + 1
				console.log(this.isIn)
			},
			PickerChangeYear(e) {
				this.indexYear = e.detail.value
				// console.log(this.pickerYear[this.indexYear])
				this.year = this.pickerYear[this.indexYear]
				// console.log(this.year)
			},
			changeMethod(e) {
			  this.year = e
			},
			changeIn(e) {
			  this.isIn = e
			},
			changeSex(e) {
			  this.sex = e
			},
			addF(){
				const form = {
					customerId:this.id ,
					customerName:this.customerName ,
					company:this.company ,
					age: this.age-0,
					address: this.address,
					isIn: this.isIn,
					sex: this.sex,
					position: this.position,
					remark: this.remark,
					year:this.year ,
					phone: this.phone,
					createUserId: this.createUserId,
					createTime:this.createUserId ,
					updateUserId: this.updateUserId,
					updateTime: this.updateTime
				}
				if(this.id !== ""){
					updateCustomerInfo(form).then(()=>{
						uni.navigateBack({
							delta: 1
						});
					})
				}else{
					// console.log(2222)
					addCustomerInfo(form).then(()=>{
						// uni.navigateTo({
						// 	url:'/pages/index/index'
						// })
						uni.switchTab({
							url:'/pages/index/index'
						})
					})
				}
				
			}
		},
		mounted() {
			
		},
		onLoad:function(option){
			if(option.id!=null){
				console.log(option.id)
				this.id = option.id
				getCustomerInfo(option.id).then(data=>{
					// this.msgform = data.data
					console.log(data.data)
					this.address= data.data.address,
					this.age= data.data.age,
					this.company=data.data.company,
					this.createBy= data.data.createBy,
					this.createTime= data.data.createTime,
					this.createUserId= data.data.createUserId,
					this.customerId= data.data.customerId,
					this.customerName= data.data.customerName,
					this.isIn= data.data.isIn,
					this.params= data.data.params,
					this.phone= data.data.phone,
					this.position= data.data.position,
					this.remark= data.data.remark,
					this.searchValue= data.data.searchValue,
					this.sex= data.data.sex,
					this.updateBy= data.data.updateBy,
					this.updateTime= data.data.updateTime,
					this.updateUserId= data.data.updateUserId,
					this.year= data.data.year
					this.index = data.data.sex
					this.indexIn = data.data.isIn-1
					if(data.data.year=="2021"){
						this.indexYear=0
					}else if(data.data.year=="2022"){
						this.indexYear=1
					}else if(data.data.year=="2023"){
						this.indexYear=2
					}else if(data.data.year=="2024"){
						this.indexYear=3
					}
				})
			}
		}
	}
</script>

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