<template>
  <view class="dmodel-table">
    <view class="search">
      <u-form :model="tableParams" labelAlign="right" class="tableForm">
        <u-form-item :label="$t('工号')" label-width="60px" name="userName">
          <u-input type="text" v-model="tableParams.userName" :placeholder="$t('请扫描/输入工号')" @confirm="confirmUserName($event)"/>
        </u-form-item>
      </u-form>
    </view>
    <view>
      <zb-table ref="zbTable" rowKey="userName" :columns="tableColumn" :data="tableData" :stripe="true" @toggleRowSelection="toggleRowSelection"></zb-table>
    </view>
  </view>
</template>

<script>
import i18n from '../../../../lang/index'

export default {
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      params: {
       workunitId: this.data?.workunitId || null
      },
      total: 0,
      tableParams: {
        nickName: null,
        userName: null
      },
      tableData: [],
      tableSelectData: [],
      tableColumn: [
        {
          name: 'userName',
          label: i18n.t('工号'),
          width: 160
        },
        {
          name: 'nickName',
          label: i18n.t('姓名'),
          width: 200
        },

        {
          name: 'workunitName',
          label: i18n.t('工作单元'),
          width: 160
        }
      ]
    };
  },
  // computed: {
  // 	tableData() {
  // 		return this.data || []
  // 	}
  // },
  mounted() {
    // this.getList();
    // this.data.workstationName
  },
  methods: {
    confirmUserName(e) {
      this.tableParams.userName = e
      if (!this.tableParams.userName) return this.$u.toast(i18n.t('请输入报工人工号'))
      this.handleClick()
    },
    handleClick() {
      if (this.tableParams.userName) {
        this.params.userName = this.tableParams.userName;
      } else {
        delete this.params.userName
      }
      if (this.tableParams.nickName) {
        this.params.nickName = this.tableParams.nickName;
      } else {
        delete this.params.nickName
      }
      this.getList();
    },
    async getList() {
      const res = await this.$u.api.userQuery(this.params);
      if (res.code == 200 && res.data) {
        this.tableData.push(res.data)
      } else {
        this.$u.toast(i18n.t('查不到报工人数据'))
      }
    },
    toggleRowSelection(checked, arr) {
      this.tableSelectData = arr;
	  
    }
  }
};
</script>

<style lang="scss" scoped>
.dmodel-table {
  height: 1200rpx;
  margin-top: 20rpx;
  padding: 0 20rpx;
  position: relative;
}
.tableForm {
  display: flex;
  margin-bottom: 20rpx;
}
.btn {
  margin-left: 10px;
}
.uni-pagination-box {
  position: absolute;
  right: 20rpx;
  bottom: 40rpx;
}
</style>
