feedback.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  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 feedbackIndex = new Vue({
  16. el: "#feedbackIndex",
  17. data() {
  18. return {
  19. data: [],
  20. searchKey: '',
  21. offset: 0,
  22. limit: 10,
  23. totalPage: 0,
  24. currentPage: 1,
  25. }
  26. },
  27. created() {
  28. this.getData();
  29. },
  30. methods: {
  31. getData() {
  32. let that = this;
  33. Fast.api.ajax({
  34. url: 'shopro/feedback/index',
  35. loading: true,
  36. type: 'GET',
  37. data: {
  38. searchWhere: that.searchKey,
  39. offset: that.offset,
  40. limit: that.limit,
  41. },
  42. }, function (ret, res) {
  43. that.data = res.data.rows;
  44. that.data.forEach(i => {
  45. i.images_arr = i.images.split(',').map(i => {
  46. return Fast.api.cdnurl(i)
  47. })
  48. if(i.user.avatar){
  49. i.user.avatar_arr=i.user.avatar.split(',').map(i=>{
  50. return Fast.api.cdnurl(i)
  51. })
  52. }
  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 'edit':
  62. Fast.api.open('shopro/feedback/edit?id=' + id, '查看', {
  63. callback(data) {
  64. if (data.data) {
  65. that.getData();
  66. }
  67. }
  68. })
  69. break;
  70. case 'recyclebin':
  71. Fast.api.open('shopro/feedback/recyclebin', '查看回收站')
  72. break;
  73. case 'del':
  74. that.$confirm('此操作将删除反馈, 是否继续?', '提示', {
  75. confirmButtonText: '确定',
  76. cancelButtonText: '取消',
  77. type: 'warning'
  78. }).then(() => {
  79. Fast.api.ajax({
  80. url: 'shopro/feedback/del/ids/' + id,
  81. loading: true,
  82. type: 'POST',
  83. }, function (ret, res) {
  84. that.getData();
  85. })
  86. return false;
  87. }).catch(() => {
  88. that.$message({
  89. type: 'info',
  90. message: '已取消删除'
  91. });
  92. });
  93. break;
  94. }
  95. },
  96. goUserDetail(id){
  97. let that=this;
  98. Fast.api.open('shopro/user/user/profile?id=' + id, '查看')
  99. },
  100. handleSizeChange(val) {
  101. this.offset = 0
  102. this.limit = val;
  103. this.currentPage = 1;
  104. this.getData()
  105. },
  106. handleCurrentChange(val) {
  107. this.currentPage = val;
  108. this.offset = (val - 1) * this.limit;
  109. this.getData()
  110. },
  111. tableRowClassName({
  112. rowIndex
  113. }) {
  114. if (rowIndex % 2 == 1) {
  115. return 'bg-color';
  116. }
  117. return '';
  118. },
  119. tableCellClassName({
  120. columnIndex
  121. }) {
  122. if (columnIndex == 1 || columnIndex == 2 || columnIndex == 3 || columnIndex == 10) {
  123. return 'cell-left';
  124. }
  125. return '';
  126. },
  127. debounceFilter: debounce(function () {
  128. this.getData()
  129. }, 1000),
  130. },
  131. watch: {
  132. searchKey(newVal, oldVal) {
  133. if (newVal != oldVal) {
  134. this.offset = 0;
  135. this.limit = 10;
  136. this.currentPage = 1;
  137. this.debounceFilter();
  138. }
  139. },
  140. },
  141. })
  142. },
  143. recyclebin: function () {
  144. // 初始化表格参数配置
  145. Table.api.init({
  146. extend: {
  147. 'dragsort_url': ''
  148. }
  149. });
  150. var table = $("#table");
  151. // 初始化表格
  152. table.bootstrapTable({
  153. url: 'shopro/feedback/recyclebin' + location.search,
  154. pk: 'id',
  155. sortName: 'id',
  156. columns: [
  157. [{
  158. checkbox: true
  159. },
  160. {
  161. field: 'id',
  162. title: __('Id')
  163. },
  164. {
  165. field: 'deletetime',
  166. title: __('Deletetime'),
  167. operate: 'RANGE',
  168. addclass: 'datetimerange',
  169. formatter: Table.api.formatter.datetime
  170. },
  171. {
  172. field: 'operate',
  173. width: '130px',
  174. title: __('Operate'),
  175. table: table,
  176. events: Table.api.events.operate,
  177. buttons: [{
  178. name: 'Restore',
  179. text: __('Restore'),
  180. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  181. icon: 'fa fa-rotate-left',
  182. url: 'shopro/feedback/restore',
  183. refresh: true
  184. },
  185. {
  186. name: 'Destroy',
  187. text: __('Destroy'),
  188. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  189. icon: 'fa fa-times',
  190. url: 'shopro/feedback/destroy',
  191. refresh: true
  192. }
  193. ],
  194. formatter: Table.api.formatter.operate
  195. }
  196. ]
  197. ]
  198. });
  199. // 为表格绑定事件
  200. Table.api.bindevent(table);
  201. },
  202. edit: function () {
  203. var feedbackDetail = new Vue({
  204. el: "#feedbackDetail",
  205. data() {
  206. return {
  207. detailForm: Config.row,
  208. }
  209. },
  210. created() {
  211. if(this.detailForm.images){
  212. this.detailForm.images_arr=this.detailForm.images.split(',').map(i => {
  213. return Fast.api.cdnurl(i)
  214. })
  215. }
  216. },
  217. methods: {
  218. goUserDetail(id){
  219. let that=this;
  220. Fast.api.open('shopro/user/user/profile?id=' + id, '查看')
  221. },
  222. submitFrom(type) {
  223. let that = this;
  224. if (type == 'yes') {
  225. Fast.api.ajax({
  226. url: 'shopro/feedback/edit?id=' + that.detailForm.id,
  227. loading: true,
  228. type: 'POST',
  229. data: {
  230. data: JSON.stringify({
  231. status: that.detailForm.status,
  232. remark: that.detailForm.remark,
  233. })
  234. },
  235. }, function (ret, res) {
  236. Fast.api.close({
  237. data: true
  238. })
  239. })
  240. } else {
  241. Fast.api.close({
  242. data: false
  243. })
  244. }
  245. },
  246. },
  247. })
  248. },
  249. add: function () {
  250. Controller.api.bindevent();
  251. },
  252. api: {
  253. bindevent: function () {
  254. Form.api.bindevent($("form[role=form]"));
  255. }
  256. }
  257. };
  258. return Controller;
  259. });