| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- <?php
- use common\helpers\ComponentHelper;
- ComponentHelper::loadComponentView('com-select-cat');
- ComponentHelper::loadComponentView('com-dialog-select');
- ComponentHelper::loadComponentView('com-rich-text');
- ?>
- <script src="/resources/js/Sortable.min.js"></script>
- <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
- <div id="app" v-cloak>
- <el-card class="box-card" shadow="never" style="border:0;min-width: 1200px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
- <div slot="header">
- <el-breadcrumb separator="/">
- <el-breadcrumb-item>
- <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'electron-coupon/default/index'})">
- 电子券
- </span>
- </el-breadcrumb-item>
- <el-breadcrumb-item>{{titleName}}</el-breadcrumb-item>
- </el-breadcrumb>
- </div>
- <div class="form-body" v-loading="loading">
- <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 600px;margin:10px 0 20px 0;">
- <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
- <div>基本信息</div>
- </div>
- <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
- <el-form-item label="电子券名称:" style="margin-bottom: 20px" prop="name" label-width="100px">
- <el-input placeholder="请输入电子券名称" style="width: 450px;" v-model="submitData.name" :maxlength="20"></el-input>
- </el-form-item>
- <el-form-item label="发行数量:" style="margin-bottom: 20px" required label-width="100px" prop="amount">
- <el-input placeholder="请输入发行数量" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.amount"></el-input>
- </el-form-item>
- <el-form-item label="领取次数:" style="margin-bottom: 20px" required label-width="100px" prop="receive_times">
- <el-input placeholder="请输入领取次数" style="width: 250px;margin-right: 20px;" type="number" v-model="submitData.receive_times" :disabled="unlimit_receive_flag"></el-input>
- <el-checkbox v-model="unlimit_receive_flag">不限制</el-checkbox>
- </el-form-item>
- <el-form-item label="电子券类型:" style="margin-bottom: 20px" required label-width="100px">
- <el-radio v-model="submitData.pieces_type" :label="1">单张券</el-radio>
- <el-radio v-model="submitData.pieces_type" :label="2">多券</el-radio>
- <el-input placeholder="请输入多券内的张数" style="width: 450px;" v-model="submitData.pieces_amount" v-show="submitData.pieces_type == 2" :maxlength="20"></el-input>
- <div class="remark" v-show="submitData.pieces_type == 2">
- 单张券一次只能领取单张,多券创建好数量一次可以领取这张套券。
- </div>
- </el-form-item>
- <el-form-item label="领取条件:" style="margin-bottom: 20px" required label-width="100px">
- <el-radio v-model="submitData.receive_codition" :label="1">全体会员</el-radio>
- <el-radio v-model="submitData.receive_codition" :label="2">指定会员</el-radio>
- <el-select v-model="submitData.receive_member_level" placeholder="请选择会员等级" v-show="submitData.receive_codition == 2" style="width: 450px;">
- <el-option label="请选择等级" :value="0" :key="-1"></el-option>
- <el-option v-for="(item, index) in user_level" :label="item.name" :value="item.level" :key="index"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="领取时间:" style="margin-bottom: 20px" label-width="100px" prop="receive_datetime">
- <el-date-picker v-model="receive_datetime" @change="receiveDatetimeChange" type="datetimerange" :picker-options="pickerOptions" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" align="center">
- </el-date-picker>
- </el-form-item>
- <el-form-item label="使用时间:" style="margin-bottom: 20px" label-width="100px" prop="use_datetime">
- <el-date-picker v-model="use_datetime" @change="useDatetimeChange" type="datetimerange" :picker-options="pickerOptions" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" align="center">
- </el-date-picker>
- </el-form-item>
- <el-form-item label="激活金额:" style="margin-bottom: 20px" required label-width="100px" prop="price">
- <el-input placeholder="请输入激活金额" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.price"></el-input>
- </el-form-item>
- <!-- <el-form-item label="核销电子券奖励金额:" style="margin-bottom: 20px" label-width="100px" prop="reward_money">-->
- <!-- <el-input placeholder="请输入奖励金额" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.reward_money">-->
- <!-- <template slot="append">元</template>-->
- <!-- </el-input>-->
- <!-- </el-form-item>-->
- <el-form-item label="电子券缩略图:" label-width="100px;">
- <div style="margin-top: 10px;">
- <template v-if="submitData.pic">
- <draggable>
- <div style="margin-bottom: 20px;position: relative;cursor: move;background-color: #eee;display: flex;align-items: flex-end;width:100px">
- <com-image mode="aspectFill" width="100px" height='100px' :src="submitData.pic">
- </com-image>
- <el-button class="del-btn" size="mini" type="danger" icon="el-icon-close" circle style="position: absolute;top:-10px;right:-10px" @click="delPic()">
- </el-button>
- </div>
- </draggable>
- </template>
- <div v-if="!submitData.pic"><!-- v-if="ruleForm.pic_url.length < 9" -->
- <com-attachment style="margin-bottom: 10px;" :multiple="false" :max="1" @selected="picUrl">
- <!-- <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 750"
- placement="top"> -->
- <div flex="main:center cross:center" class="add-image-btn">
- + 添加图片
- </div>
- <!-- </el-tooltip> -->
- </com-attachment>
- </div>
- </div>
- </el-form-item>
- <el-form-item label="排序:" style="margin-bottom: 20px" label-width="100px" prop="sort">
- <el-input placeholder="数字越大,排序越靠前" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.sort"></el-input>
- </el-form-item>
- </el-form>
- <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 600px;margin:10px 0 20px 0;">
- <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
- <div>营销设置</div>
- </div>
- <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
- <el-form-item label="适用范围:" style="margin-bottom: 20px" required label-width="100px">
- <el-radio v-model="submitData.use_way" :label="1">扫码核销</el-radio>
- </el-form-item>
- <el-form-item label="可以被领取:" style="margin-bottom: 20px" required label-width="100px">
- <el-switch v-model="submitData.is_can_receive" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否">
- </el-switch>
- </el-form-item>
- <el-form-item label="领券中心可见:" style="margin-bottom: 20px" required label-width="120px">
- <el-switch v-model="submitData.is_show_in_center" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否">
- </el-switch>
- </el-form-item>
- <el-form-item label="专有券:" style="margin-bottom: 20px" required label-width="100px">
- <el-switch v-model="submitData.is_proper" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否">
- </el-switch>
- </el-form-item>
- <el-form-item label="好友赠送电子券:" style="margin-bottom: 20px" required label-width="130px">
- <el-switch v-model="submitData.is_give" :active-value="1" :inactive-value="0" active-text="开启" inactive-text="关闭">
- </el-switch>
- </el-form-item>
- <el-form-item v-if="submitData.is_give==1" label="分享有效期:" style="margin-bottom: 20px" label-width="100px" prop="share_expiry">
- <el-input placeholder="请输入分享有效期" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.share_expiry">
- <template slot="append">小时</template>
- </el-input>
- </el-form-item>
- <el-form-item label="赠送积分:" style="margin-bottom: 20px" required label-width="100px" prop="give_score">
- <el-input placeholder="请输入赠送积分数量" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.give_score"></el-input>
- <div class="remark">
- 如果是专有券,则积分给到电子券专有者,如果是通用券,则给到电子券使用者
- </div>
- </el-form-item>
- <el-form-item label="赠送佣金:" style="margin-bottom: 20px" required label-width="100px" prop="give_price">
- <el-input placeholder="请输入赠送佣金数量" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.give_price"></el-input>
- <div class="remark">
- 核销佣金只给核销电子券的核销员
- </div>
- </el-form-item>
- <el-form-item label="门店结算比例" required prop="give_store_price" label-width="110px">
- <el-col :span="12">
- <el-input type="number" v-model="submitData.give_store_price">
- <template slot="append">
- 元
- </template>
- </el-input>
- <p style="color:#C0C4CC">根据数量*佣金=门店所获得的奖励</p>
- </el-col>
- </el-form-item>
- </el-form>
- <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 600px;margin:10px 0 20px 0;">
- <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
- <div>规则设置</div>
- </div>
- <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
- <el-form-item label="使用规则:" label-width="100px">
- <!-- <com-rich-text style="width: 750px" :simple-attachment="true" v-model="submitData.rules"></com-rich-text>-->
- <el-input placeholder="请输入使用规则" style="width: 450px;margin-right: 20px;" type="textarea" v-model="submitData.rules"></el-input>
- </el-form-item>
- </el-form>
- </div>
- <el-button class="button-item" :loading="btnLoading" type="primary" @click="saveFun" size="small">保存
- </el-button>
- </el-card>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- return {
- diy_img_prefix: '<?= Yii::getAlias('@attachurl') ?>',
- isDataSelect: false,
- titleName: "添加电子券",
- loading: false,
- unlimit_receive_flag: false, // 发现数量是否限制
- receive_datetime: [], // 领取时间段
- use_datetime: [], // 使用时间段
- user_level: [],
- submitData: {
- name: '',
- amount: '',
- unlimit_receive_times: 0,
- receive_times: '',
- pieces_type: 1,
- pieces_amount: '',
- receive_codition: 1,
- receive_member_level: '',
- receive_begin_time: 0,
- receive_end_time: 0,
- use_begin_time: 0,
- use_end_time: 0,
- price: '',
- pic: '',
- sort: 0,
- use_way: 1,
- is_can_receive: 0,
- is_show_in_center: 0,
- is_give: 0,
- is_proper: 0,
- give_score: '',
- give_price: '',
- rules: '',
- created_at: 0,
- updated_at: 0,
- reward_money: 0,
- give_store_price: 0
- },
- rules: {
- name: [{
- required: true,
- message: '请输入电子券名称',
- trigger: 'blur'
- }],
- amount: [{
- required: true,
- message: '请输入发行数量',
- trigger: 'blur'
- }],
- give_score: [{
- required: true,
- message: '请输入赠送积分',
- trigger: 'blur'
- }],
- give_price: [{
- required: true,
- message: '请输入赠送佣金',
- trigger: 'blur'
- }],
- receive_times: [{
- required: true,
- message: '请输入领取次数',
- trigger: 'blur'
- }],
- price: [{
- required: true,
- message: '请输入激活金额',
- trigger: 'blur'
- }],
- },
- btnLoading: false,
- pic_url: [],
- pickerOptions: {
- shortcuts: [{
- text: '最近一周',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
- picker.$emit('pick', [start, end]);
- }
- }, {
- text: '最近一个月',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
- picker.$emit('pick', [start, end]);
- }
- }, {
- text: '最近三个月',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
- picker.$emit('pick', [start, end]);
- }
- }]
- },
- };
- },
- mounted() {
- this.submitData.updated_at = Date.parse(new Date()) / 1000; // 新建数据的更新时间
- if (getQuery('id')) {
- this.titleName = "编辑电子券";
- this.loadData(getQuery('id'));
- } else {
- this.submitData.created_at = Date.parse(new Date()) / 1000; // 新建数据的创建时间
- }
- this.getUserLevel();
- },
- watch: {
- 'unlimit_receive_flag': {
- handler(newVal, oldVal) {
- this.submitData.unlimit_receive_times = newVal ? 1 : 0;
- if (newVal && this.submitData.receive_times <= 0) {
- this.submitData.receive_times = 0;
- }
- },
- }
- },
- methods: {
- saveFun() {
- this.$refs['ruleForm'].validate((valid) => {
- if (valid) {
- if (!this.submitData.name) {
- this.$message.error('请输入电子券名称!');
- return false;
- }
- if (!this.submitData.amount) {
- this.$message.error('请输入发行数量!');
- return false;
- }
- if (this.submitData.unlimit_receive_times == 0 && this.submitData.receive_times <= 0) {
- this.$message.error('请输入领取次数!');
- return false;
- }
- // if (!this.submitData.price) {
- // this.$message.error('请输入激活金额!');
- // return false;
- // }
- if (this.submitData.receive_codition == 2 && this.submitData.receive_member_level <= 0) {
- this.$message.error('请选择等级!');
- return false;
- }
- if (this.submitData.pieces_type == 1) {
- this.submitData.pieces_amount = 1;
- }
- if (this.submitData.pieces_type == 2 && this.submitData.pieces_amount <= 1) {
- this.$message.error('请填写多券的张数,张数不小于 1');
- return false;
- }
- if (this.submitData.receive_begin_time <= 0 || this.submitData.receive_end_time <= 0 || this.submitData.receive_begin_time >= this.submitData.receive_end_time) {
- this.$message.error('请选择正确的领取时间!');
- return false;
- }
- if (this.submitData.use_begin_time <= 0 || this.submitData.use_end_time <= 0 || this.submitData.use_begin_time >= this.submitData.use_end_time) {
- this.$message.error('请选择正确的使用时间!');
- return false;
- }
- if (!this.submitData.pic) {
- this.$message.error('请添加电子券缩略图!');
- return false;
- }
- this.submitData.pieces_amount = this.submitData.pieces_amount ? this.submitData.pieces_amount : 1;
- this.submitData.receive_member_level = this.submitData.receive_member_level ? this.submitData.receive_member_level : 0;
- this.submitData.give_score = this.submitData.give_score ? this.submitData.give_score : 0;
- this.submitData.give_price = this.submitData.give_price ? this.submitData.give_price : 0;
- let data = JSON.parse(JSON.stringify(this.submitData));
- this.btnLoading = true;
- let url = 'electron-coupon/default/edit';
- request({
- params: {
- r: url,
- },
- method: 'post',
- data: data
- }).then(e => {
- this.btnLoading = false;
- if (e.data.code == 0) {
- this.$message.success(e.data.msg);
- navigateTo({
- r: 'electron-coupon/default/index',
- });
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- this.$message.error(e);
- this.btnLoading = false;
- })
- } else {
- this.$message.error('请填写必要的参数!');
- return false;
- }
- });
- },
- picUrl(e) {
- if (e.length) {
- this.submitData.pic = e[0].url;
- }
- },
- delPic(index) {
- /* this.pic_url.splice(index, 1) */
- this.submitData.pic = '';
- },
- receiveDatetimeChange() {
- if (this.receive_datetime) {
- this.submitData.receive_begin_time = Date.parse(new Date(this.receive_datetime[0]).toString()) / 1000;
- this.submitData.receive_end_time = Date.parse(new Date(this.receive_datetime[1]).toString()) / 1000;
- }
- },
- useDatetimeChange() {
- if (this.use_datetime) {
- this.submitData.use_begin_time = Date.parse(new Date(this.use_datetime[0]).toString()) / 1000;
- this.submitData.use_end_time = Date.parse(new Date(this.use_datetime[1]).toString()) / 1000;
- }
- },
- addPrize() {
- this.submitData.prize.push(JSON.parse(JSON.stringify(this.prizeObj)));
- },
- delPrize(index) {
- this.submitData.prize.splice(index, 1)
- },
- formatTime(timeStamp) {
- var date = new Date();
- date.setTime(timeStamp * 1000);
- var y = date.getFullYear();
- var m = date.getMonth() + 1;
- m = m < 10 ? ('0' + m) : m;
- var d = date.getDate();
- d = d < 10 ? ('0' + d) : d;
- var h = date.getHours();
- h = h < 10 ? ('0' + h) : h;
- var minute = date.getMinutes();
- var second = date.getSeconds();
- minute = minute < 10 ? ('0' + minute) : minute;
- second = second < 10 ? ('0' + second) : second;
- return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
- },
- loadData(id) {
- this.loading = true;
- request({
- params: {
- r: 'electron-coupon/default/info',
- inc_id: id
- },
- method: 'get',
- }).then(e => {
- this.loading = false;
- if (e.data.code == 0) {
- this.submitData = e.data.data.info;
- this.receive_datetime = [this.formatTime(this.submitData.receive_begin_time), this.formatTime(this.submitData.receive_end_time)]; // 领取时间段
- this.use_datetime = [this.formatTime(this.submitData.use_begin_time), this.formatTime(this.submitData.use_end_time)]; // 使用时间段
- this.unlimit_receive_flag = this.submitData.unlimit_receive_times == 1;
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- this.loading = false;
- });
- },
- getUserLevel() {
- request({
- params: {
- r: 'electron-coupon/default/user-level',
- },
- method: 'get',
- }).then(e => {
- if (e.data.code == 0) {
- this.user_level = e.data.data.user_level;
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- });
- }
- }
- });
- </script>
- <style>
- .form-body {
- padding: 20px;
- background-color: #fff;
- margin-bottom: 20px;
- padding-right: 20%;
- min-width: 900px;
- }
- .form-body .el-form-item {
- padding-right: 25%;
- min-width: 850px;
- }
- .form-button {
- margin: 0;
- }
- .form-button .el-form-item__content {
- margin-left: 0 !important;
- }
- .button-item {
- padding: 9px 25px;
- }
- .check-group {
- font-size: 14px !important;
- }
- .check-group .el-col {
- display: flex;
- }
- .check-group .el-input {
- margin: 0 5px;
- }
- .check-group .el-col .el-checkbox {
- display: flex;
- align-items: center;
- }
- .check-group .el-col .el-input {
- width: 100px;
- }
- .check-group .el-col .el-input .el-input__inner {
- height: 30px;
- width: 100px;
- }
- .el-checkbox-group .el-col {
- margin-bottom: 10px;
- }
- .add-image-btn {
- width: 100px;
- height: 100px;
- color: #419EFB;
- border: 1px solid #e2e2e2;
- cursor: pointer;
- }
- .remark {
- color: #cccccc;
- }
- </style>
|