<template>
	<view class="dmodel-table">
	<view class="search">
		<u-search :showAction="false" v-model="userName"  inputAlign="center" placeholder="请输入编号" ></u-search>
		<u-search :showAction="false"  v-model="nickName" inputAlign="center" placeholder="请输入名称" ></u-search>
		<u-button type="primary" @click="getList" size="medium">搜索</u-button>
	</view>
	      <zb-table ref="zbTable" rowKey="recordId"
             :columns="tableColumn" :data="tableData" :stripe="true" @toggleAllSelection="toggleAllSelection"
			@toggleRowSelection="toggleRowSelection">
		</zb-table>
	</view>
</template>

<script>
	export default {
		props: {
			data: {
				type: Object,
				default: () => {}
			}
		},
		data() {
			return {
				tableData: [],
				tableSelectData: [],
				nickName: null,
				userName: null,
				tableColumn: [{
						type: 'selection',
						width: 35
					},
					{
						name: 'userName',
						label: '编号',
						width: 160,
					},
					{
						name: 'nickName',
						label: '名称',
						width: 200,
					},

					{
						name: 'workstationName',
						label: '工作站',
						width: 160,
					},
				
				],
			}
		},
		// computed: {
		// 	tableData() {
		// 		return this.data || []
		// 	}
		// },
		mounted() {
		  console.log(this.data, 'this.data')
		  console.log(this.data.workstationName)
		  
		  this.getList()
		  // this.data.workstationName
		},
		methods: {
			
			rowClick(row, index) {
			  console.log(this.$refs.zbTable)
			  this.$refs.zbTable.checkboxSelectedAll({checked: false})
			  this.$refs.zbTable.toggleRowSelection(row)
			},
			async commonClick(type) {
				if (this.tableSelectData.length == 0) {
					return this.$u.toast('请选择一条数据！')
				}
				// 判断选中的类型是否一致
				if (this.tableSelectData.length > 1) {
					let flag = false
					for (let i = 1; i < this.tableSelectData.length; i++) {
						const pre = this.tableSelectData[i - 1]
						const cur = this.tableSelectData[i]
						flag = cur.type == pre.type
						if (!flag) {
							break;
						}
					}
					if (!flag) {
						return this.$u.toast('请选择状态相同的数据')
					}
				}
				
			},
			async getList() {
			  let params = {
			  	pageNum: 1,
			  	pageSize: 10, 
				workstationId: this.data.workstationId
			  }
			  if (this.userName) {
				  params.userName = this.userName
			  }
			  if (this.nickName) {
			  	params.nickName = this.nickName
			  }
			  const res = await this.$u.api.userQuery(params)
			  console.log(res, 'res')
			  if (res.code == 200) {
			  	this.tableData=res.rows.map(item => {
					return {
						...item,
						workstationName: this.data.workstationName
					}
				})
				
			  }	
			},
			toggleAllSelection(checked, arr) {
				this.tableSelectData = arr
			},
			toggleRowSelection(checked, arr) {
				this.tableSelectData = arr
			},
		}
	}
</script>

<style scoped>
	.dmodel-table {
		height: 500rpx;
		margin-top: 20rpx;
		padding: 0 20rpx;
	}
	.search{
		display: flex;
		margin-bottom:20rpx;
		align-items: center;
		.u-search{
			width: 400rpx !important;
			margin-right:20rpx !important;
		}
	}
</style>
