question.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. user: { field: 'id', value: '' },
  16. room_id: '',
  17. },
  18. tools: {
  19. user: {
  20. type: 'tinputprepend',
  21. label: '查询内容',
  22. placeholder: '请输入查询内容',
  23. value: {
  24. field: 'id',
  25. value: '',
  26. },
  27. options: {
  28. data: [{
  29. label: 'ID',
  30. value: 'id',
  31. },
  32. {
  33. label: '标题',
  34. value: 'title',
  35. }],
  36. }
  37. },
  38. room_id: {
  39. type: 'tselect',
  40. label: '客服分类',
  41. value: '',
  42. options: {
  43. data: [],
  44. props: {
  45. label: 'name'
  46. }
  47. },
  48. },
  49. },
  50. condition: {},
  51. }
  52. })
  53. function getChatConfig() {
  54. Fast.api.ajax({
  55. url: `shopro/chat/index/init`,
  56. type: 'GET',
  57. }, function (ret, res) {
  58. state.filter.tools.room_id.options.data = res.data.default_rooms
  59. return false
  60. }, function (ret, res) { })
  61. }
  62. function getData() {
  63. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  64. let search = composeFilter(tempSearch, {
  65. title: 'like',
  66. });
  67. Fast.api.ajax({
  68. url: 'shopro/chat/question',
  69. type: 'GET',
  70. data: {
  71. page: pagination.page,
  72. list_rows: pagination.list_rows,
  73. order: state.order,
  74. sort: state.sort,
  75. ...search,
  76. },
  77. }, function (ret, res) {
  78. state.data = res.data.data
  79. pagination.total = res.data.total
  80. return false
  81. }, function (ret, res) { })
  82. }
  83. function onChangeSort({ prop, order }) {
  84. state.order = order == 'ascending' ? 'asc' : 'desc';
  85. state.sort = prop;
  86. getData();
  87. }
  88. function onOpenFilter() {
  89. state.filter.drawer = true
  90. }
  91. function onChangeFilter() {
  92. pagination.page = 1
  93. getData()
  94. state.filter.drawer && (state.filter.drawer = false)
  95. }
  96. const pagination = reactive({
  97. page: 1,
  98. list_rows: 10,
  99. total: 0,
  100. })
  101. const batchHandle = reactive({
  102. data: [],
  103. })
  104. function onChangeSelection(val) {
  105. batchHandle.data = val
  106. }
  107. function onBatchHandle(type) {
  108. let ids = []
  109. batchHandle.data.forEach((item) => {
  110. ids.push(item.id)
  111. })
  112. switch (type) {
  113. case 'delete':
  114. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  115. confirmButtonText: '确定',
  116. cancelButtonText: '取消',
  117. type: 'warning',
  118. }).then(() => {
  119. onDelete(ids.join(','))
  120. });
  121. break;
  122. default:
  123. Fast.api.ajax({
  124. url: `shopro/chat/question/edit/id/${ids.join(',')}`,
  125. type: 'POST',
  126. data: {
  127. status: type
  128. }
  129. }, function (ret, res) {
  130. getData()
  131. }, function (ret, res) { })
  132. break;
  133. }
  134. }
  135. function onAdd() {
  136. Fast.api.open("shopro/chat/question/add?type=add", "添加", {
  137. callback() {
  138. getData()
  139. }
  140. })
  141. }
  142. function onEdit(id) {
  143. Fast.api.open(`shopro/chat/question/edit?type=edit&id=${id}`, "编辑", {
  144. callback() {
  145. getData()
  146. }
  147. })
  148. }
  149. function onDelete(id) {
  150. Fast.api.ajax({
  151. url: `shopro/chat/question/delete/id/${id}`,
  152. type: 'DELETE',
  153. }, function (ret, res) {
  154. getData()
  155. }, function (ret, res) { })
  156. }
  157. onMounted(() => {
  158. getChatConfig()
  159. getData()
  160. })
  161. return {
  162. state,
  163. getData,
  164. onChangeSort,
  165. onOpenFilter,
  166. onChangeFilter,
  167. pagination,
  168. batchHandle,
  169. onChangeSelection,
  170. onBatchHandle,
  171. onAdd,
  172. onEdit,
  173. onDelete
  174. }
  175. }
  176. }
  177. createApp('index', index);
  178. },
  179. add: () => {
  180. Controller.form();
  181. },
  182. edit: () => {
  183. Controller.form();
  184. },
  185. form: () => {
  186. const { reactive, onMounted, getCurrentInstance, nextTick } = Vue
  187. const addEdit = {
  188. setup() {
  189. const { proxy } = getCurrentInstance();
  190. const state = reactive({
  191. type: new URLSearchParams(location.search).get('type'),
  192. id: new URLSearchParams(location.search).get('id')
  193. })
  194. const form = reactive({
  195. model: {
  196. room_id: '',
  197. title: '',
  198. content: '',
  199. status: 'normal',
  200. weigh: 0,
  201. },
  202. rules: {
  203. room_id: [{ required: true, message: '请选择客服分类', trigger: ['blur', 'change'] }],
  204. title: [{ required: true, message: '请输入标题', trigger: ['blur', 'change'] }],
  205. content: [{ required: true, message: '请输入问题内容', trigger: ['blur', 'change'] }],
  206. },
  207. })
  208. function getDetail() {
  209. Fast.api.ajax({
  210. url: `shopro/chat/question/detail/id/${state.id}`,
  211. type: 'GET',
  212. }, function (ret, res) {
  213. form.model = res.data;
  214. nextTick(() => {
  215. Controller.api.bindevent();
  216. $('#questionContent').html(form.model.content)
  217. })
  218. return false
  219. }, function (ret, res) { })
  220. }
  221. const chat = reactive({
  222. config: {}
  223. })
  224. function getChatConfig() {
  225. Fast.api.ajax({
  226. url: `shopro/chat/index/init`,
  227. type: 'GET',
  228. }, function (ret, res) {
  229. chat.config = res.data
  230. return false
  231. }, function (ret, res) { })
  232. }
  233. function onConfirm() {
  234. form.model.content = $("#questionContent").val();
  235. proxy.$refs['formRef'].validate((valid) => {
  236. if (valid) {
  237. Fast.api.ajax({
  238. url: state.type == 'add' ? 'shopro/chat/question/add' : `shopro/chat/question/edit/id/${state.id}`,
  239. type: 'POST',
  240. data: form.model,
  241. }, function (ret, res) {
  242. Fast.api.close()
  243. }, function (ret, res) { })
  244. }
  245. });
  246. }
  247. onMounted(() => {
  248. getChatConfig()
  249. if (state.type == 'add') {
  250. nextTick(() => {
  251. Controller.api.bindevent();
  252. })
  253. } else if (state.type == 'edit') {
  254. getDetail()
  255. }
  256. })
  257. return {
  258. state,
  259. form,
  260. chat,
  261. onConfirm
  262. }
  263. }
  264. }
  265. createApp('addEdit', addEdit);
  266. },
  267. api: {
  268. bindevent: function () {
  269. Form.api.bindevent($("form[role=form]"));
  270. },
  271. },
  272. };
  273. return Controller;
  274. });