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

    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <QueryFormWrapper>
        <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>
        <el-col :span="8">
          <el-form-item label="物料条码" prop="materialLots">
            <el-input
              v-model="queryParams.materialLots"
              placeholder="请输入物料条码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="物料名称" prop="materialName">
            <el-input
              v-model="queryParams.materialName"
              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="outType">
                      <DictSelect
                        v-model="model.outType"
                        placeholder="请选择出库类型"
                        clearable
                        :dict-type="'WMS_OTHER_ISSUE_TYPE_ERP'"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="领用部门" prop="departmentNo">
                      <DepartmentSelect v-model="model.departmentNo" filterable placeholder="请选择领用部门" />
                    </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-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>

    <!-- 列表 -->
    <OtherIssueDocument ref="otherIssueDocument" @columns="getColumns" />
    <!-- 出库 -->
    <!-- <OtherIssue ref="otherIssue" @complete="getList" /> -->
  </div>
</template>

<script>
import { exportMaterialTransactionExcel } from '@/api/wms/output/otherIssue'
// import OtherIssue from './components/OtherIssue.vue'
import OtherIssueDocument from '../../inquirePurchase/complexDocuments/components/OtherIssueDocument.vue'
import DepartmentSelect from './components/DepartmentSelect.vue'

export default {
  name: 'MaterialTransaction',
  components: {
    // OtherIssue,
    // 列表
    OtherIssueDocument,
    // 领用部门
    DepartmentSelect
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // wms交易列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        materialNo: null,
        wmsLabelMasterId: null,
        createTime: [],
        materialName: null,
        materialLots: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        type: [{ required: true, message: '交易类型不能为空', trigger: 'change' }],
        qty: [{ required: true, message: '数量不能为空', trigger: 'blur' }]
      },
      columnList: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.$nextTick(() => {
        const otherRefs = this.$refs.otherIssueDocument
        // if (otherRefs.paramsQuery === undefined) {
        //   otherRefs.paramsQuery = this.queryParams
        // }
        otherRefs.getList()
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        type: undefined,
        materialNo: undefined,
        wmsLabelMasterId: undefined,
        qty: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs.otherIssueDocument.queryParams.pageNo = 1
      this.$refs.otherIssueDocument.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.advParams = {}
      this.$refs.otherIssueDocument.advParams = {}
      this.$refs.otherIssueDocument.queryParams.pageNo = 1
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams }
      params.pageNo = undefined
      params.pageSize = undefined
      this.$modal.confirm('是否确认导出所有wms交易数据项?').then(() => {
        this.exportLoading = true
        return exportMaterialTransactionExcel(params)
      }).then(response => {
        this.$download.excel(response, 'wms交易.xls')
        this.exportLoading = false
      }).catch(() => {})
    },
    // 出库发料
    handleIssue() {
      this.$refs.otherIssue.open = true
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams
      this.$refs.otherIssueDocument.advParams = this.advParams
      this.handleQuery()
    },
    getColumns(data) {
      this.columnList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs.otherIssueDocument.getColumnsList()
      })
    }
  }
}
</script>

