group.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. const { cssNumber } = require("jquery");
  2. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'toastr'], function ($, undefined, Backend, Table, Form, Toastr) {
  3. var Controller = {
  4. index: function () {
  5. var groupIndex = new Vue({
  6. el: "#groupIndex",
  7. data() {
  8. return {
  9. data: [],
  10. offset: 0,
  11. limit: 10,
  12. totalPage: 0,
  13. currentPage: 1,
  14. }
  15. },
  16. created() {
  17. this.getData();
  18. },
  19. methods: {
  20. getData() {
  21. let that = this;
  22. Fast.api.ajax({
  23. url: 'shopro/user/group/index',
  24. loading: true,
  25. type: 'GET',
  26. data: {
  27. offset: that.offset,
  28. limit: that.limit,
  29. },
  30. }, function (ret, res) {
  31. that.data = res.data.rows;
  32. that.totalPage = res.data.total;
  33. return false;
  34. })
  35. },
  36. operation(type, id) {
  37. let that = this;
  38. switch (type) {
  39. case 'create':
  40. Fast.api.open('shopro/user/group/add', '新建', {
  41. callback() {
  42. that.getData();
  43. }
  44. })
  45. break;
  46. case 'edit':
  47. Fast.api.open('shopro/user/group/edit?ids=' + id, '编辑', {
  48. callback() {
  49. that.getData();
  50. }
  51. })
  52. break;
  53. case 'del':
  54. that.$confirm('此操作将永久直接删除用户, 是否继续?', '提示', {
  55. confirmButtonText: '确定',
  56. cancelButtonText: '取消',
  57. type: 'warning'
  58. }).then(() => {
  59. Fast.api.ajax({
  60. url: 'shopro/user/group/del/ids/' + id,
  61. loading: true,
  62. type: 'POST',
  63. }, function (ret, res) {
  64. that.getData();
  65. })
  66. return false;
  67. }).catch(() => {
  68. that.$message({
  69. type: 'info',
  70. message: '已取消删除'
  71. });
  72. });
  73. break;
  74. }
  75. },
  76. handleSizeChange(val) {
  77. this.offset = 0
  78. this.limit = val;
  79. this.currentPage = 1;
  80. this.getData()
  81. },
  82. handleCurrentChange(val) {
  83. this.currentPage = val;
  84. this.offset = (val - 1) * this.limit;
  85. this.getData()
  86. },
  87. tableRowClassName({
  88. rowIndex
  89. }) {
  90. if (rowIndex % 2 == 1) {
  91. return 'bg-color';
  92. }
  93. return '';
  94. },
  95. tableCellClassName({
  96. columnIndex
  97. }) {
  98. if (columnIndex == 1 || columnIndex == 4) {
  99. return 'cell-left';
  100. }
  101. return '';
  102. },
  103. },
  104. })
  105. },
  106. recyclebin: function () {},
  107. add: function () {
  108. Controller.detailInit('add')
  109. },
  110. edit: function () {
  111. Controller.detailInit('edit')
  112. },
  113. detailInit: function (type) {
  114. var groupDetail = new Vue({
  115. el: "#groupDetail",
  116. data() {
  117. return {
  118. detailForm: {},
  119. detailFormInit: {
  120. name: '',
  121. image: '',
  122. rules_arr: [],
  123. rules: '',
  124. status: 'normal'
  125. },
  126. fromRules: {
  127. name: [{
  128. required: true,
  129. message: '请输入组名',
  130. trigger: 'blur'
  131. }],
  132. image: [{
  133. required: true,
  134. message: '请选择图片',
  135. trigger: 'blur'
  136. }],
  137. status: [{
  138. required: true,
  139. message: '请选择状态',
  140. trigger: 'blur'
  141. }],
  142. },
  143. detail_id: null,
  144. optType: type,
  145. nodeList: [],
  146. selectList: [],
  147. defaultProps: {
  148. children: 'children',
  149. label: 'text'
  150. },
  151. isexpand: false,
  152. expand_arr: [],
  153. ischecked: false,
  154. id_arr: [],
  155. openOrNot:true
  156. }
  157. },
  158. created() {
  159. this.detailForm = JSON.parse(JSON.stringify(this.detailFormInit))
  160. let nodeList_arr = [];
  161. Config.nodeList.forEach(i => {
  162. if (i.parent == '#') {
  163. nodeList_arr.push(i)
  164. }
  165. })
  166. nodeList_arr.forEach(i => {
  167. i.children = []
  168. Config.nodeList.forEach(k => {
  169. if (i.id == k.parent) {
  170. i.children.push(k)
  171. }
  172. })
  173. })
  174. nodeList_arr.forEach(i => {
  175. if (i.children.length > 0) {
  176. i.children.forEach(j => {
  177. j.children = []
  178. Config.nodeList.forEach(k => {
  179. if (j.id == k.parent) {
  180. j.children.push(k)
  181. }
  182. })
  183. })
  184. }
  185. })
  186. this.nodeList = nodeList_arr
  187. if (this.optType == 'edit') {
  188. for (key in this.detailForm) {
  189. this.detailForm[key] = Config.row[key]
  190. }
  191. this.detail_id = Config.row.id
  192. this.selectList = Config.nodeList
  193. let rules_arr = []
  194. this.selectList.forEach(i => {
  195. if (i.state.selected) {
  196. rules_arr.push(i.id)
  197. }
  198. })
  199. this.detailForm.rules_arr = rules_arr;
  200. }
  201. },
  202. methods: {
  203. checkedAll(val) {
  204. this.detailForm.rules_arr = []
  205. if (val) {
  206. let add_id = []
  207. this.nodeList.forEach(i => {
  208. add_id.push(i.id)
  209. if (i.children.length > 0) {
  210. i.children.forEach(j => {
  211. add_id.push(j.id)
  212. Config.nodeList.forEach(k => {
  213. add_id.push(k.id)
  214. })
  215. })
  216. }
  217. })
  218. this.detailForm.rules_arr = add_id
  219. }else{
  220. this.$refs.tree.setCheckedKeys([]);
  221. }
  222. },
  223. expandAll(val) {
  224. this.expand_arr = []
  225. if (val) {
  226. let add_id = []
  227. this.nodeList.forEach(i => {
  228. add_id.push(i.id)
  229. if (i.children.length > 0) {
  230. i.children.forEach(j => {
  231. add_id.push(j.id)
  232. Config.nodeList.forEach(k => {
  233. add_id.push(k.id)
  234. })
  235. })
  236. }
  237. })
  238. this.expand_arr = add_id
  239. }else{
  240. this.$nextTick(() => {
  241. for(var i=0;i<this.$refs.tree.store._getAllNodes().length;i++){
  242. this.$refs.tree.store._getAllNodes()[i].expanded=false;
  243. }
  244. });
  245. }
  246. },
  247. addImg() {
  248. let that = this;
  249. Fast.api.open("general/attachment/select?multiple=false", "选择图片", {
  250. callback: function (data) {
  251. that.detailForm.image = data.url;
  252. }
  253. });
  254. return false;
  255. },
  256. delImg() {
  257. this.detailForm.image = '';
  258. },
  259. selcetedStatus(val, key) {
  260. let arr_id = key.checkedKeys.concat(key.halfCheckedKeys)
  261. this.id_arr = arr_id
  262. },
  263. submitFrom(type, issub) {
  264. let that = this;
  265. if (type == 'yes') {
  266. this.$refs[issub].validate((valid) => {
  267. if (valid) {
  268. let subData = JSON.parse(JSON.stringify(that.detailForm));
  269. subData.rules = this.id_arr.join(',');
  270. delete subData.rules_arr;
  271. if (this.optType != 'add') {
  272. Fast.api.ajax({
  273. url: 'shopro/user/group/edit?ids=' + that.detail_id,
  274. loading: true,
  275. type: "POST",
  276. data: {
  277. data: JSON.stringify(subData)
  278. }
  279. }, function (ret, res) {
  280. Fast.api.close()
  281. })
  282. } else {
  283. Fast.api.ajax({
  284. url: 'shopro/user/group/add',
  285. loading: true,
  286. type: "POST",
  287. data: {
  288. data: JSON.stringify(subData)
  289. }
  290. }, function (ret, res) {
  291. Fast.api.close()
  292. })
  293. }
  294. } else {
  295. return false;
  296. }
  297. });
  298. } else {
  299. this.detailForm = JSON.parse(JSON.stringify(this.detailFormInit))
  300. }
  301. },
  302. },
  303. })
  304. },
  305. select: function () {
  306. // 初始化表格参数配置
  307. Table.api.init({
  308. extend: {
  309. index_url: 'shopro/goods/goods/index?page_type=select',
  310. }
  311. });
  312. var idArr = [];
  313. var selectArr = [];
  314. var table = $("#table");
  315. table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function (e, row) {
  316. if (e.type == 'check' || e.type == 'uncheck') {
  317. row = [row];
  318. } else {
  319. idArr = [];
  320. selectArr = []
  321. }
  322. $.each(row, function (i, j) {
  323. if (e.type.indexOf("uncheck") > -1) {
  324. var index = idArr.indexOf(j.id);
  325. var indexall = idArr.indexOf(j);
  326. if (index > -1) {
  327. idArr.splice(index, 1);
  328. }
  329. if (indexall > -1) {
  330. selectArr.splice(index, 1);
  331. }
  332. } else {
  333. idArr.indexOf(j.id) == -1 && idArr.push(j.id);
  334. selectArr.indexOf(j) == -1 && selectArr.push(j);
  335. }
  336. });
  337. });
  338. // 初始化表格
  339. table.bootstrapTable({
  340. url: $.fn.bootstrapTable.defaults.extend.index_url,
  341. sortName: 'id',
  342. showToggle: false,
  343. showExport: false,
  344. columns: [
  345. [{
  346. field: 'state',
  347. checkbox: true,
  348. },
  349. {
  350. field: 'title',
  351. title: __('Title'),
  352. align: 'left'
  353. },
  354. {
  355. field: 'image',
  356. title: __('Image'),
  357. operate: false,
  358. events: Table.api.events.image,
  359. formatter: Table.api.formatter.image
  360. },
  361. {
  362. field: 'status_text',
  363. title: __('Status'),
  364. // formatter: Table.api.formatter.status,
  365. },
  366. {
  367. field: 'createtime',
  368. title: __('Createtime'),
  369. formatter: Table.api.formatter.datetime,
  370. operate: 'RANGE',
  371. addclass: 'datetimerange',
  372. sortable: true
  373. },
  374. {
  375. field: 'operate',
  376. title: __('Operate'),
  377. events: {
  378. 'click .btn-chooseone': function (e, value, row, index) {
  379. var multiple = Backend.api.query('multiple');
  380. multiple = multiple == 'true' ? true : false;
  381. row.ids = row.id.toString()
  382. Fast.api.close({
  383. data: row,
  384. multiple: multiple
  385. });
  386. },
  387. },
  388. formatter: function () {
  389. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  390. }
  391. }
  392. ]
  393. ]
  394. });
  395. // 选中多个
  396. $(document).on("click", ".btn-choose-multi", function () {
  397. if (Backend.api.query('type') == 'activity') {
  398. var multiple = Backend.api.query('multiple');
  399. multiple = multiple == 'true' ? true : false;
  400. Fast.api.close({
  401. data: selectArr,
  402. multiple: multiple
  403. });
  404. } else {
  405. let row = {}
  406. var multiple = Backend.api.query('multiple');
  407. multiple = multiple == 'true' ? true : false;
  408. row.ids = idArr.join(",")
  409. Fast.api.close({
  410. data: row,
  411. multiple: multiple
  412. });
  413. }
  414. });
  415. // 为表格绑定事件
  416. Table.api.bindevent(table);
  417. //绑定TAB事件
  418. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  419. // var options = table.bootstrapTable(tableOptions);
  420. var typeStr = $(this).attr("href").replace('#', '');
  421. var options = table.bootstrapTable('getOptions');
  422. options.pageNumber = 1;
  423. options.queryParams = function (params) {
  424. // params.filter = JSON.stringify({type: typeStr});
  425. params.type = typeStr;
  426. params.status = typeStr.replace('t-', '');
  427. return params;
  428. };
  429. table.bootstrapTable('refresh', {});
  430. return false;
  431. });
  432. require(['upload'], function (Upload) {
  433. Upload.api.plupload($("#toolbar .plupload"), function () {
  434. $(".btn-refresh").trigger("click");
  435. });
  436. });
  437. },
  438. api: {
  439. bindevent: function () {
  440. Form.api.bindevent($("form[role=form]"));
  441. }
  442. },
  443. };
  444. return Controller;
  445. });