123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: () => {
- const { reactive, onMounted } = Vue
- const { ElMessageBox } = ElementPlus
- const index = {
- setup() {
- const state = reactive({
- data: [],
- order: '',
- sort: '',
- filter: {
- drawer: false,
- data: {
- user: { field: 'id', value: '' },
- room_id: '',
- },
- tools: {
- user: {
- type: 'tinputprepend',
- label: '查询内容',
- placeholder: '请输入查询内容',
- value: {
- field: 'id',
- value: '',
- },
- options: {
- data: [{
- label: 'ID',
- value: 'id',
- },
- {
- label: '客服名称',
- value: 'name',
- }],
- }
- },
- room_id: {
- type: 'tselect',
- label: '客服分类',
- value: '',
- options: {
- data: [],
- props: {
- label: 'name'
- }
- },
- },
- },
- condition: {},
- }
- })
- function getChatConfig() {
- Fast.api.ajax({
- url: `shopro/chat/index/init`,
- type: 'GET',
- }, function (ret, res) {
- state.filter.tools.room_id.options.data = res.data.default_rooms
- return false
- }, function (ret, res) { })
- }
- function getData() {
- let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
- let search = composeFilter(tempSearch, {
- name: 'like',
- });
- Fast.api.ajax({
- url: 'shopro/chat/customer_service',
- type: 'GET',
- data: {
- page: pagination.page,
- list_rows: pagination.list_rows,
- order: state.order,
- sort: state.sort,
- ...search,
- },
- }, function (ret, res) {
- state.data = res.data.data
- pagination.total = res.data.total
- return false
- }, function (ret, res) { })
- }
- function onChangeSort({ prop, order }) {
- state.order = order == 'ascending' ? 'asc' : 'desc';
- state.sort = prop;
- getData();
- }
- function onOpenFilter() {
- state.filter.drawer = true
- }
- function onChangeFilter() {
- pagination.page = 1
- getData()
- state.filter.drawer && (state.filter.drawer = false)
- }
- const pagination = reactive({
- page: 1,
- list_rows: 10,
- total: 0,
- })
- const batchHandle = reactive({
- data: [],
- })
- function onChangeSelection(val) {
- batchHandle.data = val
- }
- function onBatchHandle(type) {
- let ids = []
- batchHandle.data.forEach((item) => {
- ids.push(item.id)
- })
- switch (type) {
- case 'delete':
- ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- }).then(() => {
- onDelete(ids.join(','))
- });
- break;
- }
- }
- function onAdd() {
- Fast.api.open("shopro/chat/customer_service/add?type=add", "添加", {
- callback() {
- getData()
- }
- })
- }
- function onEdit(id) {
- Fast.api.open(`shopro/chat/customer_service/edit?type=edit&id=${id}`, "编辑", {
- callback() {
- getData()
- }
- })
- }
- function onDelete(id) {
- Fast.api.ajax({
- url: `shopro/chat/customer_service/delete/id/${id}`,
- type: 'DELETE',
- }, function (ret, res) {
- getData()
- }, function (ret, res) { })
- }
- onMounted(() => {
- getChatConfig()
- getData()
- })
- return {
- Fast,
- state,
- getData,
- onChangeSort,
- onOpenFilter,
- onChangeFilter,
- pagination,
- batchHandle,
- onChangeSelection,
- onBatchHandle,
- onAdd,
- onEdit,
- onDelete
- }
- }
- }
- createApp('index', index);
- },
- add: () => {
- Controller.form();
- },
- edit: () => {
- Controller.form();
- },
- form: () => {
- const { reactive, onMounted, getCurrentInstance } = Vue
- const addEdit = {
- setup() {
- const { proxy } = getCurrentInstance();
- const state = reactive({
- type: new URLSearchParams(location.search).get('type'),
- id: new URLSearchParams(location.search).get('id')
- })
- const form = reactive({
- model: {
- room_id: '',
- auth: 'admin',
- auth_id: '',
- name: '',
- avatar: '',
- max_num: 0,
- },
- rules: {
- room_id: [{ required: true, message: '请选择客服分类', trigger: ['blur', 'change'] }],
- auth_id: [{ required: true, message: '请选择所属管理员', trigger: ['blur', 'change'] }],
- name: [{ required: true, message: '请输入客服名称', trigger: ['blur', 'change'] }],
- avatar: [{ required: true, message: '请选择客服头像', trigger: ['blur', 'change'] }],
- },
- })
- function getDetail() {
- Fast.api.ajax({
- url: `shopro/chat/customer_service/detail/id/${state.id}`,
- type: 'GET',
- }, function (ret, res) {
- form.model = res.data
- form.model.auth = res.data.customer_service_user?.auth;
- form.model.auth_id = res.data.customer_service_user?.auth_id;
- getCustomerServiceSelect()
- return false
- }, function (ret, res) { })
- }
- const chat = reactive({
- config: {}
- })
- function getChatConfig() {
- Fast.api.ajax({
- url: `shopro/chat/index/init`,
- type: 'GET',
- }, function (ret, res) {
- chat.config = res.data
- return false
- }, function (ret, res) { })
- }
- const customerService = reactive({
- select: []
- })
- function getCustomerServiceSelect() {
- Fast.api.ajax({
- url: `shopro/chat/customer_service/select`,
- type: 'GET',
- data: {
- id: state.id,
- room_id: form.model.room_id,
- },
- }, function (ret, res) {
- customerService.select = res.data
- return false
- }, function (ret, res) { })
- }
- function onConfirm() {
- proxy.$refs['formRef'].validate((valid) => {
- if (valid) {
- Fast.api.ajax({
- url: state.type == 'add' ? 'shopro/chat/customer_service/add' : `shopro/chat/customer_service/edit/id/${state.id}`,
- type: 'POST',
- data: form.model,
- }, function (ret, res) {
- Fast.api.close()
- }, function (ret, res) { })
- }
- });
- }
- onMounted(() => {
- getChatConfig()
- state.type == 'edit' && getDetail()
- })
- return {
- state,
- form,
- chat,
- customerService,
- getCustomerServiceSelect,
- onConfirm
- }
- }
- }
- createApp('addEdit', addEdit);
- }
- };
- return Controller;
- });
|