123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 |
- <template>
- <div class="m-container">
- <h2>
- <el-page-header
- @back="onCancel"
- :content="pageTitle[pageType] + '商品'"
- ></el-page-header>
- </h2>
- <div class="m-core">
- <el-form :model="form" :rules="rules" ref="form" label-width="120px">
- <el-form-item label="货号" prop="sn">
- <el-input
- v-model.trim="form.sn"
- :disabled="pageDisabled"
- placeholder="请输入货号"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <el-form-item label="品牌" prop="brand">
- <el-input
- v-model.trim="form.brand"
- :disabled="pageDisabled"
- placeholder="请输入品牌"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <!-- <el-form-item label="备查货号" prop="supplyChannel" v-if="pageType == 'create'">
- <el-input v-model.trim="form.supplyChannel" placeholder="请输入备查货号" style="width: 400px"></el-input>
- </el-form-item> -->
- <el-form-item label="商品名称" prop="name">
- <el-input
- v-model.trim="form.name"
- placeholder="请输入商品名称"
- :disabled="pageDisabled"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <el-form-item label="商品类型" prop="type">
- <el-select
- v-model.trim="form.type"
- placeholder="请选择商品类型"
- :disabled="pageDisabled"
- style="width: 400px !important"
- >
- <el-option
- v-for="(item, index) in goodsType"
- :key="index"
- :label="item.label"
- :value="item.value"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="商品分类" prop="goodsCategoryId">
- <el-select
- v-model.trim="form.goodsCategoryId"
- placeholder="请选择商品分类"
- :disabled="pageDisabled"
- style="width: 400px !important"
- filterable
- >
- <el-option
- v-for="item in categoryList"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="所属分部" prop="organIdList">
- <select-all v-model.trim="form.organIdList"
- filterable
- placeholder="请选择所属分部"
- style="width: 400px !important"
- multiple
- :disabled="pageDisabled || pageType == 'update'"
- clearable>
- <el-option v-for="item in selects.branchs"
- :key="item.id"
- :label="item.name"
- :value="item.id.toString()"></el-option>
- </select-all>
- </el-form-item>
- <el-form-item label="商品型号" prop="specification">
- <el-input
- v-model.trim="form.specification"
- placeholder="请输入商品型号"
- :disabled="pageDisabled"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <!-- <el-form-item label="内部库存" prop="stockCount">
- <el-input type="number" :disabled="pageType != 'create'" v-model.trim="form.stockCount" placeholder="请输入内部库存" style="width: 400px"></el-input>
- </el-form-item>
- <el-form-item label="税务库存" prop="taxStockCount">
- <el-input type="number" :disabled="pageType != 'create'" v-model.trim="form.taxStockCount" placeholder="请输入税务库存" style="width: 400px"></el-input>
- </el-form-item> -->
- <el-form-item label="库存类型" prop="stockType">
- <el-select
- v-model="form.stockType"
- placeholder="请选择库存类型"
- :disabled="pageDisabled"
- style="width: 400px !important"
- >
- <el-option
- v-for="(item, index) in stockType"
- :key="index"
- :label="item.label"
- :value="item.value"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="市场价" prop="marketPrice">
- <el-input
- type="number"
- placeholder="请输入市场价"
- :disabled="pageDisabled"
- @mousewheel.native.prevent
- v-model.trim="form.marketPrice"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <el-form-item label="零售价" prop="discountPrice">
- <el-input
- type="number"
- placeholder="请输入零售价"
- @mousewheel.native.prevent
- :disabled="pageDisabled"
- v-model.trim="form.discountPrice"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <el-form-item label="商品团购价" prop="groupPurchasePrice">
- <el-input
- type="number"
- placeholder="请输入商品团购价"
- @mousewheel.native.prevent
- :disabled="pageDisabled"
- v-model.trim="form.groupPurchasePrice"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <el-form-item label="学员是否展示" prop="clientShow">
- <el-select
- v-model="form.clientShow"
- :disabled="pageDisabled"
- placeholder="请选择学员是否展示"
- style="width: 400px !important"
- >
- <el-option label="是" :value="1"></el-option>
- <el-option label="否" :value="0"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="管理端是否展示" prop="educationalShow">
- <el-select
- v-model="form.educationalShow"
- placeholder="请选择教务端是否展示"
- :disabled="pageDisabled"
- style="width: 400px !important"
- >
- <el-option label="是" :value="1"></el-option>
- <el-option label="否" :value="0"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="乐团是否展示" prop="musicGroupShow">
- <el-select
- v-model="form.musicGroupShow"
- :disabled="pageDisabled"
- placeholder="请选择乐团是否展示"
- style="width: 400px !important"
- >
- <el-option label="是" :value="1"></el-option>
- <el-option label="否" :value="0"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="乐团收费模式" prop="courseViewType">
- <select-all v-model.trim="form.courseViewType"
- filterable
- placeholder="请选择乐团收费模式"
- style="width: 400px !important"
- multiple
- :disabled="pageDisabled || (form.musicGroupShow != 0 && form.musicGroupShow != 1)"
- clearable>
- <el-option label="课程收费" value="0"></el-option>
- <el-option label="系统收费" value="1"></el-option>
- <el-option label="云教练收费" value="2"></el-option>
- </select-all>
- </el-form-item>
- <el-form-item label="是否库存预警" prop="stockWarning">
- <el-select
- v-model="form.stockWarning"
- placeholder="请选择库存预警"
- :disabled="pageDisabled"
- style="width: 400px !important"
- >
- <el-option label="是" :value="1"></el-option>
- <el-option label="否" :value="0"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="是否参与置换" prop="replacementShow">
- <el-select
- v-model="form.replacementShow"
- placeholder="请选择库存预警"
- :disabled="pageDisabled"
- style="width: 400px !important"
- >
- <el-option label="是" :value="1"></el-option>
- <el-option label="否" :value="0"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="商品图片" prop="image">
- <el-upload
- class="avatar-uploader"
- action="/api-web/uploadFile"
- accept=".jpg, .jpeg, .png"
- :headers="headers"
- :disabled="pageDisabled"
- :show-file-list="false"
- :on-success="handleAvatarSuccess"
- :before-upload="beforeAvatarUpload"
- >
- <img v-if="form.image" :src="form.image" class="avatar" />
- <i v-else class="el-icon-plus avatar-uploader-icon"></i>
- </el-upload>
- </el-form-item>
- <el-form-item label="商品描述" prop="brief">
- <el-input
- type="textarea"
- v-model.trim="form.brief"
- :disabled="pageDisabled"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <el-form-item label="商品详情" prop="desc">
- <el-input
- type="textarea"
- v-model.trim="form.desc"
- :disabled="pageDisabled"
- style="width: 400px"
- ></el-input>
- </el-form-item>
- <el-form-item v-if="!pageDisabled">
- <el-button @click="onSubmit('form')" type="primary"
- >保存</el-button
- >
- <el-button @click="onReSet('form')">重置</el-button>
- </el-form-item>
- </el-form>
- </div>
- </div>
- </template>
- <script>
- import {
- categoryListTree,
- goodsAdd,
- goodsUpdate,
- goodsSingleQuery,
- } from "@/api/businessManager";
- import { getToken } from "@/utils/auth";
- import { goodsType, stockType } from "@/utils/searchArray";
- let validPrice = (rule, value, callback) => {
- if ((value == "" && typeof value == "string") || value == null) {
- callback(new Error("请输入金额"));
- } else if (value < 0) {
- callback(new Error("输入金额必须大于或等于0"));
- } else if (value >= 100000) {
- callback(new Error("输入金额必须小于100000"));
- } else {
- callback();
- }
- };
- let validStock = (rule, value, callback) => {
- if ((value == "" && typeof value == "string") || value == null) {
- callback(new Error("请输入库存"));
- } else if (value < 0) {
- callback(new Error("库存数量必须大于或等于0"));
- } else {
- callback();
- }
- };
- export default {
- name: "shopOperation",
- data() {
- return {
- goodsType: goodsType,
- stockType: stockType,
- categoryList: [],
- pageType: null,
- pageTitle: {
- create: "添加",
- update: "修改",
- look: "查看",
- copy: "复制"
- },
- pageDisabled: false,
- headers: {
- Authorization: getToken(),
- },
- form: {
- sn: null,
- brand: null,
- supplyChannel: null,
- name: null,
- type: null,
- goodsCategoryId: null,
- organIdList: [],
- specification: null,
- stockCount: null,
- taxStockCount: null,
- stockType: null,
- marketPrice: null,
- discountPrice: null,
- groupPurchasePrice: null,
- clientShow: null,
- educationalShow: null,
- musicGroupShow: null,
- courseViewType: [],
- stockWarning: null,
- image: null,
- brief: null,
- desc: null,
- replacementShow:null
- },
- rules: {
- sn: [{ required: true, message: "请输入商品货号", trigger: "blur" }],
- brand: [
- {
- required: true,
- message: "请输入品牌",
- trigger: "blur",
- },
- {
- min: 2,
- max: 30,
- message: "长度在 2 到 30 个字符",
- trigger: "blur",
- },
- ],
- supplyChannel: [
- { required: true, message: "请输入备查货号", trigger: "blur" },
- ],
- name: [
- {
- required: true,
- message: "请输入商品名称",
- trigger: "blur",
- },
- {
- min: 2,
- max: 30,
- message: "长度在 2 到 30 个字符",
- trigger: "blur",
- },
- ],
- type: [
- {
- required: true,
- message: "请选择商品分类",
- trigger: "change",
- },
- ],
- goodsCategoryId: [
- {
- required: true,
- message: "请选择商品类型",
- trigger: "change",
- },
- ],
- organIdList: [
- {
- required: true,
- message: '请选择所属分部',
- trigger: "change"
- }
- ],
- specification: [
- {
- required: true,
- message: "请输入商品型号",
- trigger: "blur",
- },
- {
- min: 2,
- max: 30,
- message: "长度在 2 到 30 个字符",
- trigger: "blur",
- },
- ],
- stockCount: [
- { required: true, validator: validStock, trigger: "blur" },
- ],
- taxStockCount: [
- { required: true, validator: validStock, trigger: "blur" },
- ],
- stockType: [
- { required: true, message: "请选择库存类型", trigger: "change" },
- ],
- marketPrice: [
- {
- required: true,
- validator: validPrice,
- trigger: "blur",
- },
- ],
- discountPrice: [
- {
- required: true,
- validator: validPrice,
- trigger: "blur",
- },
- ],
- groupPurchasePrice: [
- {
- required: true,
- validator: validPrice,
- trigger: "blur",
- },
- ],
- clientShow: [
- { required: true, message: "请选择学员是否展示", trigger: "change" },
- ],
- replacementShow:[
- { required: true, message: "是否参与乐器置换", trigger: "change" },
- ],
- educationalShow: [
- {
- required: true,
- message: "请选择教务端是否展示",
- trigger: "change",
- },
- ],
- musicGroupShow: [
- { required: true, message: "请选择乐团是否展示", trigger: "change" },
- ],
- courseViewType: [
- { required: true, message: "请选乐团收费模式", trigger: 'change' },
- ],
- stockWarning: [
- { required: true, message: "请选择是否库存预警", trigger: "change" },
- ],
- image: [
- {
- required: true,
- message: "请选择图片",
- trigger: "blur",
- },
- ],
- brief: [
- {
- required: true,
- message: "请输入商品描述",
- trigger: "blur",
- },
- ],
- desc: [
- {
- required: true,
- message: "请输入商品详情",
- trigger: "blur",
- },
- ],
- },
- Fsearch: null,
- Frules: null,
- imageWidthM: 400,
- imageHeightM: 400,
- };
- },
- mounted() {
- // 获取分部
- this.$store.dispatch("setBranchs");
- this.init();
- },
- methods: {
- init() {
- let query = this.$route.query;
- if (query.paramInfo) {
- let paramInfo = JSON.parse(query.paramInfo);
- this.pageType = paramInfo.type;
- this.id = paramInfo.id;
- }
- this.pageDisabled = this.pageType == "look" ? true : false;
- this.getList();
- this.getCatagory();
- },
- onSubmit(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- let tempForm = JSON.parse(JSON.stringify(this.form))
- if(tempForm.courseViewType) {
- tempForm.courseViewType = tempForm.courseViewType.join(',')
- }
- if(tempForm.organIdList) {
- tempForm.organIdList = tempForm.organIdList.join(',')
- }
- if (this.pageType == "create" || this.pageType == 'copy') {
- if (tempForm.id) {
- // 判断有没有Id,如果有则删除
- delete tempForm.id;
- }
- tempForm.status = "NO"; // 默认上架
- goodsAdd(tempForm).then((res) => {
- this.messageTips("保存", res);
- });
- } else if (this.pageType == "update") {
- goodsUpdate(tempForm).then((res) => {
- this.messageTips("保存", res);
- });
- }
- } else {
- this.$nextTick(() => {
- let isError = document.getElementsByClassName("is-error");
- isError[0].scrollIntoView({
- block: "center",
- behavior: "smooth",
- });
- });
- return false;
- }
- });
- },
- messageTips(title, res) {
- if (res.code == 200) {
- this.$message.success(title + "成功");
- this.$store.dispatch("delVisitedViews", this.$route);
- this.$router.push({
- path: "/shopList",
- query: {
- pageInfo: this.Frules,
- searchForm: this.Fsearch,
- },
- });
- } else {
- this.$message.error(res.msg);
- }
- },
- onCancel() {
- this.$store.dispatch("delVisitedViews", this.$route);
- this.$router.push({
- path: "/shopList",
- });
- },
- onReSet(formName) {
- this.$refs[formName].resetFields();
- },
- getList() {
- if (this.pageType == "create") {
- this.form = {
- sn: null,
- brand: null,
- supplyChannel: null,
- name: null,
- type: null,
- goodsCategoryId: null,
- organIdList: [],
- specification: null,
- stockCount: null,
- taxStockCount: null,
- stockType: null,
- marketPrice: null,
- discountPrice: null,
- groupPurchasePrice: null,
- clientShow: null,
- educationalShow: null,
- musicGroupShow: null,
- courseViewType: [],
- stockWarning: null,
- image: null,
- brief: null,
- desc: null,
- };
- if (this.$refs["form"]) {
- this.$refs["form"].resetFields();
- }
- } else {
- goodsSingleQuery(this.id).then((res) => {
- if (res.code == 200) {
- let result = res.data;
- let courseViewType = null
- if(result.courseViewType) {
- courseViewType = result.courseViewType.split(',')
- }
- let organIdList = []
- if(result.organIdList) {
- organIdList = result.organIdList.split(',')
- }
- this.form = {
- id: result.id,
- sn: result.sn,
- brand: result.brand,
- supplyChannel: result.supplyChannel,
- name: result.name,
- type: result.type,
- goodsCategoryId: result.goodsCategoryId,
- organIdList: organIdList,
- specification: result.specification,
- stockCount: result.stockCount,
- taxStockCount: result.taxStockCount,
- stockType: result.stockType,
- marketPrice: result.marketPrice,
- discountPrice: result.discountPrice,
- groupPurchasePrice: result.groupPurchasePrice,
- clientShow: result.clientShow,
- educationalShow: result.educationalShow,
- musicGroupShow: result.musicGroupShow,
- courseViewType: courseViewType,
- stockWarning: result.stockWarning,
- image: result.image,
- brief: result.brief,
- desc: result.desc,
- replacementShow:result.replacementShow
- };
- }
- });
- }
- },
- getCatagory() {
- categoryListTree({
- delFlag: 0,
- rows: 9999,
- }).then((res) => {
- let result = res.data;
- if (res.code == 200) {
- let tempArray = [];
- result.rows.forEach((row) => {
- tempArray.push({
- label: row.name,
- value: row.id,
- });
- });
- this.categoryList = tempArray;
- }
- });
- },
- handleAvatarSuccess(res, file) {
- this.form.image = res.data.url;
- },
- beforeAvatarUpload(file) {
- const imageType = {
- "image/png": true,
- "image/jpeg": true,
- };
- const isImage = imageType[file.type];
- const isLt2M = file.size / 1024 / 1024 < 2;
- const imageWidth = this.imageWidthM;
- const imageHeigh = this.imageHeightM;
- const _URL = window.URL || window.webkitURL;
- const isSize = new Promise((resolve, reject) => {
- const img = new Image();
- img.onload = function () {
- if (imageWidth && imageHeigh) {
- this.width === imageWidth && this.height === imageHeigh
- ? resolve()
- : reject(`请上传${imageWidth}x${imageHeigh}尺寸图片`);
- } else if (imageWidth && !imageHeigh) {
- this.width === imageWidth
- ? resolve()
- : reject(`请上传宽为${imageWidth}的图片`);
- } else if (!imageWidth && imageHeigh) {
- this.height === imageHeigh
- ? resolve()
- : reject(`请上传高为${imageHeigh}的图片`);
- } else {
- resolve();
- }
- };
- img.src = _URL.createObjectURL(file);
- }).then(
- () => {
- return file;
- },
- (src) => {
- this.$message.error(src);
- this.uploadImgLoading = false;
- return Promise.reject();
- }
- );
- if (!isImage) {
- this.$message.error("只能上传图片格式!");
- }
- if (!isLt2M) {
- this.$message.error("上传头像图片大小不能超过 2MB!");
- }
- return isImage && isLt2M && isSize;
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .el-button--primary {
- background: #14928a;
- border-color: #14928a;
- color: #fff;
- &:hover,
- &:active,
- &:focus {
- background: #14928a;
- border-color: #14928a;
- color: #fff;
- }
- }
- .el-row {
- margin-top: 40px;
- }
- .el-col {
- display: flex;
- align-items: center;
- margin-bottom: 20px;
- justify-content: flex-end;
- margin-right: 50%;
- }
- .el-input-group {
- width: 200px;
- margin: 0 20px;
- }
- /deep/.el-tree-node__content {
- height: 40px !important;
- }
- /deep/.avatar-uploader .el-upload {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- }
- .avatar-uploader .el-upload:hover {
- border-color: #409eff;
- }
- .avatar-uploader-icon {
- font-size: 28px;
- color: #8c939d;
- width: 120px;
- height: 120px;
- line-height: 120px;
- text-align: center;
- }
- .avatar {
- width: 120px;
- height: 120px;
- display: block;
- }
- .el-select__tags .el-tag.el-tag--info.el-tag--small.el-tag--light {
- max-width: 95px;
- }
- </style>
|