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. </template>
  143. </el-input>
  144. <p style="color:#C0C4CC">根据数量*佣金=门店所获得的奖励</p>
  145. </el-col>
  146. </el-form-item>
  147. </el-form>
  148. <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 600px;margin:10px 0 20px 0;">
  149. <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
  150. <div>规则设置</div>
  151. </div>
  152. <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
  153. <el-form-item label="使用规则:" label-width="100px">
  154. <!-- <com-rich-text style="width: 750px" :simple-attachment="true" v-model="submitData.rules"></com-rich-text>-->
  155. <el-input placeholder="请输入使用规则" style="width: 450px;margin-right: 20px;" type="textarea" v-model="submitData.rules"></el-input>
  156. </el-form-item>
  157. </el-form>
  158. </div>
  159. <el-button class="button-item" :loading="btnLoading" type="primary" @click="saveFun" size="small">保存
  160. </el-button>
  161. </el-card>
  162. </div>
  163. <script>
  164. const app = new Vue({
  165. el: '#app',
  166. data() {
  167. return {
  168. diy_img_prefix: '<?= Yii::getAlias('@attachurl') ?>',
  169. isDataSelect: false,
  170. titleName: "添加电子券",
  171. loading: false,
  172. unlimit_receive_flag: false, // 发现数量是否限制
  173. receive_datetime: [], // 领取时间段
  174. use_datetime: [], // 使用时间段
  175. user_level: [],
  176. submitData: {
  177. name: '',
  178. amount: '',
  179. unlimit_receive_times: 0,
  180. receive_times: '',
  181. pieces_type: 1,
  182. pieces_amount: '',
  183. receive_codition: 1,
  184. receive_member_level: '',
  185. receive_begin_time: 0,
  186. receive_end_time: 0,
  187. use_begin_time: 0,
  188. use_end_time: 0,
  189. price: '',
  190. pic: '',
  191. sort: 0,
  192. use_way: 1,
  193. is_can_receive: 0,
  194. is_show_in_center: 0,
  195. is_give: 0,
  196. is_proper: 0,
  197. give_score: '',
  198. give_price: '',
  199. rules: '',
  200. created_at: 0,
  201. updated_at: 0,
  202. reward_money: 0,
  203. give_store_price: 0
  204. },
  205. rules: {
  206. name: [{
  207. required: true,
  208. message: '请输入电子券名称',
  209. trigger: 'blur'
  210. }],
  211. amount: [{
  212. required: true,
  213. message: '请输入发行数量',
  214. trigger: 'blur'
  215. }],
  216. give_score: [{
  217. required: true,
  218. message: '请输入赠送积分',
  219. trigger: 'blur'
  220. }],
  221. give_price: [{
  222. required: true,
  223. message: '请输入赠送佣金',
  224. trigger: 'blur'
  225. }],
  226. receive_times: [{
  227. required: true,
  228. message: '请输入领取次数',
  229. trigger: 'blur'
  230. }],
  231. price: [{
  232. required: true,
  233. message: '请输入激活金额',
  234. trigger: 'blur'
  235. }],
  236. },
  237. btnLoading: false,
  238. pic_url: [],
  239. pickerOptions: {
  240. shortcuts: [{
  241. text: '最近一周',
  242. onClick(picker) {
  243. const end = new Date();
  244. const start = new Date();
  245. end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
  246. picker.$emit('pick', [start, end]);
  247. }
  248. }, {
  249. text: '最近一个月',
  250. onClick(picker) {
  251. const end = new Date();
  252. const start = new Date();
  253. end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
  254. picker.$emit('pick', [start, end]);
  255. }
  256. }, {
  257. text: '最近三个月',
  258. onClick(picker) {
  259. const end = new Date();
  260. const start = new Date();
  261. end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
  262. picker.$emit('pick', [start, end]);
  263. }
  264. }]
  265. },
  266. };
  267. },
  268. mounted() {
  269. this.submitData.updated_at = Date.parse(new Date()) / 1000; // 新建数据的更新时间
  270. if (getQuery('id')) {
  271. this.titleName = "编辑电子券";
  272. this.loadData(getQuery('id'));
  273. } else {
  274. this.submitData.created_at = Date.parse(new Date()) / 1000; // 新建数据的创建时间
  275. }
  276. this.getUserLevel();
  277. },
  278. watch: {
  279. 'unlimit_receive_flag': {
  280. handler(newVal, oldVal) {
  281. this.submitData.unlimit_receive_times = newVal ? 1 : 0;
  282. if (newVal && this.submitData.receive_times <= 0) {
  283. this.submitData.receive_times = 0;
  284. }
  285. },
  286. }
  287. },
  288. methods: {
  289. saveFun() {
  290. this.$refs['ruleForm'].validate((valid) => {
  291. if (valid) {
  292. if (!this.submitData.name) {
  293. this.$message.error('请输入电子券名称!');
  294. return false;
  295. }
  296. if (!this.submitData.amount) {
  297. this.$message.error('请输入发行数量!');
  298. return false;
  299. }
  300. if (this.submitData.unlimit_receive_times == 0 && this.submitData.receive_times <= 0) {
  301. this.$message.error('请输入领取次数!');
  302. return false;
  303. }
  304. // if (!this.submitData.price) {
  305. // this.$message.error('请输入激活金额!');
  306. // return false;
  307. // }
  308. if (this.submitData.receive_codition == 2 && this.submitData.receive_member_level <= 0) {
  309. this.$message.error('请选择等级!');
  310. return false;
  311. }
  312. if (this.submitData.pieces_type == 1) {
  313. this.submitData.pieces_amount = 1;
  314. }
  315. if (this.submitData.pieces_type == 2 && this.submitData.pieces_amount <= 1) {
  316. this.$message.error('请填写多券的张数,张数不小于 1');
  317. return false;
  318. }
  319. if (this.submitData.receive_begin_time <= 0 || this.submitData.receive_end_time <= 0 || this.submitData.receive_begin_time >= this.submitData.receive_end_time) {
  320. this.$message.error('请选择正确的领取时间!');
  321. return false;
  322. }
  323. if (this.submitData.use_begin_time <= 0 || this.submitData.use_end_time <= 0 || this.submitData.use_begin_time >= this.submitData.use_end_time) {
  324. this.$message.error('请选择正确的使用时间!');
  325. return false;
  326. }
  327. if (!this.submitData.pic) {
  328. this.$message.error('请添加电子券缩略图!');
  329. return false;
  330. }
  331. this.submitData.pieces_amount = this.submitData.pieces_amount ? this.submitData.pieces_amount : 1;
  332. this.submitData.receive_member_level = this.submitData.receive_member_level ? this.submitData.receive_member_level : 0;
  333. this.submitData.give_score = this.submitData.give_score ? this.submitData.give_score : 0;
  334. this.submitData.give_price = this.submitData.give_price ? this.submitData.give_price : 0;
  335. let data = JSON.parse(JSON.stringify(this.submitData));
  336. this.btnLoading = true;
  337. let url = 'electron-coupon/default/edit';
  338. request({
  339. params: {
  340. r: url,
  341. },
  342. method: 'post',
  343. data: data
  344. }).then(e => {
  345. this.btnLoading = false;
  346. if (e.data.code == 0) {
  347. this.$message.success(e.data.msg);
  348. navigateTo({
  349. r: 'electron-coupon/default/index',
  350. });
  351. } else {
  352. this.$message.error(e.data.msg);
  353. }
  354. }).catch(e => {
  355. this.$message.error(e);
  356. this.btnLoading = false;
  357. })
  358. } else {
  359. this.$message.error('请填写必要的参数!');
  360. return false;
  361. }
  362. });
  363. },
  364. picUrl(e) {
  365. if (e.length) {
  366. this.submitData.pic = e[0].url;
  367. }
  368. },
  369. delPic(index) {
  370. /* this.pic_url.splice(index, 1) */
  371. this.submitData.pic = '';
  372. },
  373. receiveDatetimeChange() {
  374. if (this.receive_datetime) {
  375. this.submitData.receive_begin_time = Date.parse(new Date(this.receive_datetime[0]).toString()) / 1000;
  376. this.submitData.receive_end_time = Date.parse(new Date(this.receive_datetime[1]).toString()) / 1000;
  377. }
  378. },
  379. useDatetimeChange() {
  380. if (this.use_datetime) {
  381. this.submitData.use_begin_time = Date.parse(new Date(this.use_datetime[0]).toString()) / 1000;
  382. this.submitData.use_end_time = Date.parse(new Date(this.use_datetime[1]).toString()) / 1000;
  383. }
  384. },
  385. addPrize() {
  386. this.submitData.prize.push(JSON.parse(JSON.stringify(this.prizeObj)));
  387. },
  388. delPrize(index) {
  389. this.submitData.prize.splice(index, 1)
  390. },
  391. formatTime(timeStamp) {
  392. var date = new Date();
  393. date.setTime(timeStamp * 1000);
  394. var y = date.getFullYear();
  395. var m = date.getMonth() + 1;
  396. m = m < 10 ? ('0' + m) : m;
  397. var d = date.getDate();
  398. d = d < 10 ? ('0' + d) : d;
  399. var h = date.getHours();
  400. h = h < 10 ? ('0' + h) : h;
  401. var minute = date.getMinutes();
  402. var second = date.getSeconds();
  403. minute = minute < 10 ? ('0' + minute) : minute;
  404. second = second < 10 ? ('0' + second) : second;
  405. return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  406. },
  407. loadData(id) {
  408. this.loading = true;
  409. request({
  410. params: {
  411. r: 'electron-coupon/default/info',
  412. inc_id: id
  413. },
  414. method: 'get',
  415. }).then(e => {
  416. this.loading = false;
  417. if (e.data.code == 0) {
  418. this.submitData = e.data.data.info;
  419. this.receive_datetime = [this.formatTime(this.submitData.receive_begin_time), this.formatTime(this.submitData.receive_end_time)]; // 领取时间段
  420. this.use_datetime = [this.formatTime(this.submitData.use_begin_time), this.formatTime(this.submitData.use_end_time)]; // 使用时间段
  421. this.unlimit_receive_flag = this.submitData.unlimit_receive_times == 1;
  422. } else {
  423. this.$message.error(e.data.msg);
  424. }
  425. }).catch(e => {
  426. this.loading = false;
  427. });
  428. },
  429. getUserLevel() {
  430. request({
  431. params: {
  432. r: 'electron-coupon/default/user-level',
  433. },
  434. method: 'get',
  435. }).then(e => {
  436. if (e.data.code == 0) {
  437. this.user_level = e.data.data.user_level;
  438. } else {
  439. this.$message.error(e.data.msg);
  440. }
  441. }).catch(e => {
  442. });
  443. }
  444. }
  445. });
  446. </script>
  447. <style>
  448. .form-body {
  449. padding: 20px;
  450. background-color: #fff;
  451. margin-bottom: 20px;
  452. padding-right: 20%;
  453. min-width: 900px;
  454. }
  455. .form-body .el-form-item {
  456. padding-right: 25%;
  457. min-width: 850px;
  458. }
  459. .form-button {
  460. margin: 0;
  461. }
  462. .form-button .el-form-item__content {
  463. margin-left: 0 !important;
  464. }
  465. .button-item {
  466. padding: 9px 25px;
  467. }
  468. .check-group {
  469. font-size: 14px !important;
  470. }
  471. .check-group .el-col {
  472. display: flex;
  473. }
  474. .check-group .el-input {
  475. margin: 0 5px;
  476. }
  477. .check-group .el-col .el-checkbox {
  478. display: flex;
  479. align-items: center;
  480. }
  481. .check-group .el-col .el-input {
  482. width: 100px;
  483. }
  484. .check-group .el-col .el-input .el-input__inner {
  485. height: 30px;
  486. width: 100px;
  487. }
  488. .el-checkbox-group .el-col {
  489. margin-bottom: 10px;
  490. }
  491. .add-image-btn {
  492. width: 100px;
  493. height: 100px;
  494. color: #419EFB;
  495. border: 1px solid #e2e2e2;
  496. cursor: pointer;
  497. }
  498. .remark {
  499. color: #cccccc;
  500. }
  501. </style>