customer_service.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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: 'name',
  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. name: 'like',
  66. });
  67. Fast.api.ajax({
  68. url: 'shopro/chat/customer_service',
  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. }
  123. }
  124. function onAdd() {
  125. Fast.api.open("shopro/chat/customer_service/add?type=add", "添加", {
  126. callback() {
  127. getData()
  128. }
  129. })
  130. }
  131. function onEdit(id) {
  132. Fast.api.open(`shopro/chat/customer_service/edit?type=edit&id=${id}`, "编辑", {
  133. callback() {
  134. getData()
  135. }
  136. })
  137. }
  138. function onDelete(id) {
  139. Fast.api.ajax({
  140. url: `shopro/chat/customer_service/delete/id/${id}`,
  141. type: 'DELETE',
  142. }, function (ret, res) {
  143. getData()
  144. }, function (ret, res) { })
  145. }
  146. onMounted(() => {
  147. getChatConfig()
  148. getData()
  149. })
  150. return {
  151. Fast,
  152. state,
  153. getData,
  154. onChangeSort,
  155. onOpenFilter,
  156. onChangeFilter,
  157. pagination,
  158. batchHandle,
  159. onChangeSelection,
  160. onBatchHandle,
  161. onAdd,
  162. onEdit,
  163. onDelete
  164. }
  165. }
  166. }
  167. createApp('index', index);
  168. },
  169. add: () => {
  170. Controller.form();
  171. },
  172. edit: () => {
  173. Controller.form();
  174. },
  175. form: () => {
  176. const { reactive, onMounted, getCurrentInstance } = Vue
  177. const addEdit = {
  178. setup() {
  179. const { proxy } = getCurrentInstance();
  180. const state = reactive({
  181. type: new URLSearchParams(location.search).get('type'),
  182. id: new URLSearchParams(location.search).get('id')
  183. })
  184. const form = reactive({
  185. model: {
  186. room_id: '',
  187. auth: 'admin',
  188. auth_id: '',
  189. name: '',
  190. avatar: '',
  191. max_num: 0,
  192. },
  193. rules: {
  194. room_id: [{ required: true, message: '请选择客服分类', trigger: ['blur', 'change'] }],
  195. auth_id: [{ required: true, message: '请选择所属管理员', trigger: ['blur', 'change'] }],
  196. name: [{ required: true, message: '请输入客服名称', trigger: ['blur', 'change'] }],
  197. avatar: [{ required: true, message: '请选择客服头像', trigger: ['blur', 'change'] }],
  198. },
  199. })
  200. function getDetail() {
  201. Fast.api.ajax({
  202. url: `shopro/chat/customer_service/detail/id/${state.id}`,
  203. type: 'GET',
  204. }, function (ret, res) {
  205. form.model = res.data
  206. form.model.auth = res.data.customer_service_user?.auth;
  207. form.model.auth_id = res.data.customer_service_user?.auth_id;
  208. getCustomerServiceSelect()
  209. return false
  210. }, function (ret, res) { })
  211. }
  212. const chat = reactive({
  213. config: {}
  214. })
  215. function getChatConfig() {
  216. Fast.api.ajax({
  217. url: `shopro/chat/index/init`,
  218. type: 'GET',
  219. }, function (ret, res) {
  220. chat.config = res.data
  221. return false
  222. }, function (ret, res) { })
  223. }
  224. const customerService = reactive({
  225. select: []
  226. })
  227. function getCustomerServiceSelect() {
  228. Fast.api.ajax({
  229. url: `shopro/chat/customer_service/select`,
  230. type: 'GET',
  231. data: {
  232. id: state.id,
  233. room_id: form.model.room_id,
  234. },
  235. }, function (ret, res) {
  236. customerService.select = res.data
  237. return false
  238. }, function (ret, res) { })
  239. }
  240. function onConfirm() {
  241. proxy.$refs['formRef'].validate((valid) => {
  242. if (valid) {
  243. Fast.api.ajax({
  244. url: state.type == 'add' ? 'shopro/chat/customer_service/add' : `shopro/chat/customer_service/edit/id/${state.id}`,
  245. type: 'POST',
  246. data: form.model,
  247. }, function (ret, res) {
  248. Fast.api.close()
  249. }, function (ret, res) { })
  250. }
  251. });
  252. }
  253. onMounted(() => {
  254. getChatConfig()
  255. state.type == 'edit' && getDetail()
  256. })
  257. return {
  258. state,
  259. form,
  260. chat,
  261. customerService,
  262. getCustomerServiceSelect,
  263. onConfirm
  264. }
  265. }
  266. }
  267. createApp('addEdit', addEdit);
  268. }
  269. };
  270. return Controller;
  271. });