<template>
  <div id="PurchaseDemandList">
    <div v-if="isList">
      <el-form class="search_area" label-width="auto">
        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-form-item label="单据编码">
              <el-select v-model="queryParams.oneCode" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="供应仓库">
              <el-select v-model="queryParams.oneName" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="需求客户">
              <el-select v-model="queryParams.twoCode" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="是否已处理需求">
              <el-select v-model="queryParams.twoName" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="业务部门">
              <el-select v-model="queryParams.threeCode" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="单据类型">
              <el-select v-model="queryParams.threeName" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="需求人员">
              <el-select v-model="queryParams.fourCode" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="供应货位">
              <el-select v-model="queryParams.fourName" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="单据来源">
              <el-select v-model="queryParams.code" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="业务类型">
              <el-select v-model="queryParams.name" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="需求部门">
              <el-select v-model="queryParams.ddman" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="周期单位">
              <el-select v-model="queryParams.cgman" size="small" style="width: 200px" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="合理性校验结果">
            <el-input
              v-model="queryParams.sccj"
              size="small"
              placeholder=""
              clearable
              style="width: 200px"
            />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="需求日期">
            <el-input
              v-model="queryParams.bz"
              size="small"
              placeholder=""
              clearable
              style="width: 200px"
            />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="创建时间">
            <el-input
              v-model="queryParams.bz"
              size="small"
              placeholder=""
              clearable
              style="width: 200px"
            />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="物料编码">
            <el-input
              v-model="queryParams.bz"
              size="small"
              placeholder=""
              clearable
              style="width: 200px"
            />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="备注">
            <el-input
              v-model="queryParams.bz"
              size="small"
              placeholder=""
              clearable
              style="width: 200px"
            />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="" label-width="20px">
              <el-button type="primary" size="small" icon="el-icon-search" plain>搜索</el-button>
              <el-button size="small" icon="el-icon-refresh" plain>重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-card>
        <div class="btn_grooup">
          <el-button type="primary" size="small" @click="addDivision">新增</el-button>

          <el-dropdown size="small" @command="handleCommand">
            <el-button size="small" type="primary" style="margin-left: 10px;">
              导入<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="数据导入">数据导入</el-dropdown-item>
              <el-dropdown-item command="模板下载">模板下载</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

          <el-dropdown size="small" @command="handleCommand">
            <el-button size="small" type="primary" style="margin: 0 10px;">
              导出<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="Excel导出">Excel导出</el-dropdown-item>
              <el-dropdown-item command="导出明细">导出明细</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

          <el-button type="primary" size="small">删除</el-button>
          <el-button type="primary" size="small">打印</el-button>
        </div>
        <el-table 
          :data="tableList" 
          fit
          max-height="680"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column label="编码" align="center" prop="code"/>
          <el-table-column label="需求日期" align="center" width="200" prop="demandDate" />
          <el-table-column label="单据状态" align="center" prop="status" />
          <el-table-column label="是否已处理需求" align="center" width="150" prop="isProcess" />
          <el-table-column label="业务类型" align="center" width="150" prop="billType"/>
          <el-table-column label="是否特殊需求" align="center" width="150" prop="isSpeical" />
          <el-table-column label="需求人员" align="center" width="150" prop="demandPersonalName" />
          <el-table-column label="需求客户" align="center" prop="customerName" />
          <el-table-column label="需求部门" align="center" width="150" prop="demandDeptName" />
          <el-table-column label="供应仓库" align="center" width="120" prop="warehouseName" />
          <el-table-column label="供应货位" align="center" width="150" prop="goodsAllocationName" />
          <el-table-column label="单据来源" align="center" width="150" prop="source" />
          <el-table-column label="组织" align="center" width="150" prop="orgName" />
          <el-table-column label="备注" align="center" width="150" prop="remark" />
          <el-table-column
          fixed="right"
          label="操作"
          align="center"
          width="150"
          >
          <template slot-scope="scope">
            <el-button type="text" size="small">查看</el-button>
            <el-button type="text" size="small">编辑</el-button>
            <el-button type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
        </el-table>

        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="1"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total=total>
        </el-pagination>
      </el-card>
    </div>

    <Add v-model="isList" v-if="!isList" :pageStu="page"/>
  </div>
</template>

<script>
import Add from './add.vue'
import {getDemandList} from '@/api/purchase/purchaseDemand.js'
export default {
  name: 'PurchaseDemandList',
  components: {
    Add
  },
  data() {
    return {
      // 页面配置
      isList: true,
      // 页面状态
      page: '',
      queryParams: {
        oneCode: '',
        oneName: '',
        twoCode: '',
        twoName: '',
        threeCode: '',
        threeName: '',
        fourCode: '',
        fourName: '',
        code: '',
        name: '',
        ddman: '',
        cgman: '',
        sccj: '',
        bz: '',
        pageNum: 1,
        pageSize: 10
      },
      options: [{
        value: '1', label: '是',
      }, {
        value: '0', label: '否'
      }],
      tableList: [],
      total: 0,
      rowDetail: {},
      disable: false
    }
  },
  created() {
    this.getList(this.queryParams)
  },
  methods: {
    getList(params){
      getDemandList(params).then(res => {
        if (res.code === 200) {
          this.tableList = res.rows
          this.total = res.total
        }
      })
    },
    handleSelectionChange() {},
    handleCommand(command) {
      alert(command)
    },
    addDivision() {
      this.isList = false
      this.page = 'add'
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.queryParams.pageSize = val
      this.getList(this.queryParams)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.queryParams.pageNum = val
      this.getList(this.queryParams)
    }
  }
}
</script>

<style lang="scss" scoped>
#PurchaseDemandList {
  height: calc(100vh - 84px);
  padding: 12px;
  box-sizing: border-box;
}
.btn_grooup {
  margin-bottom: 10px;
  display: flex;
  justify-content: flex-end;
}
</style>