import { getGoodsInfo, delGoodsInfo, addGoodsInfo, updateGoodsInfo, updatePicture, goodsInfoList, goodsCategory, editGoodsWhetherShelf, stationList, } from "@/api/system/OperateGoodsInfo"; import editor from "@/components/Editor"; import stationAcatar from "../stationAvatar/index.vue"; import baseurl from "@/api/baseurl.js"; export default { components: { stationAcatar, editor }, name: "OperateGoodsInfo", data() { return { imgsurl: { pictureUrlList: [] }, imgone: "", imageUrl: "", //商品图片 value: "", datas: null, // 遮罩层 loading: true, // 选中数组 ids: [], // 非单个禁用 single: true, // 非多个禁用 multiple: true, // 显示搜索条件 showSearch: true, // 总条数 total: 0, total2: 0, // 商品基本信息表格数据 goodsInfoList: [], // 护理站列表 nurseStationlist: [], // 查询商品分类列表 goodsCategorylist: [], // 弹出层标题 title: "", // 是否显示弹出层 open: false, // open2: false, innerVisible: false, StationName: "请选择所属护理站", nursetotal: 0, nurseStationId: null, goods: [{ value: "BUSINESS", label: "买卖", }, { value: "LEASE", label: "租赁", }, ], options: [{ value: 0, label: "否", }, { value: 1, label: "是", }, ], // goodAttributeDetailsLists:[], goodDetailsLists: [], ids: 9999999, // 查询参数 shangjia: { id: null, whetherShelf: null, }, getListByUserquery: { pageNum: 1, pageSize: 10, }, queryParams: { id: null, pageNum: 1, pageSize: 10, storeInfoId: null, nurseStationId: null, goodsCategoryId: null, goodsName: null, // goodsCode: null, whetherShelf: null, shelfTime: null, goodsPictureUrl: null, goodsRemark: null, goodsUnit: null, goodsPurpose: null, sort: null, }, //权限查询 getListByUserquery: { pageNum: 1, pageSize: 10, }, // 表单参数 form: { nurseStationId: null, }, // 表单校验 rules: { goodsName: [ { required: true, message: "请输入商品名称", trigger: "blur" }, ], goodsCategoryId: [ { required: true, message: "请选择商品分类名称", trigger: "blur" }, ], goodsPurpose: [ { required: true, message: "请选择商品用途", trigger: "blur" }, ], goodsUnit: [ { required: true, message: "请输入商品度量单位", trigger: "blur" }, ], goodsPictureUrl: [ { required: true, message: "请输入选择图片", trigger: "blur" }, ], }, homestation: null, }; }, created() { this.getList(); this.goodsCategoryinfo(); }, methods: { imgs(item) { this.imgsurl.pictureUrlList.push(item); // console.log(this.imgsurl) }, upwhetherShelf(row) { console.log(row); if (row.whetherShelf == false) { var obj = { id: row.goodsInfoId, whetherShelf: 0, }; } else if (row.whetherShelf == true) { var obj = { id: row.goodsInfoId, whetherShelf: 1, }; } editGoodsWhetherShelf(obj).then((res) => { console.log(obj); if (obj.whetherShelf == 0) { this.$modal.msgSuccess("已修改上架状态为未上架"); } else { this.$modal.msgSuccess("已修改上架状态为上架"); } this.getList(); }); }, /** 查询商品基本信息列表 */ getList() { this.loading = true; goodsInfoList(this.queryParams).then((response) => { response.rows.forEach((e) => { if (e.whetherShelf == 1) { e.whetherShelf = true; } else if (e.whetherShelf == 0) { e.whetherShelf = false; } }); this.goodsInfoList = response.rows; this.total = response.total; this.loading = false; }); }, // 添加 addgoodAttributeDetail() { console.log(this.goodDetailsLists); if (this.goodDetailsLists.length == 5) { this.$message.error("最多只能5条"); } else { this.ids++; var obj = { attributePitureUrl: "", goodsPrice: "", goodsStock: "", sort: "", ids: this.ids, }; this.goodDetailsLists.push(obj); } }, // 删除 delgoodAttributeDetail(item) { console.log(item); if (item.ids && !item.attributeDetailsId) { if (this.goodDetailsLists.length == 1) { this.$message.error("最后一条不可删除"); } else { this.goodDetailsLists = this.goodDetailsLists.filter( (e) => e.ids != item.ids ); } } else if (!item.ids && item.attributeDetailsId) { if (this.goodDetailsLists.length == 1) { this.$message.error("最后一条不可删除"); } else { this.goodDetailsLists = this.goodDetailsLists.filter( (e) => e.attributeDetailsId != item.attributeDetailsId ); } } console.log(this.goodDetailsLists); }, // 取消按钮 cancel() { console.log(this.form); var obj = { pictureUrlList: [] }; if (this.imgone != this.form.goodsPictureUrl) { obj.pictureUrlList.push(this.form.goodsPictureUrl); } if (obj.pictureUrlList.length > 0) { updatePicture(obj).then((res) => { console.log(res); }); } if (this.imgsurl.pictureUrlList.length > 0) { updatePicture(this.imgsurl).then((res) => {}); } this.imgsurl={pictureUrlList:[]}; this.open = false; this.reset(); this.StationName = "请选择所属护理站"; this.goodDetailsLists = [{ attributeName: "", goodAttributeDetailsLists: [{ attributePitureUrl: "", goodsPrice: "", goodsStock: "", sort: "", }, ], }, ]; }, //页面所属护理站 ParamsStation(item) { this.info(); this.homestation = item this.innerVisible = true this.form.nurseStationId = this.queryParams.nurseStationId }, //选择护理站 clickinnerVisible() { this.info(); this.innerVisible = true; }, nurseclick(row) { if (this.homestation) { this.queryParams.nurseStationName = row.nurseStationName; this.queryParams.nurseStationId = row.id; } else { this.form.nurseStationId = row.id; this.StationName = row.nurseStationName; } this.innerVisible = false; }, handleQuery2() { this.info(); }, resetQuery2() { this.resetForm("queryForm"); this.getListByUserquery = { pageNum: 1, pageSize: 10, } this.handleQuery2(); }, addcancel() { this.innerVisible = false; this.resetQuery2(); }, // 表单重置 reset() { this.form = { id: null, storeInfoId: null, nurseStationId: null, goodsCategoryId: null, goodsName: null, // goodsCode: null, whetherShelf: null, shelfTime: null, goodsPictureUrl: null, goodsRemark: null, goodsUnit: null, goodsPurpose: null, sort: null, createBy: null, createTime: null, updateBy: null, updateTime: null, }; this.goodDetailsLists = [{ attributePitureUrl: "", goodsPrice: "", goodsStock: "", sort: "", ids: 9999999, }, ]; this.resetForm("form"); }, /** 搜索按钮操作 */ handleQuery() { this.queryParams.pageNum = 1; this.getList(); }, /** 重置按钮操作 */ resetQuery() { this.resetForm("queryForm"); this.queryParams = { pageNum: 1, pageSize: 10, goodsName: null, goodsCategoryName: null, goodsPurpose: null, }; this.handleQuery(); }, // 多选框选中数据 handleSelectionChange(selection) { console.log(selection); this.ids = selection.map((item) => item.goodsInfoId); this.single = selection.length !== 1; this.multiple = !selection.length; }, /** 新增按钮操作 */ handleAdd() { this.reset(); this.homestation = null; this.nurseStationId = ""; this.title = "商品基本信息"; // this.nurseName = "请选择护理员"; this.StationName = "请选择所属护理站"; this.goodDetailsLists = [{ attributePitureUrl: "", goodsPrice: "", goodsStock: "", sort: "", ids: 9999999, }, ]; this.open = true; }, /** 修改按钮操作 */ handleUpdate(row) { this.reset(); this.homestation = null; const id = row.goodsInfoId || this.ids; this.StationName = row.nurseStationName; if (this.StationName == null) { this.StationName = "请选择所属护理站"; } console.log(this.StationName); getGoodsInfo(id).then((response) => { this.form = response.data[0]; this.imgone = this.form.goodsPictureUrl; if (response.data[0].goodAttributeDetailsLists) { this.goodDetailsLists = response.data[0].goodAttributeDetailsLists; } this.open = true; this.title = "修改商品基本信息"; }); }, /** 提交按钮 */ submitForm() { console.log(this.form) this.form.goodAttributeDetailsLists = []; this.form.goodDetailsLists = this.goodDetailsLists; console.log(this.form); this.$refs["form"].validate((valid) => { if (valid) { if (this.form.goodsInfoId != null) { this.form.id = this.form.goodsInfoId; this.form.goodDetailsLists.forEach(e => { e.goodsPrice = Number(e.goodsPrice) }) updateGoodsInfo(this.form).then((response) => { var obj = { pictureUrlList: [] }; if (this.imgone != this.form.goodsPictureUrl) { obj.pictureUrlList.push(this.imgone); } this.imgsurl={pictureUrlList:[]}; if (obj.pictureUrlList.length > 0) { updatePicture(obj).then((res) => { console.log(res); }); } this.$modal.msgSuccess("修改成功"); this.open = false; this.getList(); }); } else { this.form.goodDetailsLists.forEach(e => { e.goodsPrice = Number(e.goodsPrice) }) // this.nurseStationId=this.form.nurseStationId addGoodsInfo(this.form).then((response) => { console.log(this.form); this.$modal.msgSuccess("新增成功"); this.StationName = "请选择所属护理站"; this.open = false; this.getList(); }); } } }); }, /** 删除按钮操作 */ handleDelete(row) { console.log("row :>> ", row); this.$confirm("是否确认删除订单信息的数据项?", "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", }) .then(() => { delGoodsInfo(row.goodsInfoId).then((res) => { var obj = { pictureUrlList: [] }; obj.pictureUrlList.push(row.goodsPictureUrl); if (obj.pictureUrlList.length > 0) { updatePicture(obj).then((res) => { console.log(res); }); } this.$message.success("删除成功"); this.getList(); }); }) .catch(() => {}); }, imgUrl(imgUrl) { console.log(imgUrl); this.form.goodsPictureUrl = imgUrl; }, attributePitureUrl(imgUrl) { console.log(imgUrl); // this.form.attributePitureUrl = imgUrl; }, attributePitureitem(item) { let items = JSON.parse(item); if (items.ids && !items.id) { this.goodDetailsLists.forEach((e) => { if (e.ids == items.ids) { e.attributePitureUrl = items.attributePitureUrl; } }); } else if (!items.ids && items.attributeDetailsId) { this.goodDetailsLists.forEach((e) => { if (e.attributeDetailsId == items.attributeDetailsId) { e.attributePitureUrl = items.attributePitureUrl; } }); } }, //商品分类 goodsCategoryinfo() { goodsCategory().then((res) => { console.log(this.form); this.goodsCategorylist = res.rows; }); }, //护理站 info() { stationList(this.getListByUserquery).then((res) => { this.nurseStationlist = res.rows; this.total2 = res.total; }); }, }, };