wangting
2024-06-14 f8035d6a65d1f610f87fa12408224176f1bf005f
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
/**
 * 按钮处理 业务类型删除
 */
import {paramLow,callPreEvent,callPostEvent,replaceFreeMarker} from '../BaseAction';
import {validatenull} from "@/util/validate";
import Vue from "vue";
import { del} from "@/api/base/actions"
 
export const doAction = (options,callback) => {
  options.paramVOS = paramLow(options.paramVOS)
  const paramVOS = Object.assign({
    url: 'uiDataController/deleteData',
    method: 'delete'
  }, options.paramVOS)
  options.paramVOS = paramVOS;
 
  options.sourceData = options.sourceData || {};
  options.dataStore = options.dataStore || [];
  if (!options.dataStore || options.dataStore.length < 1) {
    Vue.prototype.$message.error("请选择需要删除的数据");
    return false;
  }
  if (!paramVOS.multi && options.dataStore.length > 1) {
    Vue.prototype.$message.error("仅能选择一条数据来操作");
    return false;
  }
  let msg=replaceFreeMarker(paramVOS.confirmmsg,options.dataStore,options.sourceData) || ('是否删除' + (options.dataStore.length==1?"这条":"这些") + '数据' + (paramVOS.cascade?",如果有下级数据会级联删除":""));
  Vue.prototype.$confirm(msg,'提示',{}).then(()=>{
    callPreEvent(options, doBefore,function (options) {
      doDelete(options, function (type) {
        callPostEvent(options,doAfter , callback,type);
      });
    });
  }).catch(()=>{
 
  })
};
 
/**
 * 执行
 * @param options 按钮的配置信息
 * @param callback 回调
 */
export const doDelete = (options,callback)=> {
  let submitData = {
    type:options.paramVOS.type || 1,//1:删除版次,  2:删除版本,  3:删除主对象。默认值1。
    checkLinkedFlag:options.paramVOS.checklinkedflag,
    cascade:options.paramVOS.cascade,
    adminCascade:options.paramVOS.admincascade
  }
  if(options.paramVOS.checkonback){
    submitData['checkNotDelete']=options.paramVOS.checknotdelete;
    submitData['checkNotDeleteMsg']=options.paramVOS.checknotdeletemsg;
  }else if(options.paramVOS.checknotdelete){
    const notdelete = options.paramVOS.checknotdelete.split('&');
    let checknotdelete=false;
    let msgStore={};
    notdelete.forEach((item,i)=>{
      for (let j=0;j<options.dataStore.length;j++){
        if (options.dataStore[j][item.split('=')[0]] == item.split('=')[1]) {
          checknotdelete=true;
          msgStore=options.dataStore[j]
          return false;
        }
      }
    })
    if (checknotdelete) {
      Vue.prototype.$message.error(replaceFreeMarker(options.paramVOS.checknotdeletemsg,msgStore,{}) || '当前数据不允许删除');
      return false;
    }
  }
  submitData.dataList = options.dataStore;
  del(submitData,options.paramVOS.url,options.paramVOS.method).then(() => {
    Vue.prototype.$message({
      type: "success",
      message: options.paramVOS.successmsg||"删除成功!"
    });
    if(callback){
      callback("del");
    }
  });
}
/**
 * 前置事件
 * @param options 按钮的配置信息
 * @param callback 回调
 */
export const doBefore = (options,callback)=> {
  console.log('执行删除前置事件');
  if(callback){
    callback(options);
  }
}
/**
 * 后置事件
 * @param options 按钮的配置信息
 * @param callback 回调
 */
export const doAfter = (options,callback,actionType)=> {
  console.log('执行删除后置事件');
  if(callback){
    callback(actionType);
  }
}