<template>
  <div>
    <addorderline :status="status" :sys_enterpriseid="sys_enterpriseid" @onSuccess="listData();$emit('onSuccess')"></addorderline>
    <el-table :data="list" size="mini" border>
      <el-table-column prop="sonum" label="订单号" width="150" fixed></el-table-column>
      <el-table-column prop="type" label="订单类型" width="90"></el-table-column>
      <el-table-column prop="checkdate" label="审核日期" width="150"></el-table-column>
      <el-table-column prop="itemno" label="产品编码" width="150"></el-table-column>
      <el-table-column prop="itemname" label="产品名称" width="150"></el-table-column>
      <el-table-column prop="price" label="订单单价" width="90"></el-table-column>
      <el-table-column prop="uninvoiceamount" label="可开票金额" width="90"></el-table-column>
      <el-table-column prop="invoiceaqty" label="本次开票数量" width="120"></el-table-column>
      <el-table-column prop="invoiceamount" label="本次开票金额" width="120"></el-table-column>
      <el-table-column prop="remarks" label="备注" min-width="150"></el-table-column>
      <el-table-column label="操作" width="90" fixed="right">
        <template slot-scope="scope">
          <changeOrderline v-if="tool.checkAuth($route.name,'InvioceOrder')" class="inline-16" :row="scope.row" :status="status" @onSuccess="listData();$emit('onSuccess')"></changeOrderline>
          <el-button v-if="tool.checkAuth($route.name,'InvioceOrder')" :disabled="status !== '新建'" size="small" type="text" @click="deleteRow(scope.row)">删 除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="container" style="text-align:right">
      <el-pagination
        background
        small
        @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>
</template>

<script>
import addorderline from './components/addorderline.vue'
import changeOrderline from './components/changeOrderline.vue'
export default {
  props:['sys_enterpriseid','status'],
  components:{
    addorderline,
    changeOrderline
  },
  data () {
    return {
      list:[],
      param:{
        "id": "20221217091303",
        "content": {
          "sa_invoiceapplyid":0,
          "where":{
            "condition":""
          }
        }
      },
      list:[],
      total:0,
      currentPage:0
    }
  },
  methods:{
    async listData (id) {
      this.param.content.sa_invoiceapplyid = this.$route.query.id
      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 deleteRow (row) {
      const res = await this.$api.requested({
        "id": "20221217091403",
        "version":1,
        "content": {
          "sa_invoiceapply_orderids":[row.sa_invoiceapply_orderid]
        }
      })
      this.tool.showMessage(res,()=>{
        this.listData()
        this.$emit('onSuccess')
      })
    } 
  },
  mounted () {
    this.listData()
  }
}

</script>
<style>
</style>