setmeal.vue 15.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
<template>
  <div class="marketing">
    <div class="btnWrap">
      <GLButton type="primary" @click="handleCreate" size="small" icon="el-icon-plus" fn="创建套餐" mode="el-button">创建套餐</GLButton>
      <!-- <el-button :size="size" @click="showViewer = true">查看示例效果</el-button> -->
      <el-image-viewer v-if="showViewer" :on-close="
          () => {
            showViewer = false
          }
        " :url-list="srcList" style="padding:4%;" />
    </div>
    <tip-panel class="list-panel" panelMinHeight="40px" :panelContent="panelContent" v-if="isFirstShow" @closePanel="closePanel"></tip-panel>
    <template v-if="accountLevel == 4 && merchantModel == 1">
      <div class="setmeal-tabs flex-default m-t-10">
        <template v-for="(tab, index) in tabList">
          <div :class="['tab', tab.checked ? 'active' : '']" @click="changeTab(index)" :key="index">{{ tab.text }}</div>
        </template>
      </div>
    </template>

    <div class="live-room container">
      <GLTable ref="memberSetMealRef" :noDataImg="url" @setTableFinishFun="setTableFinishFun" :searchForm="searchForm" :tableParams="tableParams" :getListApi="getListApi" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
        <span slot="list" slot-scope="scope">
          <div class="content-meal">
            <div class="text-14 color-3 line-20 weight-5 m-b-10">套餐内容</div>

            <ticket :choseItemList="scope.scope.list"></ticket>
          </div>
        </span>

        <span class="table-btns" slot="optionsFun" slot-scope="scope" :data="scope.scope">
          <template v-if="!(accountLevel == 4 && activetab == 1)">
            <!-- <template v-if="scope.scope.state === 0">
              <GLButton type="text" @click="handleEdit(scope.scope)" fn="编辑套餐">编辑</GLButton>
              <GLButton type="text" @click="handleUpOption(scope.scope)" fn="上架">上架</GLButton>
              <GLButton type="text" @click="handleDelete(scope.scope)" fn="删除">删除</GLButton>
            </template>
            <template v-else-if="scope.scope.state === 1">
              <GLButton type="text" @click="handleDownOption(scope.scope)" fn="下架">下架</GLButton>
              <GLButton type="text" @click="handleEdit(scope.scope)" fn="编辑套餐">编辑</GLButton>
            </template>
            <template v-else>
              <GLButton type="text" @click="handleEdit(scope.scope)" fn="编辑套餐">编辑</GLButton>
              <GLButton type="text" @click="handleUpOption(scope.scope)" fn="上架">上架</GLButton>
              <GLButton type="text" @click="handleDelete(scope.scope)" fn="删除">删除</GLButton>
            </template>
            <GLButton type="text" @click="handleUpdateToTop(scope.scope)" v-if="scope.scope.topFlag == 2 && accountLevel != 4" fn="置顶推荐">置顶推荐</GLButton>
            <el-button type="text" v-if="scope.scope.topFlag == 1 && accountLevel != 4">已置顶推荐</el-button> -->
            <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
          </template>
        </span>
      </GLTable>
    </div>
    <!-- btnCancelLabel="关闭" -->
    <glsx-dialog title="示例效果" width="1142px" :hasScroll="false" :noBtnOk="true" :noCancel="true" :noClose="false" typeName="primary" btnSize="small" :isVisible="isDialogVisible" :showClose="false" @closeDialog="handleClose" @confirmDialog="handleClose">
      <div class="content-body">
        <div class="content-item col1">
          <div class="subTitle">1、管理后台先创建套餐</div>
          <div class="imageWrap">
            <img src="@/assets/table.png" alt="" />
          </div>
        </div>
        <div class="content-item col2">
          <div class="subTitle">2、小程序端进行展示</div>
          <div class="twoImageWrap">
            <img src="@/assets/card1.png" alt="" />
            <img src="@/assets/card2.png" alt="" />
          </div>
        </div>
      </div>
    </glsx-dialog>
  </div>
</template>

<script>
import glsxDialog from '@/components/glsx-dialog'
import url from '@/assets/empty.png'
import { getghSetMealListApi, getSetMealstoreListApi, deleteSetMeal, upDownPackage, updateToTop } from '@/api/modules/setmeal'
import { getLoginCount } from '@/api/modules/service'

import { stateList } from '@/common/constant'
import tipPanel from '@/components/tipPanel/index.vue'
import ticket from './components/ticket.vue'
export default {
  components: {
    tipPanel,
    glsxDialog,
    ticket,
    'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer')
  },
  data() {
    return {
      showViewer: false,
      url: url,
      surl: 'https://img01.glsx.com.cn/weapp/resource/saas/scrm/memberCase.png',
      srcList: ['https://img01.glsx.com.cn/weapp/resource/saas/scrm/memberCase.png'],
      isFirstShow: false,
      panelContent: '会员套餐将会展示在小程序端【会员开通】页,客户开通会员时可选择性通过购买套餐方式开通会员或直接付费开通会员。',
      size: 'small',
      searchForm: {
        merchantId: 44184606
        // merchantName
      },
      tabList: [
        {
          text: '本店套餐',
          checked: true
        },
        {
          text: '集团套餐',
          checked: false
        }
      ],
      activetab: 0,
      // 表格按钮
      tableButtonList: [
        {
          type: 'GLButton',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '编辑套餐'
          },
          listeners: {
            click: this.handleEdit
          }
        },
        {
          type: 'GLButton',
          name: '上架',
          attrs: {
            type: 'text',
            fn: '上架'
          },
          condition: row => {
            return row.state != 1
          },
          listeners: {
            click: this.handleUpOption
          }
        },
        {
          type: 'GLButton',
          name: '下架',
          attrs: {
            type: 'text',
            fn: '下架'
          },
          condition: row => {
            return row.state == 1
          },
          listeners: {
            click: this.handleDownOption
          }
        },
        {
          type: 'GLButton',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除'
          },
          condition: row => {
            return row.state != 1
          },
          listeners: {
            click: this.handleDelete
          }
        },
        {
          type: 'GLButton',
          name: '置顶推荐',
          attrs: {
            type: 'text',
            fn: '置顶推荐'
          },
          condition: row => {
            return row.topFlag == 2 && this.accountLevel != 4
          },
          listeners: {
            click: this.handleUpdateToTop
          }
        },
        {
          type: 'el-button',
          name: '已置顶推荐',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.topFlag == 1 && this.accountLevel != 4
          }
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      // 表格参数
      tableParams: {
        listName: 'list',
        // tableOption: true,
        tableColumns: [
          {
            label: '',
            prop: '',
            columnattrs: {
              type: 'expand'
            },
            addHtml: 'list'
          },
          {
            label: '套餐名称',
            prop: 'packageName',
            width: 220
          },
          {
            label: '套餐售价/元',
            prop: 'packagePrice',
            width: 180
          },
          {
            label: '说明',
            prop: 'notes',
            width: 300,
            line: 4
          },
          {
            label: '售出数量',
            prop: 'buyNumber'
          },
          {
            label: '状态',
            prop: 'state',
            formatter: cellValue => {
              return this.baseDataList.stateList.find(item => item.confId == cellValue.state).confName
            }
          },
          {
            label: '操作',
            prop: 'optionsFun',
            addHtml: 'optionsFun',
            width: 220
          }
        ]
      },
      baseDataList: {
        stateList: stateList
      },
      //查看示例  --弹窗
      isDialogVisible: false,
      merchantModel: 1, //集团:1,门店:2
      accountLevel: 0 //1,2,3,4工厂,省代,市代,门店
    }
  },
  computed: {
    getListApi() {
      const { activetab } = this
      let listApi = ''
      if (activetab == 1) {
        listApi = getghSetMealListApi
      } else {
        listApi = getSetMealstoreListApi
      }
      return listApi
    }
  },
  created() {
    if (window.__POWERED_BY_QIANKUN__) {
      //运行在qiankun容器中
      this.merchantId = this.$globalState.session.merchantId
      this.merchantModel = this.$globalState.session.merchantModel
      this.accountLevel = this.$globalState.session.accountLevel
      if (this.accountLevel != 4) {
        this.activetab = 1
      }
    }
    this.searchForm = {
      merchantId: this.merchantId
      // merchantName
    }
    this.dynamicFile()
    this.getLoginCountFun()
  },
  mounted() { },
  methods: {
    dynamicFile() {
      let { activetab, accountLevel } = this
      const saleParam = {
        label: '售出数量',
        prop: 'buyNumber'
      }
      const referencePrice = {
        label: '套餐总价',
        prop: 'referencePrice'
      }

      if ((activetab == 1 && accountLevel == 4) || accountLevel != 4) {
        this.tableParams.tableColumns.splice(4, 1, saleParam)
      } else if (activetab == 0 && accountLevel == 4) {
        this.tableParams.tableColumns.splice(4, 1, referencePrice)
      }
    },
    changeTab(index) {
      this.activetab = index
      this.tabList.forEach(item => (item.checked = false))
      this.tabList[index].checked = true
      this.handleSearch()
      this.dynamicFile()
    },
    previewPic() {
      this.$refs.previewImg.showViewer = true
    },
    getLoginCountFun() {
      //loginType:5是查会员套餐浏览次数
      getLoginCount({ loginType: 5 }).then(res => {
        //获取是否第一次点击该页面
        this.isFirstShow = res
      })
    },
    closePanel() {
      this.isFirstShow = false
    },
    handleReset() {
      this.searchForm = {
        merchantId: 44184606
      }
      this.handleSearch()
    },
    handleSearch() {
      this.$refs.memberSetMealRef.refreshTable()
    },
    setTableFinishFun() {
      //接收到的数据为空
      if (!this.$refs.memberSetMealRef.data.length) {
        this.$refs.memberSetMealRef.setTableHeightFun()
      }
    },
    //创建套餐
    handleCreate() {
      this.$router.push({
        path: '/memberCenter/setmealAddUpdate',
        query: {
          $title: encodeURI('创建套餐')
        }
      })
    },
    handleClose() {
      this.isDialogVisible = !this.isDialogVisible
    },
    //上架
    handleUpOption(row) {
      var params = {}
      params.id = row.id
      params.state = 1
      upDownPackage(params).then(res => {
        this.$message({
          message: res.code == '0' ? '上架成功' : res.message,
          type: res.code == '0' ? 'success' : 'error'
        })
        if (res.code == '0') {
          this.handleSearch()
        }
      })
    },
    handleDownOption(row) {
      var params = {}
      params.id = row.id
      params.state = 2
      this.$messageBox.confirm('下架后将隐藏且客户不能购买该套餐,已经购买的客户仍继续享有该套餐的服务?', '下架', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        // type: 'error',
        callback: action => {
          if (action == 'confirm') {
            upDownPackage(params).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/setmealAddUpdate', query: { id: row.id, $title: encodeURI('编辑套餐') } })
    },
    //置顶推荐
    handleUpdateToTop(row) {
      updateToTop({ id: row.id }).then(res => {
        console.log(res)
        this.$message({
          message: res.code == '0' ? '操作成功' : res.message,
          type: res.code == '0' ? 'success' : 'error'
        })
        if (res.code == '0') {
          this.handleSearch()
        }
      })
    },
    //   查看示例效果
    handleLook(row) { },
    handleDelete(row) {
      this.$messageBox.confirm('是否删除该套餐?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            deleteSetMeal({ id: row.id }).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>
.btnWrap {
  margin-bottom: 20px;
}

/deep/ .el-dialog__header {
  .main-title {
    font-size: 16px;

    font-weight: 700;
    color: #000000;
  }
}
/deep/ .el-dialog__body {
  border-top: 1px solid #e6e6e6;
  border-bottom: 1px solid #e6e6e6;
  padding: 20px 25px;
  .content-body {
    display: flex;

    .col2 {
      margin-left: 40px;
    }
    .content-item {
      .subTitle {
        margin-bottom: 20px;
        font-size: 18px;

        font-weight: 700;
        color: #000000;
      }
      .imageWrap,
      .twoImageWrap {
        margin-left: 25px;
        img {
          border: 1.5px solid rgba(0, 0, 0, 0.03);
          box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.03);
        }
        img + img {
          margin-left: 22px;
        }
      }
    }
  }
}
/deep/ .el-dialog__footer {
  text-align: center;
  padding: 20px;
}
/* 大图预览的关闭图标 改为大一点的白色 */
/deep/.el-image-viewer__btn.el-image-viewer__close {
  color: #5850ff;
  opacity: unset;
  top: 50px;
  right: 50px;
  width: 40px;
  height: 40px;
  font-size: 40px;
}
/deep/ .el-table__expanded-cell {
  padding: 0;
}
.list-panel {
  /deep/ .initPanel {
    margin: 0px;
  }
}
.setmeal-tabs {
  cursor: pointer;
  position: relative;
  width: 200px;
  left: calc(100% - 196px);
  .tab {
    background: #fafafa;
    border-radius: 4px 4px 0px 0px;
    border: 1px solid #eeedff;
    padding: 13px 20px;
    color: #37383a;
    line-height: 14px;
    font-size: 14px;
    width: auto;
  }
  .active {
    color: #5850ff;
  }
}
.content-meal {
  padding: 17px 0 9px 16px;
  &-logo {
    width: 59px;
    height: 22px;
    margin-right: 20px;
    img {
      width: 100%;
    }
  }
  &-list {
    width: calc(100% - 86px);
    flex-wrap: wrap;
    .every {
      margin-right: 80px;
      display: flex;
      align-items: center;
    }
    .every::before {
      content: '';
      width: 6px;
      height: 6px;
      background: #5850ff;
      border-radius: 50%;
      margin-right: 7px;
      display: inline-block;
    }
  }
}
</style>