<template>
  <div>
    <el-table
    ref="table"
      :data="list"
      style="width: 100%"
      border
      size="mini"
      highlight-current-row
      @selection-change="onSelection"
      @row-click="activeRow">
      <el-table-column
        type="selection"
        align="center">
      </el-table-column>
      <el-table-column
        prop="sa_invoicebillid"
        label="发票ID"
        width="180">
      </el-table-column>
      <el-table-column
        prop="sumtaxincludedamount"
        label="发票金额"
        width="180">
      </el-table-column>
      <el-table-column
        prop="invoiceserialnum"
        label="发票流水号">
      </el-table-column>
      <el-table-column
        prop="status"
        label="发票状态">
      </el-table-column>
      <el-table-column
        prop="rb"
        label="红蓝字">
        <template slot-scope="scope">
          <span :style="{color:scope.row.rb == 1?'blue':'red'}">{{scope.row.rb == 1?'蓝字':'红字'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="150">
        <template slot-scope="scope">
          <a class="table_row_link inline-16" :href="scope.row.paperpdfurl">纸票pdf</a>
          <a class="table_row_link inline-16" :href="scope.row.pdfurl">发票pdf</a>
        </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]"
        :pager-count="15"
        layout="total,sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <el-dialog title="编辑发票" :visible.sync="dialogFormVisible" width="500px" append-to-body>
      <el-form :model="form" size="small" label-position="right" label-width="100px">
        <el-form-item label="备注">
          <el-input v-model="form.remarks" autocomplete="off" type="textarea" :autosize="{minRows:3}" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="submit" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['status'],
  data () {
    return {
      dialogFormVisible:false,
      form:{},
      param:{
        "id": "20221229154102",
        "pageNumber":1,
        "pageSize":20,
        "content": {
          "sa_orderid":this.$route.query.id
        }
      },
      list:[],
      total:0,
      currentPage:0,
    }
  },
  methods:{
    async listData () {
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      if (res.data.length > 0) {
        this.activeRow(res.data[0])
        this.$refs.table.setCurrentRow(this.list[0])
      }
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
    activeRow (row) {
      this.$emit('activeRow',row)
    },
    onSelection (selection) {
      this.$emit('selection',selection)
    },
    async deleteRow (row) {
      const res = await this.$api.requested({
        "id": "20221223160103",
        "content": {
          "sa_invoicebillids":[row.sa_invoicebillid]
        }
      })
      this.tool.showMessage(res,()=>{
        this.listData()
      })
    },
    editRow (row) {
      this.form = Object.assign({},this.form,row)
      this.dialogFormVisible = true
    },
    async submit () {
      const res = await this.$api.requested({
        "id": "20221223154403",
        "content": {
          "sa_invoicebillid":this.form.sa_invoicebillid,
          "remarks":this.form.remarks
        }
      })
      this.tool.showMessage(res,()=>{
        this.listData()
        this.dialogFormVisible = false
      })
    }
  },
  mounted () {
    this.listData()
  }
}

</script>
<style>
</style>