hailin
2023-07-19 7b230899435f64c2191af136d8d43e273eb19d70
src/views/standardLibrary/index.vue
@@ -6,7 +6,7 @@
          v-model="filterText"
          placeholder="输入关键字进行过滤"
        />
        <el-button type="text">全部</el-button>
        <el-button type="text" @click="getAllStandard">全部</el-button>
        <el-tree
          ref="tree"
          class="filter-tree"
@@ -42,10 +42,10 @@
        </div>
        <div class="table-box">
          <el-table
            ref="standardLibraryTable"
            ref="tableData"
            :cell-style="{textAlign: 'center'}"
            :header-cell-style="{border:'0px',background:'#f5f7fa',color:'#606266',boxShadow: 'inset 0 1px 0 #ebeef5',textAlign: 'center'}"
            :data="standardLibraryTable"
            :data="tableData"
            style="width: 100%"
          >
            <el-table-column
@@ -93,19 +93,34 @@
                <el-button
                  type="text"
                  size="small"
                  @click="handleClick(scope.row)"
                  :style="{marginRight:'8px'}"
                  @click="specificationDetails(scope.row)"
                >查看</el-button>
                <el-button type="text" size="small"><i class="el-icon-more" /></el-button>
                <el-popover
                  v-model="scope.row.visible"
                  placement="top"
                  width="30"
                >
                  <div style="text-align: center; margin: 0">
                    <div>
                      <el-button size="mini" type="text">编辑</el-button>
                    </div>
                    <div>
                      <el-button size="mini" type="text">停用</el-button>
                    </div>
                  </div>
                  <el-button slot="reference" type="text"><i class="el-icon-more" /></el-button>
                </el-popover>
              </template>
            </el-table-column>
          </el-table>
          <div>
            <el-pagination
              :current-page="currentPage"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="100"
              :current-page="pageParams.pageNo"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="pageParams.pageNo"
              layout="total, sizes, prev, pager, next, jumper"
              :total="400"
              :total="pageParams.total"
            />
          </div>
        </div>
@@ -115,28 +130,15 @@
</template>
<script>
import { getStandardsList, getSerialNumberList, getSpecificationsList } from '@/api/standardLibrary'
import { getStandardsList, getSerialNumberList, getSpecificationsList, getStandardsListOfPage } from '@/api/standardLibrary'
export default {
  data() {
    return {
      visible: false,
      filterText: '',
      // 标准库bom树
      standardTree: [{
        id: 1,
        label: '一级 1',
        children: [{
          id: 4,
          label: '二级 1-1',
          children: [{
            id: 9,
            label: '三级 1-1-1'
          }, {
            id: 10,
            label: '三级 1-1-2'
          }]
        }]
      }],
      // 默认值
      standardTree: [],
      // bom的,默认值
      defaultProps: {
        children: 'children',
        label: 'label'
@@ -145,18 +147,42 @@
      searchData: {
        keyword: ''
      },
      standardLibraryTable: [
      tableData: [
        {
          id: 2,
          name: 'AB',
          updateTime: '2023-07-12 00:00:12',
          username: '小小',
          vel: 'V1.0',
          spe_state: 1
          spe_state: 1,
          visible: false
        },
        {
          id: 3,
          name: 'AB',
          updateTime: '2023-07-12 00:00:12',
          username: '小小',
          vel: 'V1.0',
          spe_state: 1,
          visible: false
        },
        {
          id: 4,
          name: 'AB',
          updateTime: '2023-07-12 00:00:12',
          username: '小小',
          vel: 'V1.0',
          spe_state: 1,
          visible: false
        }
      ],
      currentPage: 1
      pageParams: {
        pageNo: 1,
        pageSize: 10,
        total: 3
      }
    }
  },
  watch: {
@@ -174,34 +200,46 @@
    },
    async getStandardTree() {
      const { data: standard } = await getStandardsList()// 获取所有标准
      // console.log(standard)// 获取所有标准
      for (const standardItem of standard) {
        const { data: serialNumber } = await getSerialNumberList({ IdOrNameOfSerialNumber: standardItem.name, standardsId: standardItem.id })
        // console.log(children) //所有型号
        // for (const serialNumberItem of serialNumber) {
        //   // const {data} = await getSpecificationsList({})
        // }
        standardItem.children = serialNumber.map(item => ({ id: item.id, label: item.name }))
      }
      this.standardTree = standard.map(item => ({ ...item, label: item.name }))
      console.log(this.standardTree)// 获取所有标准
      console.log(standard)// 获取所有标准
      this.standardTree = standard.map(item => {
        item.serialNumber = item.serialNumber?.map(childrenItem => ({ ...childrenItem, label: childrenItem.name }))
        return { ...item, label: item.name, children: item.serialNumber }
      })
      console.log(this.standardTree)
    },
    async nodeClick(data, node, element) {
      // 数据 节点node对象 节点组件对象
      // console.log(data, node, element)
      // console.log(data.children && data.children?.length !== 0)
      if (!data.children && data.children?.length !== 0) {
      console.log(data)
      console.log('children' in data)
      if (!('children' in data)) {
        console.log('点击子节点', data)
        const res = await getSpecificationsList({ serialNumberId: data.id, specificationsName: data.label, pageNo: 1, pageSize: 10 })
        console.log(res)
        const { data: { row, total }} = await getSpecificationsList({ serialNumberId: data.id, specificationsName: data.label, pageNo: 1, pageSize: 10 })
        console.log(row)
        this.tableData = row
        this.pageParams.total = total
        return
      }
      console.log('点击父节点')
      const { data: { row, total }} = await getSerialNumberList({ standardsId: data.id, ...this.pageParams })
      // console.log('点击父节点', serialNumberList)
      this.tableData = row
      this.pageParams.total = total
    },
    specificationDetails(row) {
      // 跳转产品规格详情页
      console.log(row)
      this.$router.push(`/standardLibrary/SpecificationDetails/${row.id}`)
    },
    async getAllStandard() {
      console.log(this.pageParams)
      const { data: { row, total }} = await getStandardsListOfPage({ ...this.pageParams })
      this.pageParams.total = total
      this.tableData = row
    }
  }
}
</script>
<style lang="scss" scoped>
.standard-library-main{
  width: 100%;
  height: 100%;