pattern-rebate.php 22 KB

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