index.php 9.7 KB

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