<template>
  <div>
    <el-button size="small" type="primary" @click="onShow(dialogTableVisible = true)">新建发货单</el-button>
    <el-dialog append-to-body title="选择发货订单" :visible.sync="dialogTableVisible" width="700px">
      <el-input style="width:200px;" class="mt-10 inline-16" placeholder="请输入" v-model="param.content.where.condition" @keyup.native.enter="listData(param.content.pageNumber = 1)" @clear="listData(param.content.pageNumber = 1)" size="small" clearable>
      </el-input>
      <el-date-picker
        class="inline-16"
        v-model="param.content.where.begindate"
        type="date"
        placeholder="选择开始日期"
        value-format="yyyy-MM-dd"
        size="small"
        @change="listData(param.content.pageNumber = 1)">
      </el-date-picker>
      <el-date-picker
        v-model="param.content.where.enddate"
        type="date"
        placeholder="选择结束日期"
        value-format="yyyy-MM-dd"
        size="small"
        @change="listData(param.content.pageNumber = 1)">
      </el-date-picker>
      <el-table :data="list" size="mini" border>
        <el-table-column prop="sonum" label="订单号"></el-table-column>
        <el-table-column prop="enterprisename" label="企业名称"></el-table-column>
        <el-table-column prop="checkdate" label="审核时间"></el-table-column>
        <el-table-column prop="remarks" label="备注"></el-table-column>
        <el-table-column label="操作" width="90">
          <template slot-scope="scope">
            <el-button size="small" type="text" @click="createDispatch(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="container normal-panel" 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>
    </el-dialog>  
</div>
</template>
<script>

export default {
  data () {
    return {
      dialogTableVisible:false,
      param:{
        "id": "20221114165903",
        "version":1,
        "content": {
          "pageNumber":1,
          "pageSize":20,
          "where":{
            "condition":"",
            "sonum":"",
            "begindate":'',
            "enddate":''
          }
        }
      },
      list:[],
      total:0,
      currentPage:0
    }
  },
  methods:{
    onShow () {
      this.listData()
    },
    async listData() {
      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 createDispatch (row) {
      const res = await this.$api.requested({
        "id": "20221114135203",
        "version":1,
        "content": {
          "sa_dispatchid":0,
          "sa_orderid":row.sa_orderid,
          "sys_enterpriseid":row.sys_enterpriseid,
          "sa_logiscompid":row.sa_logiscompid,
          "rec_contactsid":row.rec_contactsid,
          "remarks":row.remarks
        }
      })
      this.tool.showMessage(res,()=>{
        this.dialogTableVisible = false
        this.$emit('onSuccess')
        this.$store.dispatch('changeDetailDrawer',true)
        this.$router.push({path:'/dispatchdetail',query:{id:res.data.sa_dispatchid,rowindex:res.data.rowindex}})
      })
    }
  }
}
</script>