<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
      @submit.native.prevent
    >
      <QueryFormWrapper>
        <el-col :span="8">
          <el-form-item label="出货单号" prop="saleOutNo">
            <el-input
              v-model="queryParams.saleOutNo"
              placeholder="请输入出货单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="销售单号" prop="saleOrderNo">
            <el-input
              v-model="queryParams.saleOrderNo"
              placeholder="请输入销售单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="物料编码" prop="materialNo">
            <el-input
              v-model="queryParams.materialNo"
              placeholder="请输入物料编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <div slot="right">
          <el-form-item label-width="0" class="text-right" style="word">
            <EasyAdvancedQuery class="mr10" label-width="98px" @advQuery="advQuery">
              <template #default="{model}">
                <el-row :gutter="10" type="flex">
                  <el-col :span="12">
                    <el-form-item label="物料名称" prop="materialName">
                      <el-input
                        v-model="model.materialName"
                        placeholder="请输入物料名称"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="客户名称" prop="customerName">
                      <el-input
                        v-model="model.customerName"
                        placeholder="请输入客户名称"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="箱号" prop="boxNo">
                      <el-input
                        v-model="model.boxNo"
                        placeholder="请输入箱号"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="数量" prop="qty">
                      <el-input
                        v-model="model.qty"
                        placeholder="请输入数量"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="创建人" prop="creator">
                      <el-input
                        v-model="model.creator"
                        placeholder="请输入创建人"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="时间范围" prop="createTime">
                      <el-date-picker
                        v-model="model.createTime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                      />
                    </el-form-item>
                  </el-col>
                </el-row>
              </template>
            </EasyAdvancedQuery>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </div>
      </QueryFormWrapper>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :columns="columnsList"
        :show-search.sync="showSearch"
        @queryTable="handleQuery"
        @saveSetting="getColumnsList"
      />
    </el-row>

    <!-- 列表 -->
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="待出库" name="salesToIssue" lazy>
        <SalesToIssue
          ref="salesToIssue"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @salesComplete="salesCompleteToIssue"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="出库中" name="inIssue" lazy>
        <!-- 已发 -->
        <InIssue
          ref="inIssue"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @salesComplete="salesComplete"
        />
      </el-tab-pane>
      <el-tab-pane label="已完成" name="salesCompleted" lazy>
        <!-- 已结束 -->
        <SalesCompleted ref="salesCompleted" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
    </el-tabs>

  </div>
</template>

<script>
import SalesToIssue from './components/SalesToIssue.vue'
import InIssue from './components/InIssue.vue'
import SalesCompleted from './components/SalesCompleted.vue'

export default {
  name: 'SaleOutOrder',
  components: {
    SalesToIssue,
    InIssue,
    SalesCompleted
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      elseShow: false,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // wms销售出库单主列表
      list: [],
      // 弹出层标题
      title: '',
      activeName: 'salesToIssue',
      // 是否显示弹出层
      open: false,
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        saleOrderNo: null,
        outStatus: null,
        testResult: null,
        saleStatus: null,
        createTime: [],
        saleOutNo: null,
        materialNo: null,
        materialName: null,
        qty: null,
        creator: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        saleOrderDetailId: [{ required: true, message: '关联销售单明细表ID不能为空', trigger: 'blur' }],
        saleOutNo: [{ required: true, message: '销售出库单号不能为空', trigger: 'blur' }]
      },
      // 显隐列
      columnsList: []
    }
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        saleOrderDetailId: undefined,
        saleOutNo: undefined,
        outStatus: undefined,
        testResult: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageNo = 1
      // this.getList()
      this.$refs[this.activeName].getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.advParams = {}
      this.$refs[this.activeName].advParams = {}
      // this.handleQuery()
      this.$refs[this.activeName].handleQuery()
    },
    handleClick(tab, event) {
      this.activeName = tab.name
    },
    salesComplete() {
      const refs = this.$refs.salesCompleted
      refs && refs.handleQuery()
    },
    salesCompleteToIssue() {
      const salesCompleted = this.$refs.salesCompleted
      salesCompleted && salesCompleted.handleQuery()
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams
      this.$refs[this.activeName].advParams = this.advParams
      this.handleQuery()
    },
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList()
      })
    }
  }
}
</script>

