serviceStore.vue 5.67 KB
<!-- 服务4S店 -->
<template>
  <d2-container class="service-store">
    <el-form
      :inline="true"
      v-model="searchForm"
      label-width="85px"
      slot="header"
    >
      <el-form-item label="商品名称">
        <el-input
          v-model="searchForm.merchantName"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          :id="tableParams.btnId"
          type="primary"
          icon="el-icon-search"
        >查询</el-button>
        <el-button @click="handleReset">重置</el-button>
      </el-form-item>
    </el-form>
    <d2-table-header>
      <auth-button category="Button"></auth-button>
    </d2-table-header>
    <d2-table
      ref="serviceStoreTable"
      :searchForm="searchForm"
      :tableParams="tableParams"
      :getListApi="getListApi"
      :beforeSearchFn="beforeSearchFn"
    >
      <auth-button
        slot="auth-button"
        slot-scope="scope"
        :data="scope.scope"
      ></auth-button>
    </d2-table>
    <relate-store-dialog
      v-if="relateStoreVisible"
      ref="relateStore"
      :relateStoreVisible="relateStoreVisible"
      :storeApi="storeApi"
      :storeSearchForm="storeSearchForm"
      :storeSelected="storeSelected"
      @handleRelateStoreConfirm="handleRelateStoreConfirm"
      @handleRelateStoreClose="handleRelateStoreClose"
    >
      <el-row slot>
        <el-col
          class="service-search"
          :span="6"
        >
          <el-select v-model="storeSearchForm.channelType">
            <el-option
              v-for="item in baseData.channelType"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-col>
        <el-col :span="8">
          <el-input
            v-model="storeSearchForm.merchantIdName"
            placeholder="支持按门店、商户号搜索"
            clearable
          ></el-input>
        </el-col>
        <el-button
          type="primary"
          @click="handleSearchStore"
        >搜索</el-button>
      </el-row>
    </relate-store-dialog>
  </d2-container>
</template>

<script>
import { getList, deleteMerchant, serviceGetMerchantList, addServiceMerchant } from '@api/serviceStore'
import { mapActions } from 'vuex'
import { BaseData, userType, ghUserType } from '@/common/constants.js'
export default {
  name: 'serviceStore',
  data() {
    return {
      searchForm: {
        merchantName: ''
      },
      getListApi: getList,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '登录账户',
          prop: 'accountName'
        }, {
          label: '商户号',
          prop: 'merchantId'
        }, {
          label: '商户名称',
          prop: 'merchantName'
        }, {
          label: '商户简称',
          prop: 'shortName'
        }, {
          label: '商户类型',
          prop: 'userType',
          formatter: (cellValue) => {
            var typeList = cellValue.channelType === 2 ? ghUserType : userType
            return typeList[cellValue.userType]
          }
        }, {
          label: '联系人',
          prop: 'contactName'
        }, {
          label: '手机号',
          prop: 'phone'
        }, {
          label: '商户地址',
          prop: 'address',
          width: '200'
        }, {
          label: '更新时间',
          prop: 'updatedDate'
        }, {
          label: '渠道',
          prop: 'channelType',
          formatter: (cellValue) => {
            return this.baseData.channelType.find(item => item.value === cellValue.channelType).name
          }
        }]
      },
      // 关联门店
      storeSearchForm: {
        channelType: 1,
        merchantIdName: ''
      },
      relateStoreVisible: false,
      storeApi: serviceGetMerchantList,
      storeSelected: [],
      baseData: {
        channelType: []
      }
    }
  },

  components: {
  },

  created() {
    this.getBaseData()
  },

  mounted() { },

  methods: {
    ...mapActions('d2admin/base', ['get']),
    beforeSearchFn() {
      return new Promise(resolve => {
        console.log('搜索前操作--')
        resolve()
      })
    },
    async getBaseData() {
      this.baseData.channelType = await this.get(BaseData.channelType)
    },
    handleReset() {
      this.searchForm = {
        merchantName: ''
      }
    },
    handleAdd() {
      // console.log(form)
      this.relateStoreVisible = true
    },
    relateCloseReset() {
      this.storeSearchForm = {
        channelType: 1,
        merchantIdName: ''
      }
    },
    handleRelateStoreConfirm(selectedData) {
      console.log(selectedData)
      addServiceMerchant({ list: selectedData }).then(res => {
        this.relateStoreVisible = false
        this.$refs.serviceStoreTable.refreshTable()
        this.notice.okTips()
        this.relateCloseReset()
      })
    },
    handleRelateStoreClose() {
      this.relateStoreVisible = false
      this.relateCloseReset()
    },
    handleSearchStore() {
      this.$refs.relateStore.getSelectingList()
    },
    handleDelete(row) {
      // console.log(row)
      this.$confirm('是否要进行删除操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteMerchant({ id: row.id }).then(res => {
          this.notice.okTips()
          this.$refs.serviceStoreTable.refreshTable()
        })
      }).catch(err => {
        console.log(err)
      })
    }
  }
}

</script>
<style>
.service-store .service-search {
  margin-bottom: 10px;
}
</style>