<!-- 搜索表单 -->
<template>
  <el-form
    label-width="80px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="计划编码:">
          <el-input clearable v-model="where.code" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="产品编码:">
          <el-input
            clearable
            v-model="where.productCode"
            placeholder="请输入"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="牌号:" label-width="80px">
          <el-input clearable v-model="where.brandNo" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="型号:" label-width="80px">
          <el-input clearable v-model="where.model" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="计划类型:" label-width="80px">
          <el-select clearable v-model="where.orderType" placeholder="请选择">
            <el-option
              v-for="item in planType"
              :label="item.label"
              :value="item.value"
              :key="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-form-item label="计划状态:" label-width="80px">
          <el-select clearable v-model="where.status" placeholder="请选择">
            <el-option
              v-for="item in statusOpt[activeName]"
              :label="item.label"
              :value="item.value"
              :key="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 9, md: 12 } : { span: 9 }">
        <el-form-item label-width="100px">
          <template slot="label">
            <el-select
              v-model="deliveryVal"
              @change="
                () => {
                  where.deliveryTime = [];
                  where.formingTime = [];
                }
              "
            >
              <el-option label="预测交货日期" value="deliveryTime"></el-option>
              <el-option label="实际交货日期" value="formingTime"></el-option>
            </el-select>
          </template>
          <el-date-picker
            v-model="where[deliveryVal]"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 7, md: 12 } : { span: 7 }">
        <el-form-item label="">
          <template slot="label">
            <el-select
              v-model="shapeVal"
              @change="
                () => {
                  where.requiredFormingTime = [];
                  where.planFormingTime = [];
                  where.formingTime = [];
                }
              "
            >
              <el-option
                label="要求成型日期"
                value="requiredFormingTime"
              ></el-option>
              <el-option
                label="预测成型日期"
                value="planFormingTime"
              ></el-option>
              <el-option label="实际成型日期" value="formingTime"></el-option>
            </el-select>
          </template>
          <el-date-picker
            v-model="where[shapeVal]"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 7, md: 12 } : { span: 7 }">
        <el-form-item label="工单发布时间:">
          <el-date-picker
            v-model="where.releaseTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
          >
            查询
          </el-button>
          <el-button @click="reset" icon="el-icon-refresh-left" type="primary"
            >重置</el-button
          >
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
  export default {
    props: ['activeName'],
    data () {
      // 默认表单数据
      const defaultWhere = {
        code: '',
        productCode: '',
        status: '',
        model: '',
        brandNo: '',
        orderType: '',
        releaseTime: [],
        deliveryTime: [],
        formingTime: [],
        requiredFormingTime: [],
        planFormingTime: [],
        executeUserName: ''
      };
      return {
        // 表单数据
        deliveryVal: '',
        shapeVal: '',
        where: { ...defaultWhere },
        treeData: [],
        statusOpt: {
          first: [
            { label: '所有状态', value: '1,2' },
            { label: '待发布', value: '1' },
            { label: '发布状态', value: '2' }
          ],
          second: [
            { label: '所有状态', value: '0,3,4,5,6' },
            { label: '待排产', value: '0' },
            { label: '待生产', value: '3' },
            { label: '生产中', value: '4' },
            { label: '已完成', value: '5' },
            { label: '已延期', value: '6' }
          ]
        },
        planType: [
          { label: '所有计划类型', value: '0,1' },
          { label: '内销计划', value: '0' },
          { label: '外销计划', value: '1' }
        ]
      };
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive () {
        return this.$store.state.theme.styleResponsive;
      }
    },
    created () {},
    methods: {
      /* 搜索 */
      search () {
        const where = this.where;

        if (where.time?.length) {
          where.startTime = where.time[0];
          where.endTime = where.time[1];
        }

        this.$emit('search', where);
      },
      /*  重置 */
      reset () {
        this.where = { ...this.defaultWhere };
        this.search();
      }
    }
  };
</script>
<style lang="scss" scoped>
  .ele-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
</style>
