faq.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted } = Vue
  5. const { ElMessageBox } = ElementPlus
  6. const index = {
  7. setup() {
  8. const state = reactive({
  9. data: [],
  10. order: '',
  11. sort: '',
  12. filter: {
  13. drawer: false,
  14. data: {
  15. keyword: '',
  16. },
  17. tools: {
  18. keyword: {
  19. type: 'tinput',
  20. label: '查询内容',
  21. placeholder: '请输入查询内容',
  22. value: '',
  23. },
  24. },
  25. condition: {},
  26. }
  27. })
  28. function getData() {
  29. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  30. let search = composeFilter(tempSearch, {
  31. keyword: 'like',
  32. });
  33. Fast.api.ajax({
  34. url: 'shopro/data/faq',
  35. type: 'GET',
  36. data: {
  37. page: pagination.page,
  38. list_rows: pagination.list_rows,
  39. order: state.order,
  40. sort: state.sort,
  41. ...search,
  42. },
  43. }, function (ret, res) {
  44. state.data = res.data.data
  45. pagination.total = res.data.total
  46. return false
  47. }, function (ret, res) { })
  48. }
  49. function onChangeSort({ prop, order }) {
  50. state.order = order == 'ascending' ? 'asc' : 'desc';
  51. state.sort = prop;
  52. getData();
  53. }
  54. function onOpenFilter() {
  55. state.filter.drawer = true
  56. }
  57. function onChangeFilter() {
  58. pagination.page = 1
  59. getData()
  60. state.filter.drawer && (state.filter.drawer = false)
  61. }
  62. const pagination = reactive({
  63. page: 1,
  64. list_rows: 10,
  65. total: 0,
  66. })
  67. const batchHandle = reactive({
  68. data: [],
  69. })
  70. function onChangeSelection(val) {
  71. batchHandle.data = val
  72. }
  73. function onBatchHandle(type) {
  74. let ids = []
  75. batchHandle.data.forEach((item) => {
  76. ids.push(item.id)
  77. })
  78. switch (type) {
  79. case 'delete':
  80. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  81. confirmButtonText: '确定',
  82. cancelButtonText: '取消',
  83. type: 'warning',
  84. }).then(() => {
  85. onDelete(ids.join(','))
  86. });
  87. break;
  88. default:
  89. Fast.api.ajax({
  90. url: `shopro/data/faq/edit/id/${ids.join(',')}`,
  91. type: 'POST',
  92. data: {
  93. status: type
  94. }
  95. }, function (ret, res) {
  96. getData()
  97. }, function (ret, res) { })
  98. break;
  99. }
  100. }
  101. function onAdd() {
  102. Fast.api.open("shopro/data/faq/add?type=add", "添加", {
  103. callback() {
  104. getData()
  105. }
  106. })
  107. }
  108. function onEdit(id) {
  109. Fast.api.open(`shopro/data/faq/edit?type=edit&id=${id}`, "编辑", {
  110. callback() {
  111. getData()
  112. }
  113. })
  114. }
  115. function onDelete(id) {
  116. Fast.api.ajax({
  117. url: `shopro/data/faq/delete/id/${id}`,
  118. type: 'DELETE',
  119. }, function (ret, res) {
  120. getData()
  121. }, function (ret, res) { })
  122. }
  123. onMounted(() => {
  124. getData()
  125. })
  126. return {
  127. state,
  128. getData,
  129. onChangeSort,
  130. onOpenFilter,
  131. onChangeFilter,
  132. pagination,
  133. batchHandle,
  134. onChangeSelection,
  135. onBatchHandle,
  136. onAdd,
  137. onEdit,
  138. onDelete
  139. }
  140. }
  141. }
  142. createApp('index', index);
  143. },
  144. add: () => {
  145. Controller.form();
  146. },
  147. edit: () => {
  148. Controller.form();
  149. },
  150. form: () => {
  151. const { reactive, onMounted, getCurrentInstance } = Vue
  152. const addEdit = {
  153. setup() {
  154. const { proxy } = getCurrentInstance();
  155. const state = reactive({
  156. type: new URLSearchParams(location.search).get('type'),
  157. id: new URLSearchParams(location.search).get('id')
  158. })
  159. const form = reactive({
  160. model: {
  161. title: '',
  162. content: '',
  163. status: 'normal',
  164. },
  165. rules: {
  166. title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  167. content: [{ required: true, message: '请输入内容', trigger: 'blur' }],
  168. },
  169. })
  170. function getDetail() {
  171. Fast.api.ajax({
  172. url: `shopro/data/faq/detail/id/${state.id}`,
  173. type: 'GET',
  174. }, function (ret, res) {
  175. form.model = res.data;
  176. return false
  177. }, function (ret, res) { })
  178. }
  179. function onConfirm() {
  180. proxy.$refs['formRef'].validate((valid) => {
  181. if (valid) {
  182. Fast.api.ajax({
  183. url: state.type == 'add' ? 'shopro/data/faq/add' : `shopro/data/faq/edit/id/${state.id}`,
  184. type: 'POST',
  185. data: form.model,
  186. }, function (ret, res) {
  187. Fast.api.close()
  188. }, function (ret, res) { })
  189. }
  190. });
  191. }
  192. onMounted(() => {
  193. state.type == 'edit' && getDetail()
  194. })
  195. return {
  196. state,
  197. form,
  198. onConfirm
  199. }
  200. }
  201. }
  202. createApp('addEdit', addEdit);
  203. }
  204. };
  205. return Controller;
  206. });