com-rebate.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <!-- 引一个当前组件 -->
  2. <?php
  3. use common\helpers\ComponentHelper;
  4. use common\helpers\AddonHelper;
  5. ComponentHelper::loadComponentView('coupon-select', AddonHelper::getAddonRootPath('Coupon') . 'backend/views/components');
  6. ComponentHelper::loadComponentView('com-coupon-select', AddonHelper::getAddonRootPath('Store') . 'client/views/coupon/component');
  7. ComponentHelper::loadComponentView('com-dialog-select');
  8. ComponentHelper::loadComponentView('com-image');
  9. ?>
  10. <template id="com-rebate">
  11. <div class="com-rebate">
  12. <el-card class="edit-card" shadow="never">
  13. <el-form :model="form" size="small">
  14. <div v-for="(setting,index) in form">
  15. <el-form-item label="是否开启推三返一" prop="is_enable">
  16. <el-switch :active-value="1" :inactive-value="0" v-model="setting.is_enable"></el-switch>
  17. </el-form-item>
  18. <el-row :gutter="16" v-if="setting.is_enable == 1">
  19. <el-col :span="24">
  20. <el-form-item label="奖励类型">
  21. <el-radio-group v-model="setting.reward_type" @change="switchReward">
  22. <el-radio :label="1">条件奖励</el-radio>
  23. <el-radio :label="2">阶梯奖励</el-radio>
  24. </el-radio-group>
  25. </el-form-item>
  26. <el-form-item label="">
  27. <el-table :data="rewardInfo" stripe style="width: 100%">
  28. <el-table-column prop="num" label="奖励条件" width="300" class="accon">
  29. <template slot-scope="scope">
  30. {{ setting.reward_type == 1 ? '每' : '' }}推荐
  31. <el-input v-model="scope.row.num" type="number" style="max-width: 200px;padding-left: 10px;" @input="validatorInfo($event,scope.$index)">
  32. <template slot="append">人购买</template>
  33. </el-input>
  34. </template>
  35. </el-table-column>
  36. <el-table-column prop="data" label="奖励内容">
  37. <template slot-scope="scope">
  38. <div style="margin-bottom: 14px;" v-for="(type,index) in scope.row.data" :key="index">
  39. <div class="ratio_change" v-show="scope.row.data[index].key!=0">
  40. <el-radio v-model="scope.row.data[index].ratio" :label="0">固定值</el-radio>
  41. <el-radio v-model="scope.row.data[index].ratio" :label="1">百分比</el-radio>
  42. </div>
  43. <div style="margin-bottom: 10px;" flex>
  44. <el-select v-model="scope.row.data[index].key" placeholder="请选择" @change="updateType($event,scope.$index,index)">
  45. <el-option v-for="item in rechargeType" :key="item.value" :label="item.label" :value="item.value" :disabled="scope.row.data.findIndex(v => v.key == item.value) != -1">
  46. </el-option>
  47. </el-select>
  48. <el-button v-if="scope.row.data[index].key == 0" style="margin-left: 12px;" @click="openCouponPop(scope.$index)">选择优惠券</el-button>
  49. <div style="margin-left: 10px;" v-else>
  50. <el-input v-model="scope.row.data[index].data" type="number" @input="validatorInfo($event,scope.$index,2,scope.row.data[index].key)">
  51. <template slot="append">
  52. <span v-if="scope.row.data[index].ratio==1">%</span>
  53. <span v-else>元</span>
  54. </template>
  55. </el-input>
  56. </div>
  57. <el-button @click="delAward(scope.row.data[index].key,scope.$index)" v-if="scope.row.data.length > 1" type="text" icon="el-icon-close" style="color: #ec1717;font-size: 20px;padding: 0;margin-left: 12px;"></el-button>
  58. </div>
  59. <el-table v-if="scope.row.data[index].key == 0" :data="scope.row.data[index].data" stripe style="width: 100%;">
  60. <el-table-column prop="name" label="优惠券名称" width="160"></el-table-column>
  61. <el-table-column prop="discount_method" label="优惠券内容"></el-table-column>
  62. <el-table-column prop="from_type" label="优惠券类型">
  63. <template slot-scope="couponScope">
  64. {{couponScope.row.from_type == 1?'平台':'门店'}}
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="库存(张)" width="160">
  68. <template slot-scope="couponScope">
  69. {{couponScope.row.total_count == -1?'不限量':couponScope.row.total_count}}
  70. </template>
  71. </el-table-column>
  72. <el-table-column prop="dcount" label="奖励张数" width="160">
  73. <template slot-scope="couponScope">
  74. <el-input v-model="couponScope.row.num" type="number" @input="validatorInfo($event,scope.$index,3,0,couponScope.$index)">
  75. <template slot="append">张</template>
  76. </el-input>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="操作" width="100" align="center">
  80. <template slot-scope="couponScope">
  81. <el-button type="text" size="small" @click="delCoupon(couponScope.$index,scope.$index)">删除</el-button>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. </div>
  86. <div v-if="scope.row.data.length != rechargeType.length">
  87. <el-button @click="addAward(scope.$index)" size="small" plain>添加奖励内容</el-button>
  88. </div>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="操作" width="100" align="center">
  92. <template slot-scope="scope">
  93. <el-button @click="deleteReward(scope.$index)" type="text" size="small">删除</el-button>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. <div>
  98. <el-button size="small" style="margin-top: 10px;" @click="addRewardInfo" v-if="(setting.reward_type == 1 && rewardInfo.length == 0) || setting.reward_type == 2">添加奖励条件</el-button>
  99. </div>
  100. </el-form-item>
  101. <template v-if="setting.reward_type == 2">
  102. <el-form-item label="阶梯重复奖励">
  103. <el-switch v-model="setting.is_repeat" :active-value="1" :inactive-value="0" active-color="#13ce66"></el-switch>
  104. <div class="tips-text" style="line-height: 24px;">
  105. 开启后阶梯奖励将会按照设置进行重复奖励,比如:<br />
  106. 手动设置:推荐1人奖励30余额,推第3人奖励50余额;<br />
  107. 自动奖励:推第4人奖励30余额,推第6人奖励50余额;<br />
  108. 自动奖励:推第7人奖励30余额,推第9人奖励50余额;<br />
  109. 自动奖励:以此类推……
  110. </div>
  111. </el-form-item>
  112. <el-form-item label="触发奖励设置">
  113. <el-switch v-model="setting.repeat_setting" :active-value="1" :inactive-value="0" active-color="#13ce66"></el-switch>
  114. <div class="tips-text" style="line-height: 24px;">
  115. 开启后,结算方式应与渠道分红结算方式保持一致,比如:<br />
  116. 结算方式为支付完成:渠道分红结算方式可设置为支付完成、订单完成;<br />
  117. 结算方式为订单完成:渠道分红结算方式只可设置为订单完成;<br />
  118. </div>
  119. </el-form-item>
  120. <el-form-item v-if="setting.repeat_setting == 1" prop="dcount" label="渠道分红设置" width="160">
  121. <span>第</span>
  122. <el-input v-model="setting.agent_limit_num" type="number" style="max-width: 200px;">
  123. <template slot="append">单</template>
  124. </el-input>
  125. <span>及其倍数的订单不触发分佣奖励</span>
  126. </el-form-item>
  127. </template>
  128. </el-col>
  129. </el-row>
  130. </div>
  131. </el-form>
  132. <!-- 优惠券弹窗 -->
  133. <coupon-select v-if="has_coupon && !is_store" :coupon-loading="couponPop" :coupon_arr="selCoupon" @submit="determine" @close="showCoupon"></coupon-select>
  134. <com-coupon-select v-if="has_coupon && is_store" :coupon-loading="couponPop" :coupon_arr="selCoupon" @submit="determine" @close="showCoupon"></com-coupon-select>
  135. </el-card>
  136. </div>
  137. </template>
  138. <script>
  139. Vue.component('com-rebate', {
  140. template: "#com-rebate",
  141. props: {
  142. setting: {
  143. type: Object,
  144. default: () => {
  145. return {};
  146. }
  147. },
  148. is_store:{
  149. type:Boolean,
  150. default:false
  151. },
  152. commission_type_map: {
  153. type: Object,
  154. default: () => {
  155. return {};
  156. }
  157. },
  158. },
  159. data() {
  160. return {
  161. form: {
  162. commission: {
  163. is_enable: 0,
  164. initiate_type: 0,
  165. initiate_level: [],
  166. consume_type: 0,
  167. consume_level: [],
  168. reward_type: 1,
  169. item_type: 'goods',
  170. reward_info: [],
  171. is_repeat: 0,
  172. join_type: 0,
  173. repeat_setting: 0,
  174. agent_limit_num: 0,
  175. }
  176. },
  177. has_coupon: true,
  178. rewardTemp1: [{
  179. num: 0,
  180. data: [{
  181. key: 0,
  182. name: "优惠券",
  183. type: 'coupon',
  184. data: [],
  185. ratio: 0,
  186. }],
  187. }], // 临时存储条件奖励类型值
  188. rewardTemp2: [{
  189. num: 0,
  190. data: [{
  191. key: 0,
  192. name: "优惠券",
  193. type: 'coupon',
  194. data: [],
  195. ratio: 0,
  196. }],
  197. }], // 临时存储阶梯奖励类型值
  198. rewardInfo: [{
  199. num: 0,
  200. data: [{
  201. key: 0,
  202. name: "优惠券",
  203. type: 'coupon',
  204. data: [],
  205. ratio: 0,
  206. }],
  207. }], //奖励内容
  208. rechargeType: [{
  209. value: 0,
  210. label: '优惠券'
  211. },
  212. {
  213. value: 1,
  214. label: '余额'
  215. },
  216. {
  217. value: 2,
  218. label: '佣金'
  219. },
  220. // {
  221. // value: 2,
  222. // label: '积分'
  223. // },
  224. ],
  225. typeArr: ['coupon', 'balance', 'commission'], //跟rechargeType对应
  226. couponPop: false,
  227. couponPopIndex: -1,
  228. selCoupon: [], //打开优惠券弹窗传递已选中的优惠券
  229. }
  230. },
  231. watch: {
  232. form: {
  233. deep: true,
  234. immediate: true,
  235. handler(value) {
  236. this.form.commission.reward_info = this.rewardInfo;
  237. this.$emit("change", JSON.stringify(value), "Rebate");
  238. }
  239. },
  240. setting: {
  241. deep: true,
  242. immediate: true,
  243. handler(value) {
  244. if (!isEmpty(value)) {
  245. this.form = value;
  246. this.rewardInfo = this.form.commission.reward_info
  247. }
  248. }
  249. },
  250. },
  251. methods: {
  252. // 添加奖励条件
  253. addAward(index) {
  254. let key = 0;
  255. for (let i = 0; i < this.rechargeType.length; i++) {
  256. let dataIndex = this.rewardInfo[index].data.findIndex(v => v.key == this.rechargeType[i].value);
  257. if (dataIndex == -1) {
  258. key = i + key;
  259. break;
  260. }
  261. }
  262. let obj = {
  263. key: this.rechargeType[key].value,
  264. name: this.rechargeType[key].label,
  265. type: this.typeArr[key],
  266. data: key == 0 ? [] : 0,
  267. ratio: 0,
  268. }
  269. if (key != 0) {
  270. obj.data = 0;
  271. }
  272. this.rewardInfo[index].data.push(obj);
  273. },
  274. // 删除奖励条件
  275. delAward(key, index) {
  276. let couponIndex = this.rewardInfo[index].data.findIndex(v => v.key == key);
  277. this.rewardInfo[index].data.splice(couponIndex, 1);
  278. },
  279. // 打开优惠券弹窗
  280. openCouponPop(index) {
  281. if (this.has_coupon == false) {
  282. this.$message.error("请安装优惠券插件");
  283. return;
  284. }
  285. this.couponPopIndex = index;
  286. let dataIndex = this.rewardInfo[index].data.findIndex(v => v.type == 'coupon');
  287. this.selCoupon = this.rewardInfo[index].data[dataIndex].data;
  288. this.couponPop = true;
  289. },
  290. showCoupon() {
  291. this.couponPopIndex = -1;
  292. this.couponPop = false;
  293. },
  294. //弹窗确定
  295. determine(arr) {
  296. let couponPopData = this.rewardInfo[this.couponPopIndex].data;
  297. let couponIndex = couponPopData.findIndex(v => v.key == 0);
  298. if (couponIndex != -1) {
  299. this.rewardInfo[this.couponPopIndex].data[couponIndex].data = arr;
  300. }
  301. this.couponPop = false;
  302. },
  303. // 删除优惠券
  304. delCoupon(selCouponIndex, index) {
  305. let couponPopData = this.rewardInfo[index].data;
  306. let couponIndex = couponPopData.findIndex(v => v.key == 0);
  307. if (couponIndex != -1) {
  308. this.rewardInfo[index].data[couponIndex].data.splice(selCouponIndex, 1);
  309. }
  310. },
  311. // 添加奖励条件
  312. addRewardInfo() {
  313. this.rewardInfo.push({
  314. num: 0,
  315. data: [],
  316. });
  317. },
  318. // 删除奖励条件
  319. deleteReward(index) {
  320. this.rewardInfo.splice(index, 1);
  321. },
  322. // 切换奖励类型
  323. switchReward(event) {
  324. let self = this;
  325. if (event == 1) {
  326. self.rewardTemp2 = self.rewardInfo;
  327. self.rewardInfo = self.rewardTemp1;
  328. } else {
  329. console.log(self.rewardInfo)
  330. self.rewardTemp1 = self.rewardInfo;
  331. self.rewardInfo = self.rewardTemp2;
  332. }
  333. },
  334. updateTime(val) {
  335. if (val) {
  336. this.formData.start_at = parseInt(val[0].getTime() / 1000);
  337. this.formData.end_at = parseInt(val[1].getTime() / 1000);
  338. } else {
  339. this.formData.start_at = "";
  340. this.formData.end_at = "";
  341. }
  342. },
  343. // 表单数值验证
  344. validatorInfo(val, index, type = 1, key, couponIndex) {
  345. console.log(type)
  346. console.info(val, index, type, key, couponIndex);
  347. if (val == '') {
  348. return;
  349. }
  350. let dataIndex = -1;
  351. if (type != 1) {
  352. dataIndex = this.rewardInfo[index].data.findIndex(v => v.key == key);
  353. }
  354. if (val <= 0) {
  355. if (type == 2) {
  356. this.rewardInfo[index].data[dataIndex].data = 0;
  357. } else if (type == 3) {
  358. this.rewardInfo[index].data[dataIndex].data[couponIndex].num = 0;
  359. } else {
  360. this.rewardInfo[index].num = 0;
  361. }
  362. return;
  363. }
  364. // 是否能最多保留两位小数
  365. let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  366. if (!reg.test(val) && type != 3) {
  367. let i = val.indexOf(".") + 3;
  368. val = val.substr(0, i)
  369. if (type == 2) {
  370. this.rewardInfo[index].data[dataIndex].data = val;
  371. } else {
  372. this.rewardInfo[index].num = val;
  373. }
  374. }
  375. if (type == 3) {
  376. // total_count
  377. val = parseInt(val);
  378. let totalCount = this.rewardInfo[index].data[dataIndex].data[couponIndex].total_count;
  379. if (totalCount < val && totalCount != -1) {
  380. this.rewardInfo[index].data[dataIndex].data[couponIndex].num = totalCount;
  381. } else {
  382. this.rewardInfo[index].data[dataIndex].data[couponIndex].num = val;
  383. }
  384. }
  385. },
  386. // 奖励奖励表单严重
  387. validatorForm() {
  388. /* this.rewardInfo.forEach(v => {
  389. if()
  390. }) */
  391. let arr = ['优惠券', '余额', '佣金'];
  392. for (let i = 0; i < this.rewardInfo.length; i++) {
  393. if (this.rewardInfo[i].num <= 0) {
  394. return "推荐人数不能小于等于0";
  395. }
  396. for (let j = 0; j < this.rewardInfo[i].data.length; j++) {
  397. if (this.rewardInfo[i].data[j].key == 0) {
  398. if (this.rewardInfo[i].data[j].data.length == 0) {
  399. return "请选择奖励内容的优惠券";
  400. }
  401. this.$delete(this.rewardInfo[i].data[j], 'ratio');
  402. text = this.validatorCoupon(this.rewardInfo[i].data[j].data);
  403. if (text) return text;
  404. } else {
  405. if (!this.rewardInfo[i].data[j].data || this.rewardInfo[i].data[j].data <= 0) {
  406. let value = '值';
  407. if (this.rewardInfo[i].data[j].ratio == 1) {
  408. value = '百分比';
  409. }
  410. return "奖励内容的" + arr[this.rewardInfo[i].data[j].key] + value + "不能为空或小于等于0";
  411. }
  412. }
  413. }
  414. }
  415. for (let i = 0; i < this.rewardInfo.length; i++) {
  416. let num = this.rewardInfo[i].num;
  417. let arr = this.rewardInfo.filter(v => v.num == num);
  418. if (arr.length > 1) {
  419. return "奖励条件不能重复"
  420. }
  421. }
  422. return "";
  423. },
  424. // 验证优惠券
  425. validatorCoupon(couponList) {
  426. for (let i = 0; i < couponList.length; i++) {
  427. if (couponList[i].num <= 0) {
  428. return "优惠券奖励数量不能小于等于0";
  429. }
  430. }
  431. return "";
  432. },
  433. // 更改奖励内容类型
  434. updateType(key, index, dataIndex) {
  435. this.rewardInfo[index].data[dataIndex].name = this.rechargeType[key].label;
  436. this.rewardInfo[index].data[dataIndex].type = this.typeArr[key];
  437. if (key == 0) {
  438. this.rewardInfo[index].data[dataIndex].data = [];
  439. } else {
  440. if (Array.isArray(this.rewardInfo[index].data[dataIndex].data)) {
  441. this.rewardInfo[index].data[dataIndex].data = 0;
  442. this.rewardInfo[index].data[dataIndex].ratio = 0;
  443. }
  444. }
  445. this.$forceUpdate()
  446. },
  447. },
  448. created() {}
  449. });
  450. </script>