edit.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. use common\helpers\AddonHelper;
  4. if ($has_coupon) {
  5. ComponentHelper::loadComponentView('coupon-select', AddonHelper::getAddonRootPath('Coupon') . 'backend/views/components');
  6. }
  7. if ($has_e_coupon) {
  8. ComponentHelper::loadComponentView('electron-coupon-select', AddonHelper::getAddonRootPath('ElectronCoupon') . 'backend/views/components');
  9. }
  10. ComponentHelper::loadComponentView('user-select', AddonHelper::getAddonRootPath('IssueCoupons') . 'backend/views/components');
  11. ?>
  12. <div id="app" v-cloak>
  13. <el-card class="never" v-loading="loading" shadow="never" style="border:0;min-width: 1200px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  14. <div slot="header">
  15. <div>
  16. <span>新增规则</span>
  17. </div>
  18. </div>
  19. <el-form :model="formData" :rules="rules" size="small" label-width="150px">
  20. <el-card style="margin-top: 10px" shadow="never">
  21. <div slot="header" class="clearfix">
  22. <div class="card-title">基本设置</div>
  23. </div>
  24. <el-form-item label="发放规则名:" prop="name">
  25. <el-input v-model="formData.name" style="max-width: 200px;"></el-input>
  26. </el-form-item>
  27. <el-form-item label="发放时间:" prop="timing_time">
  28. <!-- <el-date-picker-->
  29. <!-- v-model="formData.timing_time"-->
  30. <!-- type="datetime"-->
  31. <!-- format="yyyy-MM-dd HH:mm"-->
  32. <!-- picker-options="{start: '00:00',step: '00:30',end: '23:59'}"-->
  33. <!-- unlink-panels-->
  34. <!-- range-separator="至"-->
  35. <!-- start-placeholder="开始日期"-->
  36. <!-- end-placeholder="结束日期"-->
  37. <!-- >-->
  38. <!-- </el-date-picker>-->
  39. <el-date-picker
  40. v-model="picker_date"
  41. type="date"
  42. value-format="yyyy-MM-dd"
  43. placeholder="选择日期">
  44. </el-date-picker>
  45. <el-time-select
  46. v-model="picker_time"
  47. :picker-options="{start: '00:00',step: '00:10',end: '23:59'}"
  48. placeholder="选择时间">
  49. </el-time-select>
  50. </el-form-item>
  51. <el-form-item label="发放对象:" prop="name">
  52. <el-radio-group v-model="formData.grant_object" @change="select_grant_object">
  53. <el-radio :label="1">全部会员</el-radio>
  54. <el-radio :label="2">会员等级</el-radio>
  55. <el-radio :label="3">会员标签</el-radio>
  56. <el-radio :label="4">会员ID</el-radio>
  57. </el-radio-group>
  58. </el-form-item>
  59. <el-form-item label="" v-if="formData.grant_object == 1">
  60. <div style="font-size: 12px; color: red">发送给全部会员,需要消耗服务器大量资源,建议慎用,或者发送时间定在晚上1点到6点</div>
  61. </el-form-item>
  62. <el-form-item label="选择会员:" v-if="formData.grant_object == 4">
  63. <el-button type="primary" size="mini" @click="openuser()">选择会员</el-button>
  64. </el-form-item>
  65. <el-form-item label="已选对象:" v-if="grant_object && grant_object.length>0">
  66. <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
  67. <div style="margin: 15px 0;"></div>
  68. <el-checkbox-group v-model="formData.grant_object_content" @change="handleCheckedCitiesChange">
  69. <el-checkbox v-for="(item,index) in grant_object" :label="item.id" :key="item.id">{{item.name}}</el-checkbox>
  70. </el-checkbox-group>
  71. </el-form-item>
  72. </el-card>
  73. <el-card style="margin-top: 10px" class="edit-card" shadow="never">
  74. <div slot="header" class="clearfix">
  75. <div class="card-title">发放类型</div>
  76. </div>
  77. <el-form-item label="红包:" v-if="has_redpack">
  78. <br>
  79. 红包充值:<el-input v-model="formData.redpack" onInput="value=toNumber(value,0)" placeholder="请输入红包金额" style="max-width: 200px;"></el-input>
  80. 备注说明:<el-input type="textarea" :rows="2" placeholder="请输入备注" v-model="formData.redpack_remark" style="max-width: 500px;"></el-input>
  81. <div style="font-size: 12px; color: #999;">充值激活红包</div>
  82. </el-form-item>
  83. <el-form-item label="积分:" >
  84. <br>
  85. 积分充值:<el-input v-model="formData.score" onInput="value=toNumber(value,0)" placeholder="请输入积分金额" style="max-width: 200px;"></el-input>
  86. 备注说明:<el-input type="textarea" :rows="2" placeholder="请输入备注" v-model="formData.score_remark" style="max-width: 500px;"></el-input>
  87. </el-form-item>
  88. <el-form-item label="余额:" >
  89. <br>
  90. 余额充值:<el-input v-model="formData.balance" onInput="value=toNumber(value,2)" placeholder="请输入余额金额" style="max-width: 200px;"></el-input>
  91. 备注说明:<el-input type="textarea" :rows="2" placeholder="请输入备注" v-model="formData.balance_remark" style="max-width: 500px;"></el-input>
  92. </el-form-item>
  93. <el-row :gutter="10" v-if="has_coupon" v-if="has_coupon">
  94. <el-form-item label="选择优惠券:">
  95. <el-button type="primary" size="mini" @click="openCouponPop()">选择优惠券</el-button>
  96. </el-form-item>
  97. <el-form-item label="已选优惠券:" v-if="coupon_list.length > 0">
  98. <el-row :gutter="3">
  99. <el-col :span="3" v-for="(item,index) in coupon_list" :key="index">
  100. <el-card shadow="always" style="position: relative; margin-right: 10px;">
  101. <div>{{item.name}}</div>
  102. <div>优惠方式:{{ item.discount_method }}</div>
  103. <div>赠送数量:<span>{{item.num}}</span></div>
  104. <el-button type="danger" icon="el-icon-delete" circle style="position: absolute; right: 8px;top: 10px;" @click="handle('delete', index)"></el-button>
  105. </el-card>
  106. </el-col>
  107. </el-row>
  108. </el-form-item>
  109. </el-row>
  110. <el-row :gutter="10" v-if="has_e_coupon" v-if="has_e_coupon">
  111. <el-form-item label="选择电子券:" >
  112. <el-button type="primary" size="mini" @click="handle('e_select')">选择电子券</el-button>
  113. </el-form-item>
  114. <el-form-item label="已选电子券:" v-if="e_coupon_list.length>0">
  115. <el-row :gutter="3">
  116. <el-col :span="3" v-for="(item,index) in e_coupon_list" :key="index">
  117. <el-card shadow="always" style="position: relative; margin-right: 10px;">
  118. <div>{{item.name}}</div>
  119. <div>金额:{{ item.price }}元</div>
  120. <div>赠送数量:<span>{{item.num}}</span></div>
  121. <el-button type="danger" icon="el-icon-delete" circle style="position: absolute; right: 8px;top: 10px;" @click="handle('e_delete', index)"></el-button>
  122. </el-card>
  123. </el-col>
  124. </el-row>
  125. </el-form-item>
  126. </el-row>
  127. </el-card>
  128. </el-form>
  129. <coupon-select :coupon-loading="couponLoading" :coupon_arr="coupon_list" @submit="handleCoupon" @close="couponLoading = false"></coupon-select>
  130. <electron-coupon-select :coupon-loading="ECouponLoading" :coupon_arr="e_coupon_list" @submit="handleECoupon" @close="ECouponLoading = false"></electron-coupon-select>
  131. <user-select :user-loading="userLoading" :user_arr="user_list" @submit="handleUser" @close="userLoading = false"></user-select>
  132. </el-card>
  133. <el-button :loading="btnLoading" class="button-item" type="primary" style="margin-top: 24px;"
  134. @click="submitForm" size="small">保存
  135. </el-button>
  136. </div>
  137. <script src="<?= Yii::$app->request->baseUrl ?>/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  138. <script>
  139. const app = new Vue({
  140. el: '#app',
  141. data() {
  142. return {
  143. picker_date:null,
  144. picker_time:null,
  145. form:{},
  146. checkAll: false,
  147. isIndeterminate: true,
  148. coupon_list: [],
  149. e_coupon_list:[],
  150. user_list:[],
  151. dialogVisible: false,
  152. grant_object:[],
  153. loading: false,
  154. couponLoading:false,
  155. ECouponLoading:false,
  156. userLoading:false,
  157. btnLoading: false,
  158. couponPop: false,
  159. has_coupon: <?php echo $has_coupon ? 'true' : 'false'; ?>,
  160. has_e_coupon: <?php echo $has_e_coupon ? 'true' : 'false'; ?>,
  161. has_redpack: <?php echo $has_redpack ? 'true' : 'false'; ?>,
  162. formData: {
  163. grant_object_content:[],
  164. timing_time:'',
  165. name: '',
  166. grant_object:4,
  167. redpack: '',
  168. redpack_remark:'',
  169. score:'',
  170. score_remark:'',
  171. balance:'',
  172. balance_remark:'',
  173. coupon:[],
  174. e_coupon:[]
  175. },
  176. rules: {
  177. name: [{
  178. required: true,
  179. message: '请输入活动名称',
  180. trigger: 'blur'
  181. }],
  182. // timing_time: [{
  183. // required: true,
  184. // message: '请选择时间',
  185. // trigger: 'blur'
  186. // }],
  187. },
  188. }
  189. },
  190. mounted() {
  191. if (getQuery('id') && getQuery('id') != 0) {
  192. this.id = getQuery('id');
  193. this.send('getData');
  194. }
  195. },
  196. methods: {
  197. select_grant_object($data=1){
  198. this.checkAll = false;
  199. this.grant_object = [];
  200. if($data!=1){
  201. this.formData.grant_object_content = [];
  202. }
  203. if(this.formData.grant_object != 1){
  204. var user_ids = [];
  205. if(this.formData.grant_object == 4 && this.formData.grant_object_content && this.formData.grant_object_content.length>0){
  206. user_ids = this.formData.grant_object_content;
  207. }
  208. request({
  209. params: {r: 'issue-coupons/default/get-object', 'type': this.formData.grant_object,'user_ids':user_ids},
  210. }).then(e => {
  211. if (e.data.code == 0) {
  212. if (e.data.data) this.grant_object = e.data.data;
  213. } else {
  214. this.$message.error(e.data.msg);
  215. }
  216. this.loading = false;
  217. }).catch(e => {
  218. this.loading = false;
  219. this.$message.error(e.data.msg);
  220. })
  221. }else if(this.formData.grant_object == 4){
  222. this.userLoading = true;
  223. }
  224. },
  225. handleCheckAllChange(val) {
  226. var checkAll = [];
  227. if(this.grant_object){
  228. for(var i=0;i<this.grant_object.length;i++){
  229. checkAll.push(this.grant_object[i].id);
  230. }
  231. }
  232. this.formData.grant_object_content = val ? checkAll : [];
  233. this.isIndeterminate = false;
  234. },
  235. handleCheckedCitiesChange(value) {
  236. let checkedCount = value.length;
  237. this.checkAll = checkedCount === this.grant_object.length;
  238. this.isIndeterminate = checkedCount > 0 && checkedCount < this.grant_object.length;
  239. },
  240. send(type, param1 = null, param2 = null) {
  241. switch (type) {
  242. case 'getData':
  243. this.loading = true;
  244. request({
  245. params: {r: 'issue-coupons/default/edit', 'id': this.id},
  246. }).then(e => {
  247. if (e.data.code == 0) {
  248. if (e.data.data) {
  249. this.formData = e.data.data.detail;
  250. this.picker_date = e.data.data.picker_date
  251. this.picker_time = e.data.data.picker_time
  252. }
  253. if(e.data.data.coupon_select_list){
  254. this.coupon_list = e.data.data.coupon_select_list;
  255. }
  256. if(e.data.data.e_coupon_select_list){
  257. this.e_coupon_list = e.data.data.e_coupon_select_list;
  258. }
  259. this.select_grant_object(1);
  260. } else {
  261. this.$message.error(e.data.msg);
  262. }
  263. this.loading = false;
  264. }).catch(e => {
  265. this.loading = false;
  266. this.$message.error(e.data.msg);
  267. })
  268. break;
  269. }
  270. },
  271. // 保存
  272. submitForm() {
  273. if (!this.submit_setting()) {
  274. return false;
  275. }
  276. this.btnLoading = true,
  277. request({
  278. params: {r: 'issue-coupons/default/edit'},
  279. data: this.formData,
  280. method: 'post'
  281. }).then(e => {
  282. if (e.data.code == 0) {
  283. this.$message.success(e.data.msg);
  284. navigateTo({r: 'issue-coupons/default/index'})
  285. } else {
  286. this.$message.error(e.data.msg);
  287. }
  288. this.btnLoading = false;
  289. }).catch(e => {
  290. this.btnLoading = false,
  291. this.$message.error(e.data.msg);
  292. })
  293. },
  294. submit_setting(){
  295. this.formData.coupon = [];
  296. this.formData.e_coupon = [];
  297. console.log(this.coupon_list,666);
  298. if(this.coupon_list){
  299. for(var i=0; i<this.coupon_list.length; i++){
  300. var coupon_data = [];
  301. coupon_data.id = this.coupon_list[i].relevant_id;
  302. coupon_data.num = this.coupon_list[i].num;
  303. this.formData.coupon.push(coupon_data);
  304. }
  305. }else{
  306. this.formData.coupon = [];
  307. }
  308. // if(this.grant_object){
  309. // for (var i=0; i<this.grant_object.length; i++){
  310. // this.formData.grant_object_content.push(this.grant_object[i].id);
  311. // }
  312. // }else{
  313. // this.formData.grant_object_content = [];
  314. // }
  315. console.log(this.e_coupon_list,555);
  316. if(this.e_coupon_list){
  317. for(var i=0; i<this.e_coupon_list.length; i++){
  318. var e_coupon_data = [];
  319. e_coupon_data.id = this.e_coupon_list[i].coupon_id;
  320. e_coupon_data.num = this.e_coupon_list[i].num;
  321. this.formData.e_coupon.push(e_coupon_data);
  322. }
  323. }else{
  324. this.formData.e_coupon = [];
  325. }
  326. if(!this.formData.score && !this.formData.redpack && !this.formData.balance && this.formData.coupon.length <=0 && this.formData.e_coupon.length <=0){
  327. this.$message.error("发放内容必须选一样");
  328. return false;
  329. }
  330. if (isEmpty(this.picker_date) || isEmpty(this.picker_time)) {
  331. this.$message.error("请设置发放时间");
  332. return false;
  333. }
  334. this.formData.timing_time = this.picker_date + ' ' + this.picker_time;
  335. return true;
  336. },
  337. //打开会员
  338. openuser(){
  339. this.userLoading = true;
  340. },
  341. // 打开优惠券弹窗
  342. openECouponPop() {
  343. if(!this.has_e_coupon){
  344. this.$message.error("请先安装电子券插件");
  345. return false;
  346. }
  347. this.ECouponLoading = true;
  348. this.ECouponPop = true;
  349. },
  350. handleECoupon(data) {
  351. this.ECcouponLoading = false;
  352. this.e_coupon_list = data
  353. },
  354. // 打开优惠券弹窗
  355. openCouponPop() {
  356. if(!this.has_coupon){
  357. this.$message.error("请先安装优惠卷插件");
  358. return false;
  359. }
  360. this.couponLoading = true;
  361. this.couponPop = true;
  362. },
  363. handleCoupon(data) {
  364. this.couponLoading = false;
  365. this.coupon_list = data
  366. },
  367. handleUser(data) {
  368. this.userLoading = false;
  369. this.user_list = [];
  370. this.user_list = data;
  371. var user_data = [];
  372. this.grant_object = [];
  373. if(this.user_list){
  374. this.formData.grant_object_content = [];
  375. for(var i=0; i<this.user_list.length; i++){
  376. user_data = [];
  377. user_data.id = this.user_list[i].use_id;
  378. user_data.name = this.user_list[i].name;
  379. this.grant_object.push(user_data);
  380. //this.formData.grant_object_content.push(user_data.id);
  381. }
  382. //console.log(this.formData.grant_object_content,555);
  383. this.handleCheckAllChange(true);
  384. this.checkAll = true;
  385. this.isIndeterminate = false;
  386. }
  387. },
  388. handle(type, data = null, data2 = null) {
  389. switch (type) {
  390. case 'select':
  391. this.couponLoading = true;
  392. break;
  393. case 'delete':
  394. this.coupon_list.splice(data, 1);
  395. break;
  396. case 'e_select':
  397. this.ECouponLoading = true;
  398. break;
  399. case 'e_delete':
  400. this.e_coupon_list.splice(data, 1);
  401. break;
  402. }
  403. }
  404. }
  405. })
  406. </script>
  407. <style>
  408. .line {
  409. background: #03C5FF;
  410. width: 5px;
  411. height: 20px;
  412. margin-right: 6px;
  413. }
  414. .form_box {
  415. background-color: #f3f3f3;
  416. padding: 0 0 20px;
  417. }
  418. .button-item {
  419. margin-top: 12px;
  420. padding: 9px 25px;
  421. }
  422. .customize-share-title {
  423. margin-top: 10px;
  424. width: 80px;
  425. height: 80px;
  426. position: relative;
  427. cursor: move;
  428. }
  429. .del-btn {
  430. position: absolute;
  431. right: -8px;
  432. top: -8px;
  433. padding: 4px 4px;
  434. }
  435. .el-input-group__append {
  436. background-color: #fff;
  437. color: #353535;
  438. }
  439. .add-image-btn {
  440. width: 100px;
  441. height: 100px;
  442. color: #419EFB;
  443. border: 1px solid #e2e2e2;
  444. cursor: pointer;
  445. }
  446. </style>