index.vue 5.73 KB
<template>
  <div class="layout">
    <div class="header">
      <d2-search
        ref="showSearch"
        :search-form="searchForm"
        :form-data="showFormData"
        label-width="100px"
        :selectPopperAppendToBody="false"
        class="d2-search"
      >
        <template slot="dateGroup">
          <search-box
            ref="timeRef"
            class="search-box"
            :hasConfig="false"
            @search="setTimeData"
          />
        </template>
      </d2-search>
      <div class="up-btns">
        <el-button
          size="small"
          type="primary"
          @click="search"
        >
          查询
        </el-button>
        <el-button
          size="small"
          @click="handleReset"
        >
          重置
        </el-button>
      </div>
    </div>

    <template v-if="loading">
      <div class="content">
        <data-group
          @openWindow="$emit('openWindow',$event)"
          :search-form="searchForm"
          ref="dataGroupRef"
        />
      </div>
    </template>
  </div>
</template>

<script type='text/ecmascript-6'>
import SearchBox from '../SearchBox'
import dataGroup from './dataGroup.vue'
import { listShop4sByRef, getCarBrandList } from "@api/merchant"
export default {
  name: '',
  components: {
    SearchBox,
    dataGroup
  },
  data () {
    return {
      loading: false,
      searchForm: {
        businessType: 4,
        businessScenarioList: [],
        brandIdList: [],
        secondBrandIdList: [],
        merchantRange: 1,
        merchantId: '',

      },
      showFormData: [
        {
          label: '归属业务',
          name: 'businessType',
          type: 'select',
          optionList: [
            { value: 2, name: '轻改' },
            { value: 3, name: '权益' },
            { value: 4, name: '延保' },
          ],
          optionId: 'value',
          optionLabel: 'name',
        },
        {
          label: '业务性质',
          name: 'businessScenarioList',
          type: 'select',
          multiple: true,
          isClear: true,
          collapseTags: true,
          optionList: [
            { confId: 1, confName: "直营渠道" },
            { confId: 2, confName: "直营4S店" },
            { confId: 4, confName: "投资收购-利丰" },
            { confId: 5, confName: "投资收购-内蒙古" },
            { confId: 6, confName: "服务商投资" }
          ],
          optionId: 'confId',
          optionLabel: 'confName',
        },
        {
          addHtml: 'dateGroup'
        },
        {
          label: '主营品牌',
          name: 'secondBrandIdList',
          type: 'select',
          multiple: true,
          isClear: true,
          collapseTags: true,
          optionList: [],
          optionId: 'id',
          optionLabel: 'label',
        },
        {
          label: '门店范围',
          name: 'merchantRange',
          type: 'select',
          optionList: [
            { value: 1, name: '展业门店' },
            { value: 2, name: '所有门店' },
          ],
          optionId: 'value',
          optionLabel: 'name',
        },
        {
          label: '门店名称',
          name: 'merchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantId',
          optionLabel: 'merchantName',
        },
      ],
      brandList: []
    }
  },
  mounted () {
    this.getServiceStore()
    this.getCarBrandList()
  },
  methods: {
    getServiceStore (merchantId) {
      listShop4sByRef({
        yqMerchantId: merchantId
      }).then((res) => {
        this.showFormData.map(item => {
          if (item.name == 'merchantId') {
            res.unshift({
              merchantName: '全部',
              merchantId: ''
            })
            item.optionList = res || []
          }
        })
      })
    },
    async getCarBrandList () {
      const res = await getCarBrandList({ containsChildren: true }),
        brandList = []
      res.map(e => {
        if (e && e.children && e.children.length) {
          e.children.map(i => {
            i.brandId = e.id
            brandList.push(i)
          })
        }
      })
      this.showFormData.map(item => {
        if (item.name == 'secondBrandIdList') {
          item.optionList = brandList || []
        }
      })
      this.brandList = brandList || []
    },
    handleReset () {
      this.searchForm = this.$options.data.call(this).searchForm
      this.$refs.timeRef.handleReset()
      this.$nextTick(() => this.search())
    },
    setTimeData (e) {
      delete e.allYear
      this.searchForm = {
        ...this.searchForm,
        ...e
      }
      this.loading = true
    },
    search () {
      const { secondBrandIdList } = this.searchForm,
        { brandList } = this
      if (secondBrandIdList.length) {
        console.log(secondBrandIdList)
        let brandIdList = []
        brandList.map(e => {
          if (secondBrandIdList.includes(e.id)) brandIdList.push(e.brandId)
        })
        brandIdList = Array.from(
          new Set([...brandIdList.map((e) => e)])
        )
        console.log(brandIdList)
        this.searchForm.brandIdList = brandIdList
      }
      this.$refs.dataGroupRef.search()
    }
  }
}
</script>

<style scoped lang='scss'>
.layout {
  height: 100%;
  padding: 0 20px;
  overflow-y: auto;
  .header {
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 9;
  }
  .up-btns {
    padding-bottom: 22px;
  }
  .d2-search{
    ::v-deep.el-select-dropdown,.el-popper{
      width: 300px !important;
    }
  }
  .search-box {
    padding: 0;
    ::v-deep.el-form {
      display: flex;
      .radio-group {
        width: fit-content;
        flex-shrink: 0;
        margin-right: 8px;
      }
      .date-picker {
        width: 217px;
      }
    }
  }
}
</style>