user.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'toastr'], function ($, undefined, Backend, Table, Form, Toastr) {
  2. var Controller = {
  3. index: function () {
  4. function debounce(handle, delay) {
  5. let time = null;
  6. return function () {
  7. let self = this,
  8. arg = arguments;
  9. clearTimeout(time);
  10. time = setTimeout(function () {
  11. handle.apply(self, arg);
  12. }, delay)
  13. }
  14. }
  15. var userIndex = new Vue({
  16. el: "#userIndex",
  17. data() {
  18. return {
  19. data: [],
  20. // chooseType: 0,
  21. // platformType: 'all',
  22. // roleType: 'all',
  23. // joinTime: '',
  24. searchKey: '',
  25. offset: 0,
  26. limit: 10,
  27. totalPage: 0,
  28. currentPage: 1,
  29. }
  30. },
  31. created() {
  32. this.getData();
  33. },
  34. methods: {
  35. getData() {
  36. let that = this;
  37. Fast.api.ajax({
  38. url: 'shopro/user/user/index',
  39. loading: true,
  40. type: 'GET',
  41. data: {
  42. searchWhere: that.searchKey,
  43. // platform: that.platformType,
  44. // role: that.roleType,
  45. // jointime: that.joinTime,
  46. offset: that.offset,
  47. limit: that.limit,
  48. },
  49. }, function (ret, res) {
  50. that.data = res.data.rows;
  51. that.data.forEach(i => {
  52. i.visible = false;
  53. })
  54. that.totalPage = res.data.total;
  55. return false;
  56. })
  57. },
  58. operation(type, id) {
  59. let that = this;
  60. switch (type) {
  61. case 'platform':
  62. that.platformType = id;
  63. break;
  64. case 'role':
  65. that.roleType = id;
  66. break;
  67. case 'filter':
  68. that.offset = 0;
  69. that.limit = 10;
  70. that.currentPage = 1;
  71. that.getData();
  72. break;
  73. case 'clear':
  74. that.platformType = 'all';
  75. that.roleType = 'all';
  76. break;
  77. case 'edit':
  78. Fast.api.open('shopro/user/user/profile?id=' + id, '查看', {
  79. callback() {
  80. that.getData();
  81. }
  82. })
  83. break;
  84. case 'del':
  85. that.$confirm('此操作将永久直接删除用户, 是否继续?', '提示', {
  86. confirmButtonText: '确定',
  87. cancelButtonText: '取消',
  88. type: 'warning'
  89. }).then(() => {
  90. Fast.api.ajax({
  91. url: 'shopro/user/user/del/ids/' + id,
  92. loading: true,
  93. type: 'POST',
  94. }, function (ret, res) {
  95. that.getData();
  96. })
  97. return false;
  98. }).catch(() => {
  99. that.$message({
  100. type: 'info',
  101. message: '已取消删除'
  102. });
  103. });
  104. break;
  105. case 'platformname':
  106. let type = ''
  107. switch (id) {
  108. case 'H5':
  109. type = 'H5'
  110. break;
  111. case 'wxOfficialAccount':
  112. type = '微信公众号'
  113. break;
  114. case 'wxMiniProgram':
  115. type = '微信小程序'
  116. break;
  117. case 'App':
  118. type = 'App'
  119. break;
  120. }
  121. return type
  122. break;
  123. default:
  124. Fast.api.open('shopro/user/user/profile?id=' + type.id, '查看', {
  125. callback() {
  126. that.getData();
  127. }
  128. })
  129. break;
  130. }
  131. },
  132. handleSizeChange(val) {
  133. this.offset = 0
  134. this.limit = val;
  135. this.currentPage = 1;
  136. this.getData()
  137. },
  138. handleCurrentChange(val) {
  139. this.currentPage = val;
  140. this.offset = (val - 1) * this.limit;
  141. this.getData()
  142. },
  143. isShoose() {
  144. this.chooseType == 0 ? 1 : 0;
  145. if (this.chooseType == 0) {
  146. this.activityType = 'all';
  147. this.priceFrist = "";
  148. this.priceLast = "";
  149. }
  150. },
  151. tableRowClassName({
  152. rowIndex
  153. }) {
  154. if (rowIndex % 2 == 1) {
  155. return 'bg-color';
  156. }
  157. return '';
  158. },
  159. tableCellClassName({
  160. columnIndex
  161. }) {
  162. if (columnIndex == 2 || columnIndex == 9) {
  163. return 'cell-left';
  164. }
  165. return '';
  166. },
  167. debounceFilter: debounce(function () {
  168. this.getData()
  169. }, 1000),
  170. },
  171. watch: {
  172. searchKey(newVal, oldVal) {
  173. if (newVal != oldVal) {
  174. this.offset = 0;
  175. this.limit = 10;
  176. this.currentPage = 1;
  177. this.debounceFilter();
  178. }
  179. },
  180. },
  181. })
  182. },
  183. recyclebin: function () { },
  184. add: function () { },
  185. profile: function () {
  186. function debounce(handle, delay) {
  187. let time = null;
  188. return function () {
  189. let self = this,
  190. arg = arguments;
  191. clearTimeout(time);
  192. time = setTimeout(function () {
  193. handle.apply(self, arg);
  194. }, delay)
  195. }
  196. }
  197. let formatterHtml = {
  198. time: (row, value) => {
  199. return `${moment(row.createtime * 1000).format('YYYY-MM-DD HH:mm:ss')}`
  200. },
  201. image: (row, value) => {
  202. return `<img src="/assets/addons/shopro/img/decorate/${row.platform}.png" />`
  203. },
  204. shareUser: (row, value) => {
  205. if (row.user) {
  206. return `<img style="width:24px;height:24px;margin-right:10px" src="${Fast.api.cdnurl(row.user.avatar)}" /><div>${row.user.nickname}</div>`
  207. }
  208. },
  209. changeNumber: (row, value) => {
  210. let str = ""
  211. if (row.money) {
  212. str = `${row.money > 0 ? '+' + row.money : row.money}`
  213. } else if (row.score) {
  214. str = `${row.score > 0 ? '+' + row.score : row.score}`
  215. }
  216. return str
  217. },
  218. shareMessage: (row, value) => {
  219. let str = ""
  220. if (row.type == "groupon") {
  221. str = `<div class="flex-1 ellipsis-item">拼团ID:${row.groupon.id}</div>`
  222. } else {
  223. if (row.goods) {
  224. str = `<img style="width:24px;height:24px;margin-right:14px;border:1px solid #E6E6E6" src="${Fast.api.cdnurl(row.goods.image)}" /><div class="flex-1 ellipsis-item">${row.goods.title}</div>`
  225. }
  226. }
  227. return str
  228. },
  229. goods: (row, value) => {
  230. if (row.goods) {
  231. return `<img style="width:24px;height:24px;margin-right:10px" src="${Fast.api.cdnurl(row.goods.image)}" /><div class="flex-1 ellipsis-item" style="text-align:left">${row.goods.title}</div>`
  232. }
  233. },
  234. coupon: (row, value) => {
  235. if (row.coupons) {
  236. return `${row.coupons[value.field]}`
  237. }
  238. },
  239. couponStatus: (row, value) => {
  240. let str = ''
  241. if (row.usetime) {
  242. str = 1
  243. } else {
  244. str = 0
  245. }
  246. return str
  247. },
  248. operUser: (row) => {
  249. let htmls = ''
  250. if (row.oper) {
  251. if (row.oper.avatar) {
  252. htmls += `<img style="width:24px;height:24px;margin-right:10px" src="${Fast.api.cdnurl(row.oper.avatar)}" />`
  253. }
  254. if (row.oper.name) {
  255. htmls += `<div class="ellipsis-item">${row.oper.name}</div>`
  256. }
  257. }
  258. return htmls
  259. },
  260. operType: (row) => {
  261. return row.oper ? row.oper.type : ''
  262. },
  263. }
  264. var userDetail = new Vue({
  265. el: "#userDetail",
  266. data() {
  267. return {
  268. data: {},
  269. groupList: [],
  270. upPassword: '',
  271. activeStatus: 'money_log',
  272. logList: [],
  273. columns: {
  274. 'money_log': [{
  275. type: 'time',
  276. field: 'createtime',
  277. title: '交易时间',
  278. width: '160px',
  279. formatter: formatterHtml.time,
  280. }, {
  281. type: 'text',
  282. field: 'wallet',
  283. title: '变动余额',
  284. width: '120px',
  285. }, {
  286. type: 'text',
  287. field: 'before',
  288. title: '变更前',
  289. width: '120px',
  290. }, {
  291. type: 'text',
  292. field: 'after',
  293. title: '剩余余额',
  294. width: '120px',
  295. }, {
  296. type: 'htmls',
  297. field: 'oper.type',
  298. title: '操作人类型',
  299. width: '120px',
  300. formatter: formatterHtml.operType,
  301. }, {
  302. type: 'htmls',
  303. field: 'oper',
  304. title: '操作人',
  305. width: '200px',
  306. formatter: formatterHtml.operUser,
  307. }, {
  308. type: 'text',
  309. field: 'memo',
  310. title: '备注',
  311. width: '400px',
  312. align: 'left',
  313. }],
  314. 'score_log': [{
  315. type: 'time',
  316. field: 'createtime',
  317. title: '交易时间',
  318. width: '160px',
  319. formatter: formatterHtml.time,
  320. }, {
  321. type: 'text',
  322. field: 'wallet',
  323. title: '变动积分',
  324. width: '120px',
  325. }, {
  326. type: 'text',
  327. field: 'before',
  328. title: '变更前',
  329. width: '120px',
  330. }, {
  331. type: 'text',
  332. field: 'after',
  333. title: '剩余积分',
  334. width: '120px',
  335. }, {
  336. type: 'htmls',
  337. field: 'oper.type',
  338. title: '操作人类型',
  339. width: '120px',
  340. formatter: formatterHtml.operType,
  341. }, {
  342. type: 'htmls',
  343. field: 'oper',
  344. title: '操作人',
  345. width: '200px',
  346. formatter: formatterHtml.operUser,
  347. }, {
  348. type: 'text',
  349. field: 'memo',
  350. title: '备注',
  351. width: '400px',
  352. align: 'left',
  353. }],
  354. 'order_log': [{
  355. type: 'time',
  356. field: 'createtime',
  357. title: '下单时间',
  358. width: '160px',
  359. formatter: formatterHtml.time,
  360. }, {
  361. type: 'order',
  362. field: 'order_sn',
  363. title: '订单号',
  364. width: '200px',
  365. }, {
  366. type: 'image',
  367. field: 'platform',
  368. title: '订单来源',
  369. width: '100px',
  370. formatter: formatterHtml.image,
  371. }, {
  372. type: 'text',
  373. field: 'type_text',
  374. title: '订单类型',
  375. width: '100px',
  376. }, {
  377. type: 'price',
  378. field: 'total_amount',
  379. title: '金额小计',
  380. width: '140px',
  381. }, {
  382. type: 'price',
  383. field: 'discount_fee',
  384. title: '优惠减免',
  385. width: '140px',
  386. }, {
  387. type: 'price',
  388. field: 'pay_fee',
  389. title: '实付金额',
  390. width: '140px',
  391. }, {
  392. type: 'text',
  393. field: 'status_text',
  394. title: '订单状态',
  395. width: '100px',
  396. }],
  397. 'share_log': [{
  398. type: 'time',
  399. field: 'createtime',
  400. title: '分享时间',
  401. width: '160px',
  402. formatter: formatterHtml.time,
  403. }, {
  404. type: 'shareUser',
  405. field: 'person',
  406. title: '被分享用户',
  407. width: '160px',
  408. formatter: formatterHtml.shareUser,
  409. }, {
  410. type: 'text',
  411. field: 'type_text',
  412. title: '分享类型',
  413. width: '100px',
  414. }, {
  415. type: 'shareMessage',
  416. field: 'type',
  417. title: '分享信息',
  418. width: '300px',
  419. align: 'left',
  420. formatter: formatterHtml.shareMessage,
  421. }, {
  422. type: 'image',
  423. field: 'platform',
  424. title: '平台',
  425. width: '120px',
  426. formatter: formatterHtml.image,
  427. }],
  428. 'goods_favorite': [{
  429. type: 'time',
  430. field: 'createtime',
  431. title: '收藏时间',
  432. width: '160px',
  433. formatter: formatterHtml.time,
  434. }, {
  435. type: 'goods',
  436. field: 'goods',
  437. title: '收藏商品',
  438. width: '300px',
  439. align: 'left',
  440. formatter: formatterHtml.goods,
  441. }],
  442. 'goods_view': [{
  443. type: 'time',
  444. field: 'createtime',
  445. title: '查看时间',
  446. width: '160px',
  447. formatter: formatterHtml.time,
  448. }, {
  449. type: 'goods',
  450. field: 'goods',
  451. title: '浏览商品',
  452. width: '300px',
  453. align: 'left',
  454. formatter: formatterHtml.goods,
  455. }],
  456. 'coupon_log': [{
  457. type: 'htmls',
  458. field: 'name',
  459. title: '优惠券名称',
  460. width: '160px',
  461. formatter: formatterHtml.coupon,
  462. }, {
  463. type: 'htmls',
  464. field: 'amount',
  465. title: '优惠券面额',
  466. width: '160px',
  467. formatter: formatterHtml.coupon,
  468. }, {
  469. type: 'couponStatus',
  470. field: 'user_order_id',
  471. title: '优惠券状态',
  472. width: '100px',
  473. formatter: formatterHtml.couponStatus,
  474. }, {
  475. type: 'time',
  476. field: 'createtime',
  477. title: '领取时间',
  478. width: '160px',
  479. formatter: formatterHtml.time,
  480. }, {
  481. type: 'time',
  482. field: 'usetime',
  483. title: '使用时间',
  484. width: '160px',
  485. formatter: formatterHtml.time,
  486. }],
  487. },
  488. page: 1,
  489. limit: 10,
  490. totalPage: 0,
  491. currentPage: 1,
  492. // 更换推荐人
  493. dialogList: [],
  494. agentDialogVisible: false,
  495. poffset: 0,
  496. plimit: 5,
  497. ptotalPage: 0,
  498. pcurrentPage: 1,
  499. parentFilterForm: {
  500. status: "normal",
  501. form_1_key: "user_id",
  502. form_1_value: ""
  503. },
  504. parentFilterFormInit: {
  505. status: "normal",
  506. form_1_key: "user_id",
  507. form_1_value: ""
  508. },
  509. parentFilterOp: {
  510. status: "=",
  511. user_id: "=",
  512. nickname: "like",
  513. mobile: "like",
  514. },
  515. selectParentAgentId: null,
  516. noRecommendationChecked: false
  517. }
  518. },
  519. created() {
  520. this.data = JSON.parse(JSON.stringify(Config.row));
  521. this.groupList = Config.groupList
  522. this.getListData(this.activeStatus)
  523. },
  524. methods: {
  525. getprofile() {
  526. let that = this;
  527. Fast.api.ajax({
  528. url: 'shopro/user/user/profile?id=' + Config.row.id,
  529. loading: true,
  530. type: 'GET',
  531. data: {},
  532. }, function (ret, res) {
  533. Config.row = res.data;
  534. that.data = JSON.parse(JSON.stringify(Config.row));
  535. return false;
  536. })
  537. },
  538. //列表
  539. radioChange(val) {
  540. this.logList = [];
  541. this.activeStatus = val;
  542. this.page = 1;
  543. this.limit = 10;
  544. this.currentPage = 1;
  545. this.getListData(val)
  546. },
  547. getListData(val) {
  548. let that = this;
  549. Fast.api.ajax({
  550. url: 'shopro/user/user/' + val + '?user_id=' + Config.row.id,
  551. loading: true,
  552. type: 'GET',
  553. data: {
  554. page: that.page,
  555. limit: that.limit,
  556. },
  557. }, function (ret, res) {
  558. that.logList = res.data.data;
  559. that.totalPage = res.data.total;
  560. return false;
  561. })
  562. },
  563. operation(type, id) {
  564. let that = this;
  565. switch (type) {
  566. case 'avatar':
  567. parent.Fast.api.open("general/attachment/select?multiple=false", "选择头像", {
  568. callback: function (data) {
  569. that.data.avatar = data.url;
  570. }
  571. });
  572. break;
  573. case 'money':
  574. Fast.api.open('shopro/user/user/money_recharge?id=' + Config.row.id, '余额充值', {
  575. callback(data) {
  576. that.getprofile();
  577. that.getListData(that.activeStatus);
  578. }
  579. })
  580. break;
  581. case 'score':
  582. Fast.api.open('shopro/user/user/score_recharge?id=' + Config.row.id, '积分充值', {
  583. callback(data) {
  584. that.getprofile();
  585. that.getListData(that.activeStatus);
  586. }
  587. })
  588. break;
  589. case 'reset':
  590. that.data = JSON.parse(JSON.stringify(Config.row))
  591. break;
  592. case 'save':
  593. subData = JSON.parse(JSON.stringify(that.data))
  594. if (that.upPassword) {
  595. subData.password = that.upPassword
  596. }
  597. Fast.api.ajax({
  598. url: 'shopro/user/user/update',
  599. loading: true,
  600. data: {
  601. data: JSON.stringify(subData)
  602. }
  603. }, function (ret, res) {
  604. Config.row = res.data
  605. that.upPassword = ''
  606. })
  607. break;
  608. case 'platformname':
  609. let type = ''
  610. switch (id) {
  611. case 'H5':
  612. type = 'H5'
  613. break;
  614. case 'wxOfficialAccount':
  615. type = '微信公众号'
  616. break;
  617. case 'wxMiniProgram':
  618. type = '微信小程序'
  619. break;
  620. case 'App':
  621. type = 'App'
  622. break;
  623. }
  624. return type
  625. break;
  626. case 'order':
  627. Fast.api.open('shopro/order/order/detail?id=' + id, '查看订单')
  628. break;
  629. case 'shareUser':
  630. Fast.api.open('shopro/user/user/profile?id=' + id, '查看')
  631. break;
  632. case 'groupon':
  633. Fast.api.open(`shopro/activity/groupon/detail/id/${id}`, "查看拼团");
  634. break;
  635. case 'goods':
  636. Fast.api.open(`shopro/goods/goods/edit/ids/${id}?id=${id}&type=edit`, "查看商品");
  637. break;
  638. }
  639. },
  640. openAgentProfile(agent_id) {
  641. let that = this;
  642. Fast.api.open(`shopro/commission/agent/profile?id=${agent_id}`, '详情', {
  643. callback(data) {
  644. that.getListData()
  645. }
  646. })
  647. },
  648. // 更换
  649. openDialog() {
  650. this.getAgentIndex();
  651. },
  652. closeDialog(opttype) {
  653. if (opttype == true) {
  654. this.reqUserChangeParentUser()
  655. } else {
  656. this.agentDialogVisible = false
  657. this.noRecommendationChecked = false
  658. }
  659. },
  660. reqUserChangeParentUser() {
  661. let that = this;
  662. if (!that.selectParentAgentId && that.selectParentAgentId != 0) {
  663. return false
  664. }
  665. Fast.api.ajax({
  666. url: 'shopro/user/user/changeParentUser?id=' + Config.row.id,
  667. loading: false,
  668. type: 'POST',
  669. data: {
  670. value: that.selectParentAgentId
  671. },
  672. }, function (ret, res) {
  673. that.selectParentAgentId = null;
  674. that.agentDialogVisible = false
  675. that.parentFilterForm.form_1_value = "";
  676. that.parentFilterForm.form_1_key = "user_id";
  677. that.noRecommendationChecked = false
  678. that.getprofile();
  679. }, function (ret, res) {
  680. that.selectParentAgentId = null;
  681. that.agentDialogVisible = false
  682. that.parentFilterForm.form_1_value = "";
  683. that.parentFilterForm.form_1_key = "user_id";
  684. that.noRecommendationChecked = false
  685. })
  686. },
  687. // init推荐人
  688. initAgentData(id) {
  689. if (id === true) {
  690. this.selectParentAgentId = 0;
  691. } else if (id === false) {
  692. this.selectParentAgentId = null;
  693. } else {
  694. this.selectParentAgentId = id;
  695. this.noRecommendationChecked = false;
  696. }
  697. },
  698. // 推荐人列表
  699. getAgentIndex() {
  700. let that = this;
  701. let filter = {}
  702. let op = {}
  703. for (key in that.parentFilterForm) {
  704. if (key == 'form_1_value') {
  705. if (that.parentFilterForm[key] != '') {
  706. filter[that.parentFilterForm.form_1_key] = that.parentFilterForm[key];
  707. }
  708. } else if (key == 'status') {
  709. if (that.parentFilterForm[key] != '' && that.parentFilterForm[key] != 'all') {
  710. filter[key] = that.parentFilterForm[key];
  711. }
  712. }
  713. }
  714. for (key in filter) {
  715. op[key] = that.parentFilterOp[key]
  716. }
  717. Fast.api.ajax({
  718. url: 'shopro/commission/agent/index',
  719. loading: false,
  720. type: 'GET',
  721. data: {
  722. offset: that.poffset,
  723. limit: that.plimit,
  724. filter: JSON.stringify(filter),
  725. op: JSON.stringify(op)
  726. },
  727. }, function (ret, res) {
  728. that.dialogList = res.data.rows;
  729. that.ptotalPage = res.data.total;
  730. that.agentDialogVisible = true;
  731. return false;
  732. })
  733. },
  734. parentDebounceFilter: debounce(function () {
  735. this.getAgentIndex()
  736. }, 1000),
  737. phandleCurrentChange(val) {
  738. this.pcurrentPage = val;
  739. this.poffset = (val - 1) * this.plimit;
  740. this.getAgentIndex()
  741. },
  742. handleSizeChange(val) {
  743. this.page = 0
  744. this.limit = val;
  745. this.currentPage = 1;
  746. this.getListData(this.activeStatus)
  747. },
  748. handleCurrentChange(val) {
  749. this.currentPage = val;
  750. this.page = val;
  751. this.getListData(this.activeStatus)
  752. },
  753. tableRowClassName({
  754. rowIndex
  755. }) {
  756. if (rowIndex % 2 == 1) {
  757. return 'bg-color';
  758. }
  759. return '';
  760. },
  761. },
  762. })
  763. },
  764. select: function () {
  765. // 初始化表格参数配置
  766. Table.api.init({
  767. extend: {
  768. index_url: 'shopro/goods/goods/index?page_type=select',
  769. }
  770. });
  771. var idArr = [];
  772. var selectArr = [];
  773. var table = $("#table");
  774. table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function (e, row) {
  775. if (e.type == 'check' || e.type == 'uncheck') {
  776. row = [row];
  777. } else {
  778. idArr = [];
  779. selectArr = []
  780. }
  781. $.each(row, function (i, j) {
  782. if (e.type.indexOf("uncheck") > -1) {
  783. var index = idArr.indexOf(j.id);
  784. var indexall = idArr.indexOf(j);
  785. if (index > -1) {
  786. idArr.splice(index, 1);
  787. }
  788. if (indexall > -1) {
  789. selectArr.splice(index, 1);
  790. }
  791. } else {
  792. idArr.indexOf(j.id) == -1 && idArr.push(j.id);
  793. selectArr.indexOf(j) == -1 && selectArr.push(j);
  794. }
  795. });
  796. });
  797. // 初始化表格
  798. table.bootstrapTable({
  799. url: $.fn.bootstrapTable.defaults.extend.index_url,
  800. sortName: 'id',
  801. showToggle: false,
  802. showExport: false,
  803. columns: [
  804. [{
  805. field: 'state',
  806. checkbox: true,
  807. },
  808. {
  809. field: 'title',
  810. title: __('Title'),
  811. align: 'left'
  812. },
  813. {
  814. field: 'image',
  815. title: __('Image'),
  816. operate: false,
  817. events: Table.api.events.image,
  818. formatter: Table.api.formatter.image
  819. },
  820. {
  821. field: 'status_text',
  822. title: __('Status'),
  823. // formatter: Table.api.formatter.status,
  824. },
  825. {
  826. field: 'createtime',
  827. title: __('Createtime'),
  828. formatter: Table.api.formatter.datetime,
  829. operate: 'RANGE',
  830. addclass: 'datetimerange',
  831. sortable: true
  832. },
  833. {
  834. field: 'operate',
  835. title: __('Operate'),
  836. events: {
  837. 'click .btn-chooseone': function (e, value, row, index) {
  838. var multiple = Backend.api.query('multiple');
  839. multiple = multiple == 'true' ? true : false;
  840. row.ids = row.id.toString()
  841. Fast.api.close({
  842. data: row,
  843. multiple: multiple
  844. });
  845. },
  846. },
  847. formatter: function () {
  848. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  849. }
  850. }
  851. ]
  852. ]
  853. });
  854. // 选中多个
  855. $(document).on("click", ".btn-choose-multi", function () {
  856. if (Backend.api.query('type') == 'activity') {
  857. var multiple = Backend.api.query('multiple');
  858. multiple = multiple == 'true' ? true : false;
  859. Fast.api.close({
  860. data: selectArr,
  861. multiple: multiple
  862. });
  863. } else {
  864. let row = {}
  865. var multiple = Backend.api.query('multiple');
  866. multiple = multiple == 'true' ? true : false;
  867. row.ids = idArr.join(",")
  868. Fast.api.close({
  869. data: row,
  870. multiple: multiple
  871. });
  872. }
  873. });
  874. // 为表格绑定事件
  875. Table.api.bindevent(table);
  876. //绑定TAB事件
  877. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  878. // var options = table.bootstrapTable(tableOptions);
  879. var typeStr = $(this).attr("href").replace('#', '');
  880. var options = table.bootstrapTable('getOptions');
  881. options.pageNumber = 1;
  882. options.queryParams = function (params) {
  883. // params.filter = JSON.stringify({type: typeStr});
  884. params.type = typeStr;
  885. params.status = typeStr.replace('t-', '');
  886. return params;
  887. };
  888. table.bootstrapTable('refresh', {});
  889. return false;
  890. });
  891. require(['upload'], function (Upload) {
  892. Upload.api.plupload($("#toolbar .plupload"), function () {
  893. $(".btn-refresh").trigger("click");
  894. });
  895. });
  896. },
  897. money_recharge: function () {
  898. Controller.rechangeInit('money')
  899. },
  900. score_recharge: function () {
  901. Controller.rechangeInit('score')
  902. },
  903. rechangeInit: function (type) {
  904. function urlParmas(par) {
  905. let value = ""
  906. window.location.search.replace("?", '').split("&").forEach(i => {
  907. if (i.split('=')[0] == par) {
  908. value = JSON.parse(decodeURI(i.split('=')[1]))
  909. }
  910. })
  911. return value
  912. }
  913. var recharge = new Vue({
  914. el: "#recharge",
  915. data() {
  916. return {
  917. rechargeType: type,
  918. rechargeForm: {
  919. user_id: urlParmas('id'),
  920. money: '',
  921. score: '',
  922. remarks: '',
  923. },
  924. rechargeFormInit: {
  925. user_id: urlParmas('id'),
  926. money: '',
  927. score: '',
  928. remarks: '',
  929. },
  930. rules: {
  931. money: [{
  932. required: true,
  933. message: '请输入充值余额',
  934. trigger: 'blur'
  935. },],
  936. score: [{
  937. required: true,
  938. message: '请输入充值积分',
  939. trigger: 'blur'
  940. },],
  941. }
  942. }
  943. },
  944. mounted() { },
  945. methods: {
  946. submitForm(type, check) {
  947. let that = this;
  948. if (type == 'yes') {
  949. that.$refs[check].validate((valid) => {
  950. if (valid) {
  951. let subData = JSON.parse(JSON.stringify(that.rechargeForm));
  952. if (that.rechargeType != 'money') {
  953. delete subData.money
  954. Fast.api.ajax({
  955. url: 'shopro/user/user/score_recharge',
  956. loading: true,
  957. data: subData
  958. }, function (ret, res) {
  959. that.rechargeType = null;
  960. that.rechargeForm = JSON.parse(JSON.stringify(that.rechargeFormInit))
  961. Fast.api.close();
  962. })
  963. } else {
  964. delete subData.score
  965. Fast.api.ajax({
  966. url: 'shopro/user/user/money_recharge',
  967. loading: true,
  968. type: "POST",
  969. data: subData
  970. }, function (ret, res) {
  971. that.rechargeType = null;
  972. that.rechargeForm = JSON.parse(JSON.stringify(that.rechargeFormInit));
  973. Fast.api.close();
  974. })
  975. }
  976. } else {
  977. return false;
  978. }
  979. });
  980. } else {
  981. that.rechargeForm = JSON.parse(JSON.stringify(that.rechargeFormInit))
  982. that.rechargeType = null;
  983. }
  984. },
  985. }
  986. })
  987. },
  988. api: {
  989. bindevent: function () {
  990. Form.api.bindevent($("form[role=form]"));
  991. }
  992. },
  993. };
  994. return Controller;
  995. });