diff --git a/src/components/uploadComponent/index.vue b/src/components/uploadComponent/index.vue index 9ecdbad..30a8057 100644 --- a/src/components/uploadComponent/index.vue +++ b/src/components/uploadComponent/index.vue @@ -35,6 +35,7 @@ import { ElMessage } from 'element-plus' // import { Base64 } from 'js-base64' const tmpUploadUrl = import.meta.env.VITE_API_URL + '/zlpt-file/file/cos/upload' + console.log(tmpUploadUrl) import { mainStore } from 'store/main' const store = mainStore() const headerInfo = reactive({ diff --git a/src/http/api/usercenter/goodsmang.ts b/src/http/api/usercenter/goodsmang.ts index dd04e36..9cb1be3 100644 --- a/src/http/api/usercenter/goodsmang.ts +++ b/src/http/api/usercenter/goodsmang.ts @@ -8,12 +8,12 @@ export const getEquipmentListApi = (data: any) => { } //获取装备详情 -export const getDetail = (id = '') => { - return get(`/material-mall/dev/getInfo/${id}`) +export const getDetailApi = (id: any) => { + return get(`/material-mall/dev/getInfo/${id}`, {}) } // 新增装备 -export const equipmentDeploymentApi = (data: any) => { +export const equipmentAddApi = (data: any) => { return post('/material-mall/dev', data) } diff --git a/src/views/user/goodsManagement/index.vue b/src/views/user/goodsManagement/index.vue index 4ee329d..3776ce0 100644 --- a/src/views/user/goodsManagement/index.vue +++ b/src/views/user/goodsManagement/index.vue @@ -4,14 +4,22 @@ import PagingComponent from 'components/PagingComponent/index.vue' import uploadComponent from 'components/uploadComponent/index.vue' import previewImg from './previewImg/index.vue' - import { ElMessage } from 'element-plus' + import { ElMessage,ElMessageBox } from 'element-plus' + import type { FormInstance } from 'element-plus' import { ref } from 'vue' import { useStore } from 'store/user' const store = useStore() import { mainStore } from 'store/main' const store2 = mainStore() import { - getEquipmentListApi,getEquipmentTypeApi,getCompanyListApi + getEquipmentTypeApi,//装备类型 + getCompanyListApi,//所属公司 + getEquipmentListApi,//列表 + getDetailApi,//详情 + equipmentAddApi,//新增 + insertDraftApi,//草稿(编辑) + removeDeviceApi,//删除 + updateUpDownApi//上下架 } from 'http/api/usercenter/goodsmang' // 注册地址拼装 @@ -42,6 +50,7 @@ console.log("treeData==========", res); deviceTypeTree.value = res.data; } + //装备类目-change const deviceTypeChange = (val: any) => { console.log(val) if(val.length > 0) { @@ -49,9 +58,28 @@ } else { queryParams.value.typeId = "" } - } - /* 查询参数 */ + } + //反显 树结构数据获取父 + const getSelectId = (list: any,id: any) => { + for (let i in list) { + if (list[i].id == id) { + //查询到就返回该数组对象的value + return [list[i].id]; + } + if (list[i].children) { + let node: any = getSelectId(list[i].children, id); + if (node !== undefined) { + //查询到把父节把父节点加到数组前面 + node.unshift(list[i].id); + return node; + } + } + } + } + + /* 装备树选中数组 */ const deviceTypeList: any = ref([]) + //日期周期 const dateRange: any = ref([]) /* 查询参数 */ const queryParams: any = ref({ @@ -62,8 +90,162 @@ pageSize: 10, pageNum: 1 }) + const queryFormRef = ref() const total: any = ref(0) const tableData: any = ref([]) + /* 查询按钮 */ + const queryTableList = () => { + queryParams.value.pageNum=1 + getList() + } + // 重置 + const resetTableList = (formEl: FormInstance | undefined) => { + if (!formEl) return + formEl.resetFields() + dateRange.value = [] + deviceTypeList.value = [] + queryParams.value.typeId = null; + queryTableList() + } + // 获取数据列表 + const getList = async () => { + console.log(queryParams.value.pageNum, '***9999', queryParams.value.pageSize) + const res: any = await getEquipmentListApi(queryParams.value) + console.log(res, '列表数据**--**') + + total.value = res.total + tableData.value = res.rows.filter((item: any) => item !== null) + } + // 获取数据列表 + getList() + + //---列表按钮事件--- + // 装备新增按钮 + const equipmentDeployment = () => { + settleinTitle.value = '新增装备' + disabledForm.value = false + isEditDisabled.value = true + equipmentDeploymentParams.value = { + deviceName: '', + deviceTypeList: [], + deviceCount: 1, + unitName: '', + code: '', + brand: '', + typeId: '', + companyId: '', + productionDate: '', + dayLeasePrice: '', + person: '', + personPhone: '', + deviceWeight: '', + } + mainFileList.value=[]; + detailsFileList.value=[]; + insurancePdf.value=[]; + examinationPdf.value=[]; + // 打开入驻弹框 + dialogFormVisibleSettlein.value = true + } + + const maId: any = ref('') + // 编辑按钮 + const editRowInfo = (row: any) => { + settleinTitle.value = '装备编辑' + getDetailData(row) + disabledForm.value = false + isEditDisabled.value = true + } + /* 查看按钮 */ + const previewRowInfo = (row: any) => { + settleinTitle.value = '装备详情' + getDetailData(row) + disabledForm.value = true + isEditDisabled.value = false + } + // 删除按钮 + const deleteRowInfo = async (row: any) => { + ElMessageBox.confirm('是否确定删除?', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }).then(() => { + const res: any = removeDeviceApi([row.maId]) + if (res.code === 200) { + ElMessage({ + type: 'success', + message: '删除成功' + }) + getList() + } + }).catch(() => {}) + } + //获取详情接口 + const getDetailData = async(row: any) => { + console.log(row,"----row----") + maId.value = row.maId; + const res: any = await getDetailApi(row.maId) + console.log(res,"----detail----") + equipmentDeploymentParams.value = res.data; + equipmentDeploymentParams.value.companyId = Number(res.data.companyId); + mainFileList.value=res.data.mainFileList; + detailsFileList.value=res.data.detailsFileList; + insurancePdf.value=res.data.insurancePdf; + examinationPdf.value=res.data.examinationPdf; + //反显 装备树 + equipmentDeploymentParams.value.deviceTypeList = getSelectId(deviceTypeTree.value, equipmentDeploymentParams.value.typeId); + dialogFormVisibleSettlein.value = true; + // equipmentDeploymentParams.value.cityId = String(equipmentDeploymentParams.value.cityId) + // equipmentDeploymentParams.value.areaId = String(equipmentDeploymentParams.value.areaId) + // equipmentDeploymentParams.value.provinceId = String( + // equipmentDeploymentParams.value.provinceId + // ) + // equipmentDeploymentParams.value.leaseScope = String( + // equipmentDeploymentParams.value.leaseScope + // ) + // equipmentDeploymentParams.value.groupId = Number(equipmentDeploymentParams.value.groupId) + // equipmentDeploymentParams.value.typeId = Number(equipmentDeploymentParams.value.typeId) + // store.getprovinceList() + // store.getmarketList(row.provinceId) + // store.getareaList(row.cityId) + // store.getDeviceTypeList() + // store.getDeviceTypeSonList(row.companyId) + // store.getDeviceTypeSunList(row.groupId) + } + + + + const ids: any = ref([]) + const handleSelectionChange = (selection:any) =>{ + ids.value = selection.map((item:any) => item.maId) + } + // 上下架(批量) + const handleUpdateUpDown = (row: any,maStatus:any) => { + ElMessageBox.confirm('是否确定操作', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }).then(() => { + let maIds = [] + if (!row){ + maIds = ids.value + } else { + maIds.push(row.maId) + } + if (maIds.length == 0){ + ElMessage({type: 'error',message: '请选择要操作的数据'}) + return + } + const res: any = updateUpDownApi({maIds,maStatus}) + if (res.code === 200) { + ElMessage({ + type: 'success', + message: '操作成功' + }) + queryTableList() + } + }).catch(() => {}) + } // // 省级数据源 // const selProvinceList: any = computed(() => { @@ -124,10 +306,11 @@ // // 设备类型小类 // const changeDeviceTypeSun = (val: any) => { // // deviceType[2] = val.split(',')[1] - // } - - - // 弹窗 + // } + + /* + ----装备弹窗----- + */ /* 查看 */ const disabledForm = ref(false) /* 编辑 */ @@ -139,8 +322,7 @@ /* * 商品入驻弹框参数 */ - const equipmentDeploymentParams: any = ref({ - /* 设备名称 */ + const equipmentDeploymentParams: any = ref({ deviceName: '', deviceTypeList: [], deviceCount: 1, @@ -159,6 +341,7 @@ const countDisabled = ref(false) //装备类目-change const dialogTypeCascader = ref() + //装备类目-change const dialogTypeChange = () => { const deviceTypeList = dialogTypeCascader.value.getCheckedNodes() console.log(deviceTypeList) @@ -177,265 +360,54 @@ const res: any = await getCompanyListApi() console.log(res, '列表数据**--**') companyDataList.value = res.data - } - // 获取数据列表 - const getList = async () => { - console.log(queryParams.value.pageNum, '***9999', queryParams.value.pageSize) - const res: any = await getEquipmentListApi(queryParams.value) - console.log(res, '列表数据**--**') - - total.value = res.total - tableData.value = res.rows.filter((item: any) => item !== null) - } - getList() - - - // 选择复选框时获取需要删除的数据源 - const getRowId = (val: any) => { - console.log(val, '需要删除的数据源**') - } - - // 编辑按钮 - const editRowInfo = (row: any) => { - settleinTitle.value = '装备入驻编辑' - // row.fileList = [] - getRowList(row) - isEditDisabled.value = true - disabledForm.value = false - } - // 删除按钮 - const deleteRowInfo = async (row: any) => { - const res: any = await deleteGoodstApi([row.maId]) - if (res.code === 200) { - ElMessage({ - type: 'success', - message: '删除成功' - }) - getList() - } - } - - /* 查看按钮 */ - const previewRowInfo = (row: any) => { - settleinTitle.value = '装备详情' - row.devPicList = [] - // row.fileList.map((item) => { - // if (item.dicId == 28) { - // row.jcUrl = item.fileUrl - // } - // if (item.dicId == 29) { - // row.bsUrl = item.fileUrl - // } - // if (item.dicId == 20) { - // row.devPicList.push(item.fileUrl) - // } - // }) - - getRowList(row) - disabledForm.value = true - isEditDisabled.value = false - } - - const getRowList = (row: any) => { - equipmentDeploymentParams.value = row - equipmentDeploymentParams.value.cityId = String(equipmentDeploymentParams.value.cityId) - equipmentDeploymentParams.value.areaId = String(equipmentDeploymentParams.value.areaId) - equipmentDeploymentParams.value.provinceId = String( - equipmentDeploymentParams.value.provinceId - ) - equipmentDeploymentParams.value.leaseScope = String( - equipmentDeploymentParams.value.leaseScope - ) - - equipmentDeploymentParams.value.companyId = Number( - equipmentDeploymentParams.value.companyId - ) - equipmentDeploymentParams.value.groupId = Number(equipmentDeploymentParams.value.groupId) - equipmentDeploymentParams.value.typeId = Number(equipmentDeploymentParams.value.typeId) - dialogFormVisibleSettlein.value = true - store.getprovinceList() - store.getmarketList(row.provinceId) - store.getareaList(row.cityId) - store.getDeviceTypeList() - store.getDeviceTypeSonList(row.companyId) - store.getDeviceTypeSunList(row.groupId) - } - - // 装备入驻按钮 - const equipmentDeployment = () => { - settleinTitle.value = '新增装备入驻' - isEditDisabled.value = true - disabledForm.value = false - equipmentDeploymentParams.value = { - /* 企业Id */ - ownCo: mainStore().userInfo.companyId, - /* 租赁范围 */ - leaseScope: '', - /* 设备所在地 */ - location: '', - /* 省 */ - provinceId: '', - /* 市 */ - cityId: '', - /* 区 */ - areaId: '', - /* 设备所在地 省 */ - addressEconomize: '', - /* 设备所在地 市 */ - addressProvince: '', - /* 设备所在地 区 */ - addressArea: '', - /* 设备类型 */ - typeId: '', - /* 设备类型大类 */ - deviceType: '', - /* 设备类型子类 */ - deviceTypeSon: '', - /* 设备类型小类*/ - deviceTypeSun: '', - /* 设备品牌 */ - brand: '', - /* 设备型号 */ - modelName: '', - /* 出场日期 */ - productionDate: '', - /* 工作小时数 */ - workingHours: '', - /* 整机序列号 */ - serialNumber: '', - /* 月租金 */ - monthLeasePrice: '', - /* 日租金 */ - dayLeasePrice: '', - /* 是否提供机手 */ - isOperator: '', - /* 机手月费用 */ - jsMonthPrice: '', - /* 机手日费用 */ - jsDayPrice: '', - /* 详细说明 */ - description: '', - /* 设备主图片 */ - picUrl: '', - /* 检测信息 ,保险信息*/ - fileList: [], - /* 设备状态 */ - maStatus: 15, - detectionList: [], - insureList: [], - picList: [] - } - // 打开入驻弹框 - dialogFormVisibleSettlein.value = true - } - - const ruleFormRef: any = ref(null) - - /* 关闭按钮 */ - const closeDialogBtn = () => { - ruleFormRef.value.resetFields() - dialogFormVisibleSettlein.value = false - } - - // 入驻框保存提交 - const submitBtn = () => { - ruleFormRef.value.validate(async (valid: any) => { - if (valid) { - if (settleinTitle.value === '装备入驻编辑') { - const res: any = await equipmentEditApi(equipmentDeploymentParams.value) - if (res.code === 200) { - ElMessage({ - type: 'success', - message: '修改成功' - }) - dialogFormVisibleSettlein.value = false - ruleFormRef.value.resetField() - getList() - } - } else { - const res: any = await equipmentDeploymentApi(equipmentDeploymentParams.value) - if (res.code === 200) { - ElMessage({ - type: 'success', - message: '入驻成功' - }) - dialogFormVisibleSettlein.value = false - ruleFormRef.value.resetField() - getList() - } - } - } - }) - } - - - // 装备入驻弹框显示隐藏 + } + // 装备弹框显示隐藏 const dialogFormVisibleSettlein: any = ref(false) - + const ruleFormRef: any = ref(null) + //表单校验规则 const equipRules = ref({ - leaseScope: [ + deviceName: [ { required: true, - message: '请选择租赁范围', + message: '请输入装备名称', + trigger: 'blur' + } + ], + deviceTypeList: [ + { + required: true, + message: '请选择装备类目', trigger: 'change' } ], - provinceId: [ + deviceCount: [ { required: true, - message: '请选择省', - trigger: 'change' + message: '请输入装备数量', + trigger: 'blur' } ], - cityId: [ + brand: [ { required: true, - message: '请选择市', - trigger: 'change' + message: '请输入装备品牌', + trigger: 'blur' } ], - areaId: [ + code: [ { required: true, - message: '请选择区', + message: '请输入装备编号', trigger: 'change' } ], companyId: [ { required: true, - message: '请选择设备类型', + message: '请选择所属公司', trigger: 'change' } ], - groupId: [ - { - required: true, - message: '请选择组别', - trigger: 'change' - } - ], - typeId: [ - { - required: true, - message: '请选择产品名称', - trigger: 'change' - } - ], - brand: [ - { - required: true, - message: '请输入设备品牌', - trigger: 'blur' - } - ], - modelName: [ - { - required: true, - message: '请输入设备型号', - trigger: 'blur' - } - ], productionDate: [ { required: true, @@ -443,77 +415,109 @@ trigger: 'change' } ], - workingHours: [ - { - required: true, - message: '请输入工作小时数', - trigger: 'blur' - } - ], - serialNumber: [ - { - required: true, - message: '请输入整机序列号', - trigger: 'blur' - } - ], - monthLeasePrice: [ - { - required: true, - message: '请输入月租金', - trigger: 'blur' - } - ], dayLeasePrice: [ { required: true, - message: '请输入天租金', + message: '请输入日租金', trigger: 'blur' } ], - isOperator: [ + person: [ + { required: true, message: "联系人不能为空", trigger: "blur" } + ], + personPhone: [ + { required: true, message: "联系电话不能为空", trigger: "blur" }, { - required: true, - message: '请确定是否需要机手', - trigger: 'blur' + pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, + message: "请输入正确的手机号码", + trigger: "blur" } ], - jsMonthPrice: [ - { - required: true, - message: '请输入机手月费用', - trigger: 'blur' - } - ], - jsDayPrice: [ - { - required: true, - message: '请输入机手日费用', - trigger: 'blur' - } - ], - detectionList: [ - { - required: true, - message: '请上传检测信息', - trigger: 'change' - } - ], - insureList: [ - { - required: true, - message: '请上传保险信息', - trigger: 'change' - } - ], - picList: [ - { - required: true, - message: '请上传设备图片信息', - trigger: 'change' - } - ] + deviceWeight: [// + { required: true, message: "整机重量不能为空", trigger: "blur" } + ], }) + // 弹框保存提交 + const submitBtn = () => { + ruleFormRef.value.validate(async (valid: any) => { + if (valid) { + if (equipmentDeploymentParams.value.deviceTypeList&&equipmentDeploymentParams.value.deviceTypeList.length > 0) { + equipmentDeploymentParams.value.typeId = equipmentDeploymentParams.value.deviceTypeList[3] + } else { + equipmentDeploymentParams.value.typeId = "" + } + if(mainFileList.value.length==0||mainFileList.value.length>6){ + ElMessage({type: 'error',message: '主展示图不得少于1张,不得多于6张'}) + return + } + if(detailsFileList.value.length==0||detailsFileList.value.length>6){ + ElMessage({type: 'error',message: '详情展示图不得少于1张,不得多于6张'}) + return + } + let param = { + ...equipmentDeploymentParams.value, + mainFileList:mainFileList.value,//主展示 + detailsFileList:detailsFileList.value,//详情展示 + insurancePdf:insurancePdf.value,//合格证 + examinationPdf:examinationPdf.value,//检测证明 + } + const res: any = await equipmentAddApi(param) + if (res.code === 200) { + ElMessage({ + type: 'success', + message: '保存成功' + }) + dialogFormVisibleSettlein.value = false + ruleFormRef.value.resetField() + getList() + } + } + }) + } + //草稿 + const saveTemp = async() => { + if (equipmentDeploymentParams.value.deviceTypeList&&equipmentDeploymentParams.value.deviceTypeList.length > 0) { + equipmentDeploymentParams.value.typeId = equipmentDeploymentParams.value.deviceTypeList[3] + } else { + equipmentDeploymentParams.value.typeId = "" + } + // if(mainFileList.value.length==0||mainFileList.value.length>6){ + // ElMessage({type: 'error',message: '主展示图不得少于1张,不得多于6张'}) + // return + // } + // if(detailsFileList.value.length==0||detailsFileList.value.length>6){ + // ElMessage({type: 'error',message: '详情展示图不得少于1张,不得多于6张'}) + // return + // } + let param = { + ...equipmentDeploymentParams.value, + mainFileList:mainFileList.value,//主展示 + detailsFileList:detailsFileList.value,//详情展示 + insurancePdf:insurancePdf.value,//合格证 + examinationPdf:examinationPdf.value,//检测证明 + } + const res: any = await insertDraftApi(param) + if (res.code === 200) { + ElMessage({ + type: 'success', + message: '保存成功' + }) + dialogFormVisibleSettlein.value = false + ruleFormRef.value.resetField() + getList() + } + } + /* 关闭按钮 */ + const closeDialogBtn = () => { + ruleFormRef.value.resetFields() + dialogFormVisibleSettlein.value = false + } + /* 关闭对话框 */ + const handleClose = (done: () => void) => { + ruleFormRef.value.resetFields() + done() + dialogFormVisibleSettlein.value = false + } /* 检测信息图片地址 */ const successResultCallBackFnjc = (val: any) => { @@ -545,23 +549,20 @@ fileUrl: val.msg }) } - - + const mainFileList: any = ref([])//主展示 const detailsFileList: any = ref([])//详情展示 const insurancePdf: any = ref([])//合格证 - const examinationPdf: any = ref([])//检测证明 - + const examinationPdf: any = ref([])//检测证明 //图片查看弹窗 const dialogVisible: any = ref(false) const dialogImageUrl = ref('') - //上传 - const upload: any = ref({ - // 设置上传的请求头部 - headers: { Authorization: "Bearer " + store2.token }, - // 上传的地址 - url: import.meta.env.VITE_API_URL + "/file/upload", - }) + //上传地址+header + const imgUploadUrl = import.meta.env.VITE_API_URL + '/file/upload' + const actionUrl = ref(imgUploadUrl) + const headerInfo = reactive({ + Authorization: "Bearer " + store2.token + }) // 文件上传前处理-上传大小 const beforeUpload = (file: any) => { if (file.size / 1024 / 1024 > 2) { @@ -585,7 +586,7 @@ const handleFileSuccess = (response: any) => { if (response.code == 200) { let obj = { - // modelId:this.maId, + modelId:maId.value, fileName: response.data.name.split("/")[4], fileUrl: response.data.url }; @@ -602,7 +603,7 @@ const handleFileSuccess2 = (response: any) => { if (response.code == 200) { let obj = { - // modelId:this.maId, + modelId:maId.value, fileName: response.data.name.split("/")[4], fileUrl: response.data.url }; @@ -619,7 +620,7 @@ const handleFileSuccess3 = (response: any) => { if (response.code == 200) { let obj = { - // modelId:this.maId, + modelId:maId.value, fileName: response.data.name.split("/")[4], fileUrl: response.data.url }; @@ -636,7 +637,7 @@ const handleFileSuccess4 = (response: any) => { if (response.code == 200) { let obj = { - // modelId:this.maId, + modelId:maId.value, fileName: response.data.name.split("/")[4], fileUrl: response.data.url }; @@ -663,25 +664,14 @@ const handleRemove = (list: any,index: Number) => { list.splice(index,1) } - - - /* 关闭对话框 */ - const handleClose = (done: () => void) => { - ruleFormRef.value.resetFields() - done() - dialogFormVisibleSettlein.value = false - } - - /* 查询按钮 */ - const queryTableList = () => { - getList() - } + +