<template>
	<view class="dmodel-table">
	      <zb-table ref="zbTable" rowKey="recordId"
             :columns="tableColumn" :data="tableData" :stripe="true" @toggleAllSelection="toggl
		  eAllSelection"
			@toggleRowSelection="toggleRowSelection">
		</zb-table>
	</view>
</template>

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

					{
						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() {
			  const params = {
			  	pageNum: 1,
			  	pageSize: 10, 
				workstationId: this.data.workstationId
			  }
			  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;
	}
</style>
