<template>
  <view class="dmodel-table">
    <view class="search">
      <u-form :model="tableParams" labelAlign="right" class="tableForm">
        <u-form-item label="检测项编号" label-width="100px" name="indexCode">
          <uni-easyinput type="text" v-model="tableParams.indexCode" placeholder="请输入编号" />
        </u-form-item>
        <u-form-item label="检测项名称" label-width="100px" name="indexName">
          <uni-easyinput type="text" v-model="tableParams.indexName" placeholder="请输入名称" />
        </u-form-item>
        <u-form-item>
          <u-button class="btn" @click="handleClick" type="primary" size="medium">搜索</u-button>
        </u-form-item>
      </u-form>
    </view>
    <view>
      <zb-table ref="zbTable" rowKey="indexCode" :columns="tableColumn" :data="tableData" :stripe="true" @toggleRowSelection="toggleRowSelection"></zb-table>
    </view>
    <view class="uni-pagination-box"><uni-pagination show-icon :page-size="params.pageSize" :current="params.pageNum" :total="total" @change="change" /></view>
  </view>
</template>

<script>
export default {
  name: 'User',
  data() {
    return {
      params: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      tableParams: {
        indexCode: '',
        indexName: ''
      },
      tableData: [],
      tableSelectData: [],
      tableColumn: [
        {
          type: 'radio',
          width: 40
        },
        {
          name: 'indexCode',
          label: '检测项编码',
          width: 160
        },
        {
          name: 'indexName',
          label: '检测项名称',
          width: 200
        }
      ]
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    handleClick() {
      if (this.tableParams.indexName) {
        this.params.indexName = this.tableParams.indexName;
      } else {
        delete this.params.indexName
      }
      if (this.tableParams.indexCode) {
        this.params.indexCode = this.tableParams.indexCode;
      } else {
        delete this.params.indexCode
      }
      this.params.pageNum = 1;
      this.getList();
    },
    async getList() {
      const res = await this.$u.api.getQcIndexList(this.params);
      console.log(res, 'res');
      if (res.code == 200) {
        this.tableData = res.rows;
        this.total = res.total;
      }
    },
    // 分页触发
    change(e) {
      this.params.pageNum = e.current;
      this.getList();
    },
    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>
