<template>
  <div class="app-container">
    <el-card>
      <span>项目名称:</span>
      <el-select v-model="projectValue" placeholder="项目名称" size="small" filterable clearable>
        <el-option
          v-for="item in project"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <el-button
        type="success"
        size="small"
        icon="el-icon-search"
        style="margin-left:10px"
        @click="total1=0;pageCurrent1=1;pageSize1=10;searchTable1()">查询</el-button>
    </el-card>

    <el-card>
      <el-table v-loading="" :data="tableData1" show-summary stripe border style="width: 100%;max-height: 500px;" height="500px" size="mini">
        <el-table-column label="序号" align="center" width="80" type="index"/>
        <el-table-column label="项目名称" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="图号" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.图号 }}
          </template>
        </el-table-column>
        <el-table-column label="名称" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.名称 }}
          </template>
        </el-table-column>
        <el-table-column label="规格" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.规格 }}
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.数量 }}
          </template>
        </el-table-column>
        <el-table-column label="单价" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.单价 }}
          </template>
        </el-table-column>
        <el-table-column label="优惠后单价" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.优惠后单价 }}
          </template>
        </el-table-column>
        <el-table-column label="优惠后小计(元)" align="center" min-width="100" prop="金额">
          <template slot-scope="scope">
            {{ scope.row.金额 = Number(scope.row.优惠后单价) * Number(scope.row.数量) }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { initProject, searchProjectTotal } from '@/api/PurchasingCenter/ProjectTotalSearch'
import { mapGetters } from 'vuex'

export default {
  name: '', // 项目总价查询
  data() {
    return {
      projectValue: '',
      project: [],
      pageCurrent1: 1,
      pageSize1: 10,
      total1: 0,
      tableData1: []
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      initProject().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.project.push({
            label: response.data[i].项目名称,
            value: response.data[i].项目流水号
          })
        }
      })
    },
    searchTable1() {
      if (this.projectValue) {
        searchProjectTotal(this.projectValue).then(response => {
          console.log(response.data)
          this.tableData1 = response.data
        })
      } else {
        this.$message.error('请选择项目')
      }
    },
    handleSizeChange1(val) {
      this.pageSize1 = val
      this.pageCurrent1 = 1
      this.searchTable1()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchTable1()
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  .el-select{
    width:200px
  }
  .el-input{
    width:200px
  }
  span{
    margin: 10px 0 10px 10px;
  }
  .searchForm .el-form-item{
    margin-bottom: 5px;
  }
  .el-tag{
    margin: 0
  }
  .el-date-editor{
    width:300px
  }
</style>
