question.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 questionIndex = new Vue({
  16. el: "#questionIndex",
  17. data() {
  18. return {
  19. data: [{
  20. createtime: 1603971286,
  21. id: 3,
  22. name: "4",
  23. status: "normal",
  24. status_text: "启用",
  25. updatetime: 1603971286,
  26. weigh: 3
  27. }],
  28. search: '',
  29. offset: 0,
  30. limit: 10,
  31. totalPage: 0,
  32. currentPage: 1,
  33. }
  34. },
  35. created() {
  36. this.getData();
  37. },
  38. methods: {
  39. getData() {
  40. let that = this;
  41. Fast.api.ajax({
  42. url: 'shopro/chat/question/index',
  43. loading: true,
  44. type: 'GET',
  45. data: {
  46. search: that.search,
  47. offset: that.offset,
  48. limit: that.limit,
  49. },
  50. }, function (ret, res) {
  51. that.data = res.data.rows;
  52. that.totalPage = res.data.total;
  53. return false;
  54. })
  55. },
  56. operation(type, id) {
  57. let that = this;
  58. switch (type) {
  59. case 'create':
  60. Fast.api.open('shopro/chat/question/add', '查看', {
  61. callback() {
  62. that.getData();
  63. }
  64. })
  65. break;
  66. case 'edit':
  67. Fast.api.open('shopro/chat/question/edit?ids='+id, '编辑', {
  68. callback() {
  69. that.getData();
  70. }
  71. })
  72. break;
  73. case 'del':
  74. that.$confirm('此操作将删除常见问题, 是否继续?', '提示', {
  75. confirmButtonText: '确定',
  76. cancelButtonText: '取消',
  77. type: 'warning'
  78. }).then(() => {
  79. Fast.api.ajax({
  80. url: 'shopro/chat/question/del/ids/' + id,
  81. loading: true,
  82. type: 'POST',
  83. }, function (ret, res) {
  84. that.getData();
  85. return false;
  86. })
  87. return false;
  88. }).catch(() => {
  89. that.$message({
  90. type: 'info',
  91. message: '已取消删除'
  92. });
  93. });
  94. break;
  95. }
  96. },
  97. handleSizeChange(val) {
  98. this.offset = 0
  99. this.limit = val;
  100. this.currentPage = 1;
  101. this.getData()
  102. },
  103. handleCurrentChange(val) {
  104. this.currentPage = val;
  105. this.offset = (val - 1) * this.limit;
  106. this.getData()
  107. },
  108. isShoose() {
  109. this.chooseType == 0 ? 1 : 0;
  110. if (this.chooseType == 0) {
  111. this.activityType = 'all';
  112. this.priceFrist = "";
  113. this.priceLast = "";
  114. }
  115. },
  116. tableCellClassName({
  117. columnIndex
  118. }) {
  119. if (columnIndex == 1 || columnIndex == 6) {
  120. return 'cell-left';
  121. }
  122. return '';
  123. },
  124. debounceFilter: debounce(function () {
  125. this.getData()
  126. }, 1000),
  127. },
  128. watch: {
  129. search(newVal, oldVal) {
  130. if (newVal != oldVal) {
  131. this.offset = 0;
  132. this.limit = 10;
  133. this.currentPage = 1;
  134. this.debounceFilter();
  135. }
  136. },
  137. },
  138. })
  139. },
  140. add: function () {
  141. Controller.initEdit('add');
  142. },
  143. edit: function () {
  144. Controller.initEdit('edit');
  145. },
  146. initEdit: function (type) {
  147. var questionDetail = new Vue({
  148. el: "#questionDetail",
  149. data() {
  150. return {
  151. optType: type,
  152. detailForm: {
  153. title: "",
  154. content: '',
  155. status: "normal",
  156. weigh: 0
  157. },
  158. rules: {
  159. title: [{
  160. required: true,
  161. message: '请输入名称',
  162. trigger: 'blur'
  163. }],
  164. content: [{
  165. required: true,
  166. message: '请输入内容',
  167. trigger: 'blur'
  168. }],
  169. status: [{
  170. required: true,
  171. message: '请选择状态',
  172. trigger: 'blur'
  173. }],
  174. weigh: [{
  175. required: true,
  176. message: '请输入权重',
  177. trigger: 'blur'
  178. }],
  179. },
  180. }
  181. },
  182. created() {},
  183. mounted() {
  184. this.$nextTick(() => {
  185. Controller.api.bindevent();
  186. })
  187. if (this.optType == 'edit') {
  188. $('#c-content').html(Config.row.content);
  189. for (var key in this.detailForm) {
  190. this.detailForm[key] = Config.row[key]
  191. }
  192. }
  193. },
  194. methods: {
  195. submitForm(formName) {
  196. let that = this;
  197. that.detailForm.content = $('#c-content').val();
  198. this.$refs[formName].validate((valid) => {
  199. if (valid) {
  200. if (that.optType == 'add') {
  201. Fast.api.ajax({
  202. url: 'shopro/chat/question/add',
  203. loading: true,
  204. type: 'POST',
  205. data: that.detailForm
  206. }, function (ret, res) {
  207. Fast.api.close();
  208. })
  209. } else {
  210. Fast.api.ajax({
  211. url: 'shopro/chat/question/edit?ids=' + Config.row.id,
  212. loading: true,
  213. type: 'POST',
  214. data: that.detailForm
  215. }, function (ret, res) {
  216. Fast.api.close();
  217. })
  218. }
  219. }
  220. })
  221. }
  222. },
  223. })
  224. },
  225. api: {
  226. bindevent: function () {
  227. Form.api.bindevent($("form[role=form]"));
  228. }
  229. }
  230. };
  231. return Controller;
  232. });