edit.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. <!-- 引一个当前组件 -->
  2. <?php
  3. use common\helpers\ComponentHelper;
  4. use common\helpers\AddonHelper;
  5. if ($has_coupon) {
  6. ComponentHelper::loadComponentView('coupon-select', AddonHelper::getAddonRootPath('Coupon') . 'backend/views/components');
  7. }
  8. ComponentHelper::loadComponentView('com-dialog-select');
  9. ?>
  10. <div id="app" v-cloak>
  11. <el-card shadow="never" style="border:0;min-width: 1200px;">
  12. <el-form ref="formData" :model="formData" label-width="150px" :rules="rules">
  13. <el-form-item label="活动名称" prop="name">
  14. <el-input v-model="formData.name" size="small" style="max-width: 200px;"></el-input>
  15. </el-form-item>
  16. <el-form-item label="活动时间" prop="active_time">
  17. <el-date-picker
  18. v-model="formData.active_time"
  19. type="datetimerange"
  20. unlink-panels
  21. size="small"
  22. range-separator="至"
  23. start-placeholder="开始日期"
  24. end-placeholder="结束日期"
  25. :picker-options="pickerOptions"
  26. @change="updateTime">
  27. </el-date-picker>
  28. </el-form-item>
  29. <el-form-item label="奖励类型">
  30. <el-radio-group v-model="formData.type" @change="switchReward">
  31. <el-radio :label="1" border size="small">条件奖励</el-radio>
  32. <el-radio :label="2" border size="small">阶梯奖励</el-radio>
  33. </el-radio-group>
  34. </el-form-item>
  35. <el-form-item label="推荐人奖励方式">
  36. <el-radio-group v-model="formData.settle_type">
  37. <el-radio :label="0" border size="small">用户注册后</el-radio>
  38. <el-radio :label="4" border size="small">订单完成后</el-radio>
  39. </el-radio-group>
  40. </el-form-item>
  41. <el-form-item>
  42. <br>
  43. <br>
  44. <el-table :data="rewardInfo" stripe style="width: 100%">
  45. <el-table-column prop="num" label="人数条件" width="300" class="accon">
  46. <template slot-scope="scope">
  47. {{ formData.type == 1 ? '每' : '' }}推荐
  48. <el-input v-model.number="scope.row.arrive_num" type="number" size="small" style="max-width: 200px;padding-left: 10px;" @input="HandleInput($event,scope.$index, 'arrive_num')">
  49. <template slot="append">注册</template>
  50. </el-input>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="消费条件" width="300" class="accon" v-if="formData.settle_type == 4">
  54. <template slot-scope="scope">
  55. 消费满<el-input v-model="scope.row.consumption_amount" size="small" type="number" style="max-width: 200px;padding-left: 10px;" @input="HandleInput($event,scope.$index, 'consumption_amount')">
  56. <template slot="append">元</template>
  57. </el-input>
  58. </template>
  59. </el-table-column>
  60. <el-table-column prop="data" label="奖励内容">
  61. <template slot-scope="scope">
  62. <div style="margin-bottom: 14px;" v-for="(type,index) in scope.row.data" :key="index">
  63. <div style="margin-bottom: 10px;" flex>
  64. <el-select v-model="scope.row.data[index].key" size="small" placeholder="请选择" @change="updateType($event,scope.$index,index)">
  65. <el-option
  66. v-for="item in rechargeType"
  67. :key="item.value"
  68. :label="item.label"
  69. :value="item.value"
  70. :disabled="scope.row.data.findIndex(v => v.key == item.value) != -1"
  71. >
  72. </el-option>
  73. </el-select>
  74. <el-button v-if="scope.row.data[index].key == 0" size="small" style="margin-left: 12px;" @click="openCouponPop(scope.$index)">选择优惠券</el-button>
  75. <div style="margin-left: 10px;" v-else>
  76. <el-input v-model="scope.row.data[index].data" size="small" type="number" @input="validatorInfo($event,scope.$index,2,scope.row.data[index].key)">
  77. <template slot="append">{{scope.row.data[index].key == 2?'分':'元'}}</template>
  78. </el-input>
  79. </div>
  80. <el-button @click="delAward(scope.row.data[index].key,scope.$index)" size="small" 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>
  81. </div>
  82. <el-table v-if="scope.row.data[index].key == 0" :data="scope.row.data[index].data" stripe style="width: 100%;">
  83. <el-table-column prop="name" label="优惠券名称" width="160"></el-table-column>
  84. <el-table-column prop="discount_method" label="优惠券内容"></el-table-column>
  85. <el-table-column label="库存(张)" width="160">
  86. <template slot-scope="couponScope">
  87. {{couponScope.row.total_count == -1?'不限量':couponScope.row.total_count}}
  88. </template>
  89. </el-table-column>
  90. <el-table-column prop="dcount" label="奖励张数" width="160">
  91. <template slot-scope="couponScope">
  92. <el-input v-model="couponScope.row.num" size="small" type="number" @input="validatorInfo($event,scope.$index,3,0,couponScope.$index)">
  93. <template slot="append">张</template>
  94. </el-input>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="操作" width="100" align="center">
  98. <template slot-scope="couponScope">
  99. <el-button type="text" size="small" @click="delCoupon(couponScope.$index,scope.$index)">删除</el-button>
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. </div>
  104. <div v-if="scope.row.data.length != rechargeType.length">
  105. <el-button @click="addAward(scope.$index)" size="small" plain>添加奖励内容</el-button>
  106. </div>
  107. </template>
  108. </el-table-column>
  109. <el-table-column label="操作" width="100" align="center">
  110. <template slot-scope="scope">
  111. <el-button @click="deleteReward(scope.$index)" size="small" type="text" size="small">删除</el-button>
  112. </template>
  113. </el-table-column>
  114. </el-table>
  115. <div>
  116. <el-button size="small" style="margin-top: 10px;" @click="addRewardInfo" v-if="(formData.type == 1 && rewardInfo && rewardInfo.length == 0) || formData.type == 2">添加奖励条件</el-button>
  117. </div>
  118. </el-form-item>
  119. <el-form-item label="被推荐人参加奖励">
  120. <el-radio-group v-model="formData.be_status">
  121. <el-radio :label="1" border size="small">关闭</el-radio>
  122. <el-radio :label="2" border size="small">开启</el-radio>
  123. </el-radio-group>
  124. </el-form-item>
  125. <el-form-item label="被推荐人奖励方式" v-if="formData.be_status == 2">
  126. <el-radio-group v-model="formData.be_settle_type">
  127. <el-radio :label="0" border size="small">用户注册后</el-radio>
  128. </el-radio-group>
  129. </el-form-item>
  130. <el-form-item>
  131. <el-table v-if="formData.be_status == 2" :data="berewardInfo" stripe style="width: 100%">
  132. <el-table-column prop="data" label="奖励内容">
  133. <template slot-scope="scope">
  134. <div style="margin-bottom: 14px;" v-for="(type,index) in scope.row.data" :key="index">
  135. <div style="margin-bottom: 10px;" flex>
  136. <el-select v-model="scope.row.data[index].key" size="small" placeholder="请选择" @change="beupdateType($event,scope.$index,index)">
  137. <el-option
  138. v-for="item in rechargeType"
  139. :key="item.value"
  140. :label="item.label"
  141. :value="item.value"
  142. :disabled="scope.row.data.findIndex(v => v.key == item.value) != -1"
  143. >
  144. </el-option>
  145. </el-select>
  146. <el-button v-if="scope.row.data[index].key == 0" size="small" style="margin-left: 12px;" @click="openbeCouponPop(scope.$index)">选择优惠券</el-button>
  147. <div style="margin-left: 10px;" v-else>
  148. <el-input v-model="scope.row.data[index].data" size="small" type="number" @input="validatorInfo2($event,scope.$index,2,scope.row.data[index].key)">
  149. <template slot="append">{{scope.row.data[index].key == 2?'分':'元'}}</template>
  150. </el-input>
  151. </div>
  152. <el-button @click="delbeAward(scope.row.data[index].key,scope.$index)" size="small" 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>
  153. </div>
  154. <el-table v-if="scope.row.data[index].key == 0" :data="scope.row.data[index].data" stripe style="width: 100%;">
  155. <el-table-column prop="name" label="优惠券名称" width="160"></el-table-column>
  156. <el-table-column prop="discount_method" label="优惠券内容"></el-table-column>
  157. <el-table-column label="库存(张)" width="160">
  158. <template slot-scope="couponScope">
  159. {{couponScope.row.total_count == -1?'不限量':couponScope.row.total_count}}
  160. </template>
  161. </el-table-column>
  162. <el-table-column prop="dcount" label="奖励张数" width="160">
  163. <template slot-scope="couponScope">
  164. <el-input v-model="couponScope.row.num" size="small" type="number" @input="validatorInfo2($event,scope.$index,3,0,couponScope.$index)">
  165. <template slot="append">张</template>
  166. </el-input>
  167. </template>
  168. </el-table-column>
  169. <el-table-column label="操作" width="100" align="center">
  170. <template slot-scope="couponScope">
  171. <el-button size="small" type="text" size="small" @click="delbeCoupon(couponScope.$index,scope.$index)">删除</el-button>
  172. </template>
  173. </el-table-column>
  174. </el-table>
  175. </div>
  176. <div v-if="scope.row.data.length != rechargeType.length">
  177. <el-button @click="addBeAward(scope.$index)" size="small" plain>添加奖励内容</el-button>
  178. </div>
  179. </template>
  180. </el-table-column>
  181. </el-table>
  182. </el-form-item>
  183. <el-form-item>
  184. <el-button type="primary" @click="submitForm" size="small" :loading="subLoading">保存</el-button>
  185. </el-form-item>
  186. </el-form>
  187. <!-- 推荐人优惠券弹窗 -->
  188. <coupon-select v-if="has_coupon" :coupon-loading="couponPop" :coupon_arr="selCoupon" @submit="determine" @close="showCoupon"></coupon-select>
  189. <!-- 被推荐优惠券弹窗 -->
  190. <coupon-select v-if="has_coupon" :coupon-loading="becouponPop" :coupon_arr="beselCoupon" @submit="determine" @close="showCoupon"></coupon-select>
  191. </el-card>
  192. </div>
  193. <script>
  194. const app = new Vue({
  195. el: '#app',
  196. data() {
  197. return {
  198. id: null,
  199. formData: {
  200. name: "",
  201. start_time: "",
  202. end_time: "",
  203. item_id: [],
  204. type: 1,
  205. arrive_num:1,
  206. active_time: [],
  207. reward_info: [],
  208. be_reward_info: [],
  209. be_status:1,
  210. be_settle_type: 0,
  211. settle_type: 4,
  212. },
  213. has_coupon: <?php echo $has_coupon ? 'true' : 'false'; ?>,
  214. rewardTemp1: [{
  215. num: 0,
  216. arrive_num: 0,
  217. consumption_amount:0,
  218. data: [{
  219. key: 0,
  220. name: "优惠券",
  221. type: 'coupon',
  222. data: []
  223. }],
  224. }],// 临时存储条件奖励类型值
  225. rewardTemp2: [{
  226. num: 0,
  227. arrive_num: 0,
  228. consumption_amount:0,
  229. data: [{
  230. key: 0,
  231. name: "优惠券",
  232. type: 'coupon',
  233. data: []
  234. }],
  235. }],// 临时存储阶梯奖励类型值
  236. rewardInfo: [{
  237. num: 0,
  238. arrive_num: 0,
  239. consumption_amount:0,
  240. data: [{
  241. key: 0,
  242. name: "优惠券",
  243. type: 'coupon',
  244. data: []
  245. }],
  246. }],//奖励内容
  247. berewardInfo: [{
  248. num: 0,
  249. arrive_num: 0,
  250. consumption_amount:0,
  251. data: [{
  252. key: 0,
  253. name: "优惠券",
  254. type: 'coupon',
  255. data: []
  256. }],
  257. }],//被奖励内容
  258. rechargeType: [
  259. {
  260. value: 0,
  261. label: '优惠券'
  262. },
  263. {
  264. value: 1,
  265. label: '余额'
  266. },
  267. {
  268. value: 2,
  269. label: '积分'
  270. },
  271. ],
  272. typeArr: ['coupon','balance','score'], //跟rechargeType对应
  273. couponPop: false,
  274. becouponPop: false,
  275. couponPopIndex: -1,
  276. becouponPopIndex: -1,
  277. rules: {
  278. name: [
  279. { required: true, message: '活动名称不能为空', trigger: 'blur' },
  280. {
  281. validator: (rule, value, callback) => {
  282. if(value.length>12||value.length<0){
  283. callback('最大长度在1-12个字内');
  284. }
  285. callback();
  286. }
  287. },
  288. ],
  289. active_time: [{ required: true, message: '活动时间不能为空', trigger: 'blur' }],
  290. },
  291. subLoading: false,
  292. selCoupon: [],//打开优惠券弹窗传递已选中的优惠券
  293. beselCoupon: [],//被推荐人打开优惠券弹窗传递已选中的优惠券
  294. pickerOptions: {
  295. shortcuts: [{
  296. text: '7天',
  297. onClick(picker) {
  298. const end = new Date();
  299. const start = new Date();
  300. end.setTime(end.getTime() + 3600 * 1000 * 24 * 7);
  301. picker.$emit('pick', [start, end]);
  302. }
  303. }, {
  304. text: '15天',
  305. onClick(picker) {
  306. const end = new Date();
  307. const start = new Date();
  308. end.setTime(end.getTime() + 3600 * 1000 * 24 * 15);
  309. picker.$emit('pick', [start, end]);
  310. }
  311. }, {
  312. text: '30天',
  313. onClick(picker) {
  314. const end = new Date();
  315. const start = new Date();
  316. end.setTime(end.getTime() + 3600 * 1000 * 24 * 30);
  317. picker.$emit('pick', [start, end]);
  318. }
  319. }]
  320. },
  321. }
  322. },
  323. created(){
  324. if (getQuery('id') && getQuery('id') != 0) {
  325. this.id = getQuery('id');
  326. this.getDetail();
  327. }
  328. },
  329. methods: {
  330. // 获取充值信息
  331. getDetail(){
  332. request({
  333. params: {
  334. r: 'recommen/default/edit',
  335. id: this.id,
  336. },
  337. method: 'get',
  338. }).then(res => {
  339. console.info(res);
  340. if(res.data.code == 0){
  341. if(res.data.data.detail) {
  342. this.formData = res.data.data.detail;
  343. this.formData.be_settle_type = 0;
  344. if(res.data.data.detail.recommen_reward) this.rewardInfo = res.data.data.detail.recommen_reward;
  345. if(res.data.data.detail.be_recommen_reward) this.berewardInfo = res.data.data.detail.be_recommen_reward;
  346. this.$set(this.formData, 'active_time', [new Date(res.data.data.detail.start_time * 1000),new Date(res.data.data.detail.end_time * 1000)]);
  347. }
  348. }
  349. })
  350. },
  351. // 添加奖励条件
  352. addAward(index){
  353. let key = 0;
  354. for(let i = 0;i<this.rechargeType.length;i++){
  355. let dataIndex = this.rewardInfo[index].data.findIndex(v => v.key == this.rechargeType[i].value);
  356. if(dataIndex == -1){
  357. key = i + key;
  358. break;
  359. }
  360. }
  361. let obj = {
  362. key,
  363. name: this.rechargeType[key].label,
  364. type: this.typeArr[key],
  365. data: key == 0?[]:"",
  366. }
  367. if(key != 0){
  368. obj.data = 0;
  369. }
  370. this.rewardInfo[index].data.push(obj);
  371. },
  372. // 添加奖励条件
  373. addBeAward(index){
  374. let key = 0;
  375. for(let i = 0;i<this.rechargeType.length;i++){
  376. let dataIndex = this.berewardInfo[index].data.findIndex(v => v.key == this.rechargeType[i].value);
  377. if(dataIndex == -1){
  378. key = i + key;
  379. break;
  380. }
  381. }
  382. let obj = {
  383. key,
  384. name: this.rechargeType[key].label,
  385. type: this.typeArr[key],
  386. data: key == 0?[]:"",
  387. }
  388. if(key != 0){
  389. obj.data = 0;
  390. }
  391. this.berewardInfo[index].data.push(obj);
  392. },
  393. // 删除奖励条件
  394. delAward(key,index){
  395. let couponIndex = this.rewardInfo[index].data.findIndex(v => v.key == key);
  396. this.rewardInfo[index].data.splice(couponIndex,1);
  397. },
  398. // 删除奖励条件
  399. delbeAward(key,index){
  400. let couponIndex = this.berewardInfo[index].data.findIndex(v => v.key == key);
  401. this.berewardInfo[index].data.splice(couponIndex,1);
  402. },
  403. // 打开优惠券弹窗
  404. openCouponPop(index){
  405. if (this.has_coupon == false) {
  406. this.$message.error("请安装优惠券插件");
  407. return;
  408. }
  409. this.couponPopIndex = index;
  410. let dataIndex = this.rewardInfo[index].data.findIndex(v => v.type == 'coupon');
  411. this.selCoupon = this.rewardInfo[index].data[dataIndex].data;
  412. this.couponPop = true;
  413. },
  414. openbeCouponPop(index){
  415. if (this.has_coupon == false) {
  416. this.$message.error("请安装优惠券插件");
  417. return;
  418. }
  419. this.becouponPopIndex = index;
  420. let dataIndex = this.berewardInfo[index].data.findIndex(v => v.type == 'coupon');
  421. this.beselCoupon = this.berewardInfo[index].data[dataIndex].data;
  422. this.becouponPop = true;
  423. },
  424. showCoupon(){
  425. this.couponPopIndex = -1;
  426. this.couponPop = false;
  427. this.becouponPopIndex = -1;
  428. this.becouponPop = false;
  429. },
  430. //弹窗确定
  431. determine(arr) {
  432. if(this.becouponPop){
  433. console.log(this.berewardInfo,88,this.becouponPopIndex);
  434. let couponPopData = this.berewardInfo[this.becouponPopIndex].data;
  435. let couponIndex = couponPopData.findIndex(v => v.key == 0);
  436. if(couponIndex != -1){
  437. this.$set(this.berewardInfo[this.becouponPopIndex].data[couponIndex],'data',arr);
  438. //this.berewardInfo[this.becouponPopIndex].data[couponIndex].data = arr;
  439. }
  440. this.becouponPop = false;
  441. }else{
  442. console.log(this.rewardInfo,99);
  443. let couponPopData = this.rewardInfo[this.couponPopIndex].data;
  444. let couponIndex = couponPopData.findIndex(v => v.key == 0);
  445. if(couponIndex != -1){
  446. this.rewardInfo[this.couponPopIndex].data[couponIndex].data = arr;
  447. }
  448. this.couponPop = false;
  449. }
  450. },
  451. // 删除优惠券
  452. delCoupon(selCouponIndex,index){
  453. let couponPopData = this.rewardInfo[index].data;
  454. let couponIndex = couponPopData.findIndex(v => v.key == 0);
  455. if(couponIndex != -1){
  456. this.rewardInfo[index].data[couponIndex].data.splice(selCouponIndex,1);
  457. }
  458. },
  459. // 删除优惠券
  460. delbeCoupon(selCouponIndex,index){
  461. let couponPopData = this.berewardInfo[index].data;
  462. let couponIndex = couponPopData.findIndex(v => v.key == 0);
  463. if(couponIndex != -1){
  464. this.berewardInfo[index].data[couponIndex].data.splice(selCouponIndex,1);
  465. }
  466. },
  467. // 添加奖励条件
  468. addRewardInfo(){
  469. this.rewardInfo.push({
  470. num: 0,
  471. arrive_num: 0,
  472. consumption_amount:0,
  473. data: [{
  474. key: 0,
  475. name: "优惠券",
  476. type: 'coupon',
  477. data: []
  478. }],
  479. });
  480. },
  481. // 删除奖励条件
  482. deleteReward(index){
  483. this.rewardInfo.splice(index,1);
  484. },
  485. // 删除奖励条件
  486. deletebeReward(index){
  487. console.log(index,999);
  488. this.berewardInfo.splice(index,1);
  489. },
  490. // 切换奖励类型
  491. switchReward(event){
  492. let self = this;
  493. if(event == 1) {
  494. self.rewardTemp2 = self.rewardInfo;
  495. self.rewardInfo = self.rewardTemp1;
  496. } else {
  497. self.rewardTemp1 = self.rewardInfo;
  498. self.rewardInfo = self.rewardTemp2;
  499. }
  500. },
  501. updateTime(val){
  502. if(val){
  503. this.formData.start_time = parseInt(val[0].getTime() / 1000);
  504. this.formData.end_time = parseInt(val[1].getTime() / 1000);
  505. } else {
  506. this.formData.start_time = "";
  507. this.formData.end_time = "";
  508. }
  509. },
  510. // 表单数值验证
  511. validatorInfo(val,index,type = 1,key,couponIndex){
  512. console.info(val,index,type,key,couponIndex);
  513. if(val == ''){
  514. return;
  515. }
  516. let dataIndex = -1;
  517. if(type != 1){
  518. dataIndex = this.rewardInfo[index].data.findIndex(v => v.key == key);
  519. }
  520. if(val <= 0){
  521. if(type == 2){
  522. this.rewardInfo[index].data[dataIndex].data = 0;
  523. } else if(type == 3){
  524. this.rewardInfo[index].data[dataIndex].data[couponIndex].num = 0;
  525. } else {
  526. this.rewardInfo[index].num = 0;
  527. }
  528. return;
  529. }
  530. // 是否能最多保留两位小数
  531. let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  532. if(!reg.test(val) && type != 3){
  533. let i = val.indexOf(".") + 3;
  534. val = val.substr(0,i)
  535. if(type == 2){
  536. this.rewardInfo[index].data[dataIndex].data = val;
  537. } else {
  538. this.rewardInfo[index].num = val;
  539. }
  540. }
  541. if(type == 3){
  542. // total_count
  543. val = parseInt(val);
  544. let totalCount = this.rewardInfo[index].data[dataIndex].data[couponIndex].total_count;
  545. if(totalCount < val && totalCount != -1){
  546. this.rewardInfo[index].data[dataIndex].data[couponIndex].num = totalCount;
  547. } else {
  548. this.rewardInfo[index].data[dataIndex].data[couponIndex].num = val;
  549. }
  550. }
  551. },
  552. validatorInfo2(val,index,type = 1,key,couponIndex){
  553. console.info(val,index,type,key,couponIndex);
  554. if(val == ''){
  555. return;
  556. }
  557. let dataIndex = -1;
  558. if(type != 1){
  559. dataIndex = this.berewardInfo[index].data.findIndex(v => v.key == key);
  560. }
  561. if(val <= 0){
  562. if(type == 2){
  563. this.berewardInfo[index].data[dataIndex].data = 0;
  564. } else if(type == 3){
  565. this.berewardInfo[index].data[dataIndex].data[couponIndex].num = 0;
  566. } else {
  567. this.berewardInfo[index].num = 0;
  568. }
  569. return;
  570. }
  571. // 是否能最多保留两位小数
  572. let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  573. if(!reg.test(val) && type != 3){
  574. let i = val.indexOf(".") + 3;
  575. val = val.substr(0,i)
  576. if(type == 2){
  577. this.berewardInfo[index].data[dataIndex].data = val;
  578. } else {
  579. this.berewardInfo[index].num = val;
  580. }
  581. }
  582. if(type == 3){
  583. // total_count
  584. val = parseInt(val);
  585. let totalCount = this.berewardInfo[index].data[dataIndex].data[couponIndex].total_count;
  586. if(totalCount < val && totalCount != -1){
  587. this.berewardInfo[index].data[dataIndex].data[couponIndex].num = totalCount;
  588. } else {
  589. this.berewardInfo[index].data[dataIndex].data[couponIndex].num = val;
  590. }
  591. }
  592. },
  593. HandleInput(e,index,name) {
  594. console.log(e,index,name);
  595. if (name == 'arrive_num') {
  596. this.rewardInfo[index][name] = parseInt(e);
  597. } else {
  598. this.rewardInfo[index][name] = ('' + e)
  599. .replace(/[^\d^\.]+/g, '')
  600. .replace(/^0+(\d)/, '$1')
  601. .replace(/^\./, '0.')
  602. .match(/^\d*(\.?\d{0,2})/g)[0] || ''
  603. }
  604. },
  605. // limitInput(value, index, name) {
  606. // this.rewardInfo[index][name] = ('' + value)
  607. // .replace(/[^\d^\.]+/g, '')
  608. // .replace(/^0+(\d)/, '$1')
  609. // .replace(/^\./, '0.')
  610. // .match(/^\d*(\.?\d{0,2})/g)[0] || ''
  611. // },
  612. // 奖励奖励表单严重
  613. validatorForm(){
  614. let arr = ['优惠券','余额','积分'];
  615. if(this.rewardInfo.length<=0){
  616. return "推荐人奖励至少添加一项";
  617. }
  618. for(let i = 0;i<this.rewardInfo.length;i++){
  619. if(this.rewardInfo[i].arrive_num <= 0 || !this.rewardInfo[i].arrive_num){
  620. return "推荐人数不能小于等于0 或者不能为空";
  621. }
  622. //推荐人
  623. for(let j = 0;j<this.rewardInfo[i].data.length;j++){
  624. if(this.rewardInfo[i].data[j].key == 0){
  625. if(this.rewardInfo[i].data[j].data.length == 0) {
  626. return "请选择奖励内容的优惠券";
  627. }
  628. text = this.validatorCoupon(this.rewardInfo[i].data[j].data);
  629. if(text) return text;
  630. } else {
  631. if(!this.rewardInfo[i].data[j].data || this.rewardInfo[i].data[j].data <= 0){
  632. return "奖励内容的" + arr[this.rewardInfo[i].data[j].key] + "值不能为空或小于等于0";
  633. }
  634. }
  635. }
  636. }
  637. if(this.berewardInfo){
  638. for(let i = 0;i<this.berewardInfo.length;i++){
  639. //被推荐人
  640. if(this.formData.be_status==2){ console.log(this.berewardInfo);
  641. for(let j = 0;j<this.berewardInfo[i].data.length;j++){
  642. if(this.berewardInfo[i].data[j].key == 0){
  643. if( this.berewardInfo[i].data[j].data ) {
  644. if(this.berewardInfo[i].data[j].data.length == 0){
  645. return "请选择奖励内容的优惠券";
  646. }
  647. text = this.validatorCoupon(this.berewardInfo[i].data[j].data);
  648. if(text) return text;
  649. }else{
  650. return "请选择奖励内容的优惠券";
  651. }
  652. } else {
  653. if(!this.berewardInfo[i].data[j].data || this.berewardInfo[i].data[j].data <= 0){
  654. return "奖励内容的" + arr[this.berewardInfo[i].data[j].key] + "值不能为空或小于等于0";
  655. }
  656. }
  657. }
  658. }
  659. }
  660. }
  661. for(let i = 0;i<this.rewardInfo.length;i++) {
  662. let num = this.rewardInfo[i].arrive_num;
  663. let arr = this.rewardInfo.filter(v => v.arrive_num == num);
  664. if(arr.length > 1){
  665. return "奖励条件不能重复"
  666. }
  667. }
  668. return "";
  669. },
  670. // 验证优惠券
  671. validatorCoupon(couponList){
  672. for(let i = 0;i<couponList.length;i++){
  673. if(couponList[i].num <= 0){
  674. return "优惠券奖励数量不能小于等于0";
  675. }
  676. }
  677. return "";
  678. },
  679. // 更改奖励内容类型
  680. updateType(key,index,dataIndex){
  681. this.rewardInfo[index].data[dataIndex].name = this.rechargeType[key].label;
  682. this.rewardInfo[index].data[dataIndex].type = this.typeArr[key];
  683. if(key == 0){
  684. this.rewardInfo[index].data[dataIndex].data = [];
  685. } else {
  686. if(Array.isArray(this.rewardInfo[index].data[dataIndex].data)){
  687. this.rewardInfo[index].data[dataIndex].data = 0;
  688. }
  689. }
  690. },
  691. // 更改奖励内容类型
  692. beupdateType(key,index,dataIndex){
  693. this.berewardInfo[index].data[dataIndex].name = this.rechargeType[key].label;
  694. this.berewardInfo[index].data[dataIndex].type = this.typeArr[key];
  695. if(key == 0){
  696. this.berewardInfo[index].data[dataIndex].data = [];
  697. } else {
  698. if(Array.isArray(this.berewardInfo[index].data[dataIndex].data)){
  699. this.berewardInfo[index].data[dataIndex].data = 0;
  700. }
  701. }
  702. },
  703. // 保存
  704. submitForm(){
  705. this.$refs['formData'].validate((valid) => {
  706. if (valid) {
  707. let text = this.validatorForm();
  708. if(text){
  709. this.$message.error(text);
  710. return;
  711. }
  712. if(!this.formData.id){
  713. if(this.formData.start_time > this.formData.end_time){
  714. this.$message.error('开始时间只能结束时间之后');
  715. return;
  716. }
  717. }
  718. this.$set(this.formData,'reward_info',this.rewardInfo);
  719. this.$set(this.formData,'be_reward_info',this.berewardInfo);
  720. //this.subLoading = true;
  721. request({
  722. params: {
  723. r: 'recommen/default/edit',
  724. },
  725. method: 'post',
  726. data: this.formData
  727. }).then(res => {
  728. console.info(res);
  729. this.subLoading = false;
  730. if(res.data.code == 0){
  731. this.$message.success("保存成功");
  732. navigateTo({
  733. r: "recommen/default/index"
  734. })
  735. } else {
  736. this.$message.error(res.data.msg);
  737. }
  738. })
  739. }
  740. });
  741. },
  742. },
  743. })
  744. </script>
  745. <style>
  746. .el-table_1_column_1 .cell{
  747. display: flex;
  748. align-items: center;
  749. }
  750. </style>