rule.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. <template>
  2. <div class="all-box">
  3. <!-- 头部提示 -->
  4. <el-alert class="diy-tip" title="如何使用积分规则?" type="success" @close="tips_close" v-if="tips_show" description show-icon>
  5. <p>先【添加规则分类】,再【添加规则】;或者直接【导入规则】</p>
  6. </el-alert>
  7. <div class="all">
  8. <div class="flex-box" v-loading="rule_loading">
  9. <div class="terr-left">
  10. <el-button size="medium" @click="add_class" type="primary">+ 添加规则分类</el-button>
  11. <div class="rule_class_box">
  12. <el-tree
  13. accordion
  14. :data="rule_tree"
  15. :expand-on-click-node="false"
  16. class="cate-tree"
  17. :props="defaultProps"
  18. :highlight-current="true"
  19. @node-click="handleNodeClick"
  20. ></el-tree>
  21. </div>
  22. </div>
  23. <div class="terr-right border-right flex-1">
  24. <div class="flex-box flex-v-ce">
  25. <div class="name">{{ selectItem.name }}</div>
  26. <el-button size="medium" plain v-if="selectItem.id" @click="edit_class">编辑</el-button>
  27. </div>
  28. <div class="flex-box btns flex-v-ce">
  29. <el-button size="small" @click="del_item" type="danger" plain>批量删除</el-button>
  30. <el-button size="small" @click="add_rule" type="primary">添加规则</el-button>
  31. <el-button size="small" @click="import_rules_show = true" plain>导入规则</el-button>
  32. </div>
  33. <el-table stripe ref="multipleTable" :data="item_list" tooltip-effect="dark" @selection-change="handleSelectionChange" @row-click="editDetails" align="center">
  34. <el-table-column type="selection" width="55"></el-table-column>
  35. <el-table-column prop="remark" label="内容" align="left"></el-table-column>
  36. <el-table-column label="分值" align="center">
  37. <template slot-scope="scope">
  38. <div v-if="scope.row.range_type == 1">
  39. <span :class="scope.row.min_point > 0 ? 'red' : 'green'">{{ scope.row.min_point }}{{ scope.row.pt_Obj.name }}</span>
  40. </div>
  41. <div v-if="scope.row.range_type == 2">
  42. <span :class="scope.row.min_point > 0 ? 'red' : 'green'">{{ scope.row.min_point }}</span>
  43. <span :class="scope.row.max_point > 0 ? 'red' : 'green'">{{ scope.row.max_point }}{{ scope.row.pt_Obj.name }}</span>
  44. </div>
  45. </template>
  46. </el-table-column>
  47. <template slot="empty">
  48. <noData></noData>
  49. </template>
  50. </el-table>
  51. </div>
  52. </div>
  53. </div>
  54. <!-- 编辑添加分类 -->
  55. <el-dialog :title="class_type == 'add' ? '添加规则分类' : '编辑规则分类'" :visible.sync="class_show" :close-on-click-modal="false" width="500px">
  56. <el-form :model="dept_formdata" ref="dept_formdata" :rules="dept_formdata_rules" label-width="80px">
  57. <el-form-item label="规则分类" prop="name"><el-input v-model="dept_formdata.name"></el-input></el-form-item>
  58. <el-form-item label="上级分类">
  59. <el-cascader
  60. v-model="dept_formdata.pid"
  61. :options="rule_tree"
  62. :props="{ checkStrictly: true, label: 'name', value: 'id', children: 'child' }"
  63. clearable
  64. ></el-cascader>
  65. </el-form-item>
  66. <el-form-item style="text-align: right; margin-bottom:0;">
  67. <el-button type="danger" @click="del_dept" v-show="class_type == 'edit'">删除分类</el-button>
  68. <el-button @click="add_dept_close('dept_formdata')">取消</el-button>
  69. <el-button type="primary" @click="submit_add_dept('dept_formdata')" :loading="dept_loading">确定</el-button>
  70. </el-form-item>
  71. </el-form>
  72. </el-dialog>
  73. <!-- 添加编辑规则 -->
  74. <el-dialog :title="rule_type == 'add' ? '添加规则' : '编辑规则'" :visible.sync="rule_show" :close-on-click-modal="false" width="550px">
  75. <el-form :model="rules_detail_form" ref="rules_detail_form" :rules="rules" label-width="80px">
  76. <el-form-item label="规则内容" prop="remark">
  77. <el-input v-model="rules_detail_form.remark" placeholder="请输入规则内容" type="textarea" :rows="3" maxlength="100" show-word-limit></el-input>
  78. </el-form-item>
  79. <el-form-item label="所属分类" prop="rule_id">
  80. <div style="position: relative;">
  81. <div
  82. style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 9;"
  83. @click="not_data"
  84. v-show="rule_tree !== null && rule_tree.length == 0"
  85. ></div>
  86. <el-cascader
  87. placeholder="请选择分类"
  88. v-model="rules_detail_form.rule_id"
  89. @visible-change="select_rule"
  90. :options="rule_tree"
  91. :props="{ checkStrictly: true, label: 'name', value: 'id', children: 'child' }"
  92. ></el-cascader>
  93. </div>
  94. </el-form-item>
  95. <el-form-item label="规则类型" prop="pt_id">
  96. <el-radio v-model="rules_detail_form.pt_id" :label="item.id" v-for="(item, index) in point_types" :key="index" v-show="item.name !== '绩效分'">
  97. {{ item.name }}
  98. </el-radio>
  99. </el-form-item>
  100. <el-form-item label="规则积分" prop="range_type">
  101. <el-radio-group v-model="rules_detail_form.range_type">
  102. <el-radio :label="item.value" v-for="(item, index) in range_type_arr" :key="index">{{ item.name }}</el-radio>
  103. </el-radio-group>
  104. </el-form-item>
  105. <el-form-item>
  106. <el-row :gutter="20" class="select_width">
  107. <el-col :span="11">
  108. <el-input
  109. placeholder="请输入分值"
  110. :rules="[{ required: true, message: '请输入加分项名称', trigger: 'blur' }]"
  111. v-model="rules_detail_form.min_point"
  112. type="Number"
  113. class="input-with-select"
  114. >
  115. <el-select v-model="integral_select_name1" slot="prepend" placeholder="请选择类型">
  116. <el-option v-for="(item, index) in integral_select" :key="index" :label="item.name" :value="item.value"></el-option>
  117. </el-select>
  118. </el-input>
  119. </el-col>
  120. <el-col :span="2" v-show="rules_detail_form.range_type == 2">至</el-col>
  121. <el-col :span="11" v-show="rules_detail_form.range_type == 2">
  122. <el-input
  123. placeholder="请输入分值"
  124. :rules="[{ required: true, message: '请输入加分项名称', trigger: 'blur' }]"
  125. v-model="rules_detail_form.max_point"
  126. type="Number"
  127. class="input-with-select"
  128. >
  129. <el-select v-model="integral_select_name2" slot="prepend" placeholder="请选择类型" style="width: 100px;">
  130. <el-option v-for="(item, index) in integral_select" :key="index" :label="item.name" :value="item.value"></el-option>
  131. </el-select>
  132. </el-input>
  133. </el-col>
  134. </el-row>
  135. </el-form-item>
  136. <el-form-item style="text-align: right; margin-bottom:0;">
  137. <el-button type="danger" @click="del_rule" :loading="delRule_loading" v-show="rule_type == 'edit'">删除规则</el-button>
  138. <el-button @click="rule_close('rules_detail_form')">取消</el-button>
  139. <el-button type="primary" v-show="rule_type == 'add'" :loading="rule_loading2" @click="add_submit_rule('rules_detail_form')">确定</el-button>
  140. <el-button type="primary" v-show="rule_type == 'edit'" :loading="rule_loading2" @click="edit_submit_rule('rules_detail_form')">确定</el-button>
  141. </el-form-item>
  142. </el-form>
  143. </el-dialog>
  144. <!-- 导入规则 -->
  145. <el-dialog title="导入规则" :visible.sync="import_rules_show" width="500px" @before-close="close_import">
  146. <el-row>
  147. <el-col :span="12">
  148. <div class="text-center">
  149. <p>1、下载规则模版,填写好规则</p>
  150. <p><img src="../assets/image/rules_mould.png" alt="" /></p>
  151. <p>规则表</p>
  152. <p>
  153. <a target="_blank" :href="'/api/download/rule_item'"><el-button type="primary">下载模板</el-button></a>
  154. </p>
  155. </div>
  156. </el-col>
  157. <el-col :span="12">
  158. <div class="text-center">
  159. <p>2、上传填好的规则表</p>
  160. <p><img src="../assets/image/rules_mould1.png" alt="" /></p>
  161. <p>仅支持xls、xlsx格式文件</p>
  162. <el-upload
  163. class="upload-demo"
  164. :headers="ATOKEN"
  165. :data="{ type: 'rule_item' }"
  166. ref="upload"
  167. :limit="1"
  168. action="https://ding.insys.g107.com/api/upload/excel"
  169. :on-preview="handlePreview"
  170. :on-remove="handleRemove"
  171. :on-success="handleSuccess"
  172. :before-upload="beforeFilesUpload"
  173. :file-list="fileList"
  174. >
  175. <el-button slot="trigger" type="primary">选取文件</el-button>
  176. </el-upload>
  177. <p><el-button type="primary" @click="submitUpload" :loading="save_loading" v-show="import_btn_show" block>导入</el-button></p>
  178. </div>
  179. </el-col>
  180. </el-row>
  181. </el-dialog>
  182. </div>
  183. </template>
  184. <script>
  185. import noData from '@/components/noData';
  186. export default {
  187. data() {
  188. return {
  189. ATOKEN: { 'A-TOKEN': this.$getToken() },
  190. tips_show: true,
  191. rule_loading: false,
  192. rule_tree: [],
  193. item_list: [],
  194. all_item_list: [],
  195. defaultProps: {
  196. id: 'id',
  197. children: 'child',
  198. label: 'name'
  199. },
  200. selectItem: { name: '积分分类' }, //选择的分类
  201. //添加分类
  202. class_show: false,
  203. delRule_loading:false,
  204. dept_formdata_rules: {
  205. name: [
  206. {
  207. required: true,
  208. message: '请输入规则分类',
  209. trigger: 'blur'
  210. },
  211. {
  212. min: 2,
  213. max: 20,
  214. message: '长度在 2 到 20 个字符',
  215. trigger: 'blur'
  216. }
  217. ]
  218. },
  219. dept_formdata: {
  220. name: '',
  221. pid: '0',
  222. cycle_type: '1'
  223. },
  224. class_type: 'add',
  225. dept_loading:false,
  226. // 规则相关
  227. del_item_id: [], //选择规则ID集合
  228. rule_loading2: false,
  229. rule_type: 'add',
  230. rule_show: false,
  231. rules_detail_form: {
  232. rule_id: '',
  233. range_type: '1',
  234. prize_type: '0',
  235. min_point: '',
  236. max_point: '',
  237. remark: '',
  238. is_attendance: '0',
  239. cycle_type: '1',
  240. pt_id: 0
  241. },
  242. rules: {
  243. remark: [
  244. {
  245. required: true,
  246. message: '请输入规则名称',
  247. trigger: 'blur'
  248. }
  249. ],
  250. rule_id: [
  251. {
  252. required: true,
  253. message: '请选择分类',
  254. trigger: 'change'
  255. }
  256. ]
  257. },
  258. integral_select_name1: '1',
  259. integral_select_name2: '1',
  260. point_types: [],
  261. range_type_arr: [
  262. {
  263. name: '固定分值',
  264. value: '1'
  265. },
  266. {
  267. name: '范围分值',
  268. value: '2'
  269. }
  270. ],
  271. integral_select: [
  272. {
  273. name: '奖分',
  274. value: '1'
  275. },
  276. {
  277. name: '扣分',
  278. value: '2'
  279. }
  280. ],
  281. //导入规则
  282. import_rules_show: false,
  283. save_loading: false,
  284. import_btn_show: false,
  285. fileList: [],
  286. file: null,
  287. flName:'',
  288. };
  289. },
  290. components: {
  291. noData
  292. },
  293. created() {
  294. this.point_types = this.$getTyps();
  295. this.getData();
  296. },
  297. mounted() {
  298. this.$nextTick(function() {
  299. if (localStorage.getItem('rule')) {
  300. this.tips_show = false;
  301. } else {
  302. this.tips_show = true;
  303. }
  304. });
  305. },
  306. methods: {
  307. // 导入相关
  308. close_import() {
  309. this.import_rules_show = false;
  310. this.import_btn_show = false;
  311. this.$refs.upload.clearFiles();
  312. },
  313. submitUpload() {
  314. this.save_loading = true;
  315. let params = {
  316. file: this.file
  317. };
  318. this.$axios.post('/api/rule/import', params).then(res => {
  319. if (res.data.code == 1) {
  320. this.close_import();
  321. this.$message.success({ message: res.data.msg });
  322. this.getData();
  323. } else {
  324. this.$message({ type: 'error', message: res.data.msg });
  325. }
  326. }).finally(() => {
  327. this.save_loading = false;
  328. });
  329. },
  330. handleSuccess(response) {
  331. if (response.code == 1) {
  332. this.file = response.data;
  333. }
  334. },
  335. handleRemove(file, fileList) {
  336. if (fileList !== null && fileList.length != 0) {
  337. this.import_btn_show = true;
  338. } else {
  339. this.import_btn_show = false;
  340. }
  341. },
  342. handlePreview(file) {
  343. console.log(file);
  344. },
  345. imgChange(file, fileList) {
  346. if (fileList !== null && fileList.length != 0) {
  347. this.import_btn_show = true;
  348. } else {
  349. this.import_btn_show = false;
  350. }
  351. },
  352. beforeFilesUpload(file) {
  353. const $ext_list = ['xlsx', 'xls'];
  354. let len = file.name.split('.').length - 1;
  355. const $ext_name = file.name.split('.')[len];
  356. if ($ext_list.indexOf($ext_name) != -1) {
  357. this.import_btn_show = true;
  358. } else {
  359. this.$message.warning('文件格式上传错误,仅支持上传xlsx,xls)');
  360. return false;
  361. }
  362. },
  363. edit_submit_rule(form) {
  364. this.rule_loading2=true;
  365. let self = this;
  366. self.$refs[form].validate(valid => {
  367. if (valid) {
  368. if (self.integral_select_name1 != '1' && self.rules_detail_form.min_point >= 0) {
  369. self.rules_detail_form.min_point = '-' + self.rules_detail_form.min_point;
  370. }
  371. if (self.integral_select_name2 != '1' && self.rules_detail_form.max_point >= 0) {
  372. self.rules_detail_form.max_point = '-' + self.rules_detail_form.max_point;
  373. }
  374. if (self.rules_detail_form.range_type == 1) {
  375. self.rules_detail_form.max_point = self.rules_detail_form.min_point;
  376. }
  377. if (parseFloat(self.rules_detail_form.min_point) > parseFloat(self.rules_detail_form.max_point)) {
  378. this.$confirm(
  379. '填写的规则积分是' +
  380. self.rules_detail_form.min_point +
  381. ' ~ ' +
  382. self.rules_detail_form.max_point +
  383. ',应该是 ' +
  384. self.rules_detail_form.max_point +
  385. ' ~ ' +
  386. self.rules_detail_form.min_point +
  387. '吧?',
  388. '提示',
  389. {
  390. confirmButtonText: '确定',
  391. cancelButtonText: '取消',
  392. type: 'warning'
  393. }
  394. )
  395. .then(() => {
  396. let min_point = self.rules_detail_form.min_point;
  397. self.rules_detail_form.min_point = self.rules_detail_form.max_point;
  398. self.rules_detail_form.max_point = min_point;
  399. let data = self.rules_detail_form;
  400. data.item_id = self.rules_detail_form.id;
  401. if (self.rules_detail_form.min_point == 0 && self.rules_detail_form.range_type == 1) {
  402. self.$message.error('积分不能为零');
  403. this.rule_loading2=false;
  404. return false;
  405. }
  406. this.$axios.post('/api/integral/rule/items/edit', data).then(res => {
  407. if (res.data.code == 1) {
  408. self.$message.success(res.data.msg);
  409. self.getData();
  410. self.rule_close(form);
  411. }
  412. }).finally(err=>{
  413. this.rule_loading2=false;
  414. });
  415. })
  416. } else {
  417. self.rules_detail_form.item_id = self.rules_detail_form.id;
  418. let data = self.rules_detail_form;
  419. data.item_id = self.rules_detail_form.id;
  420. if (self.rules_detail_form.min_point == 0 && self.rules_detail_form.range_type == 1) {
  421. self.$message.error('积分不能为零');
  422. this.rule_loading2=false;
  423. return false;
  424. }
  425. this.$axios.post('/api/integral/rule/items/edit', data).then(res => {
  426. if (res.data.code == 1) {
  427. self.$message.success(res.data.msg);
  428. self.getData();
  429. self.rule_close(form);
  430. }
  431. }).finally(() => {
  432. this.rule_loading2 = false;
  433. });
  434. }
  435. } else {
  436. this.rule_loading2=false;
  437. return false;
  438. }
  439. });
  440. },
  441. //添加规则
  442. add_submit_rule(form) {
  443. this.rule_loading2=true;
  444. let self = this;
  445. self.$refs[form].validate(valid => {
  446. if (valid) {
  447. if (self.integral_select_name1 != '1' && self.rules_detail_form.min_point >= 0) {
  448. self.rules_detail_form.min_point = '-' + self.rules_detail_form.min_point;
  449. }
  450. if (self.integral_select_name2 != '1' && self.rules_detail_form.max_point >= 0) {
  451. self.rules_detail_form.max_point = '-' + self.rules_detail_form.max_point;
  452. }
  453. if (self.rules_detail_form.range_type == 1) {
  454. self.rules_detail_form.max_point = self.rules_detail_form.min_point;
  455. }
  456. if (parseFloat(self.rules_detail_form.min_point) > parseFloat(self.rules_detail_form.max_point)) {
  457. this.$confirm(
  458. '填写的规则积分是' +
  459. self.rules_detail_form.min_point +
  460. ' ~ ' +
  461. self.rules_detail_form.max_point +
  462. ',应该是 ' +
  463. self.rules_detail_form.max_point +
  464. ' ~ ' +
  465. self.rules_detail_form.min_point +
  466. '吧?',
  467. '提示',
  468. {
  469. confirmButtonText: '确定',
  470. cancelButtonText: '取消',
  471. type: 'warning'
  472. }
  473. ).then(() => {
  474. let min_point = self.rules_detail_form.min_point;
  475. self.rules_detail_form.min_point = self.rules_detail_form.max_point;
  476. self.rules_detail_form.max_point = min_point;
  477. if (self.rules_detail_form.min_point == 0 && self.rules_detail_form.range_type == 1) {
  478. self.$message.error('积分不能为零');
  479. this.rule_loading2=false;
  480. return false;
  481. }
  482. let data = {
  483. items: [self.rules_detail_form]
  484. };
  485. this.$axios
  486. .post('/api/integral/rule/items', data)
  487. .then(res => {
  488. if (res.data.code == 1) {
  489. self.$message.success(res.data.msg);
  490. self.getData();
  491. self.rule_close(form);
  492. }
  493. }).finally(() => {
  494. this.rule_loading2 = false;
  495. });
  496. });
  497. } else {
  498. self.rules_detail_form.item_id = self.rules_detail_form.id;
  499. if (self.rules_detail_form.min_point == 0 && self.rules_detail_form.range_type == 1) {
  500. self.$message.error('积分不能为零');
  501. this.rule_loading2=false;
  502. return false;
  503. }
  504. let data = {
  505. items: [self.rules_detail_form]
  506. };
  507. this.$axios.post('/api/integral/rule/items', data).then(res => {
  508. if (res.data.code == 1) {
  509. self.$message.success(res.data.msg);
  510. self.getData();
  511. self.rule_close(form);
  512. }
  513. }).finally(() => {
  514. this.rule_loading2 = false;
  515. });
  516. }
  517. } else {
  518. this.rule_loading2=false;
  519. return false;
  520. }
  521. });
  522. },
  523. //删除规则
  524. del_rule() {
  525. let self = this;
  526. let data = {
  527. item_id: [this.rules_detail_form.id]
  528. };
  529. this.delRule_loading=true;
  530. self.$confirm('此操作将永久删除该选项, 是否继续?', '提示').then(() => {
  531. this.$axios.post('/api/integral/rule/items/destroy', data).then(res => {
  532. if (res.data.code == 1) {
  533. self.$message.success(res.data.msg);
  534. self.rule_show = false;
  535. self.getData(true);
  536. }
  537. }).finally(() => {
  538. this.delRule_loading = false;
  539. });
  540. });
  541. },
  542. //关闭规则弹窗
  543. rule_close(form) {
  544. this.rule_show = false;
  545. this.$refs[form].resetFields();
  546. },
  547. select_rule(val) {
  548. if (!val) {
  549. this.rules_detail_form.rule_id = this.rules_detail_form.rule_id[this.rules_detail_form.rule_id.length - 1];
  550. }
  551. },
  552. not_data() {
  553. this.$confirm('暂时没有积分分类,是否前往添加?', '提示', {
  554. confirmButtonText: '确定',
  555. cancelButtonText: '取消',
  556. type: 'warning'
  557. }).then(() => {
  558. this.rule_show = false;
  559. this.class_show = true;
  560. })
  561. },
  562. add_rule() {
  563. this.rule_show = true;
  564. this.rule_type = 'add';
  565. this.rules_detail_form = {
  566. rule_id: '',
  567. range_type: '1',
  568. prize_type: '0',
  569. min_point: '',
  570. max_point: '',
  571. remark: '',
  572. is_attendance: '0',
  573. cycle_type: '1',
  574. pt_id: 2
  575. };
  576. this.integral_select_name1 = '1';
  577. this.integral_select_name2 = '1';
  578. },
  579. del_item() {
  580. if (this.del_item_id.length == 0) {
  581. this.$message.error('请选择积分细则');
  582. return false;
  583. }
  584. this.$confirm('此操作将永久删除该选项, 是否继续?', '提示', {
  585. confirmButtonText: '确定',
  586. cancelButtonText: '取消',
  587. type: 'warning'
  588. }).then(() => {
  589. let data = {
  590. item_id: this.del_item_id
  591. };
  592. this.$axios
  593. .post('/api/integral/rule/items/destroy', data)
  594. .then(res => {
  595. if (res.data.code == 1) {
  596. this.$message.success(res.data.msg);
  597. this.getData(true);
  598. this.handleNodeClick(this.selectItem);
  599. }
  600. })
  601. });
  602. },
  603. editDetails(val) {
  604. this.rules_detail_form = JSON.parse(JSON.stringify(val));
  605. if (this.rules_detail_form.min_point == this.rules_detail_form.max_point) {
  606. this.rules_detail_form.range_type = '1';
  607. } else {
  608. this.rules_detail_form.range_type = '2';
  609. }
  610. if (this.rules_detail_form.min_point < 0) {
  611. this.integral_select_name1 = '2';
  612. } else {
  613. this.integral_select_name1 = '1';
  614. }
  615. if (this.rules_detail_form.max_point < 0) {
  616. this.integral_select_name2 = '2';
  617. } else {
  618. this.integral_select_name2 = '1';
  619. }
  620. this.rule_show = true;
  621. this.rule_type = 'edit';
  622. },
  623. handleSelectionChange(val) {
  624. this.del_item_id = [];
  625. val.forEach(element => {
  626. this.del_item_id.push(element.id);
  627. });
  628. },
  629. handleNodeClick(e) {
  630. var items = this.getItemData(e);
  631. this.selectItem = {
  632. child: e.child,
  633. id: e.id,
  634. name:e.name,
  635. pid: e.pid,
  636. };
  637. this.flName=e.name;
  638. this.item_list = items;
  639. },
  640. getItemData(e) {
  641. var ids = [];
  642. var lists = [];
  643. if (e.child && e.child.length > 0) {
  644. ids.push(e.id);
  645. e.child.map(item => {
  646. ids.push(item.id);
  647. if (item.child && item.child.length > 0) {
  648. item.child.map(item1 => {
  649. ids.push(item1.id);
  650. if (item1.child && item1.child.length > 0) {
  651. item1.child.map(item2 => {
  652. ids.push(item2.id);
  653. });
  654. }
  655. });
  656. }
  657. });
  658. for (var i = 0; i < ids.length; i++) {
  659. lists.push(...this.filterItem(ids[i]));
  660. }
  661. } else {
  662. lists = this.filterItem(e.id);
  663. }
  664. return lists;
  665. },
  666. //根据分类ID获取对应的规则
  667. filterItem(id) {
  668. var all_item_list = this.all_item_list;
  669. var items = all_item_list.filter(item => {
  670. return item.rule_id == id;
  671. });
  672. return items;
  673. },
  674. getData(is) {
  675. this.rule_loading = true;
  676. var that = this;
  677. this.$axios.get('api/integral/rule/trees', { params: { cycle_type: 1 } }).then(res => {
  678. var item_list = res.data.data.item_list || [];
  679. var list = [];
  680. for (let i in item_list) {
  681. for (let k in item_list[i]) {
  682. item_list[i][k].pt_Obj = that.$getTyps(item_list[i][k].pt_id);
  683. list.push(item_list[i][k]);
  684. }
  685. }
  686. that.rule_tree = res.data.data.rule_tree || [];
  687. that.item_list = list;
  688. that.all_item_list = list;
  689. if (is) {
  690. that.handleNodeClick(that.selectItem);
  691. } else {
  692. this.selectItem = { name: '积分分类' }; //选择的分类
  693. }
  694. }).finally(() => {
  695. this.rule_loading = false;
  696. });
  697. },
  698. //编辑分组
  699. edit_class() {
  700. this.class_show = true;
  701. this.class_type = 'edit';
  702. this.dept_formdata={
  703. child: this.selectItem.child,
  704. id: this.selectItem.id,
  705. name: this.selectItem.name,
  706. pid: this.selectItem.pid,
  707. }
  708. },
  709. //添加分组
  710. submit_add_dept(form) {
  711. this.dept_loading=true;
  712. let that = this;
  713. that.$refs[form].validate(valid => {
  714. if (valid) {
  715. if (that.class_type == 'edit') {
  716. delete that.dept_formdata.child;
  717. that.dept_formdata.rule_id = that.dept_formdata.id;
  718. if(typeof(that.dept_formdata.pid)=='number'){
  719. }else{
  720. if(that.dept_formdata.pid.length>0){
  721. that.dept_formdata.pid =that.dept_formdata.pid[that.dept_formdata.pid.length - 1];
  722. }else{
  723. that.dept_formdata.pid=0;
  724. }
  725. }
  726. this.$axios.post('/api/integral/rule/edit', that.dept_formdata).then(res => {
  727. if (res.data.code == 1) {
  728. that.selectItem.name=that.dept_formdata.name;
  729. that.$message.success('修改积分分类成功');
  730. this.getData(true);
  731. this.add_dept_close('dept_formdata');
  732. }
  733. }).finally(() => {
  734. this.dept_loading = false;
  735. });
  736. } else {
  737. if (that.dept_formdata.pid !== null && that.dept_formdata.pid.length == 0) {
  738. that.dept_formdata.pid = 0;
  739. } else {
  740. that.dept_formdata.pid = that.dept_formdata.pid[that.dept_formdata.pid.length - 1];
  741. }
  742. this.$axios.post('/api/integral/rule', that.dept_formdata).then(res => {
  743. if (res.data.code == 1) {
  744. that.$message.success('添加积分分类成功');
  745. this.getData(true);
  746. this.add_dept_close('dept_formdata');
  747. }
  748. }).finally(() => {
  749. this.dept_loading = false;
  750. });
  751. }
  752. } else {
  753. this.dept_loading=false;
  754. }
  755. });
  756. },
  757. //删除分组
  758. del_dept() {
  759. this.$confirm('此操作将永久删除该分组, 是否继续?', '提示', {
  760. confirmButtonText: '确定',
  761. cancelButtonText: '取消',
  762. type: 'warning'
  763. }).then(() => {
  764. this.$axios.post('/api/integral/rule/destroy', { rule_id: this.selectItem.id }).then(res => {
  765. if (res.data.code == 1) {
  766. this.$message.success(res.data.msg);
  767. this.getData();
  768. this.add_dept_close('dept_formdata');
  769. }
  770. });
  771. });
  772. },
  773. //关闭弹窗
  774. add_dept_close(form) {
  775. this.class_show = false;
  776. // this.$refs[form].resetFields();
  777. },
  778. //关闭提示
  779. tips_close() {
  780. localStorage.setItem('rule', 'true');
  781. this.tips_show = false;
  782. },
  783. //添加分类
  784. add_class() {
  785. this.class_show = true;
  786. this.class_type = 'add';
  787. this.dept_formdata = {
  788. name: '',
  789. pid: '0',
  790. cycle_type: '1'
  791. };
  792. }
  793. }
  794. };
  795. </script>
  796. <style scoped lang="scss">
  797. .select_width .el-select {
  798. width: 80px;
  799. }
  800. .text-center {
  801. text-align: center;
  802. }
  803. .text-center p {
  804. padding: 10px 0;
  805. }
  806. .terr-right {
  807. .name {
  808. font-size: 18px;
  809. margin-right: 20px;
  810. }
  811. .btns button {
  812. margin-top: 20px;
  813. margin-right: 5px;
  814. }
  815. }
  816. .rule_class_box {
  817. ::v-deep .el-tree-node {
  818. border-bottom: 1px #f8f8f8 solid;
  819. }
  820. ::v-deep .el-tree-node__content {
  821. padding: 10px 0;
  822. border-bottom: 1px #f8f8f8 solid;
  823. }
  824. ::v-deep .el-tree-node__content:hover {
  825. background: #ecf5ff;
  826. border-radius: 4px;
  827. }
  828. ::v-deep .is-current .el-tree-node__content .el-icon-caret-right {
  829. color: #409eff !important;
  830. }
  831. ::v-deep .is-current .el-tree-node__content .el-tree-node__label {
  832. color: #409eff !important;
  833. }
  834. ::v-deep .is-current .el-tree-node__children .el-icon-caret-right {
  835. color: #c0c4cc !important;
  836. }
  837. ::v-deep .is-current .el-tree-node__children .el-tree-node__label {
  838. color: #606266 !important;
  839. }
  840. ::v-deep .el-tree-node__label {
  841. overflow: hidden;
  842. text-overflow: ellipsis;
  843. white-space: nowrap;
  844. }
  845. }
  846. .terr-left button {
  847. margin: 0 auto;
  848. display: block;
  849. margin-bottom: 20px;
  850. }
  851. </style>