link.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. var linkIndex = new Vue({
  5. el: "#linkIndex",
  6. data() {
  7. return {
  8. linkData: [],
  9. isData: false,
  10. activeName: null,
  11. activeIndex: null,
  12. }
  13. },
  14. mounted() {
  15. this.activeName = null
  16. this.getData();
  17. },
  18. methods: {
  19. getData() {
  20. let that = this;
  21. that.isData = false;
  22. Fast.api.ajax({
  23. url: 'shopro/link/index',
  24. loading: true,
  25. type: 'GET',
  26. }, function (ret, res) {
  27. that.linkData = res.data;
  28. if (that.activeName == null && that.activeIndex == null) {
  29. that.activeName = that.linkData[0].group ? that.linkData[0].group : '其它';
  30. that.activeIndex = 0;
  31. }
  32. return false;
  33. })
  34. },
  35. tabClick(tab, event) {
  36. this.activeName = tab.name;
  37. this.activeIndex = Number(tab.index);
  38. },
  39. operation(opttype, id, idx, type) {
  40. let that = this;
  41. switch (opttype) {
  42. case 'delete':
  43. that.$confirm('此操作将永久删除链接, 是否继续?', '提示', {
  44. confirmButtonText: '确定',
  45. cancelButtonText: '取消',
  46. type: 'warning'
  47. }).then(() => {
  48. Fast.api.ajax({
  49. url: 'shopro/link/del/ids/' + id,
  50. loading: true,
  51. type: 'POST',
  52. }, function (ret, res) {
  53. that.activeName=null;
  54. that.activeIndex=null;
  55. that.getData();
  56. })
  57. }).catch(() => {
  58. that.$message({
  59. type: 'info',
  60. message: '已取消删除'
  61. });
  62. });
  63. break;
  64. case 'add':
  65. Fast.api.open("shopro/link/add", "创建链接", {
  66. callback(data) {
  67. if (data.data) {
  68. that.getData();
  69. }
  70. }
  71. });
  72. break;
  73. case 'edit':
  74. Fast.api.open("shopro/link/edit?id=" + id, "编辑链接", {
  75. callback(data) {
  76. if (data.data) {
  77. that.getData();
  78. }
  79. }
  80. });
  81. break;
  82. case 'recyclebin':
  83. Fast.api.open("shopro/link/recyclebin", "回收站");
  84. break;
  85. }
  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 == 2 || columnIndex == 6) {
  99. return 'cell-left';
  100. }
  101. return '';
  102. },
  103. },
  104. })
  105. },
  106. select: function () {
  107. var linkSelect = new Vue({
  108. el: "#linkSelect",
  109. data() {
  110. return {
  111. linkData: [],
  112. searchWhere: '',
  113. activeIndex: 0,
  114. selectedid: null,
  115. rowData: {},
  116. multiple: new URLSearchParams(location.search).get('multiple'),
  117. dialogVisible: false,
  118. isAll:false
  119. }
  120. },
  121. mounted() {
  122. this.getData();
  123. this.$nextTick(() => {
  124. $('.scroll-item').each(function (i, element) {
  125. var h = $(element).height();
  126. });
  127. });
  128. window.addEventListener('scroll', this.handleScroll, true)
  129. },
  130. methods: {
  131. checkedAll(val) {
  132. this.isAll = val;
  133. this.rowData=[];
  134. this.linkData.forEach(i => {
  135. if(i.children && i.children.length>0){
  136. i.children.forEach(j=>{
  137. j.selected=val
  138. })
  139. }
  140. })
  141. if(val){
  142. this.linkData.forEach(i => {
  143. if(i.children && i.children.length>0){
  144. i.children.forEach(j=>{
  145. this.rowData.push(j)
  146. })
  147. }
  148. })
  149. }
  150. this.$forceUpdate();
  151. },
  152. getData() {
  153. let that = this;
  154. Fast.api.ajax({
  155. url: 'shopro/link/select',
  156. type: "GET",
  157. }, function (ret, res) {
  158. that.linkData = res.data;
  159. return false;
  160. })
  161. },
  162. operation(type, rows, index, idx) {
  163. let multiple = false;
  164. let that = this;
  165. switch (type) {
  166. case 'cancel':
  167. Fast.api.close({
  168. data: {},
  169. multiple: multiple
  170. });
  171. break;
  172. case 'define':
  173. let row = this.rowData;
  174. if (that.multiple == 'true') {
  175. if (row.length > 0) {
  176. var multiplePath = []
  177. row.forEach(r => {
  178. r.path_name = r.name;
  179. multiplePath.push(r.path)
  180. })
  181. row = {
  182. path: multiplePath.join(',')
  183. }
  184. Fast.api.close({
  185. data: row,
  186. multiple: multiple
  187. });
  188. }
  189. } else {
  190. Fast.api.close({
  191. data: row,
  192. multiple: multiple
  193. });
  194. }
  195. break;
  196. case 'select':
  197. if (that.multiple == 'true') {
  198. this.linkData[index].children[idx].selected = !this.linkData[index].children[idx].selected;
  199. let rowsArr = []
  200. this.linkData.forEach(e => {
  201. if (e.children && e.children.length > 0) {
  202. e.children.forEach(i => {
  203. if (i.selected) {
  204. rowsArr.push(i)
  205. }
  206. })
  207. }
  208. });
  209. this.rowData = rowsArr;
  210. } else {
  211. this.linkData.forEach(e => {
  212. if (e.children && e.children.length > 0) {
  213. e.children.forEach(i => {
  214. i.selected = false;
  215. })
  216. }
  217. });
  218. this.linkData[index].children[idx].selected = !this.linkData[index].children[idx].selected;
  219. this.rowData = rows;
  220. let row = JSON.parse(JSON.stringify(this.rowData));
  221. switch (row.path) {
  222. case '/pages/app/coupon/detail':
  223. Fast.api.open("shopro/coupons/select", __('Choose'), {
  224. callback: function (data) {
  225. row.path_name = row.name + '-' + data.data.name
  226. row.path += '?id=' + data.data.id.toString();
  227. that.rowData = row;
  228. }
  229. });
  230. break;
  231. case '/pages/goods/list':
  232. Fast.api.open("shopro/category/select?from=group", __('Choose'), {
  233. callback: function (data) {
  234. console.log(data,'data')
  235. row.path_name = row.name + '-' + data.data.category_name
  236. row.path += '?id=' + data.data.id.toString()
  237. that.rowData = row;
  238. }
  239. });
  240. break;
  241. case '/pages/goods/detail':
  242. parent.Fast.api.open("shopro/goods/goods/select?multiple=" + false, __('Choose'), {
  243. callback: function (data) {
  244. row.path_name = row.name + '-' + data.data.title
  245. row.path += '?id=' + data.data.id.toString()
  246. that.rowData = row;
  247. }
  248. });
  249. break;
  250. case '/pages/public/richtext':
  251. Fast.api.open("shopro/richtext/select", __('Choose'), {
  252. callback: function (data) {
  253. row.path_name = row.name + '-' + data.data.title
  254. row.path += '?id=' + data.data.id.toString()
  255. that.rowData = row;
  256. }
  257. });
  258. break;
  259. case '/pages/public/poster/index':
  260. that.dialogVisible = true;
  261. that.rowData = row;
  262. break;
  263. case '/pages/index/view':
  264. Fast.api.open("shopro/decorate/select?type=custom", __('Choose'), {
  265. callback: function (data) {
  266. row.path_name = row.name + '-' + data.data.name;
  267. row.path += '?id=' + data.data.id.toString()
  268. that.rowData = row;
  269. }
  270. });
  271. break;
  272. case '/pages/index/category':
  273. Fast.api.open("shopro/category/select?from=link", __('Choose'), {
  274. callback: function (data) {
  275. row.path_name = row.name + '-' + data.data.category_name
  276. row.path += '?id=' + data.data.id.toString()
  277. that.rowData = row;
  278. }
  279. });
  280. break;
  281. default:
  282. row.path_name = row.name
  283. that.rowData = row;
  284. }
  285. }
  286. this.$forceUpdate();
  287. break;
  288. }
  289. },
  290. selected(index) {
  291. location.href = "#" + index
  292. this.activeIndex = index;
  293. },
  294. posterUser() {
  295. let that = this;
  296. let row = that.rowData;
  297. that.dialogVisible = false;
  298. row.path_name = '个人海报'
  299. row.path = row.path + '?posterType=user'
  300. that.rowData = row;
  301. },
  302. posterGood() {
  303. let that = this;
  304. let row = that.rowData;
  305. that.dialogVisible = false;
  306. parent.Fast.api.open("shopro/goods/goods/select?multiple=" + false, __('Choose'), {
  307. callback: function (data) {
  308. row.path_name = '商品海报'
  309. row.path += '?posterType=goods&id=' + data.data.id.toString()
  310. that.rowData = row;
  311. }
  312. });
  313. },
  314. handleScroll() {
  315. let arr = [];
  316. let heightArr = [];
  317. $('.scroll-item').each(function (i, element) {
  318. var v = $(element).offset().top;
  319. var h = $(element).outerHeight(true);
  320. arr.push(v);
  321. heightArr.push(h)
  322. });
  323. let handel = [];
  324. let indexs = [];
  325. arr.forEach((i, index) => {
  326. if (i > 0) {
  327. handel.push(i);
  328. indexs.push(index);
  329. }
  330. })
  331. if (handel[0] < heightArr[indexs[0]] / 2) {
  332. this.activeIndex = indexs[0];
  333. } else {
  334. this.activeIndex = indexs[0] - 1;
  335. }
  336. },
  337. },
  338. })
  339. },
  340. recyclebin: function () {
  341. // 初始化表格参数配置
  342. Table.api.init({
  343. extend: {
  344. 'dragsort_url': ''
  345. }
  346. });
  347. var table = $("#table");
  348. // 初始化表格
  349. table.bootstrapTable({
  350. url: 'shopro/link/recyclebin' + location.search,
  351. pk: 'id',
  352. sortName: 'id',
  353. columns: [
  354. [{
  355. checkbox: true
  356. },
  357. {
  358. field: 'id',
  359. title: __('Id')
  360. },
  361. {
  362. field: 'name',
  363. title: __('Name'),
  364. align: 'left'
  365. },
  366. {
  367. field: 'deletetime',
  368. title: __('Deletetime'),
  369. operate: 'RANGE',
  370. addclass: 'datetimerange',
  371. formatter: Table.api.formatter.datetime
  372. },
  373. {
  374. field: 'operate',
  375. width: '130px',
  376. title: __('Operate'),
  377. table: table,
  378. events: Table.api.events.operate,
  379. buttons: [{
  380. name: 'Restore',
  381. text: __('Restore'),
  382. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  383. icon: 'fa fa-rotate-left',
  384. url: 'shopro/link/restore',
  385. refresh: true
  386. },
  387. {
  388. name: 'Destroy',
  389. text: __('Destroy'),
  390. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  391. icon: 'fa fa-times',
  392. url: 'shopro/link/destroy',
  393. refresh: true
  394. }
  395. ],
  396. formatter: Table.api.formatter.operate
  397. }
  398. ]
  399. ]
  400. });
  401. // 为表格绑定事件
  402. Table.api.bindevent(table);
  403. },
  404. add: function () {
  405. Controller.detailInit('add');
  406. },
  407. edit: function () {
  408. Controller.detailInit('edit');
  409. },
  410. detailInit: function (type) {
  411. var linkDetail = new Vue({
  412. el: "#linkDetail",
  413. data() {
  414. return {
  415. optType: type,
  416. detailForm: {},
  417. detailFormInit: {
  418. group: '',
  419. name: '',
  420. path: ''
  421. },
  422. rulesForm: {
  423. group: [{
  424. required: true,
  425. message: '请输入所属分组',
  426. trigger: 'blur'
  427. }],
  428. name: [{
  429. required: true,
  430. message: '请输入名称',
  431. trigger: 'blur'
  432. }],
  433. path: [{
  434. required: true,
  435. message: '请输入路径',
  436. trigger: 'blur'
  437. }],
  438. },
  439. }
  440. },
  441. mounted() {
  442. this.detailForm = JSON.parse(JSON.stringify(this.detailFormInit))
  443. if (this.optType == 'edit') {
  444. for (key in this.detailForm) {
  445. this.detailForm[key] = Config.row[key]
  446. }
  447. }
  448. },
  449. methods: {
  450. addpath() {
  451. this.detailForm.children.push({
  452. name: '',
  453. path: ''
  454. })
  455. },
  456. submitForm(check) {
  457. let that = this;
  458. this.$refs[check].validate((valid) => {
  459. if (valid) {
  460. if (that.optType != 'add') {
  461. Fast.api.ajax({
  462. url: 'shopro/link/edit?id=' + Config.row.id,
  463. loading: true,
  464. type: "POST",
  465. data: {
  466. data: JSON.stringify(this.detailForm)
  467. }
  468. }, function (ret, res) {
  469. Fast.api.close({
  470. data: true,
  471. // type: 'edit'
  472. })
  473. })
  474. } else {
  475. Fast.api.ajax({
  476. url: 'shopro/link/add',
  477. loading: true,
  478. type: "POST",
  479. data: {
  480. data: JSON.stringify(this.detailForm)
  481. }
  482. }, function (ret, res) {
  483. Fast.api.close({
  484. data: true,
  485. })
  486. })
  487. }
  488. } else {
  489. return false;
  490. }
  491. });
  492. }
  493. }
  494. })
  495. },
  496. api: {
  497. bindevent: function () {
  498. Form.api.bindevent($("form[role=form]"));
  499. }
  500. }
  501. };
  502. return Controller;
  503. });