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

    <!-- 搜索工作栏 -->
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <QueryFormWrapper>
        <el-col :span="8">
          <el-form-item label="退料单号" prop="orderNo">
            <el-input
              v-model="queryParams.orderNo"
              placeholder="请输入退料单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="退料状态" prop="status">
            <DictSelect v-model="queryParams.status" placeholder="请选择退料状态" dict-type="WMS_RETURN_STATUS" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="退料类型" prop="returnType">
            <DictSelect v-model="queryParams.returnType" placeholder="请选择退料类型" dict-type="WMS_MATERIAL_RETURN_TYPE" />
          </el-form-item>
        </el-col>
        <div slot="right">
          <el-form-item label-width="0" class="text-right" style="word">
            <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">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <right-toolbar
        :show-search.sync="showSearch"
        :columns="columnsList"
        @queryTable="handleQuery"
        @saveSetting="getColumnsList"
      />
    </el-row>

    <!-- 列表 -->
    <el-tabs v-model="tabActivedName" type="border-card" @tab-click="tabClick">
      <el-tab-pane
        v-for="item in approvalList"
        :key="item.code"
        :label="item.name"
        :name="item.code"
      >
        <ReturnList :ref="item.code" @columns="getColumns" />
      </el-tab-pane>
    </el-tabs>
    <!-- 退料日志 -->
    <!-- <ReturnLogs ref="returnLogs" /> -->
    <!-- 退料操作 -->
    <ReturnMaterialList ref="returnMaterials" />
    <!-- 退料前置详情查看 -->
    <!-- <ReturnDetails ref="returnDetails" /> -->
  </div>
</template>

<script>
import ReturnList from './components/ReturnList.vue'
// import ReturnLogs from './components/ReturnLogs.vue'
import ReturnMaterialList from './components/ReturnMaterialList.vue'
// import ReturnDetails from './components/ReturnDetails.vue'

export default {
  name: 'MaterialReturn',
  components: {
    ReturnList,
    ReturnMaterialList
  },
  provide() {
    return {
      headerFormFn: () => this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // wms来料退货单列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      approvalList: [
        {
          name: '待提交',
          code: 'Tosubmit',
          auditStatus: -1
        },
        {
          name: 'QC待审核',
          code: 'submitted',
          auditStatus: 0
        },
        {
          name: '待过账',
          code: 'qcApproval',
          auditStatus: 1
        },
        {
          name: '已结束',
          code: 'transferItems',
          auditStatus: 2
        }
      ],
      tabActivedName: 'Tosubmit',
      // 查询参数
      queryParams: {
        orderNo: null,
        remark: null,
        createTime: [],
        status: null,
        returnType: null
      },
      // 表单 参数
      form: {},
      // 显隐列
      columnsList: []

    }
  },
  created() {
    // this.getList()
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.handleParams()
      this.$refs[this.tabActivedName][0].getList()
    },
    // 退料传参
    handleParams() {
      const bomRef = this.$refs[this.tabActivedName][0]
      if (this.tabActivedName === 'Tosubmit') {
        bomRef.queryParams.auditStatus = -1
      } else if (this.tabActivedName === 'submitted') {
        bomRef.queryParams.auditStatus = 0
      } else if (this.tabActivedName === 'qcApproval') {
        bomRef.queryParams.auditStatus = 1
      } else {
        bomRef.queryParams.auditStatus = 2
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleParams()
      this.handleQuery()
    },
    tabClick(v) {
      this.$nextTick(() => {
        const bomRef = this.$refs[this.tabActivedName][0]
        this.handleParams()
        bomRef.handleQuery()
      })
    },
    // 新增
    handleAdd() {
      this.$refs.returnMaterials.open = true
    },
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.tabActivedName][0].getColumnsList()
      })
    }
  }
}
</script>
