<template>
  <div id="search-1">
    <el-row>
      <el-col :span="24" class="main">
        <el-form :model="form" ref="form" label-width="130px">
          <el-col :span="24">
            <el-col :span="6">
              <el-form-item label="商品名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入商品名称" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="规格名称" prop="spec_name">
                <el-input v-model="form.spec_name" placeholder="请输入规格名称" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="店铺名称" prop="type">
                <el-select
                  v-model="form.shop"
                  filterable
                  remote
                  reserve-keyword
                  placeholder="请输入商铺名称"
                  :remote-method="querySearch"
                  :loading="loading"
                  @change="handleSelect"
                >
                  <el-option v-for="item in shopList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="商品分类" prop="tags">
                <el-cascader
                  v-model="form.tags"
                  :options="tagsList"
                  :props="propss"
                  clearable
                  filterable
                  :show-all-levels="false"
                  @change="changeTags"
                ></el-cascader>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="6">
              <el-form-item label="供应商" prop="source">
                <el-input v-model="form.source" placeholder="请输入供应商" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24" class="btn">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="onSubmit('form')">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="toReset('form')">重置</el-button>
          </el-col>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'search-1',
  props: { form: { type: Object }, shopList: { type: Array }, tagsList: { type: Array } },
  components: {},
  data: function () {
    return {
      loading: false,
      propss: { multiple: false, label: 'label', value: 'code' },
    };
  },
  created() {},
  methods: {
    querySearch(value) {
      this.loading = true;
      this.$emit('querySearch', value);
      this.loading = false;
    },
    changeTags(value) {
      this.$emit('changeTags', value);
    },
    handleSelect(value) {
      this.$set(this.form, `shop`, value);
    },
    onSubmit() {
      this.$emit('onSubmit');
    },
    toReset(formName) {
      this.$refs[formName].resetFields();
      this.$emit('toReset');
    },
  },
  computed: {},
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .btn {
    text-align: right;
  }
  /deep/.el-form-item {
    float: left;
    width: 100%;
    margin: 0 0 10px 0;
  }
}
</style>
