123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- <template>
- <div class="app-container goods-add">
- <el-divider content-position="left">商品信息</el-divider>
- <el-form ref="addItem" :rules="rules" :model="addData" label-width="120px">
- <el-row :gutter="40" style="width: 600px">
- <el-col :span="23">
- <el-form-item label="商品名称:" prop="title">
- <el-input v-model="addData.title" placeholder="请输入商品名称"/>
- </el-form-item>
- </el-col>
- <el-col :span="23">
- <el-form-item label="商品主图:" prop="picUrl">
- <Upload v-model="mainPicUrl" :limit="10" />
- <div class="tip">第一张图片将作为商品列表图片,最多上传10张,多张图片之间可随意调整位置,支持jpg、png格式,推荐750*750px;</div>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="40" style="width: 500px">
- <el-col :span="23">
- <el-form-item label="支持盲豆兑换:" prop="exchangeShow">
- <el-switch
- v-model="addData.exchangeShow"
- :active-value="1"
- :inactive-value="0"
- />
- <div class="tip">关闭则不再兑换大厅显示,不支持盲豆兑换。</div>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="40" style="width: 500px">
- <el-col :span="23">
- <el-form-item label="商品分类:" prop="categoryId">
- <el-select
- v-model="addData.categoryId"
- placeholder="请选择商品分类"
- clearable
- >
- <el-option :label="item.name" :value="item.categoryId" v-for="(item, index) in goodsCategoryItemsList" :key="index" />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="40" style="width: 500px">
- <el-col :span="23">
- <el-form-item label="供应商:" prop="supplerId">
- <el-select
- v-model="addData.supplerId"
- placeholder="请选择供应商"
- clearable
- >
- <el-option :label="item.name" :value="item.id" v-for="(item, index) in SupplierList" :key="index" />
- </el-select>
- <a style="margin-left: 20px;color:#3983EF;" @click="handleAdd">创建供应商</a>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="40" style="width: 500px">
- <el-col :span="23">
- <el-form-item label="商品采购链接:">
- <el-input v-model="addData.shoppingLink" placeholder="请输入商品采购链接"/>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="40" style="width: 500px">
- <el-col :span="23">
- <el-form-item label="商品标签:">
- <el-select
- v-model="addData.tagIds"
- placeholder="请选择商品标签"
- multiple
- clearable
- >
- <el-option :label="item.name" :value="item.tagId" v-for="(item, index) in goodsTagItemsList" :key="index" />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="23">
- <el-form-item label="商家信息:">
- <Upload v-model="MerchantInformation" :limit="10" />
- <div class="tip">上传商家营业执照</div>
- </el-form-item>
- </el-col>
- </el-row>
- <el-divider content-position="left">价格库存</el-divider>
- <el-row>
- <el-col :span="23">
- <el-form-item label="启用多SKU:">
- <el-switch
- v-model="addData.multiSku"
- :active-value="1"
- :inactive-value="0"
- />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="22">
- <el-form-item prop="skuList">
- <Spec ref="spec" @valid="update" :multiSku="addData.multiSku" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row v-if="addData.multiSku === 0" :gutter="40" style="width: 600px">
- <el-col :span="23">
- <el-form-item label="价格:" prop="value">
- <el-input v-model="addData.value" type="number" placeholder="请输入商品价格">
- <template slot="append">元</template>
- </el-input>
- </el-form-item>
- </el-col>
- <el-col :span="23">
- <el-form-item label="兑换盲豆数量:" prop="exchangePrice">
- <el-input v-model="addData.exchangePrice" type="number" placeholder="请输入盲豆数量">
- <template slot="append">盲豆</template>
- </el-input>
- </el-form-item>
- </el-col>
- <el-col :span="23">
- <el-form-item label="采购价格:" prop="cost">
- <el-input v-model="addData.cost" type="number" placeholder="请输入商品采购价格">
- <template slot="append">元</template>
- </el-input>
- </el-form-item>
- </el-col>
- <el-col :span="23">
- <el-form-item label="商品编码:" prop="goodsCode">
- <el-input v-model="addData.goodsCode" type="text" placeholder="请输入商品编码">
- </el-input>
- </el-form-item>
- </el-col>
- <el-col :span="23">
- <el-form-item label="库存:" prop="quantity">
- <el-input v-model="addData.quantity" type="number" placeholder="请输入商品库存">
- <template slot="append">件</template>
- </el-input>
- </el-form-item>
- </el-col>
- </el-row>
- <!-- <el-divider content-position="left">商品详情</el-divider> -->
- <el-row>
- <el-col :span="22">
- <el-form-item label="商品详情" prop="description">
- <wang-editor ref="editor" v-model="addData.description" />
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <br>
- <el-row>
- <el-col :span="24" style="text-align: center">
- <el-button type="info" @click="$router.replace('/goods/list')">取消</el-button>
- <el-button type="primary" @click="updateItem()">保存</el-button>
- </el-col>
- </el-row>
- <add-supplier
- v-if="createShow"
- :dialog-show="createShow"
- @close="close"
- />
- </div>
- </template>
- <script>
- import Upload from '@/components/DragImageUpload'
- import WangEditor from '@/components/WangEditor'
- import Spec from './components/spec'
- import TinyEditor from '@/components/TinyEditor'
- import { getGoodsDetail, addGoods } from '@/api/business/goods'
- import { goodsCategoryItems } from '@/api/business/category'
- import { getSupplierList } from '@/api/business/supplier'
- import { goodsTagItems } from '@/api/business/tag'
- import { publicFileGetUrl } from "@/api/common"
- import { accDiv, accMul } from '@/utils/util'
- import AddSupplier from "../supplier/components/addSupplier";
- export default {
- components: {
- TinyEditor,
- WangEditor,
- Upload,
- Spec,
- AddSupplier
- },
- data() {
- return {
- IMG_URL: publicFileGetUrl,
- id: this.$route.query.id,
- goodsCategoryItemsList: [],
- SupplierList: [],
- goodsTagItemsList: [],
- addData: {
- multiSku: 0,
- description: ''
- },
- createShow:false,
- rules: {
- title: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
- picUrl: [{ required: true, message: '请上传商品图片', trigger: 'change' }],
- categoryId: [{ required: true, message: '请选择商品分类', trigger: 'change' }],
- supplerId: [{ required: true, message: '请选择供应商', trigger: 'change' }],
- exchangeShow: [{ required: true, message: '请选择是否支持盲豆兑换', trigger: 'change' }],
- multiSku: [{ required: true, message: '请选择SKU类型', trigger: 'change' }],
- value: [
- { required: true, message: '请输商品入价格', trigger: 'blur' },
- { pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/, message: "请输入正确的金额,最多两位小数", trigger: ["blur", "change"] }
- ],
- exchangePrice: [
- { required: true,message:'请输入盲豆数量', trigger: 'blur' },
- { pattern: /^([1-9]\d*)$/, message: "请输入正确盲豆数量", trigger: ["blur", "change"] }
- ],
- cost: [
- { required: false, message: '请输入采购价格', trigger: 'blur' },
- { pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/, message: "请输入正确的金额,最多两位小数", trigger: ["blur", "change"] }
- ],
- quantity: [
- { required: true, message: '请输入库存', trigger: 'blur' },
- { pattern: /^([1-9]\d*)$/, message: "请输入正确的数字", trigger: ["blur", "change"] }
- ],
- description: [{ required: true, message: '请输入商品详情', trigger: 'blur' }]
- }
- }
- },
- computed: {
- mainPicUrl: {
- get() {
- return this.addData.picUrl ? this.addData.picUrl.split(',').map(item => {
- return {
- fileName: item
- }
- }) : []
- },
- set(val) {
- this.$set(this.addData, 'picUrl', val.map(item => { return item.fileName }).toString())
- }
- },
- MerchantInformation:{
- get() {
- return this.addData.merchantInfo ? this.addData.merchantInfo.split(',').map(item => {
- return {
- fileName: item
- }
- }) : []
- },
- set(val) {
- this.$set(this.addData, 'merchantInfo', val.map(item => { return item.fileName }).toString())
- }
- }
- },
- created() {
- this.getGoodsCategoryItems()
- this.getSupplierItems()
- this.getGoodsTagItems()
- if (this.id) {
- getGoodsDetail(this.id).then(res => {
- const { goodsId, title, goodsCode, picUrl,merchantInfo, exchangeShow, multiSku, value, exchangePrice, cost, quantity, description, skuList, categoryId, supplerId, shoppingLink, tagIds } = res.data
- this.addData = {
- value: accDiv(value, 100),
- cost: cost == '' || cost == null ? '' : accDiv(cost, 100),
- goodsId, title, goodsCode, picUrl,merchantInfo, exchangeShow, multiSku, exchangePrice, quantity, description, skuList, categoryId, supplerId, shoppingLink, tagIds
- }
- if(description) {
- this.$refs.editor.setContent(description)
- }
- if (multiSku && skuList instanceof Array && skuList.length > 0) {
- this.$nextTick(() => {
- this.$refs.spec.setSkuList(skuList)
- })
- }
- })
- }
- },
- methods: {
- getGoodsCategoryItems(){
- goodsCategoryItems({}).then(res => {
- this.goodsCategoryItemsList = res && res.data
- })
- },
- //获取供应商
- getSupplierItems(){
- getSupplierList({name:""}).then(res => {
- this.SupplierList = res && res.rows
- })
- },
- handleAdd() {
- this.createShow = true;
- },
- close(){
- this.createShow = false;
- this.getSupplierItems()
- },
- getGoodsTagItems(){
- goodsTagItems({}).then(res => {
- this.goodsTagItemsList = res && res.data
- })
- },
- updateItem() {
- if (this.addData.multiSku == 1) {
- this.$refs.spec.getSkuList()
- } else {
- this.update()
- }
- },
- update(skuList) {
- this.$refs.addItem.validate((valid, items) => {
- if (valid) {
- this.addData.skuList = skuList
- const { value, cost,exchangePrice, description, ...rest } = this.addData
- addGoods({...rest, ...{
- value: accMul(value, 100),
- cost: cost == '' || cost == null ? '' : accMul(cost, 100),
- exchangePrice: accMul(exchangePrice, 1),
- description: encodeURI(description)
- }}).then(res => {
- if (res.code === 0) {
- this.$message({
- message: this.addData.goodsId ? '修改成功!' : '添加成功!',
- type: 'success'
- })
- this.$store.dispatch('tagsView/delView', this.$route)
- this.$router.go(-1)
- }
- })
- } else {
- if (items && Object.keys(items).length>0) {
- this.$message({
- message: items[Object.keys(items)[0]][0].message,
- type: 'warning'
- })
- }
- }
- })
- }
- }
- }
- </script>
- <style lang="scss">
- .goods-add {
- .tip {
- font-size: 12px;
- color: #999;
- }
- .el-divider {
- .is-left {
- color: #409EFF;
- font-size: 20px;
- font-weight: bolder;
- left: 10px;
- }
- }
- }
- </style>
|