| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914 |
- <template>
- <view class="app-content">
- <form @submit="formSubmit">
- <view class="module-com input-line-wrap">
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">名称</view>
- <input v-model="form.name" placeholder-class="phcolor" class="tui-input" name="name" placeholder="请填写名称" @input="fillName($event)" maxlength="50" type="text" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">初始名称</view>
- <view style="color:#CCCCCC;width:450upx;height:45upx;" @click.stop="notModify">
- {{form.name}}
- </view>
-
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">拼音缩写</view>
- <input v-model="form.py" placeholder-class="phcolor" class="tui-input" name="py" placeholder="请填写拼音首字母缩写" maxlength="50" type="text" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">价格</view>
- <input v-model="form.hjPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;" placeholder-class="phcolor"
- class="tui-input" name="hjPrice" @focus="form.hjPrice=''" placeholder="大客价" type="digit" />
- <input v-model="form.price" style="width:130upx;border:1upx solid #3385FF;text-align:center;height:50upx;color:#3385FF;margin-left:30upx;" placeholder-class="phcolor"
- class="tui-input" name="price" @focus="form.price=''" placeholder="批发价" type="digit" @input="priceLinkage()" />
- <input v-model="form.skPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;margin-left:30upx;" placeholder-class="phcolor"
- class="tui-input" name="skPrice" @focus="form.skPrice=''" placeholder="零售价" type="digit" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">特价</view>
- <input v-model="form.hjDiscountPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;" placeholder-class="phcolor"
- class="tui-input" name="hjDiscountPrice" @focus="form.hjDiscountPrice=''" placeholder="会员特价" type="digit" />
- <input v-model="form.discountPrice" style="width:130upx;border:1upx solid #3385FF;margin-left:30upx;color:#3385FF;text-align:center;height:50upx;" placeholder-class="phcolor" @input="tjLinkage()"
- class="tui-input" name="discountPrice" @focus="form.discountPrice=''" placeholder="无特价填0" maxlength="50" type="digit" />
- <input v-model="form.skDiscountPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;margin-left:30upx;" placeholder-class="phcolor"
- class="tui-input" name="skDiscountPrice" @focus="form.skDiscountPrice=''" placeholder="零售特价" type="digit" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">成本</view>
- <input v-model="form.cost" style="width:260upx;" placeholder-class="phcolor" @focus="form.cost=''" class="tui-input" name="cost" placeholder="请输入" type="digit"/>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title" style="color:#3385FF;font-weight:bold;">库存</view>
- <input v-model="form.stock" style="width:260upx;" placeholder-class="phcolor" @focus="form.stock=''" @input="changeStock($event)" class="tui-input" name="stock" placeholder="请输入" type="digit"/>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">库存不足</view>
- <view>
- <button class="admin-button-com middle" :class="form.virtualStock == 0 ? 'blue' : 'default'" @click="virtualStockChange(0)">关闭自动补充</button>
- <button class="admin-button-com middle" :class="form.virtualStock == 1 ? 'blue' : 'default'" @click="virtualStockChange(1)" style="margin-left:38upx;">开启自动补充</button>
- </view>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :arrow="true">
- <view class="tui-title">分类</view>
- <input v-model="form.classId" name="classId" type="text" hidden />
- <view style="color:#CCCCCC;width:450upx;height:45upx;" @click.stop="changeClass()" v-if="form.classId == 0">
- 请选择分类
- </view>
- <view @click.stop="changeClass()" style="width:450upx;height:45upx;" v-else>
- {{form.className}}
- </view>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <div class="tui-title">比例类型</div>
- <radio-group class="tui-input flex-center-between" @change="ratioTypeChange">
- <label class="list" for="fixedLink">
- <radio id="fixedLink" value="0" :checked="form.ratioType == 0" style="transform: scale(0.7,0.7);" />
- <span class="checkbox-text" style="font-size:30upx;">固定</span>
- </label>
- <label class="list" for="dimLink">
- <radio id="dimLink" value="1" :checked="form.ratioType == 1" style="transform: scale(0.7,0.7);" />
- <span class="checkbox-text" style="font-size:30upx;">模糊(若干)</span>
- </label>
- </radio-group>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :arrow="true">
- <div class="tui-title">大单位</div>
- <picker mode="selector" :value="form.bigUnitId" :range="unitData" range-key="name" @change="changeBigUnitFn" class="tui-input">
- <input v-model="form.bigUnitId" name="bigUnitId" type="text" hidden />
- <div v-if="form.bigUnitId">{{ bigUnitSelectedData.name }}</div>
- <div class="tui-placeholder" style="height:45upx;" v-else>请选择</div>
- </picker>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :arrow="true">
- <div class="tui-title">小单位</div>
- <picker mode="selector" :value="form.smallUnitId" :range="unitData" range-key="name" @change="changeSmallUnitFn" class="tui-input">
- <input v-model="form.smallUnitId" name="smallUnitId" type="text" hidden />
- <div v-if="form.smallUnitId">{{ smallUnitSelectedData.name }}</div>
- <div class="tui-placeholder" v-else>请选择</div>
- </picker>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false" v-if="form.ratioType == 0">
- <view class="tui-title">单位比</view>
- <input v-model="form.ratio" placeholder-class="phcolor" class="tui-input" name="ratio" @focus="form.ratio=''" placeholder="1扎=20支,请填写20" maxlength="50" type="number" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">每扎重量</view>
- <input v-model="form.weight" placeholder-class="phcolor" class="tui-input" name="weight" @focus="form.weight=''" placeholder="公斤" maxlength="50" type="digit" />
- <view class="weight-reminder-icon" @click="showWeightPopup">
- <text style="color: #999; font-size: 32upx; font-weight: bold;">?</text>
- </view>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">库存预警</view>
- <input v-model="form.stockWarning" @focus="form.stockWarning=''" placeholder-class="phcolor" class="tui-input" name="stockWarning" placeholder="请填写" maxlength="50" type="number" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">花材状态</view>
- <view class="switch_bx">
- <text v-if="form.status == 1">上架</text>
- <text v-else>下架</text>
- </view>
- </tui-list-cell>
- </view>
- <view class="module-com input-line-wrap goods-wrap">
- <view class="module-tit">
- <span>花材图片(最多5张)</span>
- <span class="app-color-3"></span>
- </view>
- <view class="module-det">
- <htz-image-upload :max="5" :compress="true" v-model="currentImgData" :headers="headers"
- @uploadSuccess="imgUploadSuccess" @imgDelete="imgDeleteFn" :action="getLoginInfo.imgUploadApi">
- </htz-image-upload>
- </view>
- <tui-list-cell class="line-cell category-wrap" :hover="false">
- <view class="tui-title">封面</view>
- <view class="tui-input">
- <block v-if="coverImgData.length > 0">
- <button class="admin-button-com" :class="[(form.cover == item) ? '' : 'default']"
- v-for="(item, index) in coverImgData" :key="index"
- @click="selCoverFn(index)" >第{{ index + 1 }}张</button>
- </block>
- <view v-else class="no-img-tip">请先上传图片</view>
- <view v-if="coverImgData.length > 0" class="use-img">选择上面的图片作为封面</view>
- </view>
- </tui-list-cell>
- </view>
- <view class="module-com input-line-wrap">
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">大客加价</view>
- <input v-model="form.hjAddPrice" placeholder-class="phcolor" class="tui-input" name="hjAddPrice" @focus="form.hjAddPrice=''" placeholder="在成本价基础上多卖的金额" maxlength="50" type="digit" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">批发加价</view>
- <input v-model="form.addPrice" placeholder-class="phcolor" class="tui-input" name="addPrice" @focus="form.addPrice=''" placeholder="在成本价基础上多卖的金额" maxlength="50" type="digit" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">零售加价</view>
- <input v-model="form.skMore" placeholder-class="phcolor" class="tui-input" name="skMore" @focus="form.skMore=''" placeholder="在成本价基础上多卖的金额" type="digit" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">顺序值</view>
- <input v-model="form.inTurn" placeholder-class="phcolor" class="tui-input" name="inTurn" @focus="form.inTurn=''" placeholder="请填写数字" type="number" />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <view class="tui-title">类型</view>
- <view>
- <button class="admin-button-com mini-btn" :class="form.kind == 0 ? 'blue' : 'default'" @click="kindChange(0)">鲜花</button>
- <button class="admin-button-com mini-btn" :class="form.kind == 1 ? 'blue' : 'default'" @click="kindChange(1)">绿植</button>
- <button class="admin-button-com mini-btn" :class="form.kind == 2 ? 'blue' : 'default'" @click="kindChange(2)">苗木(筛)</button>
- <button class="admin-button-com mini-btn" :class="form.kind == 3 ? 'blue' : 'default'" @click="kindChange(3)">苗木(穴)</button>
- </view>
- </tui-list-cell>
- </view>
- <view class="app-footer">
- <button class="admin-button-com big default" @click="goBack()">取消</button>
- <button v-if="option.ptItemId" class="admin-button-com big blue" formType="submit" @click="status = 1">添加</button>
- <button v-else class="admin-button-com big blue" formType="submit" @click="status = 1">确认</button>
- </view>
- </form>
- <uni-popup ref="classRef" background-color="#fff" type="center" :animation="false" class="class-popup-style">
- <view style="margin-left:30upx;margin-top:19upx;font-size:27upx;font-weight:bold;">请选择分类:</view>
- <view style="display:flex;padding:20upx;height:auto;justify-content: space-between;align-items:center;flex-wrap:wrap;max-height:80vh;overflow:auto;">
- <view v-for="(item, index) in itemClassData" :key="index" @tap.stop="setThisClass(item)" style="margin-bottom:20upx;margin-left:3upx;">
- <image :src="item.cover" style="width:120upx;height:120upx;border-radius:10upx;"></image>
- <view style="margin-top:5upx;overflow: hidden;white-space: nowrap;width:120upx;text-align:center;">{{item.name}}</view>
- </view>
- </view>
- </uni-popup>
- <uni-popup ref="weightRef" background-color="#fff" type="center" :animation="false" class="weight-popup-style">
- <view class="weight-popup-container">
- <view class="weight-popup-title">花材重量参考</view>
- <view class="weight-popup-content">
- <view class="weight-item" v-for="(item, index) in weightReferenceData" :key="index">
- <text class="weight-name">{{ item.name }}</text>
- <text class="weight-value">{{ item.weight }}</text>
- </view>
- </view>
- <view class="weight-popup-note">以上含纸箱平摊下来的重量,供参考</view>
- <view class="weight-popup-footer">
- <button class="admin-button-com big blue" @click="closeWeightPopup">确定</button>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import TuiListCell from "@/components/plugin/list-cell";
- const form = require("@/utils/formValidation.js");
- import { getAllItemClass } from "@/api/item-class";
- import { getAllUnit } from "@/api/unit";
- import { addProduct,cloneProduct,getProductDetail,py } from "@/api/product";
- import { getPtItemDetail } from "@/api/pt-item";
- import { mapGetters } from "vuex"
- //图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
- import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
- export default {
- name: "item-detail",
- components: {
- TuiListCell,
- htzImageUpload
- },
- data() {
- return {
- status: 1,
- currentImgData: [],
- form: {
- id:0,
- name:"",
- py:"",
- stock:0,
- virtualStock:0,
- ratio:'',
- bigUnitId:1,
- smallUnitId:2,
- classId:'',
- className:'',
- price:'',
- skPrice:'',
- hjPrice:'',
- skMore:0,
- inTurn:100,
- addPrice:0,
- hjAddPrice:0,
- discountPrice:0,
- skDiscountPrice:0,
- hjDiscountPrice:0,
- cost:0,
- weight:'',
- cover:'',
- images:[],
- stockWarning:5,
- status:2,
- itemId:0,
- smallRatio:1,
- ratioType:0,
- cpInfo:[],
- kind:0
- },
- itemClassData:[],
- unitData:[],
- smallUnitSelectedData:{},
- bigUnitSelectedData:{},
- hasRequest:0,
- productData:{id:0},
- headers:{token:''},
- backCpInfo:{cpId:0,cpName:'',needUpdate:0},
- weightReferenceData:[
- {name: '单头玫瑰', weight: '1.2公斤'},
- {name: '多头玫瑰', weight: '1.2公斤'},
- {name: '百合', weight: '2.7公斤'},
- {name: '康乃馨', weight: '1公斤'},
- {name: '向日葵', weight: '2.7公斤或3公斤'},
- {name: '其他', weight: '0.5公斤或1公斤'}
- ]
- };
- },
- computed:{
- ...mapGetters(["getLoginInfo","getDictionariesInfo"]),
- coverImgData() {
- return this.form.images || [];
- }
- },
- onLoad(option) {
- if(option.id){
- this.form.id = this.option.id
- }
- const token = uni.getStorageSync('token')
- this.headers.token = token
- },
- onShow(){
- let that = this
- if(this.backCpInfo.needUpdate == 1){
- let needAdd = 1;
- if (!this.$util.isEmpty(this.form.cpInfo)) {
- that.form.cpInfo.forEach((item) => {
- if(item.cpId == that.backCpInfo.cpId){
- needAdd = 0
- }
- })
- }
- if(needAdd == 1){
- that.form.cpInfo.push({cpId:that.backCpInfo.cpId,cpName:that.backCpInfo.cpName})
- that.backCpInfo.needUpdate = 0
- that.$forceUpdate()
- }
- }
- },
- methods: {
- selCoverFn(index) {
- this.form.cover = this.form.images[index];
- },
- showWeightPopup(){
- this.$refs.weightRef.open('center')
- },
- closeWeightPopup(){
- this.$refs.weightRef.close()
- },
- delOneCp(info,index){
- let that = this
- that.$util.confirmModal({content:'确认删除'+info.cpName+'?'},() => {
- that.form.cpInfo.splice(index,1)
- that.$forceUpdate()
- })
- },
- changeCp(item){
- this.$util.pageTo({url: '/admin/cp/list?skip=1'})
- },
- changeClass(item){
- this.$refs.classRef.open('center')
- },
- setThisClass(info){
- this.$refs.classRef.close()
- this.form.classId = info.id ? info.id : 0
- this.form.className = info.name ? info.name : ''
- this.$forceUpdate()
- },
- tjLinkage(){
- if(this.form.discountPrice && Number(this.form.discountPrice)>0){
- let skMore = this.form.skMore ? Number(this.form.skMore) : 0
- let hjAddPrice = this.form.hjAddPrice ? Number(this.form.hjAddPrice) : 0
- let addPrice = this.form.addPrice ? Number(this.form.addPrice) : 0
- let skAddNum = Number(skMore) - Number(addPrice)
- skAddNum = skAddNum.toFixed(2)
- let skAmount = Number(skAddNum) + Number(this.form.discountPrice)
- if(skAmount>0){
- skAmount = skAmount.toFixed(2)
- skAmount = parseFloat(skAmount)
- this.form.skDiscountPrice = skAmount
- }else{
- this.form.skDiscountPrice = 0.01
- }
- let hjSubNum = Number(addPrice) - Number(hjAddPrice)
- hjSubNum = hjSubNum.toFixed(2)
- let hjAmount = Number(this.form.discountPrice) - Number(hjSubNum)
- if(hjAmount > 0){
- hjAmount = hjAmount.toFixed(2)
- hjAmount = parseFloat(hjAmount)
- this.form.hjDiscountPrice = hjAmount
- }else{
- this.form.hjDiscountPrice = 0.01
- }
- }else{
- this.form.skDiscountPrice = 0
- this.form.hjDiscountPrice = 0
- }
- },
- priceLinkage(){
- if(this.form.price && Number(this.form.price)>0){
- let skMore = this.form.skMore ? Number(this.form.skMore) : 0
- let hjAddPrice = this.form.hjAddPrice ? Number(this.form.hjAddPrice) : 0
- let addPrice = this.form.addPrice ? Number(this.form.addPrice) : 0
- let skAddNum = Number(skMore) - Number(addPrice)
- skAddNum = skAddNum.toFixed(2)
- let skAmount = Number(skAddNum) + Number(this.form.price)
- if(skAmount>0){
- skAmount = skAmount.toFixed(2)
- skAmount = parseFloat(skAmount)
- this.form.skPrice = skAmount
- }else{
- this.form.skPrice = ''
- }
- let hjSubNum = Number(addPrice) - Number(hjAddPrice)
- hjSubNum = hjSubNum.toFixed(2)
- let hjAmount = Number(this.form.price) - Number(hjSubNum)
- if(hjAmount > 0){
- hjAmount = hjAmount.toFixed(2)
- hjAmount = parseFloat(hjAmount)
- this.form.hjPrice = hjAmount
- }else{
- this.form.hjPrice = ''
- }
- }else{
- this.form.skPrice = ''
- this.form.hjPrice = ''
- this.form.discountPrice = 0
- this.form.skDiscountPrice = 0
- this.form.hjDiscountPrice = 0
- }
- },
- notModify(){
- this.$msg('不可修改')
- },
- goStockDetail(item){
- this.$util.pageTo({url: "/pagesStorehouse/stockWarn/detailed?id="+item.id+'&name='+item.name})
- },
- statusChange(e){
- this.form.status = e.detail.value ? 1 : 2;
- },
- kindChange(kind){
- this.form.kind = kind
- },
- ratioTypeChange(e){
- this.form.ratioType = e.detail.value
- },
- // 切换库存不足时是否自动补充;开启前二次确认,避免误触
- virtualStockChange(value){
- if (value === this.form.virtualStock) return
- const doChange = () => {
- this.form.virtualStock = value
- }
- if (value === 1) {
- this.$util.confirmModal({ content: '开启后,库存不足时会自动补充,确认开启?' }, doChange)
- } else {
- doChange()
- }
- },
- //如果库存被修改则花材状态变化
- changeStock(event){
- let num = Number(event.target.value)
- if(num > 0){
- this.form.status = 1
- }else{
- this.form.status = 2
- }
- },
- //获取拼音首字母 shish 20210707
- fillName(event){
- let val = event.target.value
- py({
- name:val
- }).then(res => {
- if(res.data.py){
- this.form.py = res.data.py
- }
- });
- },
- goBack(){
- uni.navigateBack({ delta: 1 })
- },
- changeBigUnitFn(e){
- this.bigUnitSelectedData = this.unitData[e.detail.value];
- this.form.bigUnitId = this.bigUnitSelectedData.id;
- },
- changeSmallUnitFn(e){
- this.smallUnitSelectedData = this.unitData[e.detail.value];
- this.form.smallUnitId = this.smallUnitSelectedData.id;
- },
- getPtItemInfo(ptItemId){
- getPtItemDetail({id:ptItemId}).then(res=>{
- if (this.$util.isEmpty(res.data)) {
- return;
- }
- Object.keys(this.form).forEach((i, index) => {
- this.form[i] = res.data[i];
- });
- this.currentImgData.push(res.data.cover)
- this.form.cover = [res.data.shortCover]
- this.form.stock = ''
- // 平台采用/复制新建默认关闭自动补充,需用户主动开启
- this.form.virtualStock = 0
- this.form.itemId = ptItemId
- this.form.classId = ''
- this.form.status = 1
- this.form.id = 0
- this.form.price = ''
- this.form.skPrice = ''
- this.form.hjPrice = ''
- this.form.skMore = 6
- this.form.addPrice = 3
- this.form.hjAddPrice = 3
- this.form.discountPrice = 0
- this.form.cost = 0
- this.form.inTurn = 100
- })
- },
- getDetail() {
- return getProductDetail({ id: this.option.id }).then(res => {
- if (this.$util.isEmpty(res.data)) {
- return;
- }
- Object.keys(this.form).forEach((i, index) => {
- this.form[i] = res.data[i];
- });
- const imageUrls = (res.data.images || '').split(',').filter(i => i);
- this.form.images = imageUrls;
- this.currentImgData = imageUrls.map(url => {
- return this.constant.imgUrl + '/' + url + '?x-oss-process=image/resize,m_fill,h_700,w_700'
- });
- this.form.cover = res.data.shortCover || '';
- if (!this.form.cover && this.form.images.length > 0) {
- this.form.cover = this.form.images[0];
- }
- this.form.price = res.data.prePrice
- this.form.stock = 0
- // 复制新建默认关闭自动补充,需用户主动开启
- this.form.virtualStock = 0
- let currentClass = this.itemClassData.filter(
- e => this.form.classId == e.id
- )[0];
- this.form.className = currentClass.name ? currentClass.name : ''
- this.smallUnitSelectedData = this.unitData.filter(
- e => this.form.smallUnitId == e.id
- )[0];
- this.bigUnitSelectedData = this.unitData.filter(
- e => this.form.bigUnitId == e.id
- )[0];
- this.productData = res.data
- this.productData.id = 0
- });
- },
- imgUploadSuccess(res) {
- var _res = JSON.parse(res.data)
- if(_res.code == 1){
- this.currentImgData.push(_res.data.bigUrl)
- this.form.images.push(_res.data.shortUrl)
- if (!this.form.cover) {
- this.form.cover = _res.data.shortUrl;
- }
- }
- },
- imgDeleteFn(res){
- const index = res.index;
- const deletedUrl = this.form.images[index];
- this.form.images.splice(index, 1);
- if (this.form.cover === deletedUrl) {
- this.form.cover = this.form.images[0] || '';
- }
- },
- init() {
- //从平台选择花材
- if(!this.$util.isEmpty(this.option.ptItemId)){
- uni.setNavigationBarTitle({title: "确认花材信息"})
- }
- if(this.hasRequest == 1){
- return
- }
- this._getAllUnit().then(res=>{
- this._getAllItemClass().then(res => {
- if(this.form.id == 0){
- this.smallUnitSelectedData = this.unitData.filter(e => 2 == e.id)[0];
- this.bigUnitSelectedData = this.unitData.filter(e => 1 == e.id)[0];
- //从平台选择花材
- if(!this.$util.isEmpty(this.option.ptItemId)){
- this.getPtItemInfo(this.option.ptItemId)
- }
- }else{
- this.getDetail();
- }
- });
- })
- this.hasRequest = 1
- },
- async _getAllUnit() {
- await getAllUnit().then(res => {
- if (this.$util.isEmpty(res.data)){
- return false;
- }
- this.unitData = res.data.list;
- });
- },
- async _getAllItemClass() {
- await getAllItemClass().then(res => {
- if (this.$util.isEmpty(res.data)){
- return false;
- }
- this.itemClassData = res.data;
- });
- },
- // 确认
- confirmFn() {
- if (this.$util.isEmpty(this.form.images)) {
- this.$msg("请上传图片")
- return false
- }
- if (!this.form.cover && this.form.images.length > 0) {
- this.form.cover = this.form.images[0];
- }
- let requestHost = addProduct
- if(this.form.id && this.form.id != 0){
- requestHost = cloneProduct;
- }else{
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.stock) == false){
- uni.showToast({title:"请填写库存,没有请填0",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.discountPrice) == false){
- uni.showToast({title:"请填写特价,没有特价请填0",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.cost) == false){
- uni.showToast({title:"请填写成本",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.price) == false){
- uni.showToast({title:"请填写批发价",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.hjPrice) == false){
- uni.showToast({title:"请填写大客价",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.skPrice) == false){
- uni.showToast({title:"请填写零售价",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.addPrice) == false){
- uni.showToast({title:"请填写批发加价",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.skMore) == false){
- uni.showToast({title:"请填写零售加价",icon:"none"})
- return;
- }
- if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.hjAddPrice) == false){
- uni.showToast({title:"请填写大客加价",icon:"none"})
- return;
- }
- }
- let form = JSON.parse(JSON.stringify(this.form))
- form.images = form.images.join(',')
- uni.showLoading({mask:true})
- requestHost({...form,appVersion:1}).then(res => {
- uni.hideLoading()
- if(res.code == 1){
- this.$msg("操作成功");
- //返回上一页带参数
- let pages = getCurrentPages();
- let prevPage = pages[ pages.length - 2 ];
- let hidden = 0
- if(this.form.stock > this.form.stockWarning){
- hidden = 1
- }
- prevPage.$vm.modifyStock = {id:this.form.id,stock:this.form.stock,hidden:hidden};
- uni.navigateBack({})
- }
- });
- },
- // 表单验证
- formSubmit(e) {
- // 表单规则
- let rules = [
- {
- name: "name",
- rule: ["required"],
- msg: ["请填写名称"]
- },
- {
- name: "py",
- rule: ["required"],
- msg: ["请填写拼音缩写"]
- },{
- name: "stock",
- rule: ["required"],
- msg: ["请填写库存,没有填0"]
- },
- {
- name: "bigUnitId",
- rule: ["required"],
- msg: ["请选择大单位"]
- },
- {
- name: "smallUnitId",
- rule: ["required"],
- msg: ["请选择小单位"]
- },
- {
- name: "price",
- rule: ["required"],
- msg: ["请填写批发价"]
- },
- {
- name: "skPrice",
- rule: ["required"],
- msg: ["请填写零售价"]
- },
- {
- name: "hjPrice",
- rule: ["required"],
- msg: ["请填写大客价"]
- },
- {
- name: "addPrice",
- rule: ["required"],
- msg: ["请填写批发加价"]
- },
- {
- name: "hjAddPrice",
- rule: ["required"],
- msg: ["请填写大客加价"]
- },
- {
- name: "discountPrice",
- rule: ["required"],
- msg: ["不做特价请填0"]
- },
- {
- name: "cost",
- rule: ["required"],
- msg: ["请填写成本"]
- },
- {
- name: "skMore",
- rule: ["required"],
- msg: ["请填写零售加价"]
- },
- {
- name: "weight",
- rule: ["required"],
- msg: ["请填写重量"]
- },
- {
- name: "classId",
- rule: ["required"],
- msg: ["请选择分类"]
- },
- {
- name: "stockWarning",
- rule: ["required"],
- msg: ["请填写库存预警"]
- }
- ];
- // 进行表单检查
- let formData = e.detail.value;
- let checkRes = form.validation(formData, rules);
- // 验证通过!
- if (!checkRes) {
- this.confirmFn()
- } else {
- this.$msg(checkRes);
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .app-content {
- min-height: calc(100vh - 100upx);
- padding-bottom: 150upx;
- }
- // 公共模块
- .module-com {
- margin-bottom: 20upx;
- background-color: #fff;
- color: $fontColor2;
- .module-tit {
- padding: 20upx 30upx;
- font-size: 28upx;
- }
- .module-det {
- padding: 0 30upx;
- }
- }
- .use-img{
- font-size: 22rpx;
- color: #999999;
- padding-left: 4rpx 8rpx;
- line-height: 1.5;
- }
- .no-img-tip {
- font-size: 26rpx;
- color: #cccccc;
- padding: 12rpx 0;
- }
- .category-wrap {
- align-items: flex-start;
- padding-bottom: 0 !important;
- .tui-input {
- @include disFlex(center, flex-start);
- flex-wrap: wrap;
- .admin-button-com {
- margin-right: 20upx;
- margin-bottom: 20upx;
- position: relative;
- z-index: 9999;
- }
- }
- }
- .summary-wrap {
- .goods-summary {
- height: 400upx;
- }
- }
- .app-footer {
- justify-content: space-evenly;
- z-index: 9999;
- .admin-button-com {
- width: 46%;
- }
- }
- // 权重提醒图标样式
- .weight-reminder-icon {
- margin-left: 20upx;
- padding: 10upx;
- width: 60upx;
- height: 60upx;
- display: flex;
- align-items: center;
- justify-content: center;
- background-color: #f5f5f5;
- border-radius: 50%;
- border: 1upx solid #ddd;
- }
- // 权重弹窗样式
- .weight-popup-style {
- .weight-popup-container {
- width: 600upx;
- max-height: 80vh;
- padding: 30upx;
- border-radius: 16upx;
- background-color: #fff;
- z-index:9999;
- .weight-popup-title {
- font-size: 32upx;
- font-weight: bold;
- color: #333;
- text-align: center;
- margin-bottom: 30upx;
- }
-
- .weight-popup-content {
- .weight-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 20upx 0;
- border-bottom: 1upx solid #f0f0f0;
-
- &:last-child {
- border-bottom: none;
- }
-
- .weight-name {
- font-size: 28upx;
- color: #333;
- font-weight: 500;
- }
-
- .weight-value {
- font-size: 28upx;
- color: #666;
- }
- }
- }
-
- .weight-popup-note {
- margin-top: 30upx;
- padding: 20upx;
- background-color: #f8f8f8;
- border-radius: 8upx;
- font-size: 28upx;
- color: #999;
- line-height: 1.5;
- }
-
- .weight-popup-footer {
- margin-top: 30upx;
- display: flex;
- justify-content: center;
- }
- }
- }
- .class-popup-style {
- z-index: 99999;
- }
- </style>
|