edit.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-select-cat');
  4. ComponentHelper::loadComponentView('com-dialog-select');
  5. ComponentHelper::loadComponentView('com-rich-text');
  6. ?>
  7. <script src="/resources/js/Sortable.min.js"></script>
  8. <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  9. <div id="app" v-cloak>
  10. <el-card class="box-card" shadow="never" style="border:0;min-width: 1200px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  11. <div slot="header">
  12. <el-breadcrumb separator="/">
  13. <el-breadcrumb-item>
  14. <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'electron-coupon/default/index'})">
  15. 电子券
  16. </span>
  17. </el-breadcrumb-item>
  18. <el-breadcrumb-item>{{titleName}}</el-breadcrumb-item>
  19. </el-breadcrumb>
  20. </div>
  21. <div class="form-body" v-loading="loading">
  22. <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 600px;margin:10px 0 20px 0;">
  23. <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
  24. <div>基本信息</div>
  25. </div>
  26. <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
  27. <el-form-item label="电子券名称:" style="margin-bottom: 20px" prop="name" label-width="100px">
  28. <el-input placeholder="请输入电子券名称" style="width: 450px;" v-model="submitData.name" :maxlength="20"></el-input>
  29. </el-form-item>
  30. <el-form-item label="发行数量:" style="margin-bottom: 20px" required label-width="100px" prop="amount">
  31. <el-input placeholder="请输入发行数量" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.amount"></el-input>
  32. </el-form-item>
  33. <el-form-item label="领取次数:" style="margin-bottom: 20px" required label-width="100px" prop="receive_times">
  34. <el-input placeholder="请输入领取次数" style="width: 250px;margin-right: 20px;" type="number" v-model="submitData.receive_times" :disabled="unlimit_receive_flag"></el-input>
  35. <el-checkbox v-model="unlimit_receive_flag">不限制</el-checkbox>
  36. </el-form-item>
  37. <el-form-item label="电子券类型:" style="margin-bottom: 20px" required label-width="100px">
  38. <el-radio v-model="submitData.pieces_type" :label="1">单张券</el-radio>
  39. <el-radio v-model="submitData.pieces_type" :label="2">多券</el-radio>
  40. <el-input placeholder="请输入多券内的张数" style="width: 450px;" v-model="submitData.pieces_amount" v-show="submitData.pieces_type == 2" :maxlength="20"></el-input>
  41. <div class="remark" v-show="submitData.pieces_type == 2">
  42. 单张券一次只能领取单张,多券创建好数量一次可以领取这张套券。
  43. </div>
  44. </el-form-item>
  45. <el-form-item label="领取条件:" style="margin-bottom: 20px" required label-width="100px">
  46. <el-radio v-model="submitData.receive_codition" :label="1">全体会员</el-radio>
  47. <el-radio v-model="submitData.receive_codition" :label="2">指定会员</el-radio>
  48. <el-select v-model="submitData.receive_member_level" placeholder="请选择会员等级" v-show="submitData.receive_codition == 2" style="width: 450px;">
  49. <el-option label="请选择等级" :value="0" :key="-1"></el-option>
  50. <el-option v-for="(item, index) in user_level" :label="item.name" :value="item.level" :key="index"></el-option>
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item label="领取时间:" style="margin-bottom: 20px" label-width="100px" prop="receive_datetime">
  54. <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">
  55. </el-date-picker>
  56. </el-form-item>
  57. <el-form-item label="使用时间:" style="margin-bottom: 20px" label-width="100px" prop="use_datetime">
  58. <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">
  59. </el-date-picker>
  60. </el-form-item>
  61. <el-form-item label="激活金额:" style="margin-bottom: 20px" required label-width="100px" prop="price">
  62. <el-input placeholder="请输入激活金额" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.price"></el-input>
  63. </el-form-item>
  64. <!-- <el-form-item label="核销电子券奖励金额:" style="margin-bottom: 20px" label-width="100px" prop="reward_money">-->
  65. <!-- <el-input placeholder="请输入奖励金额" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.reward_money">-->
  66. <!-- <template slot="append">元</template>-->
  67. <!-- </el-input>-->
  68. <!-- </el-form-item>-->
  69. <el-form-item label="电子券缩略图:" label-width="100px;">
  70. <div style="margin-top: 10px;">
  71. <template v-if="submitData.pic">
  72. <draggable>
  73. <div style="margin-bottom: 20px;position: relative;cursor: move;background-color: #eee;display: flex;align-items: flex-end;width:100px">
  74. <com-image mode="aspectFill" width="100px" height='100px' :src="submitData.pic">
  75. </com-image>
  76. <el-button class="del-btn" size="mini" type="danger" icon="el-icon-close" circle style="position: absolute;top:-10px;right:-10px" @click="delPic()">
  77. </el-button>
  78. </div>
  79. </draggable>
  80. </template>
  81. <div v-if="!submitData.pic"><!-- v-if="ruleForm.pic_url.length < 9" -->
  82. <com-attachment style="margin-bottom: 10px;" :multiple="false" :max="1" @selected="picUrl">
  83. <!-- <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 750"
  84. placement="top"> -->
  85. <div flex="main:center cross:center" class="add-image-btn">
  86. + 添加图片
  87. </div>
  88. <!-- </el-tooltip> -->
  89. </com-attachment>
  90. </div>
  91. </div>
  92. </el-form-item>
  93. <el-form-item label="排序:" style="margin-bottom: 20px" label-width="100px" prop="sort">
  94. <el-input placeholder="数字越大,排序越靠前" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.sort"></el-input>
  95. </el-form-item>
  96. </el-form>
  97. <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 600px;margin:10px 0 20px 0;">
  98. <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
  99. <div>营销设置</div>
  100. </div>
  101. <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
  102. <el-form-item label="适用范围:" style="margin-bottom: 20px" required label-width="100px">
  103. <el-radio v-model="submitData.use_way" :label="1">扫码核销</el-radio>
  104. </el-form-item>
  105. <el-form-item label="可以被领取:" style="margin-bottom: 20px" required label-width="100px">
  106. <el-switch v-model="submitData.is_can_receive" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否">
  107. </el-switch>
  108. </el-form-item>
  109. <el-form-item label="领券中心可见:" style="margin-bottom: 20px" required label-width="120px">
  110. <el-switch v-model="submitData.is_show_in_center" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否">
  111. </el-switch>
  112. </el-form-item>
  113. <el-form-item label="专有券:" style="margin-bottom: 20px" required label-width="100px">
  114. <el-switch v-model="submitData.is_proper" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否">
  115. </el-switch>
  116. </el-form-item>
  117. <el-form-item label="好友赠送电子券:" style="margin-bottom: 20px" required label-width="130px">
  118. <el-switch v-model="submitData.is_give" :active-value="1" :inactive-value="0" active-text="开启" inactive-text="关闭">
  119. </el-switch>
  120. </el-form-item>
  121. <el-form-item v-if="submitData.is_give==1" label="分享有效期:" style="margin-bottom: 20px" label-width="100px" prop="share_expiry">
  122. <el-input placeholder="请输入分享有效期" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.share_expiry">
  123. <template slot="append">小时</template>
  124. </el-input>
  125. </el-form-item>
  126. <el-form-item label="赠送积分:" style="margin-bottom: 20px" required label-width="100px" prop="give_score">
  127. <el-input placeholder="请输入赠送积分数量" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.give_score"></el-input>
  128. <div class="remark">
  129. 如果是专有券,则积分给到电子券专有者,如果是通用券,则给到电子券使用者
  130. </div>
  131. </el-form-item>
  132. <el-form-item label="赠送佣金:" style="margin-bottom: 20px" required label-width="100px" prop="give_price">
  133. <el-input placeholder="请输入赠送佣金数量" style="width: 450px;margin-right: 20px;" type="number" v-model="submitData.give_price"></el-input>
  134. <div class="remark">
  135. 核销佣金只给核销电子券的核销员
  136. </div>
  137. </el-form-item>
  138. <el-form-item label="门店结算比例" required prop="give_store_price" label-width="110px">
  139. <el-col :span="12">
  140. <el-input type="number" v-model="submitData.give_store_price">
  141. <template slot="append">
  142. 元
  143. </template>
  144. </el-input>
  145. <p style="color:#C0C4CC">根据数量*佣金=门店所获得的奖励</p>
  146. </el-col>
  147. </el-form-item>
  148. </el-form>
  149. <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 600px;margin:10px 0 20px 0;">
  150. <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
  151. <div>规则设置</div>
  152. </div>
  153. <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
  154. <el-form-item label="使用规则:" label-width="100px">
  155. <!-- <com-rich-text style="width: 750px" :simple-attachment="true" v-model="submitData.rules"></com-rich-text>-->
  156. <el-input placeholder="请输入使用规则" style="width: 450px;margin-right: 20px;" type="textarea" v-model="submitData.rules"></el-input>
  157. </el-form-item>
  158. </el-form>
  159. </div>
  160. <el-button class="button-item" :loading="btnLoading" type="primary" @click="saveFun" size="small">保存
  161. </el-button>
  162. </el-card>
  163. </div>
  164. <script>
  165. const app = new Vue({
  166. el: '#app',
  167. data() {
  168. return {
  169. diy_img_prefix: '<?= Yii::getAlias('@attachurl') ?>',
  170. isDataSelect: false,
  171. titleName: "添加电子券",
  172. loading: false,
  173. unlimit_receive_flag: false, // 发现数量是否限制
  174. receive_datetime: [], // 领取时间段
  175. use_datetime: [], // 使用时间段
  176. user_level: [],
  177. submitData: {
  178. name: '',
  179. amount: '',
  180. unlimit_receive_times: 0,
  181. receive_times: '',
  182. pieces_type: 1,
  183. pieces_amount: '',
  184. receive_codition: 1,
  185. receive_member_level: '',
  186. receive_begin_time: 0,
  187. receive_end_time: 0,
  188. use_begin_time: 0,
  189. use_end_time: 0,
  190. price: '',
  191. pic: '',
  192. sort: 0,
  193. use_way: 1,
  194. is_can_receive: 0,
  195. is_show_in_center: 0,
  196. is_give: 0,
  197. is_proper: 0,
  198. give_score: '',
  199. give_price: '',
  200. rules: '',
  201. created_at: 0,
  202. updated_at: 0,
  203. reward_money: 0,
  204. give_store_price: 0
  205. },
  206. rules: {
  207. name: [{
  208. required: true,
  209. message: '请输入电子券名称',
  210. trigger: 'blur'
  211. }],
  212. amount: [{
  213. required: true,
  214. message: '请输入发行数量',
  215. trigger: 'blur'
  216. }],
  217. give_score: [{
  218. required: true,
  219. message: '请输入赠送积分',
  220. trigger: 'blur'
  221. }],
  222. give_price: [{
  223. required: true,
  224. message: '请输入赠送佣金',
  225. trigger: 'blur'
  226. }],
  227. receive_times: [{
  228. required: true,
  229. message: '请输入领取次数',
  230. trigger: 'blur'
  231. }],
  232. price: [{
  233. required: true,
  234. message: '请输入激活金额',
  235. trigger: 'blur'
  236. }],
  237. },
  238. btnLoading: false,
  239. pic_url: [],
  240. pickerOptions: {
  241. shortcuts: [{
  242. text: '最近一周',
  243. onClick(picker) {
  244. const end = new Date();
  245. const start = new Date();
  246. end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
  247. picker.$emit('pick', [start, end]);
  248. }
  249. }, {
  250. text: '最近一个月',
  251. onClick(picker) {
  252. const end = new Date();
  253. const start = new Date();
  254. end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
  255. picker.$emit('pick', [start, end]);
  256. }
  257. }, {
  258. text: '最近三个月',
  259. onClick(picker) {
  260. const end = new Date();
  261. const start = new Date();
  262. end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
  263. picker.$emit('pick', [start, end]);
  264. }
  265. }]
  266. },
  267. };
  268. },
  269. mounted() {
  270. this.submitData.updated_at = Date.parse(new Date()) / 1000; // 新建数据的更新时间
  271. if (getQuery('id')) {
  272. this.titleName = "编辑电子券";
  273. this.loadData(getQuery('id'));
  274. } else {
  275. this.submitData.created_at = Date.parse(new Date()) / 1000; // 新建数据的创建时间
  276. }
  277. this.getUserLevel();
  278. },
  279. watch: {
  280. 'unlimit_receive_flag': {
  281. handler(newVal, oldVal) {
  282. this.submitData.unlimit_receive_times = newVal ? 1 : 0;
  283. if (newVal && this.submitData.receive_times <= 0) {
  284. this.submitData.receive_times = 0;
  285. }
  286. },
  287. }
  288. },
  289. methods: {
  290. saveFun() {
  291. this.$refs['ruleForm'].validate((valid) => {
  292. if (valid) {
  293. if (!this.submitData.name) {
  294. this.$message.error('请输入电子券名称!');
  295. return false;
  296. }
  297. if (!this.submitData.amount) {
  298. this.$message.error('请输入发行数量!');
  299. return false;
  300. }
  301. if (this.submitData.unlimit_receive_times == 0 && this.submitData.receive_times <= 0) {
  302. this.$message.error('请输入领取次数!');
  303. return false;
  304. }
  305. // if (!this.submitData.price) {
  306. // this.$message.error('请输入激活金额!');
  307. // return false;
  308. // }
  309. if (this.submitData.receive_codition == 2 && this.submitData.receive_member_level <= 0) {
  310. this.$message.error('请选择等级!');
  311. return false;
  312. }
  313. if (this.submitData.pieces_type == 1) {
  314. this.submitData.pieces_amount = 1;
  315. }
  316. if (this.submitData.pieces_type == 2 && this.submitData.pieces_amount <= 1) {
  317. this.$message.error('请填写多券的张数,张数不小于 1');
  318. return false;
  319. }
  320. if (this.submitData.receive_begin_time <= 0 || this.submitData.receive_end_time <= 0 || this.submitData.receive_begin_time >= this.submitData.receive_end_time) {
  321. this.$message.error('请选择正确的领取时间!');
  322. return false;
  323. }
  324. if (this.submitData.use_begin_time <= 0 || this.submitData.use_end_time <= 0 || this.submitData.use_begin_time >= this.submitData.use_end_time) {
  325. this.$message.error('请选择正确的使用时间!');
  326. return false;
  327. }
  328. if (!this.submitData.pic) {
  329. this.$message.error('请添加电子券缩略图!');
  330. return false;
  331. }
  332. this.submitData.pieces_amount = this.submitData.pieces_amount ? this.submitData.pieces_amount : 1;
  333. this.submitData.receive_member_level = this.submitData.receive_member_level ? this.submitData.receive_member_level : 0;
  334. this.submitData.give_score = this.submitData.give_score ? this.submitData.give_score : 0;
  335. this.submitData.give_price = this.submitData.give_price ? this.submitData.give_price : 0;
  336. let data = JSON.parse(JSON.stringify(this.submitData));
  337. this.btnLoading = true;
  338. let url = 'electron-coupon/default/edit';
  339. request({
  340. params: {
  341. r: url,
  342. },
  343. method: 'post',
  344. data: data
  345. }).then(e => {
  346. this.btnLoading = false;
  347. if (e.data.code == 0) {
  348. this.$message.success(e.data.msg);
  349. navigateTo({
  350. r: 'electron-coupon/default/index',
  351. });
  352. } else {
  353. this.$message.error(e.data.msg);
  354. }
  355. }).catch(e => {
  356. this.$message.error(e);
  357. this.btnLoading = false;
  358. })
  359. } else {
  360. this.$message.error('请填写必要的参数!');
  361. return false;
  362. }
  363. });
  364. },
  365. picUrl(e) {
  366. if (e.length) {
  367. this.submitData.pic = e[0].url;
  368. }
  369. },
  370. delPic(index) {
  371. /* this.pic_url.splice(index, 1) */
  372. this.submitData.pic = '';
  373. },
  374. receiveDatetimeChange() {
  375. if (this.receive_datetime) {
  376. this.submitData.receive_begin_time = Date.parse(new Date(this.receive_datetime[0]).toString()) / 1000;
  377. this.submitData.receive_end_time = Date.parse(new Date(this.receive_datetime[1]).toString()) / 1000;
  378. }
  379. },
  380. useDatetimeChange() {
  381. if (this.use_datetime) {
  382. this.submitData.use_begin_time = Date.parse(new Date(this.use_datetime[0]).toString()) / 1000;
  383. this.submitData.use_end_time = Date.parse(new Date(this.use_datetime[1]).toString()) / 1000;
  384. }
  385. },
  386. addPrize() {
  387. this.submitData.prize.push(JSON.parse(JSON.stringify(this.prizeObj)));
  388. },
  389. delPrize(index) {
  390. this.submitData.prize.splice(index, 1)
  391. },
  392. formatTime(timeStamp) {
  393. var date = new Date();
  394. date.setTime(timeStamp * 1000);
  395. var y = date.getFullYear();
  396. var m = date.getMonth() + 1;
  397. m = m < 10 ? ('0' + m) : m;
  398. var d = date.getDate();
  399. d = d < 10 ? ('0' + d) : d;
  400. var h = date.getHours();
  401. h = h < 10 ? ('0' + h) : h;
  402. var minute = date.getMinutes();
  403. var second = date.getSeconds();
  404. minute = minute < 10 ? ('0' + minute) : minute;
  405. second = second < 10 ? ('0' + second) : second;
  406. return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  407. },
  408. loadData(id) {
  409. this.loading = true;
  410. request({
  411. params: {
  412. r: 'electron-coupon/default/info',
  413. inc_id: id
  414. },
  415. method: 'get',
  416. }).then(e => {
  417. this.loading = false;
  418. if (e.data.code == 0) {
  419. this.submitData = e.data.data.info;
  420. this.receive_datetime = [this.formatTime(this.submitData.receive_begin_time), this.formatTime(this.submitData.receive_end_time)]; // 领取时间段
  421. this.use_datetime = [this.formatTime(this.submitData.use_begin_time), this.formatTime(this.submitData.use_end_time)]; // 使用时间段
  422. this.unlimit_receive_flag = this.submitData.unlimit_receive_times == 1;
  423. } else {
  424. this.$message.error(e.data.msg);
  425. }
  426. }).catch(e => {
  427. this.loading = false;
  428. });
  429. },
  430. getUserLevel() {
  431. request({
  432. params: {
  433. r: 'electron-coupon/default/user-level',
  434. },
  435. method: 'get',
  436. }).then(e => {
  437. if (e.data.code == 0) {
  438. this.user_level = e.data.data.user_level;
  439. } else {
  440. this.$message.error(e.data.msg);
  441. }
  442. }).catch(e => {
  443. });
  444. }
  445. }
  446. });
  447. </script>
  448. <style>
  449. .form-body {
  450. padding: 20px;
  451. background-color: #fff;
  452. margin-bottom: 20px;
  453. padding-right: 20%;
  454. min-width: 900px;
  455. }
  456. .form-body .el-form-item {
  457. padding-right: 25%;
  458. min-width: 850px;
  459. }
  460. .form-button {
  461. margin: 0;
  462. }
  463. .form-button .el-form-item__content {
  464. margin-left: 0 !important;
  465. }
  466. .button-item {
  467. padding: 9px 25px;
  468. }
  469. .check-group {
  470. font-size: 14px !important;
  471. }
  472. .check-group .el-col {
  473. display: flex;
  474. }
  475. .check-group .el-input {
  476. margin: 0 5px;
  477. }
  478. .check-group .el-col .el-checkbox {
  479. display: flex;
  480. align-items: center;
  481. }
  482. .check-group .el-col .el-input {
  483. width: 100px;
  484. }
  485. .check-group .el-col .el-input .el-input__inner {
  486. height: 30px;
  487. width: 100px;
  488. }
  489. .el-checkbox-group .el-col {
  490. margin-bottom: 10px;
  491. }
  492. .add-image-btn {
  493. width: 100px;
  494. height: 100px;
  495. color: #419EFB;
  496. border: 1px solid #e2e2e2;
  497. cursor: pointer;
  498. }
  499. .remark {
  500. color: #cccccc;
  501. }
  502. </style>