<template>
  <div>
    <el-button size="small" type="text" @click="onshow">产品清单</el-button>
    <el-drawer
      title="产品清单"
      :visible.sync="drawer"
      append-to-body
      direction="rtl"
      :show-close="false"
      size="80%">
      <div style="border-top:1px solid #eeeeee; padding:20px 16px; margin-bottom:0px">
        <el-row :gutter="10">
          <el-col :span="3">
            <span class="search__label">项目编号:</span>
            <span class="topTile">{{data.projectnum}}</span>
          </el-col>
          <el-col :span="3">
            <span class="search__label">项目名称:</span>
            <span class="topTile">{{data.projectname}}</span>
          </el-col>
          <el-col :span="3">
            <span class="search__label">项目类型:</span>
            <span class="topTile">{{data.projecttype}}</span>
          </el-col>
          <el-col :span="3">
            <span class="search__label">项目地址:</span>
            <span class="topTile">{{data.address}}</span>
          </el-col>
          <el-col :span="3">
            <span class="search__label">预测金额(元):</span>
            <span class="topTile">{{data.sumprojectamount}}</span>
          </el-col>
        </el-row>
      </div>
      <div class="drawer__panel">
        <el-input class="mt-10" style="width:200px" suffix-icon="el-icon-search" size="small" placeholder="搜索" v-model="param.content.where.condition" @keyup.native.enter="listData(param.content.pageNumber = 1)" @clear="listData(param.content.pageNumber = 1)" clearable></el-input>
        <el-table
          ref="multipleTable"
          :data="list"
          style="width: 100%"
          size="mini"
          border>
        <el-table-column
            prop="itemno"
            label="产品编号"
            width="180">
        </el-table-column>
        <el-table-column
            prop="itemname"
            label="产品名称"
            width="180">
        </el-table-column>
        <el-table-column
            label="型号"
            width="180">
          <template slot-scope="scope">
            <p><span>{{scope.row.model}}</span></p>
          </template>
        </el-table-column>
        <el-table-column
              label="规格"
              width="180">
            <template slot-scope="scope">
              <p><span>{{scope.row.spec}}</span></p>
            </template>
        </el-table-column>
        <el-table-column
            prop="caliber"
            label="口径"
            width="180">
        </el-table-column>
        <el-table-column
            prop="pressure"
            label="压力"
            width="180">
        </el-table-column>
        <el-table-column
            prop="material"
            label="材质"
            width="180">
        </el-table-column>
        <el-table-column
            prop="brand"
            label="品牌"
            width="180">
          <template slot-scope="scope">
            <p v-for="(item,index) in scope.row.brand" :key="index">
              <span style="float: left" v-if="index === scope.row.brand.length -1">{{item?item.brandname+'':'--'}}</span>
              <span style="float: left" v-else>{{item?item.brandname+',':'--'}}</span>
            </p>
          </template>
        </el-table-column>
        <el-table-column
            prop="itemclass"
            label="类别"
            width="180">
          <template slot-scope="scope">
            <p v-for="(item,index) in scope.row.itemclass" :key="index">
              <span style="float: left" v-if="index === scope.row.itemclass.length -1">{{item?item.itemclassname+'':'--'}}</span>
              <span style="float: left" v-else>{{item?item.itemclassname+',':'--'}}</span>
            </p>
          </template>
        </el-table-column>
        <el-table-column
            prop="unitid"
            label="计量单位"
            width="100">
          <template slot-scope="scope">
            <el-tag size="mini" type="info" effect="plain">{{scope.row.unitname}}/{{scope.row.axunitname}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="数量"
          width="180"
          fixed="right">
          <template slot-scope="scope">
            {{scope.row.outqty}}
          </template>
        </el-table-column>
        <el-table-column
            prop="marketprice"
            label="牌价"
            width="100">
        </el-table-column>
        <el-table-column
            prop="outamount"
            label="金额"
            width="100"
            fixed="right">
        </el-table-column>
        </el-table>
        <div class="container normal-panel flex-align-center flex-between">
          <p v-if="list[0]" class="topTile">金额合计(元):{{list[0].sumamount}}</p>
          <p v-else class="topTile">金额合计(元):0</p>
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[20, 50, 100, 200]"
            layout="total,sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import previewImage from '@/components/previewImage/index.vue'
export default {
  props:['id','sa_salesforecastbillid','data'],
  components:{
    previewImage
  },
  data () {
    return {
      drawer:false,
      param:{
        "id": 20220906154703,
        "content": {
          "sa_salesforecastbillid":'',
          "where":{
            "sa_projectid":'',
            "condition":""
          }
        }
      },
      list:[],
      currentPage:0,
      total:0
    }
  },
  methods:{
    onshow(){
      this.drawer = true
      console.log("接收数据")
      console.log(this.id,this.sa_salesforecastbillid,this.data)
      this.listData(this.id)
    },
    async listData (sa_projectid) {
      this.param.content.sa_salesforecastbillid = this.sa_salesforecastbillid
      this.param.content.where.sa_projectid = sa_projectid
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
    async qtyChange () {
      this.list = this.list.filter(e=>{
        e.outamount = e.outqty * e.marketprice
        return e
      })
      const res = await this.$api.requested({
        "id": 20220906155003,
        "version":1,
        "content": {
          "sa_salesforecastmodelid":this.mainData.sa_salesforecastmodelid,
          "sa_salesforecastbillid":this.$route.query.id,
          "sa_projectid": this.param.content.where.sa_projectid,
          "itemclassinfos": this.list.map(e=>{
            return {
              "sa_salesforecastid":e.sa_salesforecastid,
              "itemclassnum": e.itemclassnum,
              "orderqty": e.orderqty,
              "orderamount": e.orderamount,
              "invoiceqty": e.invoiceqty,
              "invoiceamount": e.invoiceamount,
              "outqty": e.outqty,
              "outamount": e.outamount,
              "itemid":e.itemid
            }
          })
        }
      })
      this.tool.showMessage(res,()=>{

      })
    },
    async deleteProduct (row) {
      const res = await this.$api.requested({
        "id": 20220906155103,
        "version":1,
        "content": {
            "sa_salesforecastid":row.sa_salesforecastid,
            "sa_projectid":0,
            "sa_salesforecastbillid":this.$route.query.id
        }
      })
      this.tool.showMessage(res,()=>{
        this.listData()
      })
    }
  },
  mounted () {
  }
}

</script>
<style>
  .topTile{
    font-size: 14px;
    color: #666666
  }
</style>