<template>
	<div id="app" class="app-container" style="margin: 10px;">
		<el-form :inline="true" :model="parameter" class="demo-form-inline">
		  <el-form-item label="用户ID">
		    <el-input v-model="parameter.UserId" placeholder="用户ID"></el-input>
		  </el-form-item>
		  <el-form-item label="手机号">
		   <!-- <el-select v-model="formInline.region" placeholder="活动区域">
		      <el-option label="区域一" value="shanghai"></el-option>
		      <el-option label="区域二" value="beijing"></el-option>
		    </el-select> -->
			<el-input v-model="parameter.Phone" placeholder="手机号"></el-input>
		  </el-form-item>
		  <el-form-item>
		    <el-button type="primary" @click="SubmitUser">查询</el-button>
		  </el-form-item>
		</el-form>
		<el-table style="margin-top: 5px;" v-loading="listLoading" :data="userlist" element-loading-text="Loading"
			border fit highlight-current-row>
			<el-table-column label="上线" align="center">
				<template slot-scope="scope">
					{{scope.row.ParentUserId}}
				</template>
			</el-table-column>
			<el-table-column label="微信头像" width="120" align="center">
				<template slot-scope="scope">
					<img :src="scope.row.beijintupian" style="width: 50px;height: 50px;" />
				</template>
			</el-table-column>
			<el-table-column label="用户ID" width="120" align="center">
				<template slot-scope="scope">
					{{scope.row.id}}
				</template>
			</el-table-column>
			<el-table-column label="用户微信名" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.username }}</span>
				</template>
			</el-table-column>
			<el-table-column label="称呼" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.full_name }}</span>
				</template>
			</el-table-column>
			<el-table-column label="手机号码" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.phone }}</span>
				</template>
			</el-table-column>
			<el-table-column label="备用手机" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.updphone }}</span>
				</template>
			</el-table-column>
			<el-table-column label="地址" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.address }}</span>
				</template>
			</el-table-column>
			
			
			<el-table-column label="车型" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.CarModel }}</span>
				</template>
			</el-table-column>
			<el-table-column label="颜色" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.CarColour }}</span>
				</template>
			</el-table-column>
			<el-table-column label="划痕" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.Scratch }}</span>
				</template>
			</el-table-column>
			<el-table-column label="腐蚀" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.Corrosion}}</span>
				</template>
			</el-table-column>
			<el-table-column label="破损" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.BeDamaged }}</span>
				</template>
			</el-table-column>
			<el-table-column label="飞漆" align="center">
				<template slot-scope="scope">
					<span>{{ scope.row.FlyingPaint }}</span>
				</template>
			</el-table-column>
			
			<el-table-column label="余额" align="center" v-if="false">
				<template slot-scope="scope">
					<span>￥{{ scope.row.balance/100 }}</span>
				</template>
			</el-table-column>
			<el-table-column label="已完成单数" align="center" v-if="false">
				<template slot-scope="scope">
					<span>{{scope.row.nowNum }}</span>
				</template>
			</el-table-column>
			<el-table-column label="性别" align="center" v-if="false">
				<template slot-scope="scope">
					<el-tag :type="scope.row.sex==0?'success':'warn'">
						<span>{{ scope.row.sex==0?'男':'女'}}</span>
					</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="生日" align="center" v-if="false">
				<template slot-scope="scope">
					<span>{{ scope.row.birthday }}</span>
				</template>
			</el-table-column>
			<el-table-column label="注册时间" align="center" v-if="false">
				<template slot-scope="scope">
					{{ scope.row.add_time }}
				</template>
			</el-table-column>
			<el-table-column label="用户角色" align="center">
				<template slot-scope="scope">
					<el-tag :key="scope.row.type" type="warning" effect="dark">
						{{scope.row.type==0?'超级管理员':scope.row.type==1?'管理员':scope.row.type==2?'普通用户':scope.row.type==3?'推广专员':scope.row.type==4?'客户经理':'未知' }}
					</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="用户状态" align="center">
				<template slot-scope="scope">
					<el-tag :key="scope.row.status" v-if="scope.row.status==='0'" type="success" effect="dark">
						使用中
					</el-tag>
					<el-tag :key="scope.row.status" v-if="scope.row.status==='-99'" type="danger" effect="dark">
						禁用中
					</el-tag>
				</template>
			</el-table-column>
			<el-table-column fixed="right" label="操作" width="230">
				<template slot-scope="scope">
					<el-dropdown @command="(e)=>{handleCommand(e,scope.row.id,scope.row)}">
						<span class="el-dropdown-link">
							操作<el-icon class="el-icon--right">
								<arrow-down />
							</el-icon>
						</span>
						<template #dropdown>
							<el-dropdown-menu>
								<el-dropdown-item command="h">查看客户
								</el-dropdown-item>
								<el-dropdown-item command="i">查看专员
								</el-dropdown-item>
								<el-dropdown-item command="a">升级成客户经理
								</el-dropdown-item>
								<el-dropdown-item command="e">升级成推广专员
								</el-dropdown-item>
								<el-dropdown-item command="b">删除</el-dropdown-item>
								<el-dropdown-item command='c' v-if="false">编辑</el-dropdown-item>
								<el-dropdown-item command='d' v-if="false">车辆信息</el-dropdown-item>
								<el-dropdown-item command="f" v-if="scope.row.status==0">拉黑用户</el-dropdown-item>
								<el-dropdown-item command="g" v-else>取消拉黑</el-dropdown-item>
							</el-dropdown-menu>
						</template>
					</el-dropdown>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination background layout="prev, pager, next" :total="parameter.TotalCount" @current-change="Pages"
			style="text-align: right;margin-top: 10px;">
		</el-pagination>
		<el-dialog title="查看客户" :visible.sync="dialogVisibleSub" width="100%">
			<el-table :data="SubList" element-loading-text="Loading" border fit highlight-current-row>
				<el-table-column label="用户ID" width="120" align="center">
					<template slot-scope="scope">
						{{scope.row.id}}
					</template>
				</el-table-column>
				<el-table-column label="用户微信名" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.username }}</span>
					</template>
				</el-table-column>
				<el-table-column label="别名" align="center" v-if="false">
					<template slot-scope="scope">
						<span>{{ scope.row.full_name }}</span>
					</template>
				</el-table-column>
				<el-table-column label="用户电话" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.phone }}</span>
					</template>
				</el-table-column>
				<el-table-column label="备用电话" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.updphone }}</span>
					</template>
				</el-table-column>
				<el-table-column label="地址" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.address }}</span>
					</template>
				</el-table-column>
				<el-table-column label="余额" align="center">
					<template slot-scope="scope">
						<span>￥{{ scope.row.balance/100 }}</span>
					</template>
				</el-table-column>
				<el-table-column label="已完成单数" align="center">
					<template slot-scope="scope">
						<span>{{scope.row.nowNum }}</span>
					</template>
				</el-table-column>
				<el-table-column label="性别" align="center" v-if="false">
					<template slot-scope="scope">
						<el-tag :type="scope.row.sex==0?'success':'warn'">
							<span>{{ scope.row.sex==0?'男':'女'}}</span>
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="生日" align="center" v-if="false">
					<template slot-scope="scope">
						<span>{{ scope.row.birthday }}</span>
					</template>
				</el-table-column>
			</el-table>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleSub = false">取 消</el-button>
				<el-button type="primary" @click="dialogVisibleSub = false">确 定</el-button>
			</span>
			<el-pagination background layout="prev, pager, next" :total="SubModel.TotalCount" @current-change="PageSub"
				style="text-align: center;margin-top: 10px;">
			</el-pagination>
		</el-dialog>

		<el-dialog title="查看专员" :visible.sync="dialogVisibleCom" width="100%">
			<el-table :data="CommiserList" element-loading-text="Loading" border fit highlight-current-row>
				<el-table-column label="用户ID" width="120" align="center">
					<template slot-scope="scope">
						{{scope.row.id}}
					</template>
				</el-table-column>
				<el-table-column label="用户微信名" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.username }}</span>
					</template>
				</el-table-column>
				<el-table-column label="别名" align="center" v-if="false">
					<template slot-scope="scope">
						<span>{{ scope.row.full_name }}</span>
					</template>
				</el-table-column>
				<el-table-column label="用户电话" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.phone }}</span>
					</template>
				</el-table-column>
				<el-table-column label="备用电话" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.updphone }}</span>
					</template>
				</el-table-column>
				<el-table-column label="地址" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.address }}</span>
					</template>
				</el-table-column>
				<el-table-column label="余额" align="center" >
					<template slot-scope="scope">
						<span>￥{{ scope.row.balance/100 }}</span>
					</template>
				</el-table-column>
				<el-table-column label="已完成单数" align="center" >
					<template slot-scope="scope">
						<span>{{scope.row.nowNum }}</span>
					</template>
				</el-table-column>
				<el-table-column label="性别" align="center" v-if="false">
					<template slot-scope="scope">
						<el-tag :type="scope.row.sex==0?'success':'warn'">
							<span>{{ scope.row.sex==0?'男':'女'}}</span>
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="生日" align="center" v-if="false">
					<template slot-scope="scope">
						<span>{{ scope.row.birthday }}</span>
					</template>
				</el-table-column>
			</el-table>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleCom = false">取 消</el-button>
				<el-button type="primary" @click="dialogVisibleCom = false">确 定</el-button>
			</span>
			<el-pagination background layout="prev, pager, next" :total="ComTotalCount"
				style="text-align: center;margin-top: 10px;">
			</el-pagination>
		</el-dialog>


		<el-dialog title="编辑" :visible.sync="dialogVisible" width="50%">

			<el-form ref="form" :model="form" label-width="80px" :rules="rules">
				<el-form-item label="账户名" prop="username">
					<el-input v-model="form.username"></el-input>
				</el-form-item>
				<el-form-item label="身份证号" prop="ID_card" v-if="false">
					<el-input v-model="form.ID_card"></el-input>
				</el-form-item>
				<el-form-item label="手机号" prop="phone">
					<el-input v-model="form.phone"></el-input>
				</el-form-item>
				<el-form-item label="地址" prop="address">
					<el-input v-model="form.address"></el-input>
				</el-form-item>
				<el-form-item label="备注" prop="remark">
					<el-input v-model="form.remark"></el-input>
				</el-form-item>
				<el-form-item label="性别" prop="sex">
					<!-- 0男  1-女 -->
					<el-select v-model="form.sex" placeholder="请选择">
						<el-option label="男" value="0"></el-option>
						<el-option label="女" value="1"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="生日" prop="birthday">
					<el-date-picker v-model="form.birthday" type="date" placeholder="选择日期">
					</el-date-picker>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="UpdSubmit">确 定</el-button>
			</span>
		</el-dialog>
		<el-dialog title="车辆信息" :visible.sync="dialogVisibleCar" width="50%">

			<el-table :data="tableData" style="width: 100%">
				<el-table-column prop="date" label="ID" width="180" v-if="false">
					<template slot-scope="scope">
						{{scope.row.id}}
					</template>
				</el-table-column>
				<el-table-column prop="date" label="用户ID" width="180" v-if="false">
					<template slot-scope="scope">
						{{scope.row.id}}
					</template>
				</el-table-column>
				<el-table-column prop="date" label="车型" width="180">
					<template slot-scope="scope">
						{{scope.row.CarModel}}
					</template>
				</el-table-column>
				<el-table-column prop="Scratch" label="漆面划痕" width="180">
					<template slot-scope="scope">
						{{scope.row.Scratch}}
					</template>
				</el-table-column>
				<el-table-column prop="Corrosion" label="漆面腐蚀" width="180">
					<template slot-scope="scope">
						{{scope.row.Corrosion}}
					</template>
				</el-table-column>
				<el-table-column prop="BeDamaged" label="漆面破损" width="180">
					<template slot-scope="scope">
						{{scope.row.BeDamaged}}
					</template>
				</el-table-column>
				<el-table-column prop="FlyingPaint" label="沥青飞漆" width="180">
					<template slot-scope="scope">
						{{scope.row.FlyingPaint}}
					</template>
				</el-table-column>
				<el-table-column prop="CarDefault" label="默认车辆" width="180">
					<template slot-scope="scope">
						<el-tag :type="scope.row.CarDefault==true?'success':'warn'">
							{{scope.row.CarDefault==true?'默认车辆':'非默认车辆'}}
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="AddTime" label="添加时间" width="180">
					<template slot-scope="scope">
						{{scope.row.AddTime}}
					</template>
				</el-table-column>
				<el-table-column prop="UpdateTime" label="修改时间" width="180">
					<template slot-scope="scope">
						{{scope.row.UpdateTime}}
					</template>
				</el-table-column>
				<el-table-column prop="UpdateTime" label="设为默认" width="180">
					<template slot-scope="scope">
						<el-button type="success" @click="SetDefault(scope.row)">设为默认</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination background layout="prev, pager, next" :total="CarModel.TotalCount" @current-change="PagesCar"
				style="text-align: right;margin-top: 10px;">
			</el-pagination>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleCar = false">取 消</el-button>
				<el-button type="primary" @click="dialogVisibleCar = false">确 定</el-button>
			</span>
		</el-dialog>

		<el-dialog title="上级ID编号" :visible.sync="dialogVisibleT" width="90%">
			<el-form :inline="true">
				<el-form-item label="关键字">
					<el-input v-model="ManagerModel.KeyWord" placeholder="关键字查询"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="success" @click="SubmitManager">提交</el-button>
				</el-form-item>
			</el-form>
			<!-- <el-input v-model="updateType.ParentUserId" placeholder="请输入上级ID"></el-input> -->
			<el-table :data="ManagerList" element-loading-text="Loading" border fit highlight-current-row
				ref="multipleTable" @row-click="singleElection">
				<el-table-column label="" width="65">
					<template slot-scope="scope">
						<el-radio class="radio" :label="scope.$index" v-model="radiodata">&nbsp;</el-radio>
					</template>
				</el-table-column>
				<el-table-column label="用户ID" width="120" align="center">
					<template slot-scope="scope">
						{{scope.row.id}}
					</template>
				</el-table-column>
				<el-table-column label="用户微信名" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.username }}</span>
					</template>
				</el-table-column>
				<el-table-column label="别名" align="center" v-if="false">
					<template slot-scope="scope">
						<span>{{ scope.row.full_name }}</span>
					</template>
				</el-table-column>
				<el-table-column label="用户电话" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.phone }}</span>
					</template>
				</el-table-column>
				<el-table-column label="备用电话" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.updphone }}</span>
					</template>
				</el-table-column>
				<el-table-column label="地址" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.address }}</span>
					</template>
				</el-table-column>
				<el-table-column label="余额" align="center">
					<template slot-scope="scope">
						<span>￥{{ scope.row.balance/100 }}</span>
					</template>
				</el-table-column>
				<el-table-column label="已完成单数" align="center">
					<template slot-scope="scope">
						<span>{{scope.row.nowNum }}</span>
					</template>
				</el-table-column>
				<el-table-column label="性别" align="center" v-if="false">
					<template slot-scope="scope">
						<el-tag :type="scope.row.sex==0?'success':'warn'">
							<span>{{ scope.row.sex==0?'男':'女'}}</span>
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="生日" align="center" v-if="false">
					<template slot-scope="scope">
						<span>{{ scope.row.birthday }}</span>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination background layout="prev, pager, next" :total="ManagerModel.TotalCount"
				@current-change="PagesManager" style="text-align: right;margin-top: 10px;">
			</el-pagination>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleT = false">取 消</el-button>
				<el-button type="primary" @click="UpdateUserType">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>
<script>
	import {
		GetUserByCar,
		GetUserList,
		UpdateUserType,
		DeleteUser,
		Save,
		Blacklist,
		NoBlacklist,
		GetUserListByInviteeUserId,
		GetCommissionerByManage,
		GetUserListBytManager
	} from '@/api/user'
	import {
		GetVehicleListByUser,
		UpdateCarDefault,
	} from '../../api/VehicleManagement.js'
	import utils from '../../utils/utils.js'
	export default {
		data() {
			return {
				tableData: [],
				radiodata: '',
				dialogVisibleCom: false,
				dialogVisibleSub: false,
				dialogVisibleT: false,
				dialogVisible: false,
				dialogVisibleCar: false,
				dialogVisiblecommissioner: false,
				rules: {
					username: [{
						required: true,
						message: '请输入账户名',
						trigger: 'blur'
					}],
					ID_card: [{
						required: true,
						message: '请输入身份证号码',
						trigger: 'blur'
					}, {
						min: 6,
						max: 30,
						message: '长度在 6 到 30 个字符'
					}, {
						pattern: /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,
						message: '请输入正确的身份证号码'
					}],
					phone: [{
						required: true,
						message: '请输入电话号码',
						trigger: 'blur'
					}, {
						pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
						message: '请输入正确的手机号格式'
					}],
					address: [{
						required: true,
						message: '请输入地址',
						trigger: 'blur'
					}],
					sex: [{
						required: true,
						message: '请选择年龄',
						trigger: 'blur'
					}],
					birthday: [{
						required: true,
						message: '请选择生日',
						trigger: 'blur'
					}],

				},
				//经理下面的专员
				CommiserList: [],
				// 条数
				ComTotalCount: 0,
				userlist: [],
				// 该用户下级信息
				SubList: [],
				listLoading: true,
				parameter: {
					"UserId": 0,
					"Phone": "",
					"KeyWord": "",
					"TotalCount": 0,
					"PageIndex": 1,
					"PageSize": 20,
					"Sort": [{
						"Field": "id",
						"Type": 0
					}]
				},
				// {
				// 	pageIndex: 1,
				// 	pageSize: 10,
				// 	sort: "id",
				// 	sortOrder: 2,
				// 	keyword: "",
				// 	status: 1
				// },
				total: 0,
				updateType: {
					UserId: 0,
					UserType: 2,
					ParentUserId: 0
				},
				form: {
					"ParentUserId": 0,
					"InviteeUserId": 0,
					"beijintupian": "",
					"birthday": "",
					"ID_card": "",
					"address": "",
					"id": 0,
					"username": "",
					"password": "",
					"author": "",
					"status": "",
					"type": 0,
					"full_name": "",
					"add_time": "2022-01-20T13:27:24.548Z",
					"update_time": "2022-01-20T13:27:24.548Z",
					"remark": "",
					"avatar": "",
					"phone": "",
					"openid": "",
					"sex": "",
					"balance": 0
				},
				CarModel: {
					"UserId": 0,
					"KeyWord": "",
					"TotalCount": 0,
					"PageIndex": 1,
					"PageSize": 10,
					"Sort": [{
						"Field": "id",
						"Type": 0
					}]
				},
				// 默认
				CarDefaultModel: {
					"id": 0,
					"UserId": 0
				},
				SubModel: {
					"ParentUserId": 0,
					"KeyWord": "",
					"TotalCount": 0,
					"PageIndex": 1,
					"PageSize": 10,
					"Sort": [{
						"Field": "",
						"Type": 0
					}]
				},
				ManagerModel: {
					"KeyWord": "",
					"TotalCount": 0,
					"PageIndex": 1,
					"PageSize": 10,
					"Sort": [{
						"Field": "id",
						"Type": 0
					}]
				},
				ManagerList: []
			}
		},

		created() {},
		mounted() {
			this.GetUserListHeadler();
		},
		methods: {
			PagesManager(e) {
				this.ManagerModel.PageIndex = e
				this.ShowManager()
			},
			Pages(e) {
				this.parameter.pageIndex = e
				this.GetUserListHeadler()
			},
			PageSub(e) {
				this.SubModel.PageIndex = e
				this.ShowSub()
			},
			PagesCar(e) {
				this.CarModel.PageIndex = e
				this.ShowCar()
			},
			GetUserListHeadler() {
				GetUserByCar(this.parameter).then(res => {
					res.data.data.rows.forEach((item, index) => {
						item.birthday = utils.formatTime(item.birthday, "yyyy-MM-dd")
					})
					this.userlist = res.data.data.rows
					this.parameter.TotalCount=res.data.data.total
					console.log('经理', this.userlist)
					this.listLoading = false;
				});
			},
			// 提交查询
			SubmitUser(){
				this.GetUserListHeadler()
			},
			handleCommand(value, val, item) {
				if (value == "a") {
					this.UpdateUserTypeHeadler(val);
				}
				if (value == "b") {
					this.DelUserHeadler(val)
				}
				if (value == "c") {
					this.UpdateUserHeadler(item)
				}
				if (value == "d") {
					this.ShowCar(val)
				}
				if (value == "e") {
					this.ShowUpgrade(val)
					// this.UpdateUserType(val)
					// this.dialogVisibleT=true
				}
				if (value == 'f') {
					// 拉黑
					this.BlacklistSubmit(val)
				}
				if (value == 'g') {
					// 取消拉黑
					this.NoBlacklistSubmit(val)
				}
				if (value == 'h') {
					// 显示下级信息
					this.ShowSub(val)
				}
				if (value == 'i') {
					// 显示经理下面的专员
					this.ShowCommissioner(val)
				}
			},
			// 显示经理下面的专员
			ShowCommissioner(val) {
				this.dialogVisibleCom = true
				let json = {
					UserId: val
				}
				GetCommissionerByManage(json).then(res => {
					console.log('数据专员', res)
					this.CommiserList = res.data.data
					this.ComTotalCount = res.data.data.length
				})
			},
			// 查询该用户下级数据
			ShowSub(val) {
				this.dialogVisibleSub = true
				console.log('val数据', val)
				this.SubModel.ParentUserId = val
				GetUserListByInviteeUserId(this.SubModel).then(res => {
					console.log('查询数据', res)
					this.SubModel.TotalCount = res.data.data.total
					this.SubList = res.data.data.rows
					console.log('查询下级数据', this.SubList)
				})
			},
			BlacklistSubmit(id) {
				// 拉黑
				Blacklist(id).then(res => {
					if (res.data.code == 200) {
						this.$message.success('拉黑成功')
						this.GetUserListHeadler()
					} else {
						this.$message.error('拉黑失败')
					}
				})
			},
			NoBlacklistSubmit(id) {
				// 取消拉黑
				NoBlacklist(id).then(res => {
					if (res.data.code == 200) {
						this.$message.success('取消拉黑成功')
						this.GetUserListHeadler()
					} else {
						this.$message.error('取消拉黑失败')
					}
				})
			},
			// 查询销售经理  (升级推广专员)
			ShowManager() {
				GetUserListBytManager(this.ManagerModel).then(res => {
					console.log('销售经理', res)
					this.ManagerModel.TotalCount = res.data.data.total
					this.ManagerList = res.data.data.rows
				})
			},
			SubmitManager() {
				this.ShowManager()
			},
			// 选择推广经理
			singleElection(row) {
				console.log('数据啊啊啊row', row)
				this.updateType.ParentUserId = row.id
			},
			// 升级推广专员打开页面传参
			ShowUpgrade(val) {
				this.dialogVisibleT = true
				this.ShowManager()
				// 升级成推广专员
				this.updateType.UserId = val
				this.updateType.UserType = 3
				console.log('ID', this.updateType)
			},
			UpdateUserType() {
				// 修改成推广专员
				// this.updateType = {
				// 	UserId: UserId,
				// 	UserType: 3,
				// 	ParentUserId: 0
				// };
				this.$confirm('确定把该用户升级成推广专员？', '消息', {
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					callback: (action) => {
						if (action == "confirm") {
							UpdateUserType(this.updateType).then(res => {
								if (res.data.code == 200) {
									this.$confirm('该用户已升级成推广专员', '消息', {
										confirmButtonText: '确认',
										cancelButtonText: '取消',
										callback: (action) => {
											this.GetUserListHeadler();
										},
									})
								} else {
									this.$confirm(res.data.message, '消息', {
										confirmButtonText: '确认',
										cancelButtonText: '取消'
									})
								}
							});
						}
					},
				})
			},
			// 设为默认车辆
			SetDefault(item) {
				console.log('数据', item)
				if (item.CarDefault == true) {
					this.$message.error('该车辆已是默认车辆')
				} else {
					this.CarDefaultModel.id = item.id
					this.CarDefaultModel.UserId = this.CarModel.UserId
					UpdateCarDefault(this.CarDefaultModel).then(res => {
						console.log('默认', res)
						if (res.data.code == 200) {
							this.$message.success('修改默认车辆成功')
							this.ShowCar()
						} else {
							this.$message.error(res.data.message)
						}
					})
				}
			},
			// 查询车辆信息
			ShowCar(id) {
				console.log('车辆ID', id)
				this.CarModel.UserId = id
				this.dialogVisibleCar = true
				GetVehicleListByUser(this.CarModel).then(res => {
					console.log('车辆信息', res)
					if (res.data.code == 200) {
						res.data.data.rows.forEach((item, index) => {
							item.add_time = utils.formatTime(item.add_time, "yyyy-MM-dd HH:mm:ss")
							item.UpdateTime = utils.formatTime(item.UpdateTime, "yyyy-MM-dd HH:mm:ss")
						})
						this.tableData = res.data.data.rows
						this.CarModel.TotalCount = res.data.data.total
					}
				})
			},
			UpdSubmit() {
				// 修改提交信息
				this.$refs.form.validate((valid) => {
					if (valid) {
						Save(this.form).then(res => {
							console.log('提交', res)
							if (res.data.code == 200) {
								this.$message.success('修改成功')
								this.dialogVisible = false
								this.GetUserListHeadler()
							} else {
								this.$message.error('修改失败')
							}
						})
					}
				})
			},
			// 修改信息
			UpdateUserHeadler(item) {
				console.log('item', item)
				this.dialogVisible = true
				this.form.birthday = item.birthday
				this.form.ID_card = item.ID_card
				this.form.address = item.address
				this.form.id = item.id
				this.form.username = item.username
				this.form.add_time = item.add_time
				this.form.update_time = item.update_time
				this.form.remark = item.remark
				this.form.phone = item.phone
				this.form.sex = item.sex
				// -------------------
				this.form.InviteeUserId = item.InviteeUserId
				this.form.ParentUserId = item.ParentUserId
				this.form.beijintupian = item.beijintupian
				this.form.password = item.password
				this.form.author = item.author
				this.form.status = item.status
				this.form.type = item.type
				this.form.full_name = item.full_name
				this.form.avatar = item.avatar
				this.form.openid = item.openid
				this.form.balance = item.balance
			},
			DelUserHeadler(Id) {
				DeleteUser({
					ids: Id
				}).then(res => {
					console.log('res', res)
					if (res.data.code == 200) {
						this.$message.success('删除成功')
						this.GetUserListHeadler()
					} else {
						this.$message.error('删除失败')
					}
				})
			},
			UpdateUserTypeHeadler(UserId) {
				this.updateType = {
					UserId: UserId,
					UserType: 4,
					ParentUserId: 0
				};
				this.$confirm('确定把该用户升级成客户经理？', '消息', {
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					callback: (action) => {
						if (action == "confirm") {
							UpdateUserType(this.updateType).then(res => {
								if (res.data.code == 200) {
									this.$confirm('该用户已升级成客户经理', '消息', {
										confirmButtonText: '确认',
										cancelButtonText: '取消',
										callback: (action) => {
											this.GetUserListHeadler();
										},
									})
								} else {
									this.$confirm(res.data.message, '消息', {
										confirmButtonText: '确认',
										cancelButtonText: '取消'
									})
								}
							});
						}
					},
				})
			}
		}
	}
</script>

<style>
</style>
