<template>
  <div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      height="500px"
      style="width: 100%;"
      size="small"
      stripe
      border>
      <!-- <el-table-column
        type="selection"
        width="55"
        align="center">
      </el-table-column> -->
      <el-table-column
        prop="rowno"
        label="行号">
      </el-table-column>
      <el-table-column
        prop="itemno"
        label="产品编码">
      </el-table-column>
      <el-table-column
        prop="itemname"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="erpitemno"
        label="品号">
      </el-table-column>
      <el-table-column
          prop="model"
          label="型号">
      </el-table-column>
      <el-table-column
          prop="spec"
          label="规格">
      </el-table-column>
      <el-table-column
        prop="unitname"
        label="单位">
      </el-table-column>
      <el-table-column
        prop="price"
        label="单价">
        <template slot-scope="scope">
          {{tool.formatAmount(scope.row.price,2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="qty"
        label="发货数量">
      </el-table-column>
      <el-table-column
        prop="amount"
        label="发货金额">
      </el-table-column>
      <el-table-column
        prop="undeliqty"
        label="未发货数量">
      </el-table-column>
      <el-table-column
        prop="remarks"
        label="备注">
      </el-table-column>
      <el-table-column
        prop="suminqty"
        label="erp即时库存">
      </el-table-column>
      <el-table-column
        prop="deliedqty"
        width="120px"
        label="drp可发货数量">
      </el-table-column>
      <el-table-column label="操作" v-if="type === 'edit'" width="90">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="deleteOrderProduct(scope.row)">删 除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top:16px;text-align:right">
      <el-pagination
        background
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="param.content.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  props:['type'],
  data () {
    return {
      tableData:[],
      param:{
        "id": 20221115104703,
        "content": {
          "sa_orderid": 0,
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
              "condition": ""
          }
        },
      },
      total:0,
      currentPage:0,
      time: null
    }
  },
  methods:{
    async listData () {
      this.param.content.sa_dispatchid = this.$route.query.id
      const res = await this.$api.requested(this.param)
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      console.log(res.data);
      
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    async deleteOrderProduct (row) {
      const res = await this.$api.requested({
        "id": 20221115104803,
        "content": {
          "sa_dispatch_itemsids": [row.sa_dispatch_itemsid]
        },
      })
      this.tool.showMessage(res,()=>{
        this.listData()
        this.$emit('onSuccess')
      })
    },
    async updateOrderProduct (val) {
      const res  = await this.$api.requested({
        "id": 20221110145302,
        "content": val
      })
    },
    qtyChange (val,index) {
      let that = this
      this.$set(this.tableData,index,val)
      // console.log(val,this.tableData)
      // // 防抖
      if(this.time !== null){
        clearTimeout(this.time);
      }
      this.time = setTimeout(() => {
        that.updateOrderProduct({
          "sa_orderitemsid":val.sa_orderitemsid,
          "sa_orderid":this.$route.query.id,//订单ID
          "itemid":val.itemid,//商品ID
          "type":"数量",//调整类型，目前只支持数量
          "oldvalue":val.qty,//原值
          "newvalue":val.qty,//调整后值
          "remarks":val.remarks
        })
      },500)
    }
  },
  mounted () {
    this.listData()
  }
}

</script>
<style>
</style>