<template>
  <div class="div1">

    <div class="div2" style="padding-bottom: 10px">

      <el-form ref="form" :model="param" label-width="80px">

        <el-row :gutter="24">
          <el-col :span="4">
            <el-form-item label="相关单号:">
              <el-input type="textarea" v-model="param.RELATED_BILL" :rows="1"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="日志类型:">
              <el-select v-model="param.LOG_TYPE"   multiple filterable  placeholder="请选择工厂" style="width: 100%;">
                <el-option
                    v-for="item in Log"
                    :key="item.index"
                    :label="item.LOG_TYPE"
                    :value="item.LOG_TYPE"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="源库位:" >
              <el-input  type="textarea" v-model="param.loc1_code" :rows="1"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="目标库位:">
              <el-input type="textarea" v-model="param.loc_code" :rows="1"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="料号:">
              <el-input type="textarea" v-model="param.i_code" :rows="1"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="LOC:">
              <el-select v-model="param.PROP_C2"  multiple filterable placeholder="请选择LOC" style="width: 100%;">
                <el-option
                    v-for="item in LOCS"
                    :key="item.ID"
                    :label="item.PROP_C2"
                    :value="item.PROP_C2"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row :gutter="24" v-show="isShow">

          <el-col :span="4">
            <el-form-item label="操作员">
              <el-input type="textarea" v-model="param.OPERATOR" :rows="1"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="发生时间:">
              <el-date-picker style="width: 325px"
                              v-model="param.OCCUR_TIME"
                              type="daterange"
                              align="right"
                              unlink-panels
                              range-separator="至"
                              start-placeholder="开始日期"
                              end-placeholder="结束日期"
                              :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-col>

        </el-row>

        <el-button type="success" @click="find">查找</el-button>
        <el-button type="success" @click="rest">重置</el-button>&nbsp;&nbsp;
        <el-checkbox v-model="checked" @change="Allquesr">是否显示全部查询条件</el-checkbox>
      </el-form>

    </div>



    <el-table
        v-loading="this.tableloding"
        :height="MaxHeight"
        :header-cell-style="{background:'#000',color:'#fff'}"
        :data="tableData"
        id="educe-table"
        ref="tableData"
        style="width: 100%;">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          fixed
          label="序号"
          v-if="false"
          width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column-->
<!--          label="ID"-->
<!--          width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <div slot="reference" class="name-wrapper">-->
<!--            <span>{{ scope.row.id}}</span>-->
<!--          </div>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column
          label="相关单号"
          width="150">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.RELATED_BILL }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="日记类型"
          width="120">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span v-if="scope.row.LOG_TYPE=='ARRANGEMENT'">整理</span>
            <span v-else-if="scope.row.LOG_TYPE=='RECEIVING'">入库</span>
            <span v-else-if="scope.row.LOG_TYPE=='SHIPPING'">拣配</span>
            <span v-else-if="scope.row.LOG_TYPE=='FROZEN'">冻结</span>
            <span v-else-if="scope.row.LOG_TYPE=='CHECK_ADJUST'">盘点调整</span>
            <span v-else-if="scope.row.LOG_TYPE=='HAND_ORDER'">交单</span>
            <span v-else-if="scope.row.LOG_TYPE=='MOVE'">移库</span>
            <span v-else-if="scope.row.LOG_TYPE=='SOLUTION_K'">解K</span>
            <span v-else-if="scope.row.LOG_TYPE=='RECEIVING_ADJUST'">其它入库</span>
            <span v-else-if="scope.row.LOG_TYPE=='SHIPPING_ADJUST'">其它出库</span>
            <span v-else-if="scope.row.LOG_TYPE=='CONVERT_PACKAGEUNIT'">工单退料</span>
            <span v-else-if="scope.row.LOG_TYPE=='INVENTORY_ADJUST'">调整</span>
            <span v-else-if="scope.row.LOG_TYPE=='COUNT_ADJUST'">删除库存</span>
            <span v-else-if="scope.row.LOG_TYPE=='PROCESS_DOWN'">取消整理</span>
            <span v-else-if="scope.row.LOG_TYPE=='PROCESS_UP'">合单</span>
            <span v-else-if="scope.row.LOG_TYPE=='MODIFY_LOT'">批次调整</span>
            <span v-else-if="scope.row.LOG_TYPE=='MODIFY_STATUS'">状态调整</span>
            <span v-else-if="scope.row.LOG_TYPE=='COMPANY_TRANS_OUT'">异常登记</span>
            <span v-else-if="scope.row.LOG_TYPE=='COMPANY_TRANS_IN'">取消分配</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="单据类型"
          width="100">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.NAME }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="源库位"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.loc1_code }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="目标库位"
          width="s80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.loc_code }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="料号"
          width="160">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.i_code }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          :show-overflow-tooltip="true"
          label="描述"
          width="180">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.i_name }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="单位"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.UNIT }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="发生数量"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.number }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="操作人"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.OPERATOR }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="发生日期"
          width="100">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.OCCUR_TIME!=null?new Date(scope.row.OCCUR_TIME).toISOString().replace('T','').substring(0,10):scope.row.OCCUR_TIME}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="发生时间"
          width="100">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.OCCUR_TIME!=null?new Date(scope.row.OCCUR_TIME).toISOString().replace('T','').substring(10,18):scope.row.OCCUR_TIME}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          :show-overflow-tooltip="true"
          label="备注"
          width="120">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.DESCRIPTION }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="批号"
          width="100">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.PROP_C1 }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="LOC"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.PROP_C2 }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="特殊标记"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.PROP_C3 }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="供应商编号"
          width="100">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{scope.row.PROP_C5}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          :show-overflow-tooltip="true"
          label="暂存原因"
          width="100">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.PROP_C8}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="工厂"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.PROP_C9 }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="工作站"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.endRegion}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          label="容器"
          width="80">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <span>{{ scope.row.LP}}</span>
          </div>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[ 50, 100, 200,500]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "Kucunrizhi",
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      tableloding: false,
      isShow:false,//是否展示全部搜索条件
      tableData: [],
      pageSize: 50,
      pageNum: 1,
      total: 3,
      param: {
        //相关单号
        RELATED_BILL: '',
        //日志类型
        LOG_TYPE: [],
        //源库位
        loc1_code: '',
        //目标库位
        loc_code: '',
        //料号
        i_code: '',
        //LOC
        PROP_C2: [],
        //操作员
        OPERATOR: '',
        //发生时间
        OCCUR_TIME: [],
      },
      LOCS: [],
      Log: [],
      checked: false,
    }
  },computed:{
    MaxHeight(){
      if(this.checked){
        return  window.innerHeight - 285 +"px";
      }else{
        return  window.innerHeight - 240 +"px";
      }

    }
  },
  mounted() {
    this.queryUser();
    this.LOC();
    this.LogS();
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageNum = 1;
      this.pageSize = val;
      this.queryUser();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val;
      this.queryUser();
    },
    LOC(){
      //LOC下拉列表数据加载
      this.$axios.post(this.$httpUrl + '/Rukuzhengli/LOC', {

      }).then(res => res.data)
          .then(res => {
            if (res.code == 200) {
              this.LOCS = res.data;
            } else {
              this.$message.error('获取数据失败');
            }

            // eslint-disable-next-line no-unused-vars
          },err=>{
            this.tableloding=false;
          })
    },
    LogS(){
      //日志类型下拉列表数据加载
      this.$axios.post(this.$httpUrl + '/Kucunrizhi/log', {

      }).then(res => res.data)
          .then(res => {
            if (res.code == 200) {
              this.Log = res.data;
            } else {
              this.$message.error('获取数据失败');
            }

            // eslint-disable-next-line no-unused-vars
          },err=>{
            this.tableloding=false;
          })
    },
    queryUser() {
      //列表数据加载
      this.$axios.post(this.$httpUrl + '/Kucunrizhi/queryRi', {
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        param: this.param,
      }).then(res => res.data)
          .then(res => {
            if (res.code == 200) {
              this.tableData = res.data
              this.total = res.total
            } else {
              this.$message.error('获取数据失败');
            }

            // eslint-disable-next-line no-unused-vars
          },err=>{
            this.tableloding=false;
          })

    },
    find(){
      this.queryUser();
    },
    Allquesr(){
      //查询按钮
      if(this.checked){
        this.isShow=true;
      }else {
        this.isShow=false;
      }
    },
    rest() {
      //条件查询重置
      this.checked=false;
      this.isShow=false;
      this.param={};
    },
  }
}
</script>


<style lang="scss" scoped>

</style>
