rule_item_add.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="rule_item_add_box">
  3. <van-nav-bar title="创建规则" left-text="返回" @click-left="$route_back" left-arrow right-text="保存" @click-right="data_verify"></van-nav-bar>
  4. <div class="body_com has_header">
  5. <scroller>
  6. <van-cell-group>
  7. <van-cell required>
  8. <Mtextarea required v-model="item.remark" placeholder="输入规则内容" :text_max="100" :imgs_max="3"></Mtextarea>
  9. </van-cell>
  10. </van-cell-group>
  11. <van-cell-group>
  12. <van-cell title="分值" class="cell-right-4rem">
  13. <van-radio-group v-model="item.range_type" direction="horizontal" class="radio_button" slot="right-icon">
  14. <van-radio class="list" :name="1">固定分</van-radio>
  15. <van-radio class="list" :name="2">范围分</van-radio>
  16. </van-radio-group>
  17. </van-cell>
  18. <van-field required label="固定分值" type="Number" v-if="item.range_type == 1" v-model="item.min_point" placeholder="输入分值"/>
  19. <van-field required label="最小分值" type="Number" v-if="item.range_type == 2" v-model="item.min_point" placeholder="输入最小分值"/>
  20. <van-field required label="最大分值" type="Number" v-if="item.range_type == 2" v-model="item.max_point" placeholder="输入最大分值"/>
  21. </van-cell-group>
  22. <van-cell-group class="choose">
  23. <CategorySelectorCell required title="选择分类" v-model="rule_cate" :max="2" :multi="false"></CategorySelectorCell>
  24. </van-cell-group>
  25. <van-cell-group>
  26. <van-cell title="积分类型" class="cell-right-4rem">
  27. <van-radio-group v-model="item.pt_id" direction="horizontal" slot="right-icon" class="radio_button">
  28. <van-radio class="list" v-for="(item, index) in types_list" :name="item.id" :key="index">{{item.name}}</van-radio>
  29. </van-radio-group>
  30. </van-cell>
  31. </van-cell-group>
  32. <!--
  33. <van-cell-group>
  34. <van-cell title="奖扣周期" class="cell-right-4rem">
  35. <template slot="right-icon">
  36. <van-switch v-model="cycle" size="24" />
  37. </template>
  38. </van-cell>
  39. <van-cell title="考勤挂钩" class="cell-right-4rem" v-show="item.cycle_type == 2">
  40. <van-radio-group class="radio_button" slot="right-icon" v-model="item.is_attendance" direction="horizontal">
  41. <van-radio class="list" :name="0">否</van-radio>
  42. <van-radio class="list" :name="1">是</van-radio>
  43. </van-radio-group>
  44. </van-cell>
  45. </van-cell-group>
  46. -->
  47. </scroller>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import Vue from 'vue'
  53. import { Switch } from 'vant'
  54. import request from '@/utils/request'
  55. import Mtextarea from '@/components/common/Mtextarea'
  56. import CategorySelectorCell from '@/components/common/CategorySelectorCell'
  57. Vue.use(Switch)
  58. export default {
  59. name: 'rule_item_add',
  60. components: {
  61. Mtextarea, CategorySelectorCell
  62. },
  63. data () {
  64. return {
  65. data: {
  66. items: []
  67. },
  68. rule_cate: [],
  69. cycle: false,
  70. item: {
  71. rule_id: 0,
  72. prize_type: 1,
  73. range_type: 1,
  74. min_point: 0,
  75. max_point: 0,
  76. remark: '',
  77. is_attendance: 0,
  78. cycle_type: 1,
  79. pt_id: 0
  80. },
  81. send_loading: false,
  82. types_list: []
  83. }
  84. },
  85. watch: {
  86. cycle (val) {
  87. if (val) {
  88. this.item.cycle_type = 2
  89. } else {
  90. this.item.cycle_type = 1
  91. }
  92. },
  93. rule_cate (val) {
  94. if (val.length > 0) {
  95. this.item.rule_id = val[0].id
  96. } else {
  97. this.item.rule_id = 0
  98. }
  99. }
  100. },
  101. methods: {
  102. data_verify () {
  103. let self = this
  104. self.$validator.validateAll().then(result => {
  105. if (!result) {
  106. self.$notify({type: 'danger', message: self.$validator.errors.items[0].msg})
  107. } else {
  108. self.send()
  109. }
  110. })
  111. },
  112. send () {
  113. let self = this
  114. if (self.rule_cate.length == 0) {
  115. self.$notify({type: 'danger', message: '请选择分类'})
  116. return false
  117. }
  118. if (self.item.remark == '') {
  119. self.$notify({type: 'danger', message: '请输入规则内容'})
  120. return false
  121. }
  122. if (self.item.range_type == 1 && self.item.min_point == 0) {
  123. self.$notify({ type: 'danger', message: '固定分值不能为零' })
  124. return false
  125. }
  126. if (self.item.rule_id == 0) {
  127. self.$notify({ type: 'danger', message: '请选择积分分类' })
  128. return false
  129. }
  130. self.data.items = []
  131. if (self.item.range_type == 1) {
  132. self.item.max_point = self.item.min_point
  133. }
  134. self.data.items.push(self.item)
  135. self.send_loading = true
  136. self.$toast.loading({
  137. message: '正在处理'
  138. })
  139. request( 'post','/api/integral/rule/items',self.data).then(res => {
  140. self.send_loading = false
  141. self.$toast.clear()
  142. if (res.data.code == 1) {
  143. self.$toast('创建成功')
  144. setTimeout(() => {
  145. self.$keep_alive_update('add_item_info', {})
  146. self.$route_back()
  147. }, 500)
  148. } else {
  149. self.$toast(res.data.msg)
  150. }
  151. }).catch(e => {
  152. self.send_loading = false
  153. self.$toast.clear()
  154. })
  155. },
  156. get_point_types () {
  157. let self = this
  158. self.types_list = []
  159. let list = this.$store.getters.point_types
  160. for (let i in list) {
  161. if (list[i].code != 'JX') {
  162. if (list[i].code == 'BF') {
  163. self.item.pt_id = list[i].id
  164. }
  165. self.types_list.push(list[i])
  166. }
  167. }
  168. }
  169. },
  170. created () {
  171. if (this.$route.query.rule_id) {
  172. this.item.rule_id = this.$route.query.rule_id
  173. this.$nextTick(() => {
  174. this.rule_cate = [{id: this.item.rule_id * 1, name: this.$route.query.rule_name}]
  175. })
  176. }
  177. this.get_point_types()
  178. }
  179. }
  180. </script>
  181. <style scoped>
  182. .body_com {
  183. height: calc(100% - 0.92rem);
  184. position: relative;
  185. }
  186. </style>