index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-rich-text');
  4. ?>
  5. <style>
  6. .el-card__header {
  7. padding: 8px 20px;
  8. }
  9. .el-card__body {
  10. padding: 15px;
  11. }
  12. </style>
  13. <div id="app" v-cloak>
  14. <el-card class="box-card" shadow="never">
  15. <el-tabs v-model="activeName" @tab-click="handle('switch')">
  16. <el-tab-pane label="奖励配置" name="reward">
  17. <el-form v-if="reward" ref="form" :model="form" label-width="120px" size="small" v-loading="loading">
  18. <el-card v-if="isShow" class="edit-card" shadow="never">
  19. <div slot="header" class="clearfix">
  20. <div class="card-title">优惠券奖励</div>
  21. </div>
  22. <el-row type="flex">
  23. <el-form-item label="每日签到赠送" required>
  24. <el-select class="width-150" placeholder="请选择优惠券" @change="handle('todayCoupon', $event)" v-model="form.today_coupon_name">
  25. <el-option v-for="items in coupon_list" :label="coupon_list.items" :value="items">
  26. </el-option>
  27. </el-select>
  28. <el-input class="width-150" min=1 onchange="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : '1'" v-model="form.today_coupon.num" type="number"></el-input> 张
  29. </el-form-item>
  30. </el-row>
  31. <el-button @click="handle('couponAdd')" size="small" type="text">
  32. <i class="el-icon-plus" style="font-weight: bolder;margin-left: 5px;"></i>
  33. <span style="color: #353535;font-size: 14px">新增优惠券规则</span>
  34. </el-button>
  35. <div class="rule" shadow="never" v-if="form.coupon && form.coupon.length > 0" v-for="(item, index) in form.coupon" :key="item.id">
  36. <el-row type="flex">
  37. <el-form-item label="连续签到" required style="margin: 0; padding:0;">
  38. <el-input class="width-150" min=1 onchange="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : '1'" v-model.number="item.day" type="number"></el-input>
  39. 天 赠送优惠券
  40. <el-select class="width-150" @change="handle('selectCoupon', $event, index)" placeholder="请选择优惠券" v-model="item.coupon_name">
  41. <el-option v-for="items in coupon_list" :label="coupon_list.items" :value="items">
  42. </el-option>
  43. </el-select>
  44. <el-input class="width-150" min=1 onchange="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : '1'" v-model.number="item.num" type="number"></el-input> 张
  45. </el-form-item>
  46. <el-button type="text" size="small" style="margin-left:10px;" @click="handle('couponDel', index)">删除规则</el-button>
  47. </el-row>
  48. </div>
  49. <el-row type="flex" required>
  50. <el-form-item style="margin-top: 20px;">
  51. <template slot='label'>
  52. <span>是否循环奖励</span>
  53. <el-tooltip effect="dark" content="开启后按照规则设计天数重新计算签到奖励"
  54. placement="top">
  55. <i class="el-icon-info"></i>
  56. </el-tooltip>
  57. </template>
  58. <el-switch class="width-150" v-model="form.is_coupon_sign_repeat" :active-value="1" :inactive-value="0"></el-switch>
  59. </el-form-item>
  60. </el-row>
  61. </el-card>
  62. <el-card class="edit-card" shadow="never">
  63. <div slot="header" class="clearfix">
  64. <div class="card-title">积分奖励</div>
  65. </div>
  66. <el-row type="flex">
  67. <el-form-item label="每日签到赠送" required>
  68. <el-input class="width-150" min=1 onchange="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : '1'" v-model="form.today_score.num" type="number"></el-input>
  69. <el-select class="width-150" placeholder="请选择资产类型" @change="handle('todayCoupon', $event)" v-model="form.today_score.give_type">
  70. <el-option v-for="items in give_type" :label="items.title" :value="items.name"></el-option>
  71. </el-select>
  72. </el-form-item>
  73. </el-row>
  74. <el-button @click="handle('scoreAdd')" size="small" type="text">
  75. <i class="el-icon-plus" style="font-weight: bolder;margin-left: 5px;"></i>
  76. <span style="color: #353535;font-size: 14px">新增积分规则</span>
  77. </el-button>
  78. <div class="rule" shadow="never" v-if="form.score && form.score.length > 0" v-for="(item, index) in form.score" :key="item.id">
  79. <el-row type="flex">
  80. <el-form-item label="连续签到" required style="margin: 0; padding:0;">
  81. <el-input class="width-150" min=1 onchange="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : '1'" v-model.number="item.day" type="number"></el-input> 天 赠送
  82. <el-input class="width-150" min=1 onchange="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : '1'" v-model.number="item.num" type="number"></el-input>
  83. <el-select class="width-150" placeholder="请选择资产类型" @change="handle('todayCoupon', $event)" v-model="item.give_type">
  84. <el-option v-for="items in give_type" :label="items.title" :value="items.name"></el-option>
  85. </el-select>
  86. </el-form-item>
  87. <el-button size="small" type="text" style="margin-left:10px;" @click="handle('scoreDel', index)">删除规则</el-button>
  88. </el-col>
  89. </el-row>
  90. </div>
  91. <el-row type="flex" required>
  92. <el-form-item style="margin-top: 20px;">
  93. <template slot='label'>
  94. <span>是否循环奖励</span>
  95. <el-tooltip effect="dark" content="开启后按照规则设计天数重新计算签到奖励"
  96. placement="top">
  97. <i class="el-icon-info"></i>
  98. </el-tooltip>
  99. </template>
  100. <el-switch class="width-150" v-model="form.is_score_sign_repeat" :active-value="1" :inactive-value="0"></el-switch>
  101. </el-form-item>
  102. </el-row>
  103. </el-card>
  104. </el-form>
  105. </el-tab-pane>
  106. <el-tab-pane label="规则配置" name="setting">
  107. <el-card v-if="setting" class="edit-card" shadow="never" v-loading="loading" style="min-width: 1000px;">
  108. <div class='form-body' ref="body">
  109. <el-form label-position="left" label-width="100px">
  110. <!-- <el-form-item label="是否开启">
  111. <el-switch v-model="status" :active-value="1" :inactive-value="0"></el-switch>
  112. </el-form-item> -->
  113. <el-form-item label="签到规则">
  114. <com-rich-text style="width: 750px" :simple-attachment="true" v-model="rule"></com-rich-text>
  115. </el-form-item>
  116. </el-form>
  117. </div>
  118. </el-card>
  119. </el-tab-pane>
  120. </el-tabs>
  121. <el-button class="button-item" :loading="loading" type="primary" size="small" @click="send('submit')">保存</el-button>
  122. </el-card>
  123. </div>
  124. <script>
  125. const app = new Vue({
  126. el: '#app',
  127. data() {
  128. return {
  129. reward: true,
  130. setting: false,
  131. loading: false,
  132. isShow: false,
  133. rule: '',
  134. status: 1,
  135. line: {
  136. width: '450px',
  137. marginLeft: '-150px'
  138. },
  139. form: {
  140. //status:1,
  141. score: [],
  142. coupon: [],
  143. today_score: {
  144. num: 0,
  145. give_type: '',
  146. },
  147. today_coupon: {
  148. coupon_id: 0,
  149. num: 0
  150. },
  151. is_coupon_sign_repeat: 0,
  152. is_score_sign_repeat: 0,
  153. today_coupon_name: '优惠券'
  154. },
  155. coupon_list: {},
  156. coupon_list_data: {},
  157. score_temp: {
  158. day: 0,
  159. num: 0,
  160. },
  161. coupon_temp: {
  162. day: 0,
  163. num: 0,
  164. coupon_id: 0,
  165. },
  166. activeName: 'reward',
  167. give_type: [],
  168. }
  169. },
  170. created() {
  171. this.send('getData');
  172. },
  173. methods: {
  174. handle(type, param1 = null, param2 = null) {
  175. //切换选项卡
  176. switch (type) {
  177. case 'switch':
  178. if (this.activeName == 'reward') {
  179. this.send('getData');
  180. this.reward = true;
  181. this.setting = false;
  182. } else {
  183. this.send('setting');
  184. this.reward = false;
  185. this.setting = true;
  186. }
  187. break;
  188. //删除优惠券
  189. case 'couponDel':
  190. if (this.form.coupon && this.form.coupon.length > param1) {
  191. this.form.coupon.splice(param1, 1);
  192. }
  193. break;
  194. //新增优惠券规则
  195. case 'couponAdd':
  196. this.form.coupon.push(JSON.parse(JSON.stringify(this.coupon_temp)));
  197. break;
  198. //选择优惠券
  199. case 'selectCoupon':
  200. let id = 0;
  201. for (coupon_id in this.coupon_list) {
  202. if (this.coupon_list[coupon_id] == param1) {
  203. id = coupon_id;
  204. }
  205. }
  206. if (id != 0) {
  207. this.form.coupon[param2]['coupon_id'] = id;
  208. }
  209. console.log(this.form.coupon);
  210. break;
  211. //签到每日奖励优惠券
  212. case 'todayCoupon':
  213. let cid = 0;
  214. let ids = getKeys(this.coupon_list, param1);
  215. if (ids.length) {
  216. this.form.today_coupon_name = param1;
  217. this.form.today_coupon.coupon_id = ids[0];
  218. }
  219. break;
  220. //新增积分规则
  221. case 'scoreAdd':
  222. this.form.score.push(JSON.parse(JSON.stringify(this.score_temp)));
  223. break;
  224. //删除积分
  225. case 'scoreDel':
  226. if (this.form.score && this.form.score.length > param1) {
  227. this.form.score.splice(param1, 1);
  228. }
  229. break;
  230. default:
  231. break;
  232. }
  233. },
  234. send(type) {
  235. switch (type) {
  236. //获取奖励
  237. case 'getData':
  238. this.reward = true;
  239. this.setting = false;
  240. this.loading = true;
  241. request({
  242. params: {
  243. r: 'sign-in/default/index',
  244. group: this.activeName
  245. },
  246. method: 'get',
  247. }).then(e => {
  248. this.loading = false;
  249. if (e.data.code == 0) {
  250. if (e.data.data.coupon_list) {
  251. for (let i in e.data.data.coupon_list) {
  252. this.coupon_list[e.data.data.coupon_list[i]['id']] = e.data.data.coupon_list[i]['name'];
  253. }
  254. }
  255. this.isShow = e.data.data.isShow;
  256. this.give_type = e.data.data.give_type;
  257. this.coupon_list_data = e.data.data.coupon_list;
  258. this.form.score = e.data.data.reward_score;
  259. this.form.coupon = e.data.data.reward_coupon;
  260. this.form.today_score = e.data.data.today_score;
  261. this.form.is_coupon_sign_repeat = e.data.data.is_coupon_sign_repeat;
  262. this.form.is_score_sign_repeat = e.data.data.is_score_sign_repeat;
  263. this.form.today_coupon = e.data.data.today_coupon;
  264. if (!this.form.score) {
  265. this.form.score = [];
  266. }
  267. if (!this.form.coupon) {
  268. this.form.coupon = [];
  269. }
  270. if (this.form.today_coupon && this.form.today_coupon.coupon_id) {
  271. this.form.today_coupon_name = this.coupon_list[this.form.today_coupon.coupon_id] ? this.coupon_list[this.form.today_coupon.coupon_id] : '请选择优惠券';
  272. }
  273. }
  274. }).catch(e => {
  275. this.loading = false;
  276. this.$message.error(e.data.msg);
  277. })
  278. break;
  279. //规则
  280. case 'setting':
  281. this.reward = false;
  282. this.setting = true;
  283. request({
  284. params: {
  285. r: 'sign-in/default/index',
  286. group: this.activeName
  287. },
  288. method: 'get',
  289. }).then(e => {
  290. this.loading = false;
  291. if (e.data.code == 0) {
  292. this.rule = e.data.data.rule;
  293. this.status = e.data.data.status;
  294. }
  295. }).catch(e => {
  296. this.loading = false;
  297. this.$message.error(e.data.msg);
  298. })
  299. break
  300. case 'submit':
  301. if (this.activeName == 'reward') {
  302. if (this.form.coupon && this.form.coupon.length > 0) {
  303. for (let i = 0; i < this.form.coupon.length; i++) {
  304. if (this.form.coupon[i]['num'] <= 0) {
  305. this.$message.error('赠送优惠券数量必须大于0');
  306. return false;
  307. }
  308. if (this.form.coupon[i]['coupon_id'] == 0) {
  309. this.$message.error('请选择需要赠送的优惠券');
  310. return false;
  311. }
  312. if (this.coupon_list_data[this.form.coupon[i]['coupon_id']] &&
  313. this.form.coupon[i]['num'] > this.coupon_list_data[this.form.coupon[i]['coupon_id']]['total_count'] &&
  314. this.coupon_list_data[this.form.coupon[i]['coupon_id']]['total_count'] != '-1'
  315. ) {
  316. this.$message.error('优惠券数量不足,剩下' + this.coupon_list_data[this.form.coupon[i]['coupon_id']]['total_count'] + '张');
  317. return false;
  318. }
  319. let couponDay = this.form.coupon[i]['day'] || 1;
  320. }
  321. }
  322. if (this.form.score && this.form.score.length > 0) {
  323. for (let i = 0; i < this.form.score.length; i++) {
  324. if (this.form.score[i]['num'] <= 0) {
  325. this.$message.error('赠送积分数量必须大于0');
  326. return false;
  327. }
  328. }
  329. }
  330. // if (this.form.today_coupon.num <= 0 || this.form.today_coupon.coupon_id == 0) {
  331. // this.$message.error('请选择需要赠送的优惠券');
  332. // return false;
  333. // }
  334. this.loading = true;
  335. let data = this.form;
  336. data['group'] = 'reward';
  337. request({
  338. params: {
  339. r: 'sign-in/default/index'
  340. },
  341. data: this.form,
  342. method: 'post',
  343. }).then(e => {
  344. this.loading = false;
  345. this.$message.success(e.data.msg);
  346. }).catch(e => {
  347. this.loading = false;
  348. this.$message.error(e.data.msg);
  349. })
  350. } else {
  351. this.loading = true;
  352. request({
  353. params: {
  354. r: 'sign-in/default/index'
  355. },
  356. data: {
  357. rule: this.rule,
  358. status: this.status,
  359. group: "setting"
  360. },
  361. method: 'post',
  362. }).then(e => {
  363. this.loading = false;
  364. this.$message.success(e.data.msg);
  365. }).catch(e => {
  366. this.loading = false;
  367. this.$message.error(e.data.msg);
  368. })
  369. }
  370. break;
  371. }
  372. }
  373. }
  374. })
  375. </script>
  376. <style>
  377. .rule + .rule {
  378. margin-top: 5px;
  379. }
  380. </style>