helongyang
2025-06-03 166a45a9d44e03e63552c6afa975c9ef0cc902e5
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
import gridBody from './extend/materielcodeprintView.vue'
import modelHeader from './extend/materielcodeSelectView.vue'
import modelBody from './extend/purchaseOrderNoSelectView.vue'
import modelFooter from './extend/GetOrderQuantityView.vue'
import modelSpec from './extend/GetOrderMaterielSpec.vue'
let extension = {
  components: {
    //查询界面扩展组件
    gridHeader: '',
    gridBody: gridBody,
    gridFooter: '',
    //新建、编辑弹出框扩展组件
    modelHeader: modelHeader,
    modelBody: modelBody,
    modelFooter: modelFooter,
    modelSpec: modelSpec
  },
  tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写)
  buttons: { view: [], box: [], detail: [] }, //扩展的按钮
  methods: {
    //获取表单配置
    getOption(field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    formatDate(dateStr) {
      let date = new Date(dateStr);
      let year = date.getFullYear();
      let month = String(date.getMonth() + 1).padStart(2, "0");
      let day = String(date.getDate()).padStart(2, "0");
      return year + "-" + month + "-" + day;
    },
    //下面这些方法可以保留也可以删除
    onInit() {  //框架初始化配置前,
      this.$nextTick(() => {
        this.editFormOptions.forEach((option) => {
          option.forEach((item) => {
            if (item.field == 'materielCode') {
              //初始化弹出框选择器配置
              item.extra = {
                icon: 'el-icon-zoom-out', //显示图标
                text: '选择数据', //显示文本
                style: 'color: #3a8ee6;font-size: 13px;cursor: pointer;',
                //触发事件
                click: (item) => {
                  this.$refs.modelHeader.open(this.editFormFields.warehouseId);
                }
              };
            }
          });
        });
        this.editFormOptions.forEach((option) => {
          option.forEach((item) => {
            if (item.field == 'purchaseOrderNo') {
              //初始化弹出框选择器配置
              item.extra = {
                icon: 'el-icon-zoom-out', //显示图标
                text: '选择数据', //显示文本
                style: 'color: #3a8ee6;font-size: 13px;cursor: pointer;',
                //触发事件
                click: (item) => {
                  this.$refs.modelBody.open(this.editFormFields.materielCode);
                }
              };
            }
          });
        });
        this.editFormOptions.forEach((option) => {
          option.forEach((item) => {
            if (item.field == 'quantity') {
              //初始化弹出框选择器配置
              item.extra = {
                icon: 'el-icon-zoom-out', //显示图标
                text: '采购单最大数量', //显示文本
                style: 'color: #3a8ee6;font-size: 13px;cursor: pointer;',
                //触发事件
                click: (item) => {
                  this.$refs.modelFooter.open(this.editFormFields.purchaseOrderNo);
                }
              };
            }
          });
        });
        this.editFormOptions.forEach((option) => {
          option.forEach((item) => {
            if (item.field == 'materielSpec') {
              //初始化弹出框选择器配置
              item.extra = {
                icon: 'el-icon-zoom-out', //显示图标
                text: '选择物料规格', //显示文本
                style: 'color: #3a8ee6;font-size: 13px;cursor: pointer;',
                //触发事件
                click: (item) => {
                  this.$refs.modelSpec.open(this.editFormFields.purchaseOrderNo,this.editFormFields.materielCode);
                }
              };
            }
          });
        });
        // warehouseIdOption.onChange = (val, option) => {
        //   this.editFormFields.materielCode = "";
        //   materielCodeOption.data = [];
        //   this.editFormFields.purchaseOrderNo = "";
        //   purchaseOrderNoOption.data = [];
        //   if (val == null || val == 0) {
        //     return this.$error("请选择仓库!")
        //   }
        //   this.http.post("/api/PurchaseOrderDetail/GetPurchaseOrderDetailMaterielCode?warehouseId=" + val, {}, true).then(
        //     source => {
        //       if (!source.status) return this.$error(source.message);
        //       this.$nextTick(() => {
 
        //         for (let i = 0; i < source.data.length; i++) {
        //           materielCodeOption.data.push({ key: source.data[i], value: source.data[i] })
        //         }
        //       })
        //     })
        // }
        // materielCodeOption.onChange = (val, option) => {
        //   this.editFormFields.purchaseOrderNo = "";
        //   purchaseOrderNoOption.data = [];
        //   if (val == null || val == 0) {
        //     return this.$error("请选择物料编号!")
        //   }
        //   this.http.post("/api/PurchaseOrderDetail/GetPurchaseOrderNos?materielCode=" + val, {}, true).then(
        //     source => {
        //       if (!source.status) return this.$error(source.message);
        //       this.$nextTick(() => {
        //         for (let i = 0; i < source.data.length; i++) {
        //           purchaseOrderNoOption.data.push({ key: source.data[i], value: source.data[i] })
        //         }
        //       });
        //     })
        // }
      });
 
      // 页面加载时初始化已高亮的行
      const initHighlightedRows = () => {
        try {
          const highlightedRowIds = localStorage.getItem('highlightedRowIds');
          if (highlightedRowIds) {
            this.highlightedRowIds = JSON.parse(highlightedRowIds);
          } else {
            this.highlightedRowIds = [];
          }
        } catch (e) {
          console.error('Failed to load highlighted rows from localStorage:', e);
          this.highlightedRowIds = [];
        }
      };
 
      // 保存高亮行ID到本地存储
      const saveHighlightedRows = () => {
        try {
          localStorage.setItem('highlightedRowIds', JSON.stringify(this.highlightedRowIds));
        } catch (e) {
          console.error('Failed to save highlighted rows to localStorage:', e);
        }
      };
 
      // 在组件初始化时调用
      initHighlightedRows();
 
      this.columns.push({
        field: '操作',
        title: '操作',
        width: 90,
        fixed: 'right',
        align: 'center',
        formatter: (row) => {
          return (
            '<i style="cursor: pointer;color: #2d8cf0;" class="el-icon-printer">打印</i>'
          );
        },
        click: (row) => {
          // 打开详情
          this.$refs.gridBody.open(row);
          // 获取行的唯一标识(假设row.id是唯一ID)
          const rowId = row.id;
          // 添加到已高亮列表
          if (!this.highlightedRowIds.includes(rowId)) {
            this.highlightedRowIds.push(rowId);
            // 保存到本地存储
            saveHighlightedRows();
            // 刷新表格以应用样式
            this.$refs.gridBody.refresh();
          }
        }
      });
 
      // 配置cellStyle
      this.columns.forEach((column) => {
        // 保存原有的cellStyle函数
        const originalCellStyle = column.cellStyle;
        
        column.cellStyle = (row) => {
          // 先应用原有的样式逻辑
          let style = originalCellStyle ? originalCellStyle(row) : {};
          
          // 如果行被标记为高亮,则添加绿色背景
          if (this.highlightedRowIds.includes(row.id)) {
            style = {
              ...style,
              background: '#d4edda', 
              color: '#155724'
            };
          }
          
          return style;
        };
      });
    },
    onInited() {
      //框架初始化配置后
      //如果要配置明细表,在此方法操作
      //this.detailOptions.columns.forEach(column=>{ });
    },
    searchBefore(param) {
      //界面查询前,可以给param.wheres添加查询参数
      //返回false,则不会执行查询
      return true;
    },
    searchAfter(result) {
      //查询后,result返回的查询数据,可以在显示到表格前处理表格的值
      return true;
    },
    addBefore(formData) {
      //新建保存前formData为对象,包括明细表,可以给给表单设置值,自己输出看formData的值
      return true;
    },
    updateBefore(formData) {
      //编辑保存前formData为对象,包括明细表、删除行的Id
      return true;
    },
    rowClick({ row, column, event }) {
      //查询界面点击行事件
      // this.$refs.table.$refs.table.toggleRowSelection(row); //单击行时选中当前行;
    },
    modelOpenAfter(row) {
      //点击编辑、新建按钮弹出框后,可以在此处写逻辑,如,从后台获取数据
      //(1)判断是编辑还是新建操作: this.currentAction=='Add';
      //(2)给弹出框设置默认值
      //(3)this.editFormFields.字段='xxx';
      //如果需要给下拉框设置默认值,请遍历this.editFormOptions找到字段配置对应data属性的key值
      //看不懂就把输出看:console.log(this.editFormOptions)
      let isAdd = this.currentAction == 'Add';
      if (isAdd) {
        let date = new Date();
        let year = date.getFullYear();
        let month = String(date.getMonth() + 1).padStart(2, "0");
        let day = String(date.getDate()).padStart(2, "0");
        let hour= String(date.getHours()).padStart(2, "0");
        let minute= String(date.getMinutes()).padStart(2, "0");
        let second= String(date.getSeconds()).padStart(2, "0");
        //将year截取后两位
        this.editFormFields.lotNo = (year.toString().substr(-2)) + month+day + hour + minute+second;
        this.editFormFields.productionDate = year + "-" + month + "-" + day;
        this.editFormFields.effectiveDate = year + 2 + "-" + month + "-" + day;
      }
    }
  }
};
export default extension;