123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <template>
- <div class="rule_item_add_box">
- <van-nav-bar title="创建规则" left-text="返回" @click-left="$route_back" left-arrow right-text="保存" @click-right="data_verify"></van-nav-bar>
- <div class="body_com has_header">
- <scroller>
- <van-cell-group>
- <van-cell required>
- <Mtextarea required v-model="item.remark" placeholder="输入规则内容" :text_max="100" :imgs_max="3"></Mtextarea>
- </van-cell>
- </van-cell-group>
- <van-cell-group>
- <van-cell title="分值" class="cell-right-4rem">
- <van-radio-group v-model="item.range_type" direction="horizontal" class="radio_button" slot="right-icon">
- <van-radio class="list" :name="1">固定分</van-radio>
- <van-radio class="list" :name="2">范围分</van-radio>
- </van-radio-group>
- </van-cell>
- <van-field required label="固定分值" type="Number" v-if="item.range_type == 1" v-model="item.min_point" placeholder="输入分值"/>
- <van-field required label="最小分值" type="Number" v-if="item.range_type == 2" v-model="item.min_point" placeholder="输入最小分值"/>
- <van-field required label="最大分值" type="Number" v-if="item.range_type == 2" v-model="item.max_point" placeholder="输入最大分值"/>
- </van-cell-group>
- <van-cell-group class="choose">
- <CategorySelectorCell required title="选择分类" v-model="rule_cate" :max="2" :multi="false"></CategorySelectorCell>
- </van-cell-group>
- <van-cell-group>
- <van-cell title="积分类型" class="cell-right-4rem">
- <van-radio-group v-model="item.pt_id" direction="horizontal" slot="right-icon" class="radio_button">
- <van-radio class="list" v-for="(item, index) in types_list" :name="item.id" :key="index">{{item.name}}</van-radio>
- </van-radio-group>
- </van-cell>
- </van-cell-group>
- <!--
- <van-cell-group>
- <van-cell title="奖扣周期" class="cell-right-4rem">
- <template slot="right-icon">
- <van-switch v-model="cycle" size="24" />
- </template>
- </van-cell>
- <van-cell title="考勤挂钩" class="cell-right-4rem" v-show="item.cycle_type == 2">
- <van-radio-group class="radio_button" slot="right-icon" v-model="item.is_attendance" direction="horizontal">
- <van-radio class="list" :name="0">否</van-radio>
- <van-radio class="list" :name="1">是</van-radio>
- </van-radio-group>
- </van-cell>
- </van-cell-group>
- -->
- </scroller>
- </div>
- </div>
- </template>
- <script>
- import Vue from 'vue'
- import { Switch } from 'vant'
- import request from '@/utils/request'
- import Mtextarea from '@/components/common/Mtextarea'
- import CategorySelectorCell from '@/components/common/CategorySelectorCell'
- Vue.use(Switch)
- export default {
- name: 'rule_item_add',
- components: {
- Mtextarea, CategorySelectorCell
- },
- data () {
- return {
- data: {
- items: []
- },
- rule_cate: [],
- cycle: false,
- item: {
- rule_id: 0,
- prize_type: 1,
- range_type: 1,
- min_point: 0,
- max_point: 0,
- remark: '',
- is_attendance: 0,
- cycle_type: 1,
- pt_id: 0
- },
- send_loading: false,
- types_list: []
- }
- },
- watch: {
- cycle (val) {
- if (val) {
- this.item.cycle_type = 2
- } else {
- this.item.cycle_type = 1
- }
- },
- rule_cate (val) {
- if (val.length > 0) {
- this.item.rule_id = val[0].id
- } else {
- this.item.rule_id = 0
- }
- }
- },
- methods: {
- data_verify () {
- let self = this
- self.$validator.validateAll().then(result => {
- if (!result) {
- self.$notify({type: 'danger', message: self.$validator.errors.items[0].msg})
- } else {
- self.send()
- }
- })
- },
- send () {
- let self = this
- if (self.rule_cate.length == 0) {
- self.$notify({type: 'danger', message: '请选择分类'})
- return false
- }
- if (self.item.remark == '') {
- self.$notify({type: 'danger', message: '请输入规则内容'})
- return false
- }
- if (self.item.range_type == 1 && self.item.min_point == 0) {
- self.$notify({ type: 'danger', message: '固定分值不能为零' })
- return false
- }
- if (self.item.rule_id == 0) {
- self.$notify({ type: 'danger', message: '请选择积分分类' })
- return false
- }
- self.data.items = []
- if (self.item.range_type == 1) {
- self.item.max_point = self.item.min_point
- }
- self.data.items.push(self.item)
- self.send_loading = true
- self.$toast.loading({
- message: '正在处理'
- })
- request( 'post','/api/integral/rule/items',self.data).then(res => {
- self.send_loading = false
- self.$toast.clear()
- if (res.data.code == 1) {
- self.$toast('创建成功')
- setTimeout(() => {
- self.$keep_alive_update('add_item_info', {})
- self.$route_back()
- }, 500)
- } else {
- self.$toast(res.data.msg)
- }
- }).catch(e => {
- self.send_loading = false
- self.$toast.clear()
- })
- },
- get_point_types () {
- let self = this
- self.types_list = []
- let list = this.$store.getters.point_types
- for (let i in list) {
- if (list[i].code != 'JX') {
- if (list[i].code == 'BF') {
- self.item.pt_id = list[i].id
- }
- self.types_list.push(list[i])
- }
- }
- }
- },
- created () {
- if (this.$route.query.rule_id) {
- this.item.rule_id = this.$route.query.rule_id
- this.$nextTick(() => {
- this.rule_cate = [{id: this.item.rule_id * 1, name: this.$route.query.rule_name}]
- })
- }
- this.get_point_types()
- }
- }
- </script>
- <style scoped>
- .body_com {
- height: calc(100% - 0.92rem);
- position: relative;
- }
- </style>
|