如洲 陈
2025-09-30 7d9cd28b1dc0fdae6ac016cae467ad9600c7c2c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
 * 消息中心工具函数
 * 提供保存消息记录和更新接口记录的功能
 */
 
import Vue from 'vue';
import store from '@/store';
 
/**
 * 保存消息记录
 * @param {Object} options - 配置选项
 * @param {String} options.type - 消息类型,A-审核,B-反审核等
 * @param {Object} options.requestInfo - 请求信息,包含url和data
 * @param {Object} options.messageCenter - 消息中心数据
 * @param {String} options.billNo - 单据编号
 * @param {String} options.billType - 单据类型,如"采购入库单"
 * @param {String} options.userName - 用户账号
 * @param {Function} options.callback - 保存成功后的回调函数,参数为消息ID
 */
function saveMessage(options) {
  const { type, requestInfo, messageCenter, billNo, billType, userName, callback } = options;
  
  let title = `${billType}${billNo}审核`;
  let tableName = `MES_INV_ITEM_INS_${type}`;
 
  if (type === "B") {
    title = `${billType}${billNo}反审核`;
  }
 
  const entity = {
    data: JSON.stringify(requestInfo.data),
    url: requestInfo.url,
    pid: messageCenter.id,
    dealWith: 0,
    result: 0,
    status: 1,
    seq: messageCenter.seq + 1,
    createBy: userName,
    title: title,
    route: billNo,
    tableName: tableName,
    contentType: "application/json",
  };
 
  // 使用Vue.prototype.$post方法
  if (Vue.prototype.$post) {
    Vue.prototype.$post({
      url: "/MessageCenter/Insert",
      data: entity
    }).then(res => {
      if (callback && typeof callback === 'function') {
        callback(res.data.tbBillList);
      }
    });
  } else {
    // 兼容性处理,直接使用uni.request
    uni.request({
      url: store.state.serverInfo.serverAPI + "/MessageCenter/Insert",
      method: "POST",
      data: entity,
      success: (res) => {
        if (callback && typeof callback === 'function') {
          callback(res.data.tbBillList);
        }
      }
    });
  }
}
 
/**
 * 更新接口记录表
 * @param {Object} messageCenter - 消息中心数据对象
 * @param {Function} callback - 更新成功后的回调函数,参数为成功状态和消息
 */
function updateMessage(messageCenter, callback) {
  // 使用Vue.prototype.$post方法
  if (Vue.prototype.$post) {
    Vue.prototype.$post({
      url: "/MessageCenter/ResetUpdate",
      data: messageCenter
    }).then(res => {
      const success = res.data.tbBillList > 0;
      const message = success ? "问题记录成功!" : "问题记录失败!!!";
      
      if (callback && typeof callback === 'function') {
        callback(success, message);
      }
    });
  } else {
    // 兼容性处理,直接使用uni.request
    uni.request({
      url: store.state.serverInfo.serverAPI + "/MessageCenter/ResetUpdate",
      method: "POST",
      data: messageCenter,
      success: (res) => {
        const success = res.data.tbBillList > 0;
        const message = success ? "问题记录成功!" : "问题记录失败!!!";
        
        if (callback && typeof callback === 'function') {
          callback(success, message);
        }
      }
    });
  }
}
 
export default {
  saveMessage,
  updateMessage
};