|
@@ -0,0 +1,312 @@
|
|
|
+<template>
|
|
|
+ <div class="app-container goods-add">
|
|
|
+ <el-divider content-position="left">基础信息</el-divider>
|
|
|
+ <el-form ref="addItem" :rules="rules" :model="addData" label-width="120px">
|
|
|
+ <el-row :gutter="10">
|
|
|
+ <el-form-item label="门店:" prop="channelId">
|
|
|
+ <el-select v-model="addData.channelId" placeholder="请选择门店" :disabled="id?true:false" style="width: 240px;" filterable :filter-method="dataFilter">
|
|
|
+ <el-option v-for="(item) in siteList" :key="item.channelId" :label="item.name" :value="item.channelId">
|
|
|
+ <div>
|
|
|
+ <span style="float: left;">{{item.name}} </span>
|
|
|
+ <span style="float: right;">{{item.mobile}}</span>
|
|
|
+ </div>
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-row :gutter="10">
|
|
|
+ <el-col :span="7">
|
|
|
+ <el-form-item label="兑换码数量:" prop="quantity">
|
|
|
+ <el-input v-model="addData.quantity" placeholder="请输入兑换码数量" :disabled="id?true:false" style="width: 240px;" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="6" v-if="id?true:false">
|
|
|
+ <div class="clk" @click="toCodelist()">
|
|
|
+ 查看
|
|
|
+ </div>
|
|
|
+ </el-col>
|
|
|
+
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-form-item label="有效期:" prop="validityPeriod">
|
|
|
+ <el-select v-model="addData.validityPeriod" placeholder="请选择有效期" :disabled="id?true:false" style="width: 240px;">
|
|
|
+ <el-option label="三个月" value="threeMoths"></el-option>
|
|
|
+ <el-option label="六个月" value="sixMonths"></el-option>
|
|
|
+ <el-option label="永久" value="forever"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-row>
|
|
|
+ <el-divider content-position="left">商品设置</el-divider>
|
|
|
+ <el-row :gutter="10">
|
|
|
+ <el-col :span="22">
|
|
|
+ <el-form-item label="" prop="goodsList">
|
|
|
+ <!-- 奖级列表 -->
|
|
|
+ <code-list ref="awards" :id="id?id:''" v-model="goodsList" @handleCommand="handleCommand" @close="close" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <el-row v-if="!id">
|
|
|
+ <el-col :span="24" style="text-align: center">
|
|
|
+ <el-button type="info" @click="$router.replace('/marketing/marketing')">取消</el-button>
|
|
|
+ <el-button type="primary" @click="update()">保存</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <!-- 添加商品 -->
|
|
|
+ <goods-add :dialog-visible="goodsTableVisible" @close="close" @confirmGoods="confirmGoods" v-if="goodsTableVisible" />
|
|
|
+ <!-- 添加券 -->
|
|
|
+ <coupon-add :dialog-visible="couponTableVisible" @close="close" @confirmCoupon="confirmCoupon" v-if="couponTableVisible" />
|
|
|
+ <!-- 添加券包 -->
|
|
|
+ <coupon-pkg-add :dialog-visible="couponPkgTableVisible" @close="close" @confirmCouponPkg="confirmCouponPkg" v-if="couponPkgTableVisible" />
|
|
|
+ <!-- 添加盲豆 -->
|
|
|
+ <coin-add :dialog-visible="coinTableVisible" @close="close" @confirmCoin="confirmCoin" v-if="coinTableVisible" />
|
|
|
+
|
|
|
+ <!-- 查询兑换码 -->
|
|
|
+ <exchange-code-list v-if="exchangeCodeShow" @cancel="exchangeCodeShow = false" :exchangeCodeShow="exchangeCodeShow" :id="id"/>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { publicFileGetUrl } from "@/api/common";
|
|
|
+import { getExchangeCode, goodsExchangeCreate } from '@/api/business/exchangeCode'
|
|
|
+import CodeList from "./components/CodeList"
|
|
|
+import GoodsAdd from "./components/GoodsAdd"
|
|
|
+import CouponAdd from "./components/CouponAdd"
|
|
|
+import CouponPkgAdd from "./components/CouponPkgAdd"
|
|
|
+import CoinAdd from "./components/CoinAdd"
|
|
|
+
|
|
|
+import ExchangeCodeList from "./components/ExchangeCodeList"
|
|
|
+import { listAllSaleSite } from "@/api/admin/salesite";
|
|
|
+export default {
|
|
|
+ name: 'ExchangeAdd',
|
|
|
+ components: {
|
|
|
+ CodeList,
|
|
|
+ GoodsAdd,
|
|
|
+ CouponAdd,
|
|
|
+ CouponPkgAdd,
|
|
|
+ CoinAdd,
|
|
|
+ ExchangeCodeList
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ id: this.$route.query.id,
|
|
|
+ siteList: [],//门店列表
|
|
|
+ siteCopyList: [],//门店列表
|
|
|
+ addData: {
|
|
|
+ channelId: '',//门店
|
|
|
+ siteName: '',//门店名称
|
|
|
+ type: '',//
|
|
|
+ quantity: '',//数量
|
|
|
+ goodsList: [],//兑换码关联商品
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ channelId: [{ required: true, message: '请选择门店', trigger: 'blur' }],
|
|
|
+ validityPeriod: [{ required: true, message: '请选择有效期', trigger: 'blur' }],
|
|
|
+ quantity: [
|
|
|
+ { required: true, message: "请输入兑换码", trigger: ["blur", "change"] },
|
|
|
+ { pattern: /^[1-9]\d*$/, message: "请输入正确的数字", trigger: ["blur", "change"]}]
|
|
|
+ },
|
|
|
+ // 列表
|
|
|
+ goodsList: [],
|
|
|
+ goodsTableVisible: false, // 添加商品弹框
|
|
|
+ couponTableVisible: false, // 添加卡券弹框
|
|
|
+ couponPkgTableVisible: false, // 添加券包弹框
|
|
|
+ coinTableVisible: false, // 添加盲豆弹框
|
|
|
+ pageParams: {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ },
|
|
|
+
|
|
|
+ exchangeCodeShow: false,
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ marketingPicUrl: {
|
|
|
+ get() {
|
|
|
+ return this.addData.picUrl ? this.addData.picUrl.split(',').map(item => {
|
|
|
+ return {
|
|
|
+ fileName: item
|
|
|
+ }
|
|
|
+ }) : []
|
|
|
+ },
|
|
|
+ set(val) {
|
|
|
+ this.$set(this.addData, 'picUrl', val.map(item => {
|
|
|
+ return item.fileName
|
|
|
+ }).toString())
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ if (this.id) {
|
|
|
+ getExchangeCode(this.id).then(res => {
|
|
|
+ const { channelId, quantity, siteName, validityPeriod, goodsList, id } = res.data
|
|
|
+ this.addData = { channelId, quantity, siteName, validityPeriod: JSON.parse(validityPeriod).value, goodsList, id }
|
|
|
+ if (goodsList) {
|
|
|
+ goodsList.forEach((item) => {
|
|
|
+ item.type = item.type && JSON.parse(item.type).value
|
|
|
+ item.picUrl = publicFileGetUrl + item.picUrl.split(',')[0]
|
|
|
+ });
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.awards.add(3, goodsList)
|
|
|
+ })
|
|
|
+ this.goodsList = goodsList
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.getSaleSiteList()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 获取门店下拉列表
|
|
|
+ getSaleSiteList() {
|
|
|
+ listAllSaleSite({}).then(response => {
|
|
|
+ this.siteList = response.data || [];
|
|
|
+ this.siteCopyList = response.data || [];
|
|
|
+ });
|
|
|
+ },
|
|
|
+ dataFilter(val) {
|
|
|
+ if (val) { //val存在
|
|
|
+ this.siteList = this.siteCopyList.filter((item) => {
|
|
|
+ if (!!~item.mobile.indexOf(val) || !!~item.mobile.toUpperCase().indexOf(val.toUpperCase())
|
|
|
+ || !!~item.name.indexOf(val) || !!~item.name.indexOf(val)) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else { //val为空时,还原数组
|
|
|
+ this.siteList = this.siteCopyList;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 保存
|
|
|
+ update() {
|
|
|
+ this.$refs.addItem.validate((valid, items) => {
|
|
|
+ if (valid) {
|
|
|
+ if (this.goodsList.length < 1) {
|
|
|
+ this.msgError('请至少设置一个商品!')
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 判断没有设置奖级数量
|
|
|
+ let prizeIndexThree = this.goodsList.findIndex((item) => {
|
|
|
+ return !item.quantity && item.quantity != 0;
|
|
|
+ });
|
|
|
+ if (prizeIndexThree != -1) {
|
|
|
+ this.$message.error(
|
|
|
+ `请设置"${this.goodsList[prizeIndexThree].title}"的数量!`
|
|
|
+ );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.goodsList = this.goodsList.map((item) => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ refId: item.refId || item.goodsId || item.couponId || item.id,
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const { channelId, quantity, siteName, validityPeriod, } = this.addData
|
|
|
+ goodsExchangeCreate({
|
|
|
+ channelId,
|
|
|
+ quantity,
|
|
|
+ siteName,
|
|
|
+ validityPeriod,
|
|
|
+ goodsList: this.goodsList,
|
|
|
+ id: this.addData.id ? this.addData.id : "",
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ this.$message({
|
|
|
+ message: this.addData.id ? '修改成功!' : '添加成功!',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ this.$store.dispatch('tagsView/delView', this.$route)
|
|
|
+ this.$router.go(-1)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ if (items && Object.keys(items).length > 0) {
|
|
|
+ this.$message({
|
|
|
+ message: items[Object.keys(items)[0]][0].message,
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ toCodelist() {
|
|
|
+ this.exchangeCodeShow = true
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // 添加奖品种类
|
|
|
+ handleCommand(e) {
|
|
|
+ if (e == "goods") {
|
|
|
+ this.goodsTableVisible = true;
|
|
|
+ } else if (e == "coupon") {
|
|
|
+ this.couponTableVisible = true;
|
|
|
+ } else if (e == "coupon_pkg") {
|
|
|
+ this.couponPkgTableVisible = true;
|
|
|
+ } else if (e == "coin") {
|
|
|
+ this.coinTableVisible = true;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 关闭弹框
|
|
|
+ close() {
|
|
|
+ this.goodsTableVisible = false;
|
|
|
+ this.couponTableVisible = false;
|
|
|
+ this.couponPkgTableVisible = false;
|
|
|
+ this.coinTableVisible = false;
|
|
|
+ },
|
|
|
+
|
|
|
+ // 确认选中商品
|
|
|
+ confirmGoods(arr) {
|
|
|
+ this.$refs.awards.add(1, arr)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 确认选中卡券
|
|
|
+ confirmCoupon(arr) {
|
|
|
+ this.$refs.awards.add(1, arr)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 确认选中券包
|
|
|
+ confirmCouponPkg(arr) {
|
|
|
+ this.$refs.awards.add(1, arr)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 确认输入盲豆
|
|
|
+ confirmCoin(obj) {
|
|
|
+ this.$refs.awards.add(2, obj)
|
|
|
+ },
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped lang="scss">
|
|
|
+.goods-add {
|
|
|
+ .tip {
|
|
|
+ font-size: 12px;
|
|
|
+ color: #999;
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-divider {
|
|
|
+ .is-left {
|
|
|
+ color: #409eff;
|
|
|
+ font-size: 20px;
|
|
|
+ font-weight: bolder;
|
|
|
+ left: 10px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+.clk {
|
|
|
+ display: inline-block;
|
|
|
+ line-height: 36px;
|
|
|
+ color: rgb(0, 114, 255);
|
|
|
+ font-size: 16px;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+.clk:hover {
|
|
|
+ color: rgb(64, 146, 255);
|
|
|
+}
|
|
|
+</style>
|