<template>
  <div>
    <el-form :inline="true" :model="filterQuery" class="query-form" size="mini">
      <el-form-item class="query-form-item">
        <el-input v-model="filterQuery.id" placeholder="单号"></el-input>
      </el-form-item>

      <el-form-item class="query-form-item">
        <el-input v-model="filterQuery.code" placeholder="条码查询"></el-input>
      </el-form-item>

      <el-form-item class="query-form-item">
        <el-select v-model="filterQuery.mainAction" placeholder="出入库类型">
          <el-option label="全部" value></el-option>
          <el-option label="入库" value="WareHouseIn"></el-option>
          <el-option label="出库" value="WareHouseOut"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="query-form-item">
        <el-select v-model="filterQuery.action" placeholder="业务类型">
          <el-option label="全部" value></el-option>
          <el-option label="生产入库" value="ProduceWareHouseIn"></el-option>
          <el-option label="采购入库" value="PurchaseWareHouseIn"></el-option>
          <el-option label="退货入库" value="ReturnWareHouseIn"></el-option>
          <el-option label="调拨入库" value="AllocateWareHouseIn"></el-option>
          <el-option label="销售出库" value="SalesWareHouseOut"></el-option>
          <el-option label="退货出库" value="ReturnWareHouseOut"></el-option>
          <el-option label="抽检出库" value="CheckWareHouseOut"></el-option>
          <el-option label="销毁出库" value="DestoryWareHouseOut"></el-option>
          <el-option label="调拨出库" value="AllocateWareHouseOut"></el-option>
          <el-option label="返工出库" value="ReworkWareHouseOut"></el-option>
          <el-option label="直调出库" value="DirectAllocateWareHouseOut"></el-option>
          <el-option label="盘点" value="StockCheck"></el-option>
          <el-option label="码替换" value="CodeReplace"></el-option>
          <el-option label="码注销" value="CodeDestory"></el-option>
          <!-- <el-option v-for="item in roles" :key="item.id" :label="item.name" :value="item.id"></el-option> -->
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button-group>
          <el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button>
          <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
        </el-button-group>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      style="width: 100%;"
      ref="multipleTable"
      tooltip-effect="dark"
      @selection-change="handleSelectionChange"
      @row-click="intentDetail"
    >
      <el-table-column type="selection" width="55"></el-table-column>

      <el-table-column label="ID" prop="id" fixed></el-table-column>
      <el-table-column label="业务类型" prop="action" fixed>
        <template slot-scope="scope">
          <span>{{ wareHouseMap[scope.row.action] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单号" prop="corpOrderId" fixed></el-table-column>
      <el-table-column label="往来单位" prop="fromCorp" fixed></el-table-column>
      <el-table-column label="创建时间" prop="actDate">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span>{{ scope.row.actDate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作员" prop="actor" fixed></el-table-column>
    </el-table>
    <el-pagination
      :page-size="query.limit"
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import {
    filterOrder
} from "../../api/inout/order";
import draggable from "vuedraggable";
const formJson = {
    site_id: "",
    site_name: "",
    describe: "",
    ads: []
};
export default {
    props: {
        isSelect: {
            type: Boolean,
            default: false
        }
    },

    data() {
        return {
            query: {
                page: 1,
                limit: 20
            },
            multipleSelection: [],

            list: [],

            filterQuery: {
                id: "",
                mainAction: "",
                action: "",
                page: 1,
                limit: 20,
                code: ""
            },
            curIndex: "",
            adListNoDataText: "无数据",
            queryAdIdAsyncLoading: false,
            total: 0,
            loading: true,
            index: null,

            dialogTableVisible: false,
            wareHouseMap: {
                SalesWareHouseOut: "生产入库",
                PurchaseWareHouseIn: "采购入库",
                ReturnWareHouseOut: "退货入库",
                ProduceWareHouseIn: "调拨入库",
                ProduceWareHouseOut: "销售出库",
                AllocateWareHouseIn: "退货出库",
                AllocateWareHouseOut: "调拨出库",
                ReworkWareHouseOut: "返工出库",
                DestoryWareHouseOut: "销毁出库",
                CheckWareHouseOut: "抽检出库",
                DirectAllocateWareHouseOut: "直调出库",
                CodeReplace: "码替换",
                CodeDestory: "码注销",
                StockCheck: "盘点"
            },
            formLoading: false,
            formVisible: false,
            formData: formJson,
            deleteLoading: false
        };
    },
    components: {
        draggable
    },
    methods: {
        onReset() {
            this.$router.push({
                path: ""
            });
            this.filterQuery = {
                id: "",
                mainAction: "",
                action: "",
                page: 1,
                limit: 20,
                code: ""
            };
            this.getList();
        },
        onSubmit() {
            this.getList();
        },
        handleSizeChange(val) {
            this.filterQuery.limit = val;
            this.getList();
        },
        handleCurrentChange(val) {
            this.filterQuery.page = val;
            this.getList();
        },

        //获取订单列表
        getList() {
            this.loading = true;
            filterOrder(this.filterQuery)
                .then(response => {
                    this.loading = false;
                    this.list = response.data.list || [];
                    this.total = response.data.total || 0;
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                    this.total = 0;
                });
        },
        handleSelectionChange(val) {
            console.log(val);
            this.multipleSelection = val;
        }
    },
    filters: {},
    mounted() {
        document.body.ondrop = function(event) {
            event.preventDefault();
            event.stopPropagation();
        };
    },

    created() {
        // 将参数拷贝进查询对象
        let query = this.$route.query;
        this.query = Object.assign(this.query, query);
        this.query.limit = parseInt(this.query.limit);
        // 加载表格数据
        this.getList();
    }
};
</script>

<style type="text/scss" lang="scss">
</style>
