<template>
	<view class="content">
		<u-form :model="form" ref="uForm">
			<u-form-item label="问题类型" label-position="top">
				<u-input v-model="form.typeName" type="select" :border="true" @click="typeshow = true" />
				<u-select v-model="typeshow" mode="single-column" value-name="id" label-name="value" :list="plist"
					@confirm="confirmType"></u-select>
			</u-form-item>
			<u-form-item label="问题内容" label-position="top">
				<u-input v-model="form.contentName" type="select" :border="true" @click="contentshow = true" />
				<u-select v-model="contentshow" mode="single-column" value-name="id" label-name="value" :list="list" @confirm="confirmContent"></u-select>
			</u-form-item>
			<u-form-item label="位置" label-position="top">
				<text>江苏省苏州市通园路66号</text>
				<u-button shape="square" slot='right' size="mini" @click="toshowMap" type="info">重新获取</u-button>
			</u-form-item>
			<u-form-item label-position="top" label="描述" prop="intro">
				<u-input v-model="form.intro" type='textarea' height='100' :border="true" />
			</u-form-item>
			<u-form-item label-position="top" label="附件上传" prop="intro">
				<u-upload ref="uUpload" :action="action" upload-text="选择附件" :show-tips="false"></u-upload>
			</u-form-item>
		</u-form>
		<u-button type="primary" @click="submit">提交</u-button>
		<u-popup v-model="showMap" mode="center" closeable close-icon-color="#ffffff" border-radius="14">
			<view>
				<view class="popuptitle">选择位置</view>
				<map :style="{width:width+'px',height:height+ 'px'}" :latitude="location.latitude"
					:longitude="location.longitude" id="map">
				</map>
				<view>
					<u-button type="primary" shape="square">确认选择</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showMap: false,
				typeshow: false,
				contentshow: false,
				action: "",
				location: {},
				plist: [],
				list: [],
				form: {
					type: "",
					content: "",
					typeName: "",
					contentName: ""
				},
				width: 300,
				height: 300
			}
		},
		onLoad() {
			var that = this;
			this.loadType({
				'number': "general_type",
			}, function(res) {
				that.plist = res;
			});
		},
		onReady() {
			this._mapContext = uni.createMapContext("map", this);
			let that = this;
			uni.getLocation({
				type: "gcj02",
				success(res) {
					that.location = res;
				}
			})
			uni.getSystemInfo({
				complete(res) {
					that.width = res.screenWidth * .8
					that.height = res.screenHeight * .6
				}
			})

		},
		methods: {
			loadType(data, call) {
				let that = this;
				this.util.request({
					api: '/api/admin/parameter/show',
					data: data,
					utilSuccess: function(res) {
						call(res.detail)
					},
					utilFail: function(res) {
						this.util.alert(res);
					}
				});
			},
			toshowMap() {
				this.showMap = true;
				this.addMaker();
			},
			submit() {},
			confirmType(e) {
				var that = this;
				this.form.type = e[0].value
				this.form.typeName = e[0].label
				this.loadType({
					pid: e[0].value
				}, function(res) {
					that.list = res;
				})
			},
			confirmContent(e) {
				this.form.content = e[0].value
				this.form.contentName = e[0].label
			},
			addMaker() {
				let img = "../../../static/img/location.png"
				const marker = {
					id: 1,
					iconPath: img,
					width: 50,
					height: 50,
					label: {
						width: 50,
						height: 30,
						borderWidth: 1,
						borderRadius: 10,
						bgColor: '#ffffff'
					},
					latitude: this.location.latitude,
					longitude: this.location.longitude
				};
				this._mapContext.addMarkers({
					marker,
					clear: true,
					complete(res) {
						console.log('addMarkers', res)
					},
					fail(res) {
						console.log('fail', res)
					}
				});
			}

		}
	}
</script>

<style>
	.content {
		padding: 20rpx;
	}

	.popuptitle {
		background: #2979ff;
		color: #fff;
		padding: 20rpx 30rpx;
	}
</style>
