<template>
	<view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				mine: "",
				// 用户信息
				name: "",
				depart_name: "",
				// 用户id
				people_num: 0,

				// 重名人员 原始数据
				list: [],

				// 配置参数
				user_list: []
			};
		},
		onLoad(option) {
			console.log(option)
			this.mine = option.mine

			// 设置用户信息
			this.name = option.name
			this.depart_name = option.depart_name

			this.get_list()
		},
		methods: {
			// 获取重名人员列表参数
			get_list() {
				this.$api.user_getPersonnelListByName({
					name: this.name
					// name: "王文新"
				}).then((res) => {
					console.log(res.data.data)

					this.list = res.data.data
					this.list.forEach((item, index) => {
						this.user_list.push(item.name + '-' + item.department + '-' + item.job)
					})
					console.log(this.list)
					console.log(this.user_list)

					this.choose_user()
				})
			},

			// 选择人员
			choose_user() {
				uni.showActionSheet({
					itemList: this.user_list,
					success: (res) => {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						console.log(this.list[res.tapIndex].people_code)

						this.people_num = this.list[res.tapIndex].people_code

						uni.showModal({
							title: '提示',
							content: '你选中的是：' + this.list[res.tapIndex].name + '-' + this.list[res
									.tapIndex].department + '-' + this.list[res.tapIndex].job +
								"；只能选择一次，是否确认",
							success: (res) => {
								if (res.confirm) {
									console.log('用户点击确定');

									this.$api.user_updateUserMessage({
										people_code: this.people_num
									}).then((res) => {
										console.log(res)
									})


									uni.setStorageSync('people_code', this.people_num)

									uni.redirectTo({
										url: "../../production/personnel_orientation/downhole_statistics/downhole_statistics?people_num=" +
											this.people_num + "&depart_name=" + this
											.depart_name + "&name=" + this.name +
											"&mine=" + this.mine
									})
								} else if (res.cancel) {
									this.choose_user()
									console.log('用户点击取消');
								}
							}
						});

					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			}
		}
	}
</script>

<style lang="scss">

</style>
