shop_uniapp/bundle/pages/procurement_qrcode/procurement_qrcode.vue

802 lines
19 KiB
Vue

<template>
<view class="produrment_qrcode">
<view class="produrment-tabs">
<u-tabs :list="tabsList" :is-scroll="false" :current="currentTab" :bold="true" height="100"
font-size="30rpx" active-color="#333333" inactive-color="#666666" :bar-style="styleTabsBarStyle"
@change="changeTab" />
</view>
<view v-if="currentValue == 0">
<view class="qrcode-block">
<view class="qrcode m-t-20">
<block v-if="imgSrc">
<view v-if="imgSrc">
<image :src="imgSrc" @tap="previewImage(imgSrc)"></image>
<view @tap="previewImage(imgSrc)">点击可预览二维码</view>
</view>
</block>
<block v-else>
<view>
暂无二维码
</view>
</block>
</view>
<view class="flex row-center" v-if="imgSrc">
<view class="see-shop m-r-40" @click="toCart">
我的商品
</view>
<view class="see-shop m-l-40" @click="toQrcodeCart">
二维码商品
</view>
</view>
<view v-if="imgSrc" class="submit-btn">
<button class="btn-style" @click="saveQrcode()">保存二维码</button>
</view>
</view>
</view>
<view v-if="currentValue == 1">
<view class="price-block">
<view class="price-block-produrment row-center">
<view class="price-block-produrment-info">
<u-radio-group v-model="typeRadioValue">
<u-radio
@change="choseType"
:name="0"
active-color="#fb2d2d"
>
集采价
</u-radio>
<u-radio
@change="choseType"
:name="1"
active-color="#fb2d2d"
>
代发价
</u-radio>
<u-radio
v-if="wholesale_state == 2"
@change="choseType"
:name="2"
active-color="#fb2d2d"
>
批发价
</u-radio>
</u-radio-group>
</view>
</view>
<view v-if="typeCurrent == 0">
<view class="price-block-produrment row-between">
<view class="price-block-produrment-info">
<view class="ml-24">集采价</view>
<view class="active" @click="show_produrment_text=true">
<text>{{produrment_text}}</text><u-icon name="arrow-down" size="20"></u-icon>
</view>
</view>
<view class="price-block-produrment-input mr-24">
<input v-model="formData.set_pro" class="uni-input" focus placeholder="10" />
<view>{{pro_str}}</view>
</view>
</view>
<view class="price-block-model">
<view class="price-block-model-list">
<view class="ml-24">方式</view>
<view>
<u-radio-group v-model="produrmentRadioValue">
<u-radio
@change="produrmentRadioChange"
v-for="(item, index) in produrment_way_model_list" :key="index"
:name="item.value"
:disabled="item.disabled"
active-color="#fb2d2d"
>
{{item.name}}
</u-radio>
</u-radio-group>
</view>
</view>
</view>
</view>
<view v-if="typeCurrent == 1">
<view class="price-block-produrment row-between">
<view class="price-block-produrment-info">
<view class="ml-24">代发价</view>
<view class="active" @click="show_agent_text=true">
<text>{{agent_text}}</text><u-icon name="arrow-down" size="20"></u-icon>
</view>
</view>
<view class="price-block-produrment-input mr-24">
<input v-model="formData.set_issued" class="uni-input" placeholder="10" focus/>
<view>{{issued_str}}</view>
</view>
</view>
<view class="price-block-model">
<view class="price-block-model-list">
<view class="ml-24">方式</view>
<view>
<u-radio-group v-model="agentRadioValue">
<u-radio
@change="agentRadioChange"
v-for="(item, index) in agent_way_model_list" :key="index"
:name="item.value"
:disabled="item.disabeld"
active-color="#fb2d2d"
>
{{item.name}}
</u-radio>
</u-radio-group>
</view>
</view>
</view>
</view>
<view v-if="typeCurrent == 2 && wholesale_state == 2">
<view class="price-block-produrment row-between">
<view class="price-block-produrment-info">
<view class="ml-24">批发价</view>
<view class="active" @click="show_wholesale_text=true">
<text>{{wholesale_text}}</text><u-icon name="arrow-down" size="20"></u-icon>
</view>
</view>
<view class="price-block-produrment-input mr-24">
<input v-model="formData.set_wholesale" class="uni-input" focus placeholder="10" />
<view>{{wholesale_str}}</view>
</view>
</view>
<view class="price-block-model">
<view class="price-block-model-list">
<view class="ml-24">方式</view>
<view>
<u-radio-group v-model="wholesaleRadioValue">
<u-radio
@change="wholesaleRadioChange"
v-for="(item, index) in wholesale_way_model_list" :key="index"
:name="item.value"
:disabled="item.disabled"
active-color="#fb2d2d"
>
{{item.name}}
</u-radio>
</u-radio-group>
</view>
</view>
</view>
</view>
<view class="price-block">
<scroll-view scroll-x="true" scroll-with-animation="true">
<view class="list-group">
<view v-for="(item, index) in levelOneList" :key="index" @tap="chooseTwoMenu(index, item.id)" :class="levelOneCurrent == index ? 'active' : ''">
{{item.name}}
</view>
</view>
</scroll-view>
<view style="padding: 0 20rpx;">
<view v-if="levelTwoList != ''" style="padding: 20rpx 0;">
<u-checkbox-group>
<u-checkbox
@change="checkboxChange"
v-model="item.checked"
v-for="(item, index) in levelTwoList" :key="index"
:name="item.id"
active-color="#fb2d2d"
>{{item.name}}</u-checkbox>
</u-checkbox-group>
</view>
<view v-if="levelTwoList == ''">
<view class="no-menu">暂无商品分类</view>
</view>
</view>
</view>
</view>
<view class="submit-btn">
<button :disabled="btnStatus" class="btn-style" @click="savePrice()">保存</button>
</view>
<u-action-sheet @click="chooseProdurmentText" :list="produrmentList" v-model="show_produrment_text"></u-action-sheet>
<u-action-sheet @click="chooseAgentText" :list="agentList" v-model="show_agent_text"></u-action-sheet>
<u-action-sheet @click="chooseWholesaleText" :list="wholesaleList" v-model="show_wholesale_text"></u-action-sheet>
</view>
</view>
</template>
<script>
import {baseURL} from '@/config/app';
import {getLevelOneList, getListByLevelOne} from '@/api/store';
import {getProcurement, getWeiXinQrCode, weiXinQrCodeAdd, procurementPriceAdd} from '@/api/procurement'
export default {
data() {
return {
currentTab: 0, // Tabs当前位置
typeRadioValue: 0,
produrmentRadioValue: '',
produrment_way_model_list: [
{
name: '加',
value: 3,
disabled: false
},
// {
// name: '减',
// value: 4,
// disabled: false
// },
],
produrment_way_model_list_disabled: true,
agentRadioValue: '',
agent_way_model_list: [
{
name: '加',
value: 3,
disabled: false
},
// {
// name: '减',
// value: 4,
// disabled: false
// },
],
agent_way_model_list_disabeld: false,
wholesaleRadioValue: '',
wholesale_way_model_list: [
{
name: '加',
value: 3,
disabled: false
},
// {
// name: '减',
// value: 4,
// disabled: false
// },
],
wholesale_way_model_list_disabeld: false,
formData: {
set_pro: '',
set_pro_type: 0,
set_issued: '',
set_issued_type:0,
set_wholesale: '',
set_wholesale_type:0,
goods_onetype:0,
goods_twotype: []
},
action: baseURL + '/api/file/formimage',
// Tabs 列表
tabsList: [{
name: '二维码',
value: 0,
}, {
name: '价格',
value: 1,
}],
imgSrc: '',
// Tabs滑块样式
styleTabsBarStyle: {
bottom: '12rpx',
width: '50rpx',
height: '6rpx',
background: 'green',
borderRadius: '50px',
backgroundImage: 'linear-gradient(to right, \#F79C0C, \#FF2C3C)'
},
produrmentList: [{
text: '无',
value: 0,
},{
text: '递增',
value: 1,
},
// {
// text: '递减',
// value: 2,
// },
],
agentList: [{
text: '无',
value: 0,
},{
text: '递增',
value: 1,
},
// {
// text: '递减',
// value: 2,
// },
],
wholesaleList: [{
text: '无',
value: 0,
},{
text: '递增',
value: 1,
},
// {
// text: '递减',
// value: 2,
// },
],
produrment_text:'无',
show_produrment_text: false,
agent_text:'无',
show_agent_text: false,
wholesale_text:'无',
show_wholesale_text: false,
checkboxList: [
{
name: '采集价',
value:1,
checked: false,
},
{
name: '代发价',
value:2,
checked: false,
}
],
btnStatus: false,
pro_str: '%',
issued_str: '%',
wholesale_str: '%',
levelOneList:[],
levelOneCurrent: 0,
levelTwoList:[],
chooseMenu:[],
p_id: 0,
set: 0,
typeCurrent: 0,
wholesale_state: 0
}
},
onLoad() {
this.getData()
},
methods: {
choseType(e) {
this.typeCurrent = e;
let goods_onetype = this.formData.goods_onetype;
let goods_twotype = this.formData.goods_twotype;
this.formData = {
goods_onetype: goods_onetype,
goods_twotype: goods_twotype,
set_pro: '',
set_pro_type: 0,
set_issued: '',
set_issued_type: 0,
set_wholesale: '',
set_wholesale_type: 0,
}
this.produrmentRadioValue = "";
this.agentRadioValue = "";
this.wholesaleRadioValue = "";
this.pro_str = '%';
this.issued_str = '%';
this.wholesale_str = '%';
this.produrment_text = this.produrmentList[0].text;
this.agent_text = this.agentList[0].text;
this.wholesale_text = this.wholesaleList[0].text;
},
async getData() {
let result = await getWeiXinQrCode()
if(result.code == 1) {
this.imgSrc = result.data.set_image;
this.p_id = result.data.p_id;
this.set = result.data.set;
}
let levelOneData = await getLevelOneList();
if (levelOneData.code == 1) {
this.levelOneList = levelOneData.data;
this.formData.goods_onetype = this.levelOneList[0].id;
await this.getTwoList(this.levelOneList[0].id);
}
let pro = await getProcurement()
if (pro.code == 1) {
this.wholesale_state = pro.data.content.wholesale_state;
}
},
async getTwoList(id) {
let levelTwoData = await getListByLevelOne({id});
if (levelTwoData.code == 1) {
this.levelTwoList = levelTwoData.data;
}
},
produrmentRadioChange(e) {
this.produrment_text = this.produrmentList[0].text;
this.formData.set_pro_type = e;
this.pro_str = '¥';
},
agentRadioChange(e) {
this.agent_text = this.agentList[0].text;
this.formData.set_issued_type = e;
this.issued_str = '¥';
},
wholesaleRadioChange(e) {
this.wholesale_text = this.wholesaleList[0].text;
this.formData.set_wholesale_type = e;
this.wholesale_str = '¥';
},
// 图片预览
previewImage(url) {
uni.previewImage({
urls: [url]
});
},
// 集采价选择
chooseProdurmentText(index){
this.produrment_text = this.produrmentList[index].text;
this.formData.set_pro_type = this.produrmentList[index].value;
this.produrmentRadioValue = "";
this.pro_str = '%';
},
// 代发价选择
chooseAgentText(index){
this.agent_text = this.agentList[index].text;
this.formData.set_issued_type = this.agentList[index].value;
this.agentRadioValue = "";
this.issued_str = '%';
},
chooseWholesaleText(index) {
this.wholesale_text = this.wholesaleList[index].text;
this.formData.set_wholesale_type = this.wholesaleList[index].value;
this.wholesaleRadioValue = "";
this.wholesale_str = '%';
},
// 获取价格显示内容
getPriceChoose(e) {
this.formData.price_display_way = e;
},
//选中复选框
checkboxChange(e) {
if (e.value == true) {
this.chooseMenu.push(e.name)
} else {
this.chooseMenu.forEach((v, i) => {
if (v == e.name) {
this.chooseMenu.splice(i, 1)
}
})
}
this.formData.goods_twotype = this.chooseMenu;
},
// 获取对应二级菜单
chooseTwoMenu(index, id) {
this.formData.goods_onetype = id;
this.levelOneCurrent = index;
this.levelTwoList = [];
this.chooseMenu = [];
this.getTwoList(id);
},
// 保存二维码图片
saveQrcode() {
// #ifndef H5
uni.showLoading({title: '正在下载……'});
uni.downloadFile({
url: this.imgSrc,
success: (res) => {
if (res.statusCode === 200) {
//隐藏加载框
uni.hideLoading();
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function(res) {
uni.showToast({
icon: 'none',
mask: true,
title: '文件已保存',
duration: 3000
});
},
fail: function() {
console.log('保存失败');
}
});
}
},
fail: function() {
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载'
});
}
})
// #endif
// #ifdef H5
this.$toast({
title: '请长按图片保存'
})
// #endif
},
changeTab(index) {
this.currentTab = index;
},
async savePrice() {
if (this.formData.set_pro == '' && this.formData.set_issued == '' && this.formData.set_wholesale == '') {
this.$toast({
title: '需要填写当前所选中的价格'
})
return false;
}
if (this.formData.set_pro && !this.$u.test.amount(this.formData.set_pro)) {
this.$toast({
title: '采集价格类型输入错误'
})
return false;
}
if (this.formData.set_pro && this.formData.set_pro_type == 0) {
this.$toast({
title: '采集价格方式未选择'
})
return false;
}
if (this.formData.set_issued && !this.$u.test.amount(this.formData.set_issued)) {
this.$toast({
title: '代发价类型输入错误'
})
return false;
}
if (this.formData.set_issued && this.formData.set_issued_type == 0) {
this.$toast({
title: '代发价方式未选择'
})
return false;
}
if (this.formData.set_wholesale && !this.$u.test.amount(this.formData.set_wholesale)) {
this.$toast({
title: '批发价类型输入错误'
})
return false;
}
if (this.formData.set_wholesale && this.formData.set_wholesale_type == 0) {
this.$toast({
title: '批发价方式未选择'
})
return false;
}
if (this.formData.goods_onetype == 0 || this.chooseMenu == '') {
this.$toast({
title: '商品分类未选择'
})
return false;
}
this.formData.goods_twotype = this.chooseMenu.toString()
this.btnStatus = true
const {
data,
code,
msg
} = await procurementPriceAdd(this.formData)
if(code == 1) {
this.$toast({
title: msg
})
this.btnStatus = false
}
console.log(data)
let params = {
'url': 'pages/goods_cate/goods_cate',
'set_id': data.set_id,
'p_id': data.p_id
}
let result = await weiXinQrCodeAdd(params)
if(result.code == 1) {
this.$toast({
title: '二维码已生成'
})
this.imgSrc = result.data.url;
this.currentTab = 0;
this.set = data.set_id;
this.p_id = data.p_id;
} else {
this.$toast({
title: '二维码生成错误,请重试'
})
}
},
toCart() {
uni.reLaunch({
url: `/pages/goods_cate/goods_cate?p_id=${this.p_id}`
})
},
toQrcodeCart() {
uni.reLaunch({
url: `/pages/goods_cate/goods_cate?p_id=${this.p_id}&set=${this.set}`
})
}
},
computed: {
currentValue(val) {
const {currentTab, tabsList} = this
return tabsList[currentTab] ? tabsList[currentTab].value : ''
}
}
}
</script>
<style scoped lang="scss">
.ml-24 {
margin-left: 24rpx;
}
.mr-24 {
margin-right: 24rpx;
}
.produrment_qrcode {
padding: 20rpx 30rpx;
.produrment-tabs {
border-radius: 20rpx;
overflow: hidden;
}
.qrcode {
margin-top: 40rpx;
padding: 40rpx 36rpx 40rpx 0;
border-radius: 20rpx;
background-color: #ffffff;
text-align: center;
image {
width: 400rpx;
height: 400rpx;
}
view {
margin-top: 12rpx;
color: #a9a9a9;
font-size: 24rpx;
}
}
.see-shop {
text-align: center;
margin-top: 48rpx;
color: #a9a9a9;
font-size: 28rpx;
text-decoration: underline;
}
.price-block{
margin-top: 40rpx;
background-color: #fff;
border-radius: 20rpx;
.price-block-produrment{
display: flex;
padding: 20rpx;
.price-block-produrment-info{
display: flex;
align-items: center;
}
.active {
color: rgb(255, 44, 60);
font-weight: bold;
margin: 0 12rpx;
width: 80rpx;;
}
.price-block-produrment-input {
margin-left: 20rpx;
display: flex;
justify-content: space-between;
}
}
.price-block-model {
.price-block-model-list {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20rpx;
view:first-child {
font-weight: bold;
margin-right: 10rpx;
}
}
.shop-list {
display: grid;
grid-template-column:25% 25% 25% 25%;
}
}
.produrment-line{
padding-top: 20rpx;
display: block;
height: 8rpx;
border-bottom: 1px solid #eee;
width: calc(100% - 40rpx);
margin: 0 auto;
}
.list-group {
display: inline-block;
white-space: nowrap;
margin: 20rpx 20rpx 32rpx 20rpx;
view {
display: inline-flex;
justify-content: center;
align-items: center;
background-color: #e0e0e0;
width: 200rpx;
height: 52rpx;
color: #fff;
margin-right: 10px;
border-radius: 8rpx;
}
view:last-child {
margin-right: 0;
}
.active {
background-color: #d2c3c3;
}
}
.no-menu {
text-align: center;
font-weight: bold;
font-size: 28rpx;
color: #a9a9a9;
padding-bottom: 20rpx;
}
}
.submit-btn {
margin-top: 40rpx;
width: 100%;
.btn-style {
width: 100%;
border: none;
border-radius: 999rpx;
background: #fb2d2d;
color: #fdf8f4;
display: flex;
justify-content: center;
align-items: center;
}
.disabled-btn-style {
background: #cccccc;
}
.all {
color: #000;
background: transparent;
}
}
}
</style>