pk_rules.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div style="height: 100%">
  3. <div class="pk_rules_scroller">
  4. <scroller>
  5. <div style="padding: 0 0.32rem">
  6. <van-panel class="rule_list" v-for="(item,index) in rules_list " :key="index" :title="item.name">
  7. <div class="rule_btn" v-if="hasPermission && pkStatus !== 'end'">
  8. <van-button color="#238dfa" type="primary" @click="edit_rule_btn(item)" size="mini">修改</van-button>
  9. <van-button type="danger" @click="del_rule(get_id,item)" size="mini">删除</van-button>
  10. </div>
  11. </van-panel>
  12. </div>
  13. <noData :list="rules_list"></noData>
  14. </scroller>
  15. </div>
  16. <div style="padding: 0 0.32rem;" v-if="hasPermission && pkStatus !== 'end'">
  17. <van-button type="info" block @click="add_rule_btn">新增规则</van-button>
  18. </div>
  19. <template v-else>
  20. <div style="padding: 0 0.32rem;" v-for="(item, index) in pk_info.manager_ids" :key="index">
  21. <van-button v-if="$store.getters.user_info.id == item && pkStatus !== 'end'" type="info" block
  22. @click="add_rule_btn">新增规则</van-button>
  23. </div>
  24. </template>
  25. <!-- 添加规则弹窗 -->
  26. <van-dialog class="pk_rule" v-model="show_Rule" :closeOnClickOverlay="false" :beforeClose="colseRules"
  27. show-cancel-button>
  28. <van-cell-group>
  29. <van-field v-model="popup_rules_input" rows="2" autosize label="规则" label-width="40" type="textarea"
  30. maxlength="50" placeholder="请填写规则+积分值,以便成员阅读" />
  31. </van-cell-group>
  32. </van-dialog>
  33. </div>
  34. </template>
  35. <script>
  36. import request from '@/utils/request'
  37. import Vue from 'vue'
  38. import { Panel, Dialog } from 'vant'
  39. Vue.use(Panel).use(Dialog)
  40. export default {
  41. props: {
  42. get_id: {
  43. type: String,
  44. default: '',
  45. },
  46. get_page: {
  47. type: Number,
  48. default: 1
  49. },
  50. pkStatus: {
  51. type: String,
  52. default: '',
  53. },
  54. createInfo: {
  55. type: Object,
  56. default: {}
  57. }
  58. },
  59. // 数据
  60. data() {
  61. return {
  62. show: false,
  63. rules_list: null,
  64. show_Rule: false,
  65. popup_rules_input: '',
  66. popup_rules_id: '',
  67. rules_type: 'add',
  68. pk_info: {},
  69. }
  70. },
  71. name: "pk_rules",
  72. computed: {
  73. hasPermission() {
  74. const { createInfo } = this;
  75. const { is_creator, id } = this.$store.getters.user_info
  76. return is_creator == 1 || id == createInfo.creatorId || createInfo.manages.has(id.toString())
  77. }
  78. },
  79. // 方法
  80. methods: {
  81. // 规则弹出显示
  82. showPopup() {
  83. this.show = true;
  84. },
  85. // 查询规则列表
  86. get_rules_list(id, page) {
  87. let self = this
  88. self.showLoading()
  89. request('get','/api/integral/pk/rules',{ pk_id: id, page: page,page_size:1000 }).then((res) => {
  90. if (res.data.code == '1') {
  91. self.$toast.clear()
  92. self.rules_list = res.data.data.list.list
  93. } else {
  94. self.$toast.clear()
  95. self.$toast(res.data.msg)
  96. }
  97. }).catch((e) => {
  98. self.$toast.clear()
  99. })
  100. },
  101. //删除规则
  102. del_rule(id, d) {
  103. let self = this
  104. Dialog.confirm({
  105. title: '提示',
  106. message: '确定删除此项?'
  107. }).then(() => {
  108. self.showLoading()
  109. request('delete','/api/integral/pk/rules',{ pk_id: id, rule_id: d.id }).then((res) => {
  110. if (res.data.code == 1) {
  111. self.$toast.clear()
  112. self.$toast(res.data.msg)
  113. self.get_rules_list(self.get_id, self.get_page)
  114. } else {
  115. self.$toast.clear()
  116. self.$toast(res.data.msg)
  117. }
  118. }).catch((e) => {
  119. self.$toast.clear()
  120. })
  121. }).catch(() => {
  122. // on cancel
  123. });
  124. },
  125. // 关闭 rule_popup
  126. colseRules(action, done) {
  127. let self = this
  128. if (action == 'confirm') {
  129. if (self.popup_rules_input) {
  130. if (self.rules_type == 'edit') {
  131. self.edit_rule()
  132. } else {
  133. self.add_rule(self.get_id)
  134. }
  135. done()
  136. } else {
  137. self.$notify({ type: 'danger', message: '规则不能为空' });
  138. done(false)
  139. }
  140. } else {
  141. done()
  142. }
  143. },
  144. // 编辑规则按钮
  145. edit_rule_btn(item) {
  146. this.show_Rule = true
  147. this.rules_type = 'edit'
  148. this.popup_rules_input = item.name
  149. this.popup_rules_id = item.id
  150. },
  151. // 新增规则按钮
  152. add_rule_btn() {
  153. this.show_Rule = true
  154. this.rules_type = 'add'
  155. this.popup_rules_input = ''
  156. this.popup_rules_id = ''
  157. },
  158. // 创建规则
  159. add_rule(pk_id) {
  160. let self = this
  161. self.showLoading()
  162. request('post','/api/integral/pk/rules/create',{ pk_id: pk_id, rule_name: self.popup_rules_input }).then((res) => {
  163. if (res.data.code == 1) {
  164. self.$toast.clear()
  165. self.get_rules_list(self.get_id, self.get_page)
  166. } else {
  167. self.$toast.clear()
  168. self.$toast(res.data.msg)
  169. }
  170. }).catch((e) => {
  171. self.$toast.clear()
  172. self.$toast(res.data.msg)
  173. })
  174. },
  175. // 编辑规则
  176. edit_rule() {
  177. let self = this
  178. self.showLoading()
  179. request('post','/api/integral/pk/rules',{ pk_id: self.get_id, rule_id: self.popup_rules_id, rule_name: self.popup_rules_input }).then((res) => {
  180. if (res.data.code == 1) {
  181. self.$toast.clear()
  182. self.get_rules_list(self.get_id, self.get_page)
  183. } else {
  184. self.$toast.clear()
  185. self.$toast(res.data.msg)
  186. }
  187. }).catch((e) => {
  188. self.$toast.clear()
  189. self.$toast(res.data.msg)
  190. })
  191. },
  192. // 加载
  193. showLoading() {
  194. this.$toast.loading({
  195. loadingType: "spinner",
  196. message: '正在处理'
  197. })
  198. },
  199. get_pk_info() {
  200. let self = this
  201. let data = {
  202. pk_id: self.$route.query.id
  203. }
  204. request('get','/api/integral/pk/info',data).then((res) => {
  205. if (res.data.code == 1) {
  206. self.pk_info = res.data.data || {}
  207. } else {
  208. self.$toast(res.data.msg)
  209. }
  210. })
  211. }
  212. },
  213. // 生命周期 --- 创建完成
  214. created() {
  215. // created 创建完毕状态
  216. this.get_rules_list(this.get_id, this.get_page)
  217. this.get_pk_info()
  218. },
  219. };
  220. </script>
  221. <style scoped>
  222. .read_pk_box .rule_alert {
  223. position: relative;
  224. width: calc(100vw - 0.64rem);
  225. margin: 0.2rem auto 0;
  226. }
  227. .read_pk_box /deep/ .van-overlay {
  228. position: absolute;
  229. top: 0;
  230. left: 0;
  231. width: 100vw;
  232. height: 100vh !important;
  233. background: rgba(255, 255, 255, 0.7);
  234. }
  235. .pk_rules_scroller {
  236. position: relative;
  237. height: calc(100% - 1.1rem);
  238. }
  239. </style>