index.vue 7.29 KB
<template>
  <div class="system-container special-shop">
    <div class="container">
      <search-form
        class="searchTop border-shadow"
        :formModel="searchForm"
        :formList="shopFormList"
      >
        <span slot="self">
          <el-form-item>
            <el-select
              v-model="searchForm.area"
              placeholder="请选择大区"
              @change="change('area', searchForm.area)"
              clearable
            >
              <el-option
                v-for="item in areaList"
                :key="item.id"
                :label="item.departmentName"
                :value="item.id"
              >
              </el-option>
            </el-select>
            <el-select
              v-model="searchForm.province"
              placeholder="请选择省"
              @change="change('province', searchForm.province)"
              clearable
            >
              <el-option
                v-for="item in provinceList"
                :key="item.id"
                :label="item.departmentName"
                :value="item.id"
              >
              </el-option>
            </el-select>
            <el-select
              v-model="searchForm.city"
              placeholder="请选择市"
              clearable
            >
              <el-option
                v-for="item in cityList"
                :key="item.id"
                :label="item.departmentName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </span>
        <span slot="form-slot">
          <el-button
            type="primary"
            :size="btn_size"
            icon="el-icon-search"
            :id="shopTableParams.btnId"
          >搜索</el-button>
          <el-button
            type="primary"
            :size="btn_size"
            icon="el-icon-refresh"
            @click="refresh"
          >重置</el-button>
        </span>
      </search-form>
      <h3>
        <el-button
          v-for="item in authList"
          :key="item.id"
          :type="item.type"
          :size="btn_size"
          @click="btnClick(item.pType)"
        >{{item.name}}</el-button>
      </h3>
      <basic-table
        ref="shopTable"
        :tableParams="shopTableParams"
        :getListApi="getListApi"
        :searchForm="searchForm"
        :hasNum="false"
      >
        <span
          slot="status"
          slot-scope="scope"
        >
          <span
            class="dot"
            :class="scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[1] : ''"
          ></span>
          <span class="statusText">{{ scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[0] : '--'}}</span>
        </span>
        <span
          slot="table-button"
          slot-scope="scope"
        >
          <el-button
            v-for="(j, idx) in shopTableParams.tableOption.btnList"
            :key="idx"
            :type="j.type || 'text'"
            :size="btn_size"
            @click="btnClick(j.pType, scope.scope)"
          >{{j.name}}</el-button>
        </span>
      </basic-table>
    </div>
  </div>
</template>

<script>
import { getList, deleteSpecialShop } from 'services/specialshop'
import { getSimpleRoot, getSimpleList } from 'services/common'
import { SPECIALSHOP_API } from '@/config/config'
import store from '@/store'
export default {
  data() {
    return {
      searchForm: {},
      shopFormList: [
        {
          type: 'input',
          inputType: 'text',
          prop: 'term',
          placeholder: '特约店编码|特约店名称',
        }
      ],
      shopTableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        mutiSelectName: 'specialShop',
        listName: 'list',
        tableColumns: [
          {
            label: '特约店编码',
            prop: 'shopCode'
          }, {
            label: '特约店名称',
            prop: 'shopName',
            width: 130
          }, {
            label: '店级别',
            prop: 'shopLevel'
          }, {
            label: '所属大区',
            prop: 'area'
          }, {
            label: '所属省',
            prop: 'province'
          }, {
            label: '所属市',
            prop: 'city'
          }, {
            label: '详细地址',
            prop: 'address',
            width: 220
          }, {
            label: '店围栏名',
            prop: 'fenceName',
            width: 180
          }
        ],
        tableOption: {
          width: 140,
          btnList: [
            {
              name: '删除',
              pType: 'delete'
            },
            {
              name: '编辑',
              pType: 'edit'
            },
            {
              name: '查看',
              pType: 'view'
            }
          ]
        }
      },
      getListApi: getList,
      authList: [
        {
          id: 1,
          name: '新增特约店',
          type: 'primary',
          pType: 'create'
        },
        // {
        //   id: 2,
        //   name: '批量删除',
        //   type: 'default',
        //   pType: 'delete'
        // },
        {
          id: 3,
          name: '导出Excel',
          type: 'default',
          pType: 'export'
        }
      ],
      areaList: [],
      provinceList: [],
      cityList: []
    }
  },
  mounted() {
    getSimpleRoot({}).then(res => {
      console.log(res)
      this.areaList = res.data
    })
  },
  methods: {
    refresh() {
      this.searchForm = {}
      this.$refs.shopTable.refreshTable()
    },
    btnClick(pType, scope) {
      const shopId = scope && scope.shopId;
      switch (pType) {
        case 'create':
          this.$router.push({ name: 'addShop' })
          break
        case 'export':
          this.$Common.exportExcel({
            url: `${store.state.baseURL}${SPECIALSHOP_API.EXPORT_TABLE}`,
            method: 'GET',
            data: this.searchForm
          })
          break
        case 'edit':
          this.$router.push({
            name: 'addShop',
            query: { id: shopId }
          })
          break
        case 'view':
          this.$router.push({
            name: 'addShop',
            query: { id: shopId, readonlyStatus: true }
          })
          break
        case 'delete':
          deleteSpecialShop({ shopId }).then(res => {
            const { code, message } = res;
            if (code == 200) {
              this.$refs.shopTable.refreshTable()
            } else {
              this.$message({
                message,
                type: 'error'
              });
            }
          })
          break
      }
    },
    change(name, val) {
      console.log(name, val)
      if (name == 'province' && this.searchForm.city) this.searchForm.city = ''
      if (name == 'area') {
        if (this.searchForm.province) this.searchForm.province = ''
        if (this.searchForm.city) this.searchForm.city = ''
      }
      getSimpleList({ rootId: val }).then(res => {
        if (name == 'area') this.provinceList = res.data
        else this.cityList = res.data
      })
    }
  },
}
</script>

<style scope>
.special-shop .el-select {
  width: 33%;
}
/* .search-form .el-form-item {
  max-width: none !important;
}
.vehicle .el-form .el-select .el-input {
  width: 150px;
} */
</style>