index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <div class="app-container">
  3. <el-row>
  4. <el-col :span="24">
  5. <div class="cell">
  6. <div class="cell-title">
  7. <div class="title-left">
  8. <div class="title">系统设置</div>
  9. </div>
  10. </div>
  11. <div class="cell-body">
  12. <el-form ref="formData" :rules="formRules" :model="formData">
  13. <el-form-item prop="noOne">
  14. <span>空调开启半小时不足1小时为</span>
  15. <el-input v-model="formData.noOne" maxlength="2" placeholder="请输入金额"></el-input>
  16. <span>元</span>
  17. </el-form-item>
  18. <el-form-item prop="one">
  19. <span>空调开启每小时为</span>
  20. <el-input v-model="formData.one" maxlength="2" placeholder="请输入金额"></el-input>
  21. <span>元</span>
  22. </el-form-item>
  23. <el-form-item prop="isauto">
  24. <span>自动扣款</span>
  25. <el-switch v-model="formData.isauto" active-color="#2B4CFE"></el-switch>
  26. </el-form-item>
  27. <el-form-item prop="start_tiao">
  28. <span>账户余额少于</span>
  29. <el-input v-model="formData.start_tiao" maxlength="2" placeholder="请输入金额"></el-input>
  30. <span>元,不能开启空调</span>
  31. </el-form-item>
  32. <el-form-item prop="send_jian">
  33. <span>每隔</span>
  34. <el-input v-model="formData.send_jian" maxlength="2" placeholder="请输入小时数"></el-input>
  35. <span>小时,系统自动发送通知给操作员</span>
  36. </el-form-item>
  37. <el-form-item prop="send_start">
  38. <span>每天</span>
  39. <el-time-picker :editable="false" v-model="formData.send_start" :picker-options="{
  40. start: '00:00',step: '00:01',end: '23:59'
  41. }" value-format="HH:mm:ss" placeholder="请输入时间" :clearable="false">
  42. </el-time-picker>
  43. <span>为截止时间,系统自动发送通知给操作员</span>
  44. </el-form-item>
  45. <el-form-item prop="phone">
  46. <span>使用问题联系方式</span>
  47. <el-input v-model="formData.phone" placeholder="请输入手机号" maxlength="11" class="phone-class"></el-input>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button type="primary" round @click="handle_submit">确认提交</el-button>
  51. </el-form-item>
  52. </el-form>
  53. </div>
  54. </div>
  55. </el-col>
  56. </el-row>
  57. </div>
  58. </template>
  59. <script>
  60. import {
  61. updateSet,
  62. getSet
  63. } from '@/api/systemSet';
  64. export default {
  65. data() {
  66. var checkMoney = (rule, value, callback) => {
  67. if (!value) {
  68. return callback(new Error('金额不能为空'));
  69. }
  70. setTimeout(() => {
  71. var reg = /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/
  72. if (!reg.test(value)) {
  73. callback(new Error('请输入数值型,可保留2位小数'));
  74. } else if (value < 0.01 || value > 10) {
  75. callback(new Error('范围在0.01-10'));
  76. } else {
  77. callback();
  78. }
  79. }, 100);
  80. }
  81. var checkTime = (rule, value, callback) => {
  82. if (!value) {
  83. return callback(new Error('不能为空'));
  84. }
  85. setTimeout(() => {
  86. var reg = /^(\d{1,})$/
  87. if (!reg.test(value)) {
  88. callback(new Error('请输入整数值'));
  89. } else if (value < 1 || value > 10) {
  90. callback(new Error('范围在1-10'));
  91. } else {
  92. callback();
  93. }
  94. }, 100);
  95. }
  96. var checkPhone = (rule, value, callback) => {
  97. if (!value) {
  98. return callback(new Error('请输入手机号'));
  99. }
  100. setTimeout(() => {
  101. var reg = /^1[3456789]\d{9}$/
  102. if (!reg.test(value)) {
  103. callback(new Error('手机号格式不对'));
  104. } else {
  105. callback();
  106. }
  107. }, 100);
  108. }
  109. return {
  110. formData: {
  111. noOne: '', // 半小时不足1小时
  112. one: '', // 每小时
  113. isauto: true, // 自动扣款
  114. start_tiao: '',
  115. send_jian: '',
  116. send_start: '',
  117. phone: '',
  118. state: 1,
  119. },
  120. currentPage: 1,
  121. rows: 6,
  122. // 校验规则
  123. formRules: {
  124. noOne: [{
  125. validator: checkMoney
  126. }],
  127. one: [{
  128. validator: checkMoney
  129. }],
  130. start_tiao: [{
  131. validator: checkMoney
  132. }],
  133. send_jian: [{
  134. validator: checkTime
  135. }],
  136. phone: [{
  137. validator: checkPhone
  138. }]
  139. }
  140. }
  141. },
  142. mounted() {
  143. this.get_data()
  144. },
  145. methods: {
  146. /**
  147. * 获取配置数据
  148. */
  149. get_data() {
  150. const params = {
  151. page: this.currentPage,
  152. rows: this.rows
  153. }
  154. // 开始发送请求,获取配置数据
  155. getSet(params).then((res) => {
  156. // console.log(res.rows[0]);
  157. let r = res.rows[0]
  158. this.formData.noOne = r.noOne
  159. this.formData.one = r.one
  160. this.formData.isauto = r.isauto == 1 ? true : false
  161. this.formData.start_tiao = r.start_tiao
  162. this.formData.send_jian = r.send_jian
  163. this.formData.send_start = r.send_start
  164. this.formData.phone = r.phone
  165. this.formData.state = r.state
  166. }).catch((err) => {
  167. // console.log(err);
  168. this.$message.error(err.message)
  169. })
  170. },
  171. /**
  172. * 提交修改后的配置
  173. */
  174. handle_submit() {
  175. this.$refs["formData"].validate(validate => {
  176. if (validate) {
  177. //form表单校验通过,可以进行下一步操作
  178. const params = {
  179. id: 1,
  180. noOne: this.formData.noOne,
  181. one: this.formData.one,
  182. isauto: this.formData.isauto == true ? 1 : 0,
  183. start_tiao: this.formData.start_tiao,
  184. send_jian: this.formData.send_jian,
  185. send_start: this.formData.send_start,
  186. phone: this.formData.phone,
  187. state: this.formData.state
  188. }
  189. // 开始发送更新配置请求
  190. updateSet(params).then((res) => {
  191. // console.log(res);
  192. if (res.code === 200) {
  193. this.$message.success(res.message)
  194. } else {
  195. this.$message.error(res.message)
  196. }
  197. }).catch((err) => {
  198. // console.log(err);
  199. this.$message.error(err.message)
  200. })
  201. } else {
  202. this.$message.error('验证不通过')
  203. return false
  204. }
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .app-container {
  212. background-color: #EFF2F7;
  213. padding: 10px;
  214. .el-row {
  215. .el-col {
  216. padding: 10px;
  217. .cell {
  218. padding: 30px;
  219. border-radius: 10px;
  220. background-color: #FFFFFF;
  221. // box-shadow: 5px 5px 15px #979797;
  222. box-shadow: 0px 3px 21px 0px rgba(60, 108, 254, 0.16);
  223. .cell-title {
  224. display: flex;
  225. justify-content: space-between;
  226. align-items: center;
  227. margin-bottom: 30px;
  228. padding-bottom: 30px;
  229. border-bottom: 1px solid #CCCCCC;
  230. .title {
  231. font-size: 22px;
  232. font-family: Microsoft YaHei-3970(82674968);
  233. font-weight: bold;
  234. color: #1A202B;
  235. }
  236. }
  237. .cell-body {
  238. height: 630px;
  239. ::v-deep .el-form-item {
  240. display: flex;
  241. align-items: center;
  242. white-space: nowrap;
  243. span {
  244. font-size: 16px;
  245. font-family: Microsoft YaHei-3970(82674968);
  246. color: #46515E;
  247. }
  248. .el-input,
  249. .el-input__inner {
  250. width: 90px;
  251. text-align: center;
  252. font-size: 18px;
  253. font-family: Microsoft YaHei-3970(82674968);
  254. color: #46515E;
  255. }
  256. .el-input {
  257. margin: 0 10px;
  258. width: 140px;
  259. .el-input__inner {
  260. width: 140px;
  261. }
  262. }
  263. .el-switch {
  264. margin: 0 10px;
  265. }
  266. .el-date-editor--time {
  267. width: 150px;
  268. .el-input__inner {
  269. width: 150px;
  270. }
  271. }
  272. .phone-class {
  273. width: 160px;
  274. .el-input__inner {
  275. width: 160px;
  276. }
  277. }
  278. .el-button.el-button--primary {
  279. background: #3660FF;
  280. font-size: 18px;
  281. span {
  282. color: #FFFFFF;
  283. }
  284. }
  285. .el-form-item__error {
  286. font-size: 16px
  287. }
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. </style>