index.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <div id="app" v-cloak>
  2. <el-card class="box-card" v-loading="loading" shadow="never" style="border:0;min-width: 1200px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  3. <div class="form_box">
  4. <template>
  5. <el-card>
  6. <el-form :model="basic" size="small" ref="ruleForm" :rules="rules" label-width="150px">
  7. <el-row>
  8. <el-col :span="24">
  9. <div class="title paddingTop">
  10. <span class="title-line"></span>
  11. <span>随机减条件</span>
  12. </div>
  13. <div class=" condition">
  14. <el-form-item label="订单满" v-for="(item, key) in basic.condition">
  15. <el-col :span="4">
  16. <el-form-item
  17. :key="item.key"
  18. :prop="'condition.' + key + '.total_price'"
  19. >
  20. <el-input oninput="value=value.replace(/[^0-9.]/g,'')" placeholder="请输入内容" v-model="item.total_price">
  21. <template slot="append">元</template>
  22. </el-input>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="1">减</el-col>
  26. <el-col :span="4">
  27. <el-form-item
  28. :key="item.key"
  29. :prop="'condition.' + key + '.rand_min'"
  30. >
  31. <el-input oninput="value=value.replace(/[^0-9.]/g,'')" type="text" v-model="item.rand_min" placeholder="">
  32. <template slot="append">元</template>
  33. </el-input>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="1">~</el-col>
  37. <el-col :span="4">
  38. <el-form-item
  39. :key="item.key"
  40. :prop="'condition.' + key + '.rand_max'"
  41. >
  42. <el-input oninput="value=value.replace(/[^0-9.]/g,'')" type="text" v-model="item.rand_max" placeholder="">
  43. <template slot="append">元</template>
  44. </el-input>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="2">
  48. <span @click="delCondition(key)" class="del-condition">删除</span>
  49. </el-col>
  50. <br/>
  51. <div class="tips-text" style="line-height: 24px;">
  52. 可设置阶梯式减免区间
  53. </div>
  54. </el-form-item>
  55. <el-form-item label="">
  56. <el-button class="button-item" type="primary" @click="addCondition" size="small" v-if="addBtn">添加条件</el-button>
  57. <br/>
  58. <div class="tips-text" style="line-height: 24px;">
  59. 增加新规则
  60. </div>
  61. </el-form-item>
  62. </div>
  63. </el-col>
  64. <!-- 参与权限 -->
  65. <el-col :span="24">
  66. <div class="title paddingTop">
  67. <span class="title-line"></span>
  68. <span>参与权限</span>
  69. </div>
  70. <div class="form-body root">
  71. <el-form-item label="" prop="member">
  72. <el-col :span="24">
  73. <el-checkbox-group v-model="basic.member">
  74. <el-checkbox
  75. v-for="item in member"
  76. :label="item.level"
  77. >{{ item.name }}</el-checkbox>
  78. </el-checkbox-group>
  79. </el-col>
  80. <br/>
  81. <div class="tips-text" style="line-height: 24px;">
  82. 设置等级,如这里勾选了等级VIP,只有VIP等级的用户才能享受以上设置好的随机减活动
  83. </div>
  84. </el-form-item>
  85. </div>
  86. </el-col>
  87. <!-- 应用场景 -->
  88. <el-col :span="24">
  89. <div class="title paddingTop">
  90. <span class="title-line"></span>
  91. <span>应用场景</span>
  92. </div>
  93. <div class="form-body root">
  94. <el-form-item label="" prop="order">
  95. <el-col :span="24">
  96. <el-checkbox-group v-model="basic.order">
  97. <el-checkbox
  98. v-for="item in order"
  99. :label="item.value"
  100. >{{ item.name }}</el-checkbox>
  101. </el-checkbox-group>
  102. </el-col>
  103. <br/>
  104. <div class="tips-text" style="line-height: 24px;">
  105. 选择随机减的应用场景
  106. </div>
  107. </el-form-item>
  108. </div>
  109. </el-col>
  110. </el-row>
  111. </el-form>
  112. </el-card>
  113. </template>
  114. <div style="border-top: 1px solid #dad9d9;">
  115. <el-button :loading="btnLoading" class="button-item" type="primary" style="margin-top: 10px;" @click="store('ruleForm')" size="small">保存
  116. </el-button>
  117. </div>
  118. </div>
  119. </el-card>
  120. </div>
  121. <script>
  122. const validateMoney = (rule, value, callback) => {
  123. if(!value){
  124. callback(new Error('价格不能为空'))
  125. } else if (Number(value) == 0) {
  126. callback(new Error('价格不能小于或等于0'))
  127. } else if (String(value).indexOf(".") != -1 && String(value).split('.').length > 2) {
  128. callback(new Error('请输入正确格式的金额')) //防止输入多个小数点
  129. } else if (String(value).indexOf(".") != -1 && String(value).split('.')[1].length > 2) {
  130. callback(new Error('请输入正确的小数位数')) //小数点后两位
  131. } else {
  132. callback();
  133. }
  134. };
  135. const app = new Vue({
  136. el: '#app',
  137. data() {
  138. return {
  139. addBtn: true,
  140. activeName: 'basic',
  141. loading: false,
  142. btnLoading: false,
  143. dialogVisible: false,
  144. basic: {
  145. condition: [{}],
  146. member: [],
  147. order: [],
  148. },
  149. // member
  150. member: [
  151. {
  152. level: 0,
  153. name: '全部会员',
  154. },
  155. ],
  156. // order
  157. order: [],
  158. rules: {
  159. member: {required: true, message: '选择会员权限不能为空'},
  160. // order: {required: true, message: '选择会员权限不能为空'},
  161. },
  162. // :rules="{required: true, validator: validateMoney, trigger: 'blur', message: '金额有误'}"
  163. }
  164. },
  165. mounted: function() {
  166. this.changeRules(this.basic.condition)
  167. this.loadData();
  168. },
  169. methods: {
  170. // 获取基础设置详情
  171. loadData() {
  172. this.loading = true;
  173. request({
  174. params: {
  175. r: 'rand-fee/setting/index',
  176. },
  177. method: 'get'
  178. }).then(e => {
  179. this.loading = false;
  180. if (e.data.code == 0) {
  181. if (e.data.data) {
  182. if (JSON.stringify(e.data.data.conf) != "[]") {
  183. this.basic = e.data.data.conf
  184. }
  185. this.member = this.member.concat(e.data.data.level)
  186. this.order = e.data.data.order
  187. }
  188. } else {
  189. this.$message.error(e.data.msg)
  190. }
  191. }).catch(e => {
  192. this.loading = false;
  193. })
  194. },
  195. // 添加条件
  196. addCondition() {
  197. if (this.basic.condition.length >= 10) {
  198. return
  199. }
  200. this.basic.condition.push({})
  201. },
  202. // 删除条件
  203. delCondition(key) {
  204. let condition = this.basic.condition.filter((item, index) => {
  205. return index != key
  206. })
  207. this.basic.condition = condition
  208. },
  209. // 保存
  210. store(formName) {
  211. this.$refs[formName].validate((valid) => {
  212. if (valid) {
  213. if (this.basic.condition.length <= 0) {
  214. this.$message.error('请至少设置一个条件');
  215. return
  216. }
  217. var self = this
  218. self.btnLoading = true;
  219. request({
  220. params: {
  221. r: 'rand-fee/setting/submit',
  222. },
  223. method: 'post',
  224. data: self.basic
  225. }).then(e => {
  226. self.btnLoading = false;
  227. if (e.data.code == 0) {
  228. self.$message.success(e.data.msg);
  229. } else {
  230. self.$message.error(e.data.msg);
  231. }
  232. }).catch(e => {
  233. self.$message.error(e);
  234. self.btnLoading = false;
  235. })
  236. } else {
  237. console.log(valid)
  238. }
  239. })
  240. },
  241. changeRules (val) {
  242. let self = this
  243. let validateRepeat = (rule, value, callback) => {
  244. var ary = []
  245. this.basic.condition.forEach((val) => {
  246. ary.push(val.total_price)
  247. });
  248. var nary = ary.sort();
  249. for(var i = 0; i < nary.length - 1; i++) {
  250. if(nary[i] == nary[i + 1]) {
  251. callback(new Error('请勿输入重复金额')) //
  252. }
  253. }
  254. callback();
  255. }
  256. let validateMin = (rule, value, callback) => {
  257. let key = rule.field.substr(rule.field.indexOf(".") + 1, 1)
  258. if (parseFloat(value) >= parseFloat(this.basic.condition[key].rand_max)) {
  259. callback(new Error('请勿输入大于结束金额'))
  260. } else {
  261. callback();
  262. }
  263. }
  264. let validateMax = (rule, value, callback) => {
  265. let key = rule.field.substr(rule.field.indexOf(".") + 1, 1)
  266. if (parseFloat(value) <= parseFloat(this.basic.condition[key].rand_min)) {
  267. callback(new Error('请勿输入小于开始金额'))
  268. } else {
  269. callback();
  270. }
  271. }
  272. let validateIsMax = (rule, value, callback) => {
  273. let key = rule.field.substr(rule.field.indexOf(".") + 1, 1)
  274. if (parseFloat(value) >= parseFloat(this.basic.condition[key].total_price)) {
  275. callback(new Error('请勿输入大于订单最大金额'))
  276. } else {
  277. callback();
  278. }
  279. }
  280. if (val && val.length > 0) {
  281. val.forEach((item, key) => {
  282. let condition = 'condition.' + key + '.total_price'
  283. let rand_min = 'condition.' + key + '.rand_min'
  284. let rand_max = 'condition.' + key + '.rand_max'
  285. self.rules[condition] = [
  286. {required: true, validator: validateMoney, trigger: 'blur', message: '金额有误'},
  287. {required: true, validator: validateRepeat, trigger: 'blur', message: '金额重复'}
  288. ]
  289. self.rules[rand_min] = [
  290. {required: true, validator: validateMoney, trigger: 'blur', message: '金额有误'},
  291. {required: true, validator: validateMin, trigger: 'blur', message: '请勿输入大于结束金额'},
  292. {required: true, validator: validateIsMax, trigger: 'blur', message: '请勿输入大于订单最大金额'},
  293. ]
  294. self.rules[rand_max] = [
  295. {required: true, validator: validateMoney, trigger: 'blur', message: '金额有误'},
  296. {required: true, validator: validateMax, trigger: 'blur', message: '请勿输入小于开始金额'},
  297. {required: true, validator: validateIsMax, trigger: 'blur', message: '请勿输入大于订单最大金额'}
  298. ]
  299. })
  300. }
  301. this.addBtn = (val && val.length >= 10) ? false : true
  302. }
  303. },
  304. watch: {
  305. 'basic.condition': function (val) {
  306. this.changeRules(val)
  307. },
  308. }
  309. });
  310. </script>
  311. <style>
  312. .form_box {
  313. background-color: #f3f3f3;
  314. padding: 0 0 20px;
  315. }
  316. .button-item {
  317. margin-top: 12px;
  318. padding: 9px 25px;
  319. }
  320. .el-input-group__append {
  321. background-color: #fff;
  322. color: #353535;
  323. }
  324. .el-form-item {
  325. margin-bottom: 25px !important;
  326. }
  327. .title {
  328. display: flex;
  329. align-items: center;
  330. padding: 18px 20px;
  331. /* border-top: 1px solid #F3F3F3; */
  332. border-bottom: 1px solid #F3F3F3;
  333. background-color: #fff;
  334. }
  335. .title-line {
  336. width: 4px;
  337. height: 20px;
  338. background-color: #1479F0;
  339. margin-right: 10px;
  340. }
  341. .paddingTop {
  342. margin-top: 10px;
  343. }
  344. .condition .el-col-1 {
  345. text-align: center;
  346. /* margin-left: 50px !important; */
  347. }
  348. .condition .el-col-2 {
  349. text-align: center;
  350. /* margin-left: 50px !important; */
  351. }
  352. .del-condition {
  353. cursor: pointer;
  354. }
  355. .condition .el-form-item {
  356. margin-bottom: 8px !important;
  357. }
  358. </style>