service.vue 10.4 KB
<template>
  <div class="live-room">
    <!-- //提示面板组件 -->
    <tip-panel panelWidth="616px" panelMinHeight="60px" :panelContent="panelContent" v-if="isFirstShow" @closePanel="closePanel"></tip-panel>
    <div class="live-room container">
      <el-form :inline="true" style="width: 100%" :model="searchForm" label-width="70px" label-position="right">
        <el-row>
          <!-- <el-form-item size="small"> -->
          <!-- <el-button :size="size" type="primary" icon="el-icon-plus" @click="handleCreate">创建服务</el-button>display="disabled" -->
          <GLButton type="primary" @click="handleCreate" style="margin-right: 30px" size="small" icon="el-icon-plus" fn="创建服务" mode="el-button">创建服务</GLButton>
          <!-- </el-form-item> -->
          <el-form-item size="small" label="服务名称">
            <el-input :size="size" v-model="searchForm.couponName" placeholder="请输入服务名称" clearable></el-input>
          </el-form-item>

          <el-form-item size="small" class="fr-mr0">
            <el-button :size="size" type="primary" @click="handleSearch">查询</el-button>
            <el-button :size="size" @click="handleReset">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <GLTable v-if="isReload" ref="memberServiceRef" :noDataImg="url" @setTableFinishFun="setTableFinishFun" :searchForm="searchForm" :tableParams="tableParams" :getListApi="getListApi" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
        <span slot="effectiveType" slot-scope="scope">
          <span>{{ toLabelText(scope.scope) }}</span>
        </span>
        <span slot="useType" slot-scope="scope">
          <span>{{ toRestrictLabelText(scope.scope) }}</span>
        </span>
        <span class="table-btns" slot="auth-button" slot-scope="scope" :data="scope.scope">
          <template v-if="scope.scope.status == 2">
            <!-- <el-button type="text" @click="handleLossOption(scope.scope)">失效</el-button>
            <el-button type="text" @click="handleLook(scope.scope)">查看</el-button>
            <el-button type="text" @click="handleDelete(scope.scope)">删除</el-button> -->

            <GLButton type="text" @click="handleLossOption(scope.scope)" fn="失效">失效</GLButton>
            <GLButton type="text" @click="handleLook(scope.scope)" fn="查看服务">查看</GLButton>
            <GLButton type="text" @click="handleDelete(scope.scope)" fn="删除">删除</GLButton>
          </template>
          <template v-else-if="scope.scope.status == 3">
            <!-- <el-button type="text" @click="handleLook(scope.scope)">查看</el-button>
            <el-button type="text" @click="handleDelete(scope.scope)">删除</el-button> -->
            <GLButton type="text" @click="handleLook(scope.scope)" fn="查看服务">查看</GLButton>
            <GLButton type="text" @click="handleDelete(scope.scope)" fn="删除">删除</GLButton>
          </template>
          <template v-else>
            <!-- <el-button type="text" @click="handleTakeOption(scope.scope)">生效</el-button>
            <el-button type="text" @click="handleEdit(scope.scope)">编辑</el-button>
            <el-button type="text" @click="handleDelete(scope.scope)">删除</el-button> -->
            <GLButton type="text" @click="handleTakeOption(scope.scope)" fn="生效">生效</GLButton>
            <GLButton type="text" @click="handleEdit(scope.scope)" fn="编辑服务">编辑</GLButton>
            <GLButton type="text" @click="handleDelete(scope.scope)" fn="删除">删除</GLButton>
          </template>
        </span>
      </GLTable>
    </div>
  </div>
</template>

<script>
import { getServiceListApi, effectiveService, deleteService, getLoginCount } from '@/api/modules/service'
import url from '@/assets/empty.png'
import { serviceStatusList } from '@/common/constant'
import tipPanel from '@/components/tipPanel/index.vue'
export default {
  components: {
    tipPanel
  },
  data() {
    return {
      url: url,
      isReload: true,
      isFirstShow: false,
      panelContent: '会员服务:是由门店根据自店服务项目创建的线上服务券,如“一年十二次洗车券”、“陶瓷镀膜”等,客户购买后可到店出示服务券享受服务,门店扫码进行次数核销。',
      size: 'small',
      getListApi: getServiceListApi,
      searchForm: {
        couponName: '',
        merchantId: 44184606,
        discountType: 7 //6:商品折扣券,7:会员服务
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      // 表格参数
      tableParams: {
        listName: 'list',
        // 行数据的key
        // mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        // mutiSelectName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '服务名称',
            prop: 'couponName',
            width: '180'
          },
          {
            label: '会员价(元)',
            prop: 'vipPrice',
            line: 1
          },
          {
            label: '预估成本/元',
            prop: 'anticipatedCost ',
            formatter: cellValue => {
              return cellValue.anticipatedCost / 100
            }
          },
          {
            label: '有效期',
            prop: 'effectiveType',
            addHtml: 'effectiveType'
          },
          {
            label: '使用限制',
            prop: 'useType',
            addHtml: 'useType'
          },
          {
            label: '剩余库存',
            prop: 'residueAmount',
            line: 1
            // addHtml: 'activeTime'
          },
          {
            label: '状态',
            prop: 'status',
            // width: '80',
            formatter: cellValue => {
              return this.baseDataList.serviceStatusList.find(item => item.confId == cellValue.status).confName
            }
          },
          {
            label: '创建时间',
            prop: 'createdDate',
            width: 95
          }
        ]
      },
      baseDataList: {
        serviceStatusList: serviceStatusList
      },
      merchantId: 44184606
    }
  },
  created() {
    if (window.__POWERED_BY_QIANKUN__) {
      //运行在qiankun容器中
      this.merchantId = this.$globalState.session.merchantId
      this.searchForm.merchantId = this.merchantId
    }
    this.getLoginCountFun()
  },
  mounted() {},
  methods: {
    getLoginCountFun() {
      //loginType:4是查会员服务浏览次数
      getLoginCount({ loginType: 4 }).then(res => {
        //获取是否第一次点击该页面
        this.isFirstShow = res
      })
    },
    closePanel() {
      this.isFirstShow = false
    },
    toLabelText(row) {
      switch (row.effectiveType) {
        case 3:
          return '永久有效'
        case 2:
          return row.effectiveStartTime ? row.effectiveStartTime.split(' ')[0] + '-' + row.effectiveEndTime.split(' ')[0] : ''
        case 1:
          return row.effectiveDays + '天'
      }
    },
    toRestrictLabelText(row) {
      switch (row.useType) {
        case 0:
          return '无限制'
        case 1:
          return '有效期内可使用' + row.useAmount + '次'
        case 2:
          return '每' + row.useLimitDays + '天可以使用' + row.useAmount + '次'
      }
    },

    handleReset() {
      this.isReload = false
      this.searchForm = { couponName: '', merchantId: this.merchantId, discountType: 7 }
      // this.handleSearch()
      this.$nextTick(() => {
        this.isReload = true
      })
    },
    handleSearch() {
      this.$refs.memberServiceRef.refreshTable()
    },
    setTableFinishFun(content) {
      // console.log(content, this.$refs.memberServiceRef.data.length, '获取数据')
      //接收到的数据为空
      // if (!this.$refs.memberServiceRef.data.length) {
      //   this.$refs.memberServiceRef.setTableHeightFun()
      // }
      this.$refs.memberServiceRef.data.length ? (this.$refs.memberServiceRef.tableHeightValues = '') : this.$refs.memberServiceRef.setTableHeightFun()
    },
    //创建服务
    handleCreate() {
      this.$router.push({
        path: '/memberCenter/serviceAddUpdateLook',
        query: {
          $title: encodeURI('创建服务')
        }
      })
    },
    //失效
    handleLossOption(row) {
      this.$messageBox.confirm('是否失效该服务?', '失效', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        // type: 'error',
        callback: action => {
          if (action == 'confirm') {
            effectiveService({ couponId: row.id, status: 3 }).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                this.handleSearch()
              }
            })
          }
        }
      })
    },
    //生效
    handleTakeOption(row) {
      effectiveService({ couponId: row.id, status: 2 }).then(res => {
        this.$message({
          message: res.code == '0' ? '生效成功' : res.message,
          type: res.code == '0' ? 'success' : 'error'
        })
        if (res.code == '0') {
          this.handleSearch()
        }
      })
    },
    handleEdit(row) {
      this.$router.push({
        path: '/memberCenter/serviceAddUpdateLook',
        query: {
          couponId: row.id,
          title: '编辑',
          $title: encodeURI('编辑服务')
        }
      })
    },
    handleLook(row) {
      this.$router.push({
        path: '/memberCenter/serviceAddUpdateLook',
        query: {
          couponId: row.id,
          title: '查看',
          $title: encodeURI('查看服务')
        }
      })
    },
    handleDelete(row) {
      this.$messageBox.confirm('是否删除该服务?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        // type: 'error',
        callback: action => {
          if (action == 'confirm') {
            deleteService({ couponId: row.id, merchantId: this.merchantId }).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                this.handleSearch()
              }
            })
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/.el-input--small .el-input__inner {
  width: 215px;
}
</style>