<template>
  <div class="mod-config pad" style="margin-top: 10px">

    <el-form inline="true" style="margin-top: 0px;" label-position="top">
      <el-form-item :label="'工厂编号'" style="margin-left: 20px">
        <el-select filterable v-model="searchData.site" >
          <el-option label="1-沪声" value="1"></el-option>
          <el-option label="2-赫艾" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'产品编码/名称/规格型号：'"  style="margin-left: 20px">
        <el-input v-model="searchData.searchIn" style="width: 220px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="search()" style="margin-left: 24px;height: 35px;width: 80px" type="primary">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :height="height"
      :data="tableData"
      border
      style="margin-top: 10px;width: 100%">
      <el-table-column
        prop="site"
        header-align="center"
        align="left"
        min-width="30"
        label="工厂编号">
      </el-table-column>
      <el-table-column
        prop="partNo"
        header-align="center"
        align="left"
        min-width="60"
        label="产品编码">
      </el-table-column>
      <el-table-column
        prop="partDescription"
        header-align="center"
        align="left"
        min-width="60"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="spec"
        header-align="center"
        align="left"
        min-width="60"
        label="规格型号">
      </el-table-column>
      <el-table-column
        prop=""
        fixed="right"
        header-align="center"
        align="center"
        min-width="30"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="jumpPadPartAttribute(scope.row)">属性</a> &nbsp&nbsp|&nbsp&nbsp
          <a type="text" size="small" @click="jumpPadPartPhoto(scope.row)">图纸</a>
        </template>
      </el-table-column>
    </el-table>
    <div style=" font-size: 18px;">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[20, 100, 500, 1000]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
  </div>

</template>

<script>
  import {
    searchPartData
  } from '@/api/pad.js'
  export default {
    name: 'padPart1',
    data () {
      return {
        height:200,
        tableData:[],
        searchData:{
          site:'1',
          searchIn:'',
          page: 1,
          limit: 10,
        },
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
      }

    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },
    methods: {
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.search()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.search()
      },
      jumpPadPartAttribute(row){
        let pageData={
          pageIndex: this.pageIndex,
          pageSize: this.pageSize,
          totalPage: this.totalPage,
        }
        localStorage.removeItem("search")
        localStorage.removeItem("flag")
        localStorage.setItem("partData",JSON.stringify(row))
        localStorage.setItem("search",JSON.stringify(this.searchData))
        localStorage.setItem("tableData",JSON.stringify(this.tableData))
        localStorage.setItem("pageData",JSON.stringify(pageData))
        this.$router.push('/padPartAttribute');
      },
      jumpPadPartPhoto(row){
        let pageData={
          pageIndex: this.pageIndex,
          pageSize: this.pageSize,
          totalPage: this.totalPage,
        }
        localStorage.removeItem("search")
        localStorage.removeItem("flag")
        localStorage.setItem("pictureData",JSON.stringify(row))
        localStorage.setItem("search",JSON.stringify(this.searchData))
        localStorage.setItem("tableData",JSON.stringify(this.tableData))
        localStorage.setItem("pageData",JSON.stringify(pageData))
        this.$router.push('/padPartPhoto');
      },
      search(){
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        searchPartData(this.searchData).then(({data}) => {
          this.tableData = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
        })
      },
      getData(){
        let data1= JSON.parse(localStorage.getItem("search"))
        this.searchData.site=data1.site;
        this.searchData.searchIn=data1.searchIn;
        this.tableData= JSON.parse(localStorage.getItem("tableData"))
        let pageData= JSON.parse(localStorage.getItem("pageData"))
        this.pageIndex=pageData.pageIndex
        this.pageSize=pageData.pageSize
        this.totalPage=pageData.totalPage
      }
    },
    created () {
      localStorage.removeItem("partData")
      localStorage.removeItem("pictureData")
      this.getData();
    }
  }
</script>

<style scoped>
  .el-select-dropdown__item{
    font-size: 18px;
  }
</style>
