<template>
<div>
  <el-table
    class="mt-10"
    :data="tableData"
    style="width: 100%"
    size="mini"
    border
    @row-click="rowClick">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      prop="billno"
      label="发货单号">
    </el-table-column>
    <el-table-column
      prop="sonum"
      label="订单号">
    </el-table-column>
    <el-table-column
      prop="enterprisename"
      label="企业名称">
    </el-table-column>
    <el-table-column
      prop="recheckby"
      label="收货人">
    </el-table-column>
    <el-table-column
      prop="contactsphonenumber"
      label="收货人联系电话">
    </el-table-column>
    <el-table-column
      prop="province"
      label="省市县">
      <template slot-scope="scope" v-if="scope.row.province">
        {{`${scope.row.province}-${scope.row.city}-${scope.row.county}`}}
      </template>
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址">
    </el-table-column>
    <el-table-column
    v-if="type === 'edit'"
    label="操作"
    width="90">
      <template slot-scope="scope">
      <el-button type="text" @click="deleteDisBill(scope.row)" size="small">删 除</el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
</template>

<script>
  export default {
    props:['needQuery','type'],
    data() {
      return {
        tableData: []
      }
    },
    components:{
    },
    mounted () {
      this.needQuery?this.listData():''
    },
    methods:{
      async deleteDisBill (row) {
        if (this.needQuery) {
          const res = await this.$api.requested({
            "id": "20221122133404",
            "content": {
                "sa_logisticsid":this.$route.query.id,
                "sa_logistics_itemsids":[row.sa_logistics_itemsid]
            }
          })
          this.tool.showMessage(res,()=>{
            this.listData()
          })
        } else {
          this.tableData = this.tableData.filter(e=>{
            return e.sa_dispatchid !== row.sa_dispatchid
          })
        }
      },
      async listData(){
        const res = await this.$api.requested({
        "id": 20221122133004,
          "content": {
            "sa_logisticsid": this.$route.query.id,
            "pageNumber":1,
            "pageSize":100,
            "where": {
              "condition": ""
            }
          }
        })
        this.tableData = res.data
        res.data.length > 0?this.rowClick(res.data[0]):''
      },
      rowClick (row) {
        this.$emit('rowClick',row)
      }
    }
  }
</script>
