|
|
@@ -0,0 +1,442 @@
|
|
|
+<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 required">名称</view>
|
|
|
+ <input v-model="form.name" placeholder-class="phcolor" class="tui-input" name="name" placeholder="请输入" maxlength="50" type="text" />
|
|
|
+ </tui-list-cell>
|
|
|
+ <tui-list-cell class="line-cell" :hover="false">
|
|
|
+ <view class="tui-title required">价格</view>
|
|
|
+ <input v-model="form.price" placeholder-class="phcolor" class="tui-input" name="price" placeholder="请输入" maxlength="50" type="digit" />
|
|
|
+ </tui-list-cell>
|
|
|
+ <tui-list-cell class="line-cell category-wrap" :hover="false">
|
|
|
+ <view class="tui-title">分类</view>
|
|
|
+ <view class="tui-input">
|
|
|
+ <block v-for="(item, index) in categoryData" :key="index">
|
|
|
+ <button class="admin-button-com" :class="[(form.catIds.includes(item.id + '')||form.catIds.includes(item.id*1)) ? '' : 'default']"
|
|
|
+ @click="selCategoryFn(item)" >{{ item.categoryName || '暂无' }}</button>
|
|
|
+ </block>
|
|
|
+ </view>
|
|
|
+ </tui-list-cell>
|
|
|
+ <tui-list-cell class="line-cell" :hover="false">
|
|
|
+ <view class="tui-title">主花支数</view>
|
|
|
+ <input v-model="form.flowerNum" placeholder-class="phcolor" class="tui-input" name="sold" placeholder="支数" maxlength="50" type="number" />
|
|
|
+ </tui-list-cell>
|
|
|
+ <tui-list-cell class="line-cell" :hover="false">
|
|
|
+ <view class="tui-title">历史销量</view>
|
|
|
+ <input v-model="form.sold" placeholder-class="phcolor" class="tui-input" name="sold" placeholder="选填,总销量=历史销量+真实销量" maxlength="50" type="number" />
|
|
|
+ </tui-list-cell>
|
|
|
+ <tui-list-cell class="line-cell" :hover="false">
|
|
|
+ <view class="tui-title">节日涨价</view>
|
|
|
+ <label for="autoPrice" class="tui-input" @click="autoRiseChange(form.autoRise)">
|
|
|
+ <checkbox id="autoPrice" class="ljd-checkbox" :checked="form.autoRise == 1" style="transform: scale(0.7,0.7);" ></checkbox>
|
|
|
+ <span>需要</span>
|
|
|
+ </label>
|
|
|
+ </tui-list-cell>
|
|
|
+ <tui-list-cell class="line-cell" :hover="false">
|
|
|
+ <view class="tui-title">配送类型</view>
|
|
|
+ <label for="sendType" class="tui-input" @click="needSendChange(form.needSend)">
|
|
|
+ <checkbox id="sendType" class="ljd-checkbox" :checked="form.needSend == 1" @change="giftChange" style="transform: scale(0.7,0.7);" ></checkbox>
|
|
|
+ <span>自取商品</span>
|
|
|
+ </label>
|
|
|
+ </tui-list-cell>
|
|
|
+ <tui-list-cell class="line-cell" :hover="false">
|
|
|
+ <view class="tui-title">运费</view>
|
|
|
+ <radio-group class="tui-input" @change="freightChange">
|
|
|
+ <label class="list" for="customLink">
|
|
|
+ <radio id="customLink" value="0" :checked="form.freightType == 0" style="transform: scale(0.8,0.8);" />
|
|
|
+ <span class="checkbox-text">按距离收费</span>
|
|
|
+ </label>
|
|
|
+ <label class="list" for="goodsLink">
|
|
|
+ <radio id="goodsLink" value="1" :checked="form.freightType == 1" style="transform: scale(0.8,0.8);" />
|
|
|
+ <span class="checkbox-text">免运费</span>
|
|
|
+ </label>
|
|
|
+ </radio-group>
|
|
|
+ </tui-list-cell>
|
|
|
+
|
|
|
+ <tui-list-cell class="line-cell" :hover="false">
|
|
|
+ <view class="tui-title">状态</view>
|
|
|
+ <radio-group class="tui-input" @change="statusChange">
|
|
|
+ <label class="list" for="upLink">
|
|
|
+ <radio id="upLink" value="1" :checked="form.status == 1" style="transform: scale(0.8,0.8);" />
|
|
|
+ <span class="checkbox-text">上架</span>
|
|
|
+ </label>
|
|
|
+ <label class="list" for="downLink">
|
|
|
+ <radio id="downLink" value="0" :checked="form.status == 0" style="transform: scale(0.8,0.8);" />
|
|
|
+ <span class="checkbox-text">下架</span>
|
|
|
+ </label>
|
|
|
+ </radio-group>
|
|
|
+ </tui-list-cell>
|
|
|
+
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="module-com content-box proInfo">
|
|
|
+ <view class="commodity-view">
|
|
|
+ <view class="infoAEdit">
|
|
|
+ <text>使用花材</text> <text v-if="!$util.isEmpty(selectList)" style="float:right;color:#3385ff" @click="selectItem()">修改花材</text>
|
|
|
+ </view>
|
|
|
+ <template v-if="!$util.isEmpty(selectList)">
|
|
|
+ <view class="commodity-list">
|
|
|
+ <view v-for="(s, idx) in selectList" :key="idx" class="commodity-item" >
|
|
|
+ <image class="item-icon" :src="s.cover" @click="pageTo({url:'/admin/item/detail',query:{id: s.id}})" />
|
|
|
+ <view class="item-info">
|
|
|
+ <view class="info-line">
|
|
|
+ <text class="item-name">{{ s.name }}</text>
|
|
|
+ <text class="item-price">
|
|
|
+ <text class="unit"></text>
|
|
|
+ <text class="price">
|
|
|
+ <text v-if="Number(s.bigCount)>0">{{s.bigCount}}{{s.bigUnit}}</text>
|
|
|
+ <text v-if="Number(s.smallCount)>0">{{s.smallCount}}{{s.smallUnit}}</text>
|
|
|
+ </text>
|
|
|
+ </text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <view style="text-align:center;">
|
|
|
+ <button class="admin-button-com middle blue" style="margin:0 auto;margin-top:10upx;margin-bottom:10upx;" @click="selectItem()">选择花材</button>
|
|
|
+ </view>
|
|
|
+ </template>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="module-com input-line-wrap goods-wrap">
|
|
|
+ <view class="module-tit">
|
|
|
+ <span>图片</span>
|
|
|
+ <span class="app-color-3">(最多4张)</span>
|
|
|
+ </view>
|
|
|
+ <view class="module-det">
|
|
|
+ <htz-image-upload :max="4" :compress="true" v-model="currentImgData" :headers="headers"
|
|
|
+ @uploadSuccess="imgUploadSuccess" @imgDelete="imgDeleteFn" :action="getLoginInfo.imgUploadApi">
|
|
|
+ </htz-image-upload>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="module-com input-line-wrap summary-wrap">
|
|
|
+ <view class="module-tit">商品简介</view>
|
|
|
+ <view class="module-det" style="padding-bottom: 20upx">
|
|
|
+ <textarea v-model="form.briefContent" class="goods-summary" placeholder-class="phcolor" placeholder="请输入商品简介" />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="app-footer">
|
|
|
+ <button class="admin-button-com middle default" @click="goBack">取消</button>
|
|
|
+ <button class="admin-button-com middle blue" formType="submit">保存</button>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ </form>
|
|
|
+ </view>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import { mapGetters } from "vuex";
|
|
|
+import TuiListCell from "@/components/plugin/list-cell";
|
|
|
+import AppUploader from "@/components/app-uploader";
|
|
|
+const form = require("@/utils/formValidation.js");
|
|
|
+import { getClass } from "@/api/category";
|
|
|
+import { getDetailB, addB, updateB } from "@/api/goods"
|
|
|
+//图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
|
|
|
+import htzImageUpload from './components/htz-image-upload/htz-image-upload.vue'
|
|
|
+import productMins from "@/mixins/product";
|
|
|
+export default {
|
|
|
+ name: "add",
|
|
|
+ components: { TuiListCell, AppUploader,htzImageUpload },
|
|
|
+ mixins: [productMins],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ headers:{token:''},
|
|
|
+ status: 1,
|
|
|
+ selectJobType: "addGoodsSelectItem",
|
|
|
+ form: {
|
|
|
+ name: "",
|
|
|
+ price: "",
|
|
|
+ catIds: [],
|
|
|
+ autoRise: "1",
|
|
|
+ needSend: "0",
|
|
|
+ freightType: "0",
|
|
|
+ shopImg: [],
|
|
|
+ briefContent: "",
|
|
|
+ status:1,
|
|
|
+ cover:''
|
|
|
+ },
|
|
|
+ categoryData:[],
|
|
|
+ currentImgData:[]
|
|
|
+ };
|
|
|
+ },
|
|
|
+ onLoad() {
|
|
|
+ const token = uni.getStorageSync('token')
|
|
|
+ this.headers.token = token
|
|
|
+ },
|
|
|
+ watch:{
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ selectItem(){
|
|
|
+ this.pageTo({url:'/admin/goodsManage/selectItem'})
|
|
|
+ },
|
|
|
+ goBack(){
|
|
|
+ uni.navigateBack({delta:1})
|
|
|
+ },
|
|
|
+ imgDeleteFn(res){
|
|
|
+ const index = res.index
|
|
|
+ this.form.shopImg.splice(index,1)
|
|
|
+ },
|
|
|
+ imgUploadSuccess(res) {
|
|
|
+ var _res = JSON.parse(res.data)
|
|
|
+ if(_res.code == 1){
|
|
|
+ this.currentImgData.push(_res.data.smallUrl)
|
|
|
+ this.form.shopImg.push(_res.data.shortUrl)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ init() {
|
|
|
+ getClass({flower:1}).then(res => {
|
|
|
+ if(res.code && res.code == 1){
|
|
|
+ this.categoryData = res.data
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ confirmFn() {
|
|
|
+ let that = this
|
|
|
+ if (this.$util.isEmpty(this.form.catIds)) {
|
|
|
+ this.$msg("请选择分类");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (this.$util.isEmpty(this.form.shopImg)) {
|
|
|
+ this.$msg("请上传图片");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ this.form.cover = this.form.shopImg[0]
|
|
|
+ if (this.$util.isEmpty(this.selectList)) {
|
|
|
+ this.$msg("请选择花材");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const product = this.selectList.map(ele => {
|
|
|
+ let unitName = ele.bigUnit
|
|
|
+ let unitType = 0
|
|
|
+ let num = ele.bigCount
|
|
|
+ let count = ele.bigCount
|
|
|
+ if(Number(ele.smallCount)>0){
|
|
|
+ unitType = 1
|
|
|
+ unitName = ele.smallUnit
|
|
|
+ num=ele.smallCount
|
|
|
+ count = (ele.smallCount/ele.ratio).toFixed(2)
|
|
|
+ }
|
|
|
+ return { id: ele.id, ptItemId:ele.itemId,bigName:ele.bigUnit,smallName:ele.smallUnit,unitName:unitName,cover:ele.shortCover,ratio:ele.ratio,num:num,count:count}
|
|
|
+ })
|
|
|
+ that.$util.confirmModal({content:'确认添加?'},() => {
|
|
|
+ uni.showLoading({mask:true})
|
|
|
+ let form = JSON.parse(JSON.stringify(this.form));
|
|
|
+ addB({ status: this.status, ...form,itemList:JSON.stringify(product) }).then(res => {
|
|
|
+ uni.hideLoading()
|
|
|
+ this.$msg("添加成功")
|
|
|
+ this.removeFromSaveDirect()
|
|
|
+ setTimeout(function(){
|
|
|
+ uni.navigateBack({})
|
|
|
+ },1500)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ selCategoryFn(item) {
|
|
|
+ let index = this.form.catIds.findIndex(e => e == item.id);
|
|
|
+ if (index == -1) {
|
|
|
+ this.form.catIds.push(item.id);
|
|
|
+ } else {
|
|
|
+ this.form.catIds.splice(index, 1);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ autoRiseChange(e) {
|
|
|
+ this.form.autoRise = e == "0" ? "1" : "0";
|
|
|
+ },
|
|
|
+ needSendChange(e) {
|
|
|
+ this.form.needSend = e == "0" ? "1" : "0";
|
|
|
+ },
|
|
|
+ freightChange(e) {
|
|
|
+ this.form.freightType = e.detail.value;
|
|
|
+ },
|
|
|
+ // 表单验证
|
|
|
+ formSubmit(e) {
|
|
|
+ // 表单规则
|
|
|
+ let rules = [
|
|
|
+ {
|
|
|
+ name: "name",
|
|
|
+ rule: ["required"],
|
|
|
+ msg: ["请输入名称"]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "price",
|
|
|
+ rule: ["required"],
|
|
|
+ msg: ["请输入价格"]
|
|
|
+ }
|
|
|
+ ];
|
|
|
+ // 进行表单检查
|
|
|
+ let formData = e.detail.value;
|
|
|
+ let checkRes = form.validation(formData, rules);
|
|
|
+ // 验证通过!
|
|
|
+ if (!checkRes) {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.confirmFn();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.$msg(checkRes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style lang="scss" scoped>
|
|
|
+.app-content {
|
|
|
+ min-height: calc(100vh - 100upx);
|
|
|
+ padding-bottom: 100upx;
|
|
|
+}
|
|
|
+.module-com {
|
|
|
+ margin-bottom: 20upx;
|
|
|
+ background-color: #fff;
|
|
|
+ color: $fontColor2;
|
|
|
+ .module-tit {
|
|
|
+ padding: 20upx 30upx;
|
|
|
+ font-size: 28upx;
|
|
|
+ }
|
|
|
+ .module-det {
|
|
|
+ padding: 0 30upx;
|
|
|
+ }
|
|
|
+}
|
|
|
+.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: 200upx;
|
|
|
+ }
|
|
|
+}
|
|
|
+.app-footer {
|
|
|
+ justify-content: space-evenly;
|
|
|
+ z-index: 9999;
|
|
|
+ .admin-button-com {
|
|
|
+ width: 46%;
|
|
|
+ padding-top:30upx;
|
|
|
+ padding-bottom:30upx;
|
|
|
+ }
|
|
|
+}
|
|
|
+.commodity-view {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ .commodity-list {
|
|
|
+ padding: 25upx;
|
|
|
+ .commodity-item {
|
|
|
+ display: flex;
|
|
|
+ margin-bottom: 20upx;
|
|
|
+ .item-icon {
|
|
|
+ flex-shrink: 0;
|
|
|
+ width: 120upx;
|
|
|
+ height: 120upx;
|
|
|
+ }
|
|
|
+ .item-info {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ justify-content: center;
|
|
|
+ flex: 1;
|
|
|
+ margin-left: 20upx;
|
|
|
+ .info-line {
|
|
|
+ margin-bottom: 20upx;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: flex-end;
|
|
|
+ .item-name {
|
|
|
+ color: black;
|
|
|
+ font-size: 30upx;
|
|
|
+ font-weight: 700;
|
|
|
+ overflow: hidden;
|
|
|
+ white-space: nowrap;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ width:360upx;
|
|
|
+ }
|
|
|
+ .item-price {
|
|
|
+ padding-right:30upx;
|
|
|
+ color: #333;
|
|
|
+ .price {
|
|
|
+ font-size: 28upx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .item-type {
|
|
|
+ color: #999;
|
|
|
+ font-size: 24upx;
|
|
|
+ }
|
|
|
+ .item-count {
|
|
|
+ color: #666;
|
|
|
+ font-size: 24upx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .summary-bar {
|
|
|
+ padding: 0 20upx;
|
|
|
+ height: 90upx;
|
|
|
+ display: flex;
|
|
|
+
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ border-top: 1px solid #eeeeee;
|
|
|
+ .operate-view {
|
|
|
+ display: flex;
|
|
|
+
|
|
|
+ align-items: center;
|
|
|
+ color: #3385ff;
|
|
|
+ font-size: 26upx;
|
|
|
+ .iconfont {
|
|
|
+ margin-right: 20upx;
|
|
|
+ font-size: 40upx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .describe-view {
|
|
|
+ display: flex;
|
|
|
+
|
|
|
+ align-items: center;
|
|
|
+ color: #333;
|
|
|
+ font-size: 24upx;
|
|
|
+ .price {
|
|
|
+ font-weight: bold;
|
|
|
+ font-size: 30upx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+.infoAEdit {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ height: 60upx;
|
|
|
+ line-height: 80upx;
|
|
|
+ font-size: 28;
|
|
|
+ font-weight: 700;
|
|
|
+ color: #666;
|
|
|
+ padding: 0 20upx;
|
|
|
+ .iconfont {
|
|
|
+ margin-right: 15upx;
|
|
|
+ font-size: 30upx;
|
|
|
+ }
|
|
|
+ & > .editFlr {
|
|
|
+ position: relative;
|
|
|
+ color: #1890f3;
|
|
|
+ font-size: 26upx;
|
|
|
+ &:after {
|
|
|
+ content: "";
|
|
|
+ position: absolute;
|
|
|
+ left: 0;
|
|
|
+ top: 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|