NameError: name 'arr' is not defined
时间: 2023-09-08 07:10:49 浏览: 163
This error occurs when you try to use a variable or object that has not been defined or declared in the current scope. To fix this error, you need to define or declare the variable or object before using it in your code.
For example, if you are getting this error for the variable 'arr', you can define it as follows:
```
arr = [1, 2, 3, 4, 5]
```
This will define 'arr' as a list containing the values 1 through 5. You can then use 'arr' in your code without getting a NameError.
相关问题
NameError: name 'im' is not defined. Did you mean: 'id'?
这个错误提示意味着你在使用变量`im`之前没有定义它。请检查你的代码,确保变量`im`已经被正确地定义和赋值。
例如,如果你的代码类似于以下形式:
```python
im_arr = np.array(im)
im.show()
```
这里的问题是在使用变量`im`之前没有定义它,可以将其改为以下形式:
```python
im = Image.open('D:/wjd/test.png')
im_arr = np.array(im)
im.show()
```
注意到现在`im`变量已经被定义和赋值,可以被后面的代码使用。请根据你的具体代码,正确地定义和赋值变量`im`。
Error in setup: "ReferenceError: originColums is not defined" found in
在提供的代码片段中,确实存在一个引用错误:“ReferenceError: originColums is not defined”。此错误发生在尝试使用 `originColums` 变量之前未正确初始化它。具体来说,在 `setup` 函数中,`originColums` 应该被定义并初始化为空数组或所需的初始值。
以下是修正后的代码:
```javascript
<template>
...
</template>
<script>
import Vue from 'vue'
import { ref, reactive, onMounted } from '@vue/composition-api';
import MyFastDatePicker from '@/components/date/MyFastDatePicker'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
export default {
name: 'ProjectMaterialDetails',
mixins: [JeecgListMixin, mixinDevice],
components: { MyFastDatePicker },
setup(props, context) {
const state = reactive({
nowFirst: 'projectCode',
columnsKey: 0,
projectNameList: [],
projectName_Code: '',
projectBudgetMarginWarning: 0,
expandedRowKeys: [],
workorderProjectList: [],
description: '营业报表管理页面',
fastTime: ['本月', '上月', '近半年'],
noCreate: true,
hasUpdateTime: true,
configOrderSubTypeList: [],
configOrderSubTypeTemp: undefined,
allDepartList: [],
hallCodeDataList: [],
spinning: false,
checkFlag: true,
updateTime: '',
url: {
list: "/web/materialVoucherDetails/getProjectMaterialStatistic",
exportXlsxUrl: "/web/materialVoucherDetails/exportProjectMaterialStatisticExcel",
exportPdfUrl: "/web/bizBusinessRecord/exportpdf",
exportDetailUrl: "/web/bizBusinessRecord/exportDetailExcel"
},
keyList: ['saleNum', 'saleName', 'terminalTypeName', 'userTypeName', 'configOrderMainTypeName', 'configOrderSubTypeName'],
ipagination: {
current: 1,
pageSize: 20,
pageSizeOptions: ['20', '50', '80'],
showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`,
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
originColums: [], // 初始化 originColums
columns: [
{ title: '项目编号', align: "center", dataIndex: 'projectCode', customRender: (text, row, index) => renderMergedCells(text, row, index, 'projectCode') },
{ title: '项目名称', align: "center", dataIndex: 'projectCode_dictText', customRender: (text, row, index) => renderMergedCells(text, row, index, 'projectCode_dictText') },
{ title: '(子)项目名称', align: "center", dataIndex: 'subProjectCode_dictText', customRender: (text, row, index) => renderMergedCells(text, row, index, 'subProjectCode_dictText') },
{ title: '部门名称', align: "center", dataIndex: 'orgCode_dictText', customRender: (text, row, index) => renderMergedCells(text, row, index, 'orgCode_dictText') },
{ title: '物资编号', align: "center", dataIndex: 'materialCode', scopedSlots: { customRender: 'publicText' } },
{ title: '物资名称', align: "center", dataIndex: 'materialName', scopedSlots: { customRender: 'publicText' } },
{ title: '厂商', align: "center", dataIndex: 'producerId_dictText', scopedSlots: { customRender: 'publicText' } },
{ title: '规格型号', align: "center", dataIndex: 'specification', scopedSlots: { customRender: 'publicText' } },
{ title: '单位', align: "center", dataIndex: 'unit', scopedSlots: { customRender: 'publicText' } },
{ title: '成本价(元)', align: "center", dataIndex: 'originPrice', scopedSlots: { customRender: 'publicText' } },
{ title: '领用总数', align: "center", dataIndex: 'requisitionNum', slots: { title: 'requisitionNum_title' }, scopedSlots: { customRender: 'publicText' } },
{ title: '施工用料', align: "center", dataIndex: 'constructionNum', scopedSlots: { customRender: 'publicText' } },
{ title: '验收用料', align: "center", dataIndex: 'acceptanceNum', scopedSlots: { customRender: 'publicText' } },
{ title: '结算用料', align: "center", dataIndex: 'settlementNum', scopedSlots: { customRender: 'publicText' } },
{ title: '结算余料', align: "center", dataIndex: 'settlementRemainNum', scopedSlots: { customRender: 'settlementRemainNum' } },
{ title: '盘点余料', align: "center", dataIndex: 'inventoryRemainNum', scopedSlots: { customRender: 'publicText' } },
{ title: '盘点损益', align: "center", dataIndex: 'inventoryProfitAndLossNum', slots: { title: 'inventoryProfitAndLossNum_title' }, scopedSlots: { customRender: 'inventoryProfitAndLossNum' } }
],
queryParam: {
type: '',
projectCode: '',
projectName: '',
projectName_Code: "",
subProjectName: '',
departId: '',
material: '',
producerId: '',
specification: '',
materialInventoryResult: '',
projectDateBegin: '',
projectDateEnd: ''
},
dataSource: [],
loading: false,
toggleSearchStatus: false
});
const renderMergedCells = (value, row, index, dataIndex) => {
const obj = { children: value, attrs: {} };
const dataSource = state.dataSource;
if (dataIndex === 'projectCode') {
if (index === 0 || row.projectCode_dictText !== dataSource[index - 1].projectCode_dictText) {
let rowSpan = 1;
for (let i = index + 1; i < dataSource.length; i++) {
if (dataSource[i].projectCode_dictText === row.projectCode_dictText) {
rowSpan++;
} else {
break;
}
}
obj.attrs.rowSpan = rowSpan;
} else {
obj.attrs.rowSpan = 0;
}
} else if (dataIndex === 'orgCode_dictText') {
if (index === 0 || row.orgCode_dictText !== dataSource[index - 1].orgCode_dictText || row.projectCode_dictText !== dataSource[index - 1].projectCode_dictText) {
let rowSpan = 1;
for (let i = index + 1; i < dataSource.length; i++) {
if (dataSource[i].orgCode_dictText === row.orgCode_dictText && dataSource[i].projectCode_dictText === row.projectCode_dictText) {
rowSpan++;
} else {
break;
}
}
obj.attrs.rowSpan = rowSpan;
} else {
obj.attrs.rowSpan = 0;
}
} else {
if (index === 0 || row.subProjectCode_dictText !== dataSource[index - 1].subProjectCode_dictText) {
let rowSpan = 1;
for (let i = index + 1; i < dataSource.length; i++) {
if (dataSource[i].subProjectCode_dictText === row.subProjectCode_dictText) {
rowSpan++;
} else {
break;
}
}
obj.attrs.rowSpan = rowSpan;
} else {
obj.attrs.rowSpan = 0;
}
}
return obj;
};
const materialInventoryResultChange = (val) => {
state.queryParam.materialInventoryResult = val;
forceUpdate();
};
const beforeSearchQuery = () => {
searchQuery();
departChange(state.queryParam.type);
};
const beforeSearchReset = () => {
searchReset();
departChange();
};
const deepClone = (input, hash = new WeakMap()) => {
if (input === null || typeof input !== 'object') {
return input;
}
if (hash.has(input)) {
return hash.get(input);
}
let output = Array.isArray(input) ? [] : {};
hash.set(input, output);
if (Array.isArray(input)) {
output = input.map(item => deepClone(item, hash));
} else {
for (let key in input) {
if (input.hasOwnProperty(key)) {
if (typeof input[key] === 'function') {
output[key] = input[key].bind(output);
} else {
output[key] = deepClone(input[key], hash);
}
}
}
}
return output;
};
const departChange = (val) => {
if (val == 2) {
state.nowFirst = 'orgCode_dictText';
let objectArray = deepClone(state.originColums);
let movedElement = objectArray.splice(3, 1)[0];
objectArray.unshift(movedElement);
state.columns = objectArray;
} else {
state.nowFirst = 'projectCode';
state.columns = deepClone(state.originColums);
}
state.columnsKey += 1;
};
const subProjectCodeChange = (val, options) => {
console.log('subProjectCodeChange', val, options, state.queryParam.subProjectName);
};
const projectCodeSearch = (value) => {
getAction('/web/projectRecord/searchMainProject', { order: 'desc', pageNo: 1, pageSize: 100, keyword: value }).then(res => {
state.projectNameList = res.result.map(item => ({ id: item.id, value: item.projectCode, text: item.projectName }));
});
};
const projectCodeChange = (value) => {
state.queryParam.projectName_Code = value;
const obj = state.projectNameList.find(item => item.id === value);
if (obj) {
state.exportParams.projectName = obj.text;
state.queryParam.projectName = obj.text;
} else {
state.exportParams.projectName = '';
state.queryParam.projectName = '';
}
};
const change = (val1, val2, val3) => {
console.log('改变', val3);
state.exportParams.dateTpye = val3 === 2 ? 1 : 2;
state.queryParam.projectDateBegin = val1;
state.queryParam.projectDateEnd = val2;
state.queryParam.hiddenZeroTotalAmountFlag = state.checkFlag ? 1 : 0;
};
const handelChange = () => {
state.configOrderSubTypeTemp = undefined;
state.queryParam.configOrderSubType = undefined;
state.queryParam.incomeExpenseType = '';
getConfigOrderSubTypeList();
};
const getConfigOrderSubTypeList = () => {
if (state.queryParam.configOrderMainType) {
getAction('/web/bizTransactionOrder/getOrderSubType', { configOrderMainType: state.queryParam.configOrderMainType }).then(res => {
if (res.code == 200) {
switch (state.queryParam.configOrderMainType) {
case '1':
let arr = [];
for (let i = 0; i < res.result.length; i++) {
arr.push(res.result.slice(i, i + 1));
}
arr.forEach(v => {
v.push({ value: v[0].value, label: v[0].label + '(退)' });
});
let result = [].concat.apply([], arr).filter(v => v.value != 96 && v.value != 98);
state.configOrderSubTypeList = result;
break;
case '2':
state.configOrderSubTypeList = res.result.filter(v => Number(v.value) <= 7 || Number(v.value) == 15 || Number(v.value) == 16 || Number(v.value) == 20 || Number(v.value) == 21);
break;
case '3':
state.configOrderSubTypeList = res.result.filter(v => Number(v.value) !== 7 && Number(v.value) !== 8 && Number(v.value) !== 12 && Number(v.value) !== 14 && Number(v.value) !== 10 && Number(v.value) !== 16);
break;
default:
state.configOrderSubTypeList = res.result;
break;
}
}
});
} else {
Vue.prototype.$message.warning('请选择业务类型!');
}
};
const handleChange = (val) => {
state.configOrderSubTypeList = [];
state.queryParam.configOrderSubType = '';
state.configOrderSubTypeTemp = undefined;
state.queryParam.incomeExpenseType = '';
};
const handleConfigOrderSubTypeChange = (val) => {
state.configOrderSubTypeTemp = val;
if (state.queryParam.configOrderMainType == 1) {
state.queryParam.incomeExpenseType = val.key.substr(val.key.length - 1, 1);
} else {
state.queryParam.incomeExpenseType = '';
}
};
const handleOpen = (record) => {
};
const filterOption = (input, option) => {
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
};
const searchQuery = () => {
let val = state.configOrderSubTypeTemp;
if (val) {
if (state.queryParam.configOrderMainType == 1) {
if (val.key.length == 2) {
state.queryParam.configOrderSubType = val.key.substr(0, 1);
} else {
state.queryParam.configOrderSubType = val.key.substr(0, 2);
}
} else {
state.queryParam.configOrderSubType = val.key;
}
}
loadData(1);
};
const searchReset = () => {
state.queryParam.type = '';
state.queryParam.projectName = '';
state.queryParam.subProjectName = '';
state.queryParam.departId = '';
state.queryParam.material = '';
阅读全文