Browse Source

优化代码

master
xuwenbo 4 years ago
parent
commit
e271bab225
  1. 4
      src/views/components/good/index.vue
  2. 186
      src/views/components/livegoods/index.vue
  3. 94
      src/views/wechat/goods/index.vue
  4. 101
      src/views/wechat/live/index.vue

4
src/views/components/good/index.vue

@ -116,12 +116,16 @@ export default {
that.$set(that.value,"productId", null)
that.$set(that.value,"storeName", null)
that.$set(that.value,"image", null)
this.$set(this.value,"otPrice", null)
this.$set(this.value,"price", null)
})
},
doSelect(data) {
this.$set(this.value,"productId", data.id)
this.$set(this.value,"storeName", data.storeName)
this.$set(this.value,"image", data.image)
this.$set(this.value,"otPrice", data.otPrice)
this.$set(this.value,"price", data.price)
this.dialog = false
},
toSelete() {

186
src/views/components/livegoods/index.vue

@ -0,0 +1,186 @@
<template>
<div>
<div>
<ul v-for="(item,index) in newValue" :key="index" class="el-upload-list el-upload-list--picture-card">
<li tabindex="0" class="el-upload-list__item is-ready" :style="'width: '+width+'px;height: '+height+'px'">
<div>
<img :src="item.coverImgeUrl" alt="" class="el-upload-list__item-thumbnail">
<span class="el-upload-list__item-actions">
<span class="el-upload-list__item-delete" @click="deleteGood(index)">
<i class="el-icon-delete" />
</span>
</span>
</div>
</li>
</ul>
<div tabindex="0" class="el-upload el-upload--picture-card" @click="toSelete">
<i class="el-icon-plus" />
</div>
</div>
<el-dialog :visible.sync="dialog" append-to-body width="60%" title="商品列表">
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<!-- 搜索 -->
<el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
<el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
<el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
</el-select>
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
<!-- 新增 -->
</div>
<!--表单组件-->
<!--表格渲染-->
<el-table v-loading="loading" :data="data" size="small" style="width: 100%;" @selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column prop="goodsId" label="直播商品id" />
<el-table-column prop="name" label="商品名称" />
<el-table-column prop="productId" label="关联商品id" />
<el-table-column prop="coverImgUrl" label="商品图片" >
<template slot-scope="scope">
<a :href="scope.row.coverImgeUrl" style="color: #42b983" target="_blank"><img :src="scope.row.coverImgeUrl" alt="点击打开" class="el-avatar"></a>
</template>
</el-table-column>
<el-table-column prop="url" label="商品小程序路径" />
<el-table-column prop="priceType" label="价格类型" >
<template slot-scope="scope">
<div>
<el-tag v-if="scope.row.priceType == 1" :type="''">一口价</el-tag>
<el-tag v-else-if="scope.row.priceType == 2" :type="''">价格区间</el-tag>
<el-tag v-else-if="scope.row.priceType == 3" :type="''">显示折扣价</el-tag>
</div>
</template>
</el-table-column>
<!-- <el-table-column v-if="columns.visible('price')" prop="price" label="price" />-->
<!-- <el-table-column v-if="columns.visible('price2')" prop="price2" label="price2" />-->
<el-table-column prop="auditStatus" label="审核状态" >
<!-- //012:3-->
<template slot-scope="scope">
<div>
<el-tag v-if="scope.row.auditStatus === 0" :type="''">未审核</el-tag>
<el-tag v-else-if="scope.row.auditStatus === 1" :type="''">审核中</el-tag>
<el-tag v-else-if="scope.row.auditStatus === 2" :type="''">审核通过</el-tag>
<el-tag v-else-if="scope.row.auditStatus === 3" :type="''">审核失败</el-tag>
</div>
</template>
</el-table-column>
<!-- 1, 2表示是为api添加商品否则是直播控制台添加的商品-->
<el-table-colum prop="thirdPartyTag" label="添加途径" >
<template slot-scope="scope">
<div>
<el-tag v-if="scope.row.thirdPartyTag == 0" :type="''">api添加</el-tag>
<el-tag v-else-if="scope.row.thirdPartyTag == 2" :type="''">控制台</el-tag>
</div>
</template>
</el-table-colum>
</el-table>
<div style="margin-top: 20px">
<el-button type="primary" @click="doSelect()">确定选择</el-button>
</div>
<!--分页组件-->
<el-pagination
:total="total"
:current-page="page + 1"
style="margin-top: 8px;"
layout="total, prev, pager, next, sizes"
@size-change="sizeChange"
@current-change="pageChange"
/>
</div>
</el-dialog>
</div>
</template>
<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/crud'
export default {
components: { },
mixins: [initData],
props: {
value: {
type: Array,
default() {
return []
}
},
//
width: {
type: Number,
default() {
return 150
}
},
//
height: {
type: Number,
default() {
return 150
}
}
},
data() {
return {
newValue:this.value,
delLoading: false,
visible: false,
queryTypeOptions: [
{ key: 'storeName', display_name: '商品名称' }
],
isAttr: false,
multipleSelection: []
}
},
created() {
this.$nextTick(() => {
this.init()
})
},
methods: {
deleteGood(index) {
const that = this
this.$confirm('是否确认删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
that.newValue.splice(index, 1)
that.url = []
})
},
doSelect() {
this.newValue = this.multipleSelection
this.$emit("selectGoods", this.newValue)
this.dialog = false
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
toSelete() {
this.dialog = true
},
checkPermission,
beforeInit() {
this.url = 'api/yxWechatLiveGoods'
const sort = 'goods_id,desc'
this.params = { page: this.page, size: this.size, sort: sort, auditStatus: "2" }
const query = this.query
const type = query.type
const value = query.value
if (type && value) { this.params[type] = value }
return true
}
}
}
</script>
<style scoped>
</style>

94
src/views/wechat/goods/index.vue

@ -26,49 +26,49 @@
</crudOperation>
<!--表单组件-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="800px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="200px">
<el-form-item label="选择商品" prop="coverImgeUrl" label-width="80px">
<cgood v-model="form.good" ></cgood>
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="140px">
<el-form-item label="选择商品" prop="coverImgeUrl" >
<cgood v-model="form.good":disabled="disable" ></cgood>
</el-form-item>
<el-form-item label="商品小程序路径" prop="url" label-width="80px">
<el-input v-model="form.url" style="width: 370px;" />
<el-form-item label="商品小程序路径" prop="url" >
<el-input v-model="form.url" style="width: 370px;" :disabled="disable"/>
</el-form-item>
<!-- 1一口价只需要传入priceprice2不传-->
<!-- 2价格区间price字段为左边界price2字段为右边界price和price2必传-->
<!-- 3显示折扣价price字段为原价price2字段为现价 price和price2必传-->
<el-form-item label="商品名称" prop="name" label-width="80px">
<el-input v-model="form.name" style="width: 370px;" />
<el-form-item label="商品名称" prop="name" >
<el-input v-model="form.name" style="width: 370px;" :disabled="disable"/>
</el-form-item>
<el-form-item label="价格类型" prop="priceType" label-width="80px">
<el-form-item label="价格类型" prop="priceType" >
<el-radio-group v-model="form.priceType" >
<el-radio :label="'1'" class="radio">一口价</el-radio>
<el-radio :label="'2'" class="radio">价格区间</el-radio>
<el-radio :label="'3'" class="radio">显示折扣价</el-radio>
</el-radio-group>
<p v-if="disable" style="color: #cf0f0f">商品审核通过已入库只能修改价格</p>
</el-form-item>
<el-col v-if="form.priceType=='1'" v-bind="grid">
<el-form-item label="一口价" prop="price" label-width="80px">
<el-form-item label="一口价" prop="price" >
<el-input v-model="form.price" style="width: 200px;" />
</el-form-item>
</el-col>
<el-col v-if="form.priceType=='2'" v-bind="grid">
<el-form-item label="最低价格" prop="price" label-width="80px">
<el-form-item label="最低价格" prop="price" >
<el-input v-model="form.price" style="width: 200px;"/>
</el-form-item>
</el-col>
<el-col v-if="form.priceType=='2'" v-bind="grid">
<el-form-item label="最高价格" prop="price2" label-width="80px" >
<el-form-item label="最高价格" prop="price2" >
<el-input v-model="form.price2" style="width: 200px;"/>
</el-form-item>
</el-col>
<el-col v-if="form.priceType=='3'" v-bind="grid">
<el-form-item label="市场价" prop="price" label-width="80px">
<el-form-item label="市场价" prop="price" >
<el-input v-model="form.price" style="width: 200px;" />
</el-form-item>
</el-col>
<el-col v-if="form.priceType=='3'" v-bind="grid">
<el-form-item label="现价" prop="price2" label-width="80px">
<el-form-item label="现价" prop="price2" >
<el-input v-model="form.price2" style="width: 200px;"/>
</el-form-item>
</el-col>
@ -150,13 +150,14 @@ import cgood from '@/views/components/good'
// crudpresenter
const defaultCrud = CRUD({ title: '直播商品', url: 'api/yxWechatLiveGoods', sort: 'goods_id,desc', crudMethod: { ...crudYxWechatLiveGoods }})
const defaultForm = { good: {productId: null,storeName: null,image: null}, goodsId: null, productId: null, coverImgeUrl: null, url: null, priceType: null, price: null, price2: null, name: null, thirdPartyTag: null, auditId: null, auditStatus: null }
const defaultForm = { good: {productId: null,storeName: null,image: null,price: null,otPrice: null}, goodsId: null, productId: null, coverImgeUrl: null, url: null, priceType: null, price: null, price2: null, name: null, thirdPartyTag: null, auditId: null, auditStatus: null }
export default {
name: 'YxWechatLiveGoods',
components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList,cgood},
mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
data() {
return {
isdisable: false,
syncLoading: false,
grid: {
xl: 8,
@ -171,28 +172,51 @@ export default {
del: ['admin', 'yxWechatLiveGoods:del']
},
rules: {
// coverImgUrl: [
// { required: true, message: '', trigger: 'blur' }
// ],
// url: [
// { required: true, message: '', trigger: 'blur' }
// ],
// priceType: [
// { required: true, message: '', trigger: 'blur' }
// ],
// price: [
// { required: true, message: '', trigger: 'blur' }
// ],
// name: [
// { required: true, message: '', trigger: 'blur' }
// ]
coverImgUrl: [
{ required: true, message: '商品图片不能为空', trigger: 'blur' }
],
url: [
{ required: true, message: '商品小程序路径不能为空', trigger: 'blur' }
],
priceType: [
{ required: true, message: '价格类型不能为空', trigger: 'blur' }
],
price: [
{ required: true, message: '不能为空', trigger: 'blur' }
],
name: [
{ required: true, message: '商品名称不能为空', trigger: 'blur' }
]
},
queryTypeOptions: [
{ key: 'name', display_name: '商品名称' }
]
}
},
watch: {
watch:{
'form.good': {
handler(val,oldVal){
this.form.productId = val.productId
this.form.name = val.storeName
this.form.coverImgeUrl = val.image
this.form.price = val.price
this.form.price2 = val.otPrice
this.form.priceType = '3'
this.disable=true;
},
deep:true//
},
},
computed:{
disable(){
if(this.form.auditStatus=="2"){
return this.isdisabled=true;
}else{
return this.isdisabled=false;
}
}
},
methods: {
sync() {
@ -262,12 +286,8 @@ export default {
this.form.good.productId = form.productId
this.form.good.storeName = form.name
this.form.good.image = form.coverImgeUrl
},
[CRUD.HOOK.beforeSubmit]() {
console.log(this.form)
this.form.productId = this.form.good.productId
this.form.name = this.form.good.storeName
this.form.coverImgeUrl = this.form.good.image
this.form.good.price = form.price
this.form.good.otPrice = form.price2
},
}
}

101
src/views/wechat/live/index.vue

@ -4,7 +4,7 @@
<div class="head-container">
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'-->
<crudOperation :permission="permission">
<el-tooltip slot="right" class="item" effect="dark" content="数据库中表字段变动时使用该功能" placement="top-start">
<el-tooltip slot="right" class="item" effect="dark" content="同步小程序控制台直播间数据" placement="top-start">
<el-button
class="filter-item"
size="mini"
@ -18,57 +18,64 @@
</crudOperation>
<!--表单组件-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="800px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="140px">
<el-form-item label="直播间标题" prop="name">
<el-input v-model="form.name" style="width: 370px;" />
<el-input v-model="form.name" style="width: 370px;" :disabled="isDisabled" />
</el-form-item>
<el-form-item label="背景图" prop="coverImg">
<MaterialList v-model="form.coverImgArr" style="width: 370px" type="image" :num="1" :width="150" :height="150" />
<el-form-item label="直播间背景图" prop="coverImg" >
<MaterialList v-model="form.coverImgArr" style="width: 370px" type="image" :num="1" :width="150" :height="150":disabled="isDisabled" />
</el-form-item>
<el-form-item label="分享图片" prop="shareImg">
<MaterialList v-model="form.shareImgArr" style="width: 370px" type="image" :num="1" :width="150" :height="150" />
<el-form-item label="直播间分享图片" prop="shareImg" >
<MaterialList v-model="form.shareImgArr" style="width: 370px" type="image" :num="1" :width="150" :height="150":disabled="isDisabled" />
</el-form-item>
<el-form-item label="开始时间" prop="startDate">
<el-date-picker v-model="form.startDate" type="datetime" style="width: 370px;" />
<el-form-item label="计划直播开始时间" prop="startDate" >
<el-date-picker v-model="form.startDate" type="datetime" style="width: 370px;" :disabled="isDisabled"/>
<p style="color: #cf0f0f">开播时间需要在当前时间的10分钟后,并且开始时间不能在6个月后</p>
</el-form-item>
<el-form-item label="预计结束时间" prop="endDate">
<el-date-picker v-model="form.endDate" type="datetime" style="width: 370px;" />
<el-form-item label="计划直播结束时间" prop="endDate" >
<el-date-picker v-model="form.endDate" type="datetime" style="width: 370px;" :disabled="isDisabled"/>
<p style="color: #cf0f0f">开播时间和结束时间间隔不得短于30分钟,不得超过24小时</p>
</el-form-item>
<el-form-item label="主播昵称" prop="anchorName">
<el-input v-model="form.anchorName" style="width: 370px;" />
<el-form-item label="主播昵称" prop="anchorName" :disabled="isDisabled">
<el-input v-model="form.anchorName" style="width: 370px;" :disabled="isDisabled"/>
</el-form-item>
<el-form-item label="主播微信号" prop="anchorWechat">
<el-input v-model="form.anchorWechat" style="width: 370px;" />
<el-form-item label="主播微信号" prop="anchorWechat" :disabled="isDisabled">
<el-input v-model="form.anchorWechat" style="width: 370px;" :disabled="isDisabled"/>
<p style="color: #cf0f0f">主播微信号需要实名扫描下面二维码认证</p>
<a :href="'https://image.dayouqiantu.cn/5ca04fa9c08ef.jpg'" style="color: #42b983" target="_blank"><img :src="'https://image.dayouqiantu.cn/5ca04fa9c08ef.jpg'" alt="点击打开" class="el-avatar"></a>
</el-form-item>
<el-form-item label="主播头像" prop="anchorImg">
<MaterialList v-model="form.anchorImgArr" style="width: 370px" type="image" :num="1" :width="150" :height="150" />
<el-form-item label="主播头像" prop="anchorImg" >
<MaterialList v-model="form.anchorImgArr" style="width: 370px" type="image" :num="1" :width="150" :height="150" :disabled="isDisabled"/>
</el-form-item>
<el-form-item label="直播间类型" prop="type">
<el-radio-group v-model="form.type" >
<el-form-item label="选择入库商品" >
<LiveGoods v-model="form.product" @selectGoods="getGoods" > </LiveGoods>
</el-form-item>
<el-form-item label="直播间类型" prop="type" >
<el-radio-group v-model="form.type":disabled="isDisabled" >
<el-radio :label="1" class="radio">推流</el-radio>
<el-radio :label="0">手机直播</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="横屏、竖屏" prop="screenType">
<el-radio-group v-model="form.screenType" >
<el-form-item label="横屏、竖屏" prop="screenType" >
<el-radio-group v-model="form.screenType" :disabled="isDisabled">
<el-radio :label="1" class="radio">横屏</el-radio>
<el-radio :label="0">竖屏</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="是否关闭点赞" prop="closeLike">
<el-radio-group v-model="form.closeLike" >
<el-form-item label="是否关闭点赞" prop="closeLike" >
<el-radio-group v-model="form.closeLike" :disabled="isDisabled">
<el-radio :label="1" class="radio">关闭</el-radio>
<el-radio :label="0">开启</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="是否关闭货架" prop="closeLike">
<el-radio-group v-model="form.closeGoods" >
<el-form-item label="是否关闭货架" prop="closeGoods" >
<el-radio-group v-model="form.closeGoods" :disabled="isDisabled">
<el-radio :label="1" class="radio">关闭</el-radio>
<el-radio :label="0">开启</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="是否关闭评论" prop="closeComment">
<el-radio-group v-model="form.closeComment" >
<el-form-item label="是否关闭评论" prop="closeComment" >
<el-radio-group v-model="form.closeComment" :disabled="isDisabled">
<el-radio :label="1" class="radio">关闭</el-radio>
<el-radio :label="0">开启</el-radio>
</el-radio-group>
@ -76,7 +83,7 @@
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU" :disabled="isDisabled">确认</el-button>
</div>
</el-dialog>
<!--表格渲染-->
@ -141,7 +148,7 @@
</div>
</template>
</el-table-column>
<el-table-column v-if="columns.visible('closeGoods')" prop="closeLike" label="货架" >
<el-table-column v-if="columns.visible('closeGoods')" prop="closeGoods" label="货架" >
<template slot-scope="scope">
<div>
<el-tag v-if="scope.row.closeGoods === 1" :type="''">关闭</el-tag>
@ -149,7 +156,7 @@
</div>
</template>
</el-table-column>
<el-table-column v-if="columns.visible('closeComment')" prop="closeLike" label="评论" >
<el-table-column v-if="columns.visible('closeComment')" prop="closeComment" label="评论" >
<template slot-scope="scope">
<div>
<el-tag v-if="scope.row.closeComment === 1" :type="''">关闭</el-tag>
@ -178,19 +185,26 @@ import crudYxWechatLive from '@/api/yxWechatLive'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from '@/components/material'
import LiveGoods from '@/views/components/livegoods'
import udOperation from '@crud/UD.operation'
// crudpresenter
const defaultCrud = CRUD({ title: '直播房间', url: 'api/yxWechatLive', sort: 'roomId,desc', crudMethod: { ...crudYxWechatLive }})
const defaultForm = { roomid: null, name: null, coverImge: null, startDate: null, endDate : null,shareImge: null, liveStatus: null, coverImgArr: [],shareImgArr: [],anchorImgArr: [],startTime: null, endTime: null, anchorName: null, anchorWechat: null, anchorImge: null, type: null, screenType: null, closeLike: null,closeGoods: null, closeComment: null }
const defaultCrud = CRUD({ optShow: {
add: true,
edit: false,
del: false,
download: true
},title: '直播房间', url: 'api/yxWechatLive', sort: 'roomId,desc', crudMethod: { ...crudYxWechatLive }})
const defaultForm = { product: [],roomid: null,productId: null, name: null, coverImge: null, startDate: null, endDate : null,shareImge: null, liveStatus: null, coverImgArr: [],shareImgArr: [],anchorImgArr: [],startTime: null, endTime: null, anchorName: null, anchorWechat: null, anchorImge: null, type: null, screenType: null, closeLike: null,closeGoods: null, closeComment: null }
export default {
name: 'YxWechatLive',
components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList},
components: { pagination, crudOperation, rrOperation ,MaterialList,udOperation,LiveGoods},
mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
data() {
return {
disabled: false,
syncLoading: false,
permission: {
add: ['admin', 'yxWechatLive:add'],
@ -235,7 +249,23 @@ export default {
},
watch: {
},
computed:{
isDisabled(){
if(this.disabled){
return this.isdisabled=true;
}else{
return this.isdisabled=false;
}
}
},
methods: {
getGoods(p) {
var ids = []
p.forEach((item,index) => {
ids.push(item.id)
})
this.form.productId = ids.join(",")
},
sync() {
this.crud.selections.forEach(val => {
})
@ -264,6 +294,9 @@ export default {
form.coverImgArr = [form.coverImge]
form.shareImgArr = [form.shareImge]
form.anchorImgArr = [form.anchorImge]
form.product = form.product
this.disabled = true;
console.log(form.product)
}
}
}

Loading…
Cancel
Save