<!-- 搜索表单 -->
<template>
  <el-form
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
      <!--      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">-->
      <!--        <el-form-item label="计划编号:">-->
      <!--          <el-input-->
      <!--            size="mini"-->
      <!--            clearable-->
      <!--            v-model="where.code"-->
      <!--            placeholder="请输入"-->
      <!--          />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">-->
      <!--        <el-form-item label="产品编码:">-->
      <!--          <el-input-->
      <!--            size="mini"-->
      <!--            clearable-->
      <!--            v-model="where.productCode"-->
      <!--            placeholder="请输入"-->
      <!--          />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">-->
      <!--        <el-form-item label="牌号:" label-width="80px">-->
      <!--          <el-input-->
      <!--            size="mini"-->
      <!--            clearable-->
      <!--            v-model="where.brandNo"-->
      <!--            placeholder="请输入"-->
      <!--          />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">-->
      <!--        <el-form-item label="型号:" label-width="80px">-->
      <!--          <el-input-->
      <!--            size="mini"-->
      <!--            clearable-->
      <!--            v-model="where.model"-->
      <!--            placeholder="请输入"-->
      <!--          />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
        <el-form-item label="计划类型:" label-width="80px">
          <el-select
            size="mini"
            clearable
            v-model="where.planType"
            placeholder="请选择"
            class="w100"
          >
            <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: 3, md: 12 } : { span: 3 }">
        <el-form-item label="采购类型:" label-width="80px">
          <el-select
            v-model="where.purchaseType"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option label="未采购" value="1"></el-option>
            <el-option label="已采购" value="2"></el-option>
            <el-option label="全部" value=""></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <!-- <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
        <el-form-item label="计划状态:" label-width="80px">
          <el-select
            size="mini"
            v-model="where.status"
            placeholder="请选择"
            class="w100"
          >
            <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: 6, md: 12 } : { span: 6 }"-->
      <!--        v-if="activeName == 'second'"-->
      <!--      >-->
      <!--        <el-form-item label-width="150px">-->
      <!--          <template slot="label">-->
      <!--            <el-select-->
      <!--              size="mini"-->
      <!--              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-->
      <!--            size="mini"-->
      <!--            class="w100"-->
      <!--            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: 6, md: 12 } : { span: 6 }">
        <el-form-item label="" label-width="150px">
          <template slot="label">
            <el-select
              size="mini"
              v-model="shapeVal"
              @change="
                () => {
                  where.reqMoldTime = [];
                  where.planFormingTime = [];
                  where.formingTime = [];
                }
              "
            >
              <el-option label="要求完成日期" value="reqMoldTime"></el-option>
              <el-option
                label="计划交付日期"
                value="planDeliveryTime"
              ></el-option>
              <!-- <el-option label="实际生产日期" value="formingTime"></el-option> -->
            </el-select>
          </template>
          <el-date-picker
            size="mini"
            class="w100"
            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: 9, md: 12 } : { span: 9 }"-->
      <!--        v-if="activeName == 'second'"-->
      <!--      >-->
      <!--        <el-form-item label="工单发布时间:" label-width="150px">-->
      <!--          <el-date-picker-->
      <!--            class="w100"-->
      <!--            size="mini"-->
      <!--            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: 6, md: 6 } : { span: 6 }">-->
      <!--        <el-form-item label="组织机构:">-->
      <!--          <auth-selection-->
      <!--            size="mini"-->
      <!--            data-type="Array"-->
      <!--            v-model="where.deptIds"-->
      <!--          ></auth-selection>-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->

      <el-col v-bind="styleResponsive ? { lg: 3, md: 6 } : { span: 3 }">
        <el-form-item label-width="80px" label="生产类型:">
          <el-select
            size="mini"
            clearable
            v-model="where.produceType"
            placeholder="请选择"
            class="w100"
          >
            <el-option
              v-for="item in productTypeList"
              :label="item.name"
              :value="item.code"
              :key="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
        <el-form-item>
          <el-input
            size="mini"
            clearable
            v-model="where.searchInfo"
            placeholder="请输入查询信息"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 6 } : { span: 6 }">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="search"
          >
            查询
          </el-button>
          <el-button
            @click="reset"
            icon="el-icon-refresh-left"
            size="mini"
            type="primary"
            >重置</el-button
          >
          <el-dropdown trigger="click">
            <span class="el-dropdown-link">
              展开<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu>
              <div class="searchExpend">
                <el-row>
                  <el-form-item label="计划编号:" label-width="80px">
                    <el-input
                      size="mini"
                      clearable
                      v-model="where.code"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item label="产品编码:" label-width="80px">
                    <el-input
                      size="mini"
                      clearable
                      v-model="where.productCode"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-row>

                <el-row>
                  <el-form-item label="牌号:" label-width="80px">
                    <el-input
                      size="mini"
                      clearable
                      v-model="where.brandNo"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item label="型号:" label-width="80px">
                    <el-input
                      size="mini"
                      clearable
                      v-model="where.model"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item label="批次号:" label-width="80px">
                    <el-input
                      size="mini"
                      clearable
                      v-model="where.batchNo"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-row>
                <!-- <el-row v-if="activeName == 'second'">
                  <el-form-item label-width="150px">
                    <template slot="label">
                      <el-select
                        size="mini"
                        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
                      size="mini"
                      class="w100"
                      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-row> -->
                <el-row v-if="activeName == 'second'">
                  <el-form-item label="工单发布时间:" label-width="150px">
                    <el-date-picker
                      class="w100"
                      size="mini"
                      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-row>
              </div>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
  export default {
    props: ['activeName', 'statusOpt', 'planType'],
    data() {
      // 默认表单数据
      const defaultWhere = {
        code: '',
        productCode: '',
        // status: '',
        model: '',
        brandNo: '',
        planType: '',
        deptIds: [],
        // releaseTime: [],
        // deliveryTime: [],
        formingTime: [],
        // reqMoldTime: [],
        // planFormingTime: [],
        executeUserName: '',
        searchInfo: '',
        purchaseType: '1'
      };
      return {
        // 表单数据
        deliveryVal: 'deliveryTime',
        shapeVal: 'reqMoldTime',
        where: { ...defaultWhere },
        treeData: [],
        productTypeList: [
          { code: 1, name: 'PBOM' },
          { code: 2, name: 'MBOM' },
          { code: 3, name: 'ABOM' }
          // { code: 2, name: '加工(MBOM)' },
          // { code: 3, name: '装配(ABOM)' }
        ]
      };
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    // watch: {
    //   activeName: {
    //     handler() {
    //       if (this.activeName) {
    //         this.where.status = this.statusOpt[this.activeName][0].value;
    //         this.reset();
    //       }
    //     },
    //     immediate: true
    //   }
    // },
    created() {},
    methods: {
      /* 搜索 */
      search() {
        const where = { ...this.where };
        // for (const key in where) {
        //   if (Array.isArray(where[key]) && key !== 'deptIds') {
        //     where[`${key}End`] = where[key][1];
        //     where[key] = where[key][0];
        //   }
        // }

        // where.status = where.status.split(',');
        this.$emit('search', where);
      },
      /*  重置 */
      reset() {
        this.where = { ...this.defaultWhere };
        // this.where.status = this.statusOpt[this.activeName][0].value;
        this.search();
      }
    }
  };
</script>
<style lang="scss" scoped>
  .ele-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-top: 4.5px;
  }

  .searchExpend {
    padding: 20px 50px 0 30px;
  }
</style>
