123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- <template>
- <view class="content">
- <view class="box-1">
- <view class="box-left">
- 规格列表
- <text class="imp">*</text>
- :
- </view>
- <view class="list-input" v-if="!choosearrt" @click="chooseopen()">
- 请选择规格
- </view>
- <view class="list-input clamp" v-if="choosearrt" @click="chooseopen()">
- <text>{{choosearrt.rule_name}}</text>
- </view>
- </view>
- <view class="showarrt-box" v-if="arrts.length != 0">
- <view class="showarrt-item flex" :key="index" v-for="(item,index) in arrts">
- <view class="show-name">
- {{item.value}}
- </view>
- <view class="show-info clamp" @click="open(item,index)">
- <text v-for='(ite,ind) in item.detail'>{{ite}} <text
- v-if="(ind+1) != item.detail.length">,</text></text>
- </view>
- </view>
- </view>
- <view class="btn-box flex">
- <view class="addarrt-btn " @click="open()">
- 添加新规格
- </view>
- <view class="shengchen" @click="scarrt()" v-if="arrts.length != 0">
- 立即生成
- </view>
- </view>
- <view class="batch" v-if="header.length != 0 && values.length !=0">
- <view class="batch-title">
- 批量设置
- </view>
- <view class="box-1">
- <view class="box-left">
- 商品规格图片
- <text class="imp">*</text>
- :
- </view>
- <view class="box-image" @click="navCroper(400,400,'guige')">
- <image v-if="guige" :src="guige" mode=""></image>
- <image v-else src="../../../static/img/addP.png" mode=""></image>
- </view>
- </view>
- <view class="box-1">
- <view class="box-left">
- 商品售价
- <text class="imp">*</text>
- :
- </view>
- <input type="digit" placeholder="请填写商品售价" value="" step="0.01" class="list-input" v-model="price" />
- </view>
- <view class="box-1">
- <view class="box-left">
- 商品成本价
- <text class="imp">*</text>
- :
- </view>
- <input type="digit" placeholder="请填写商品成本价" value="" step="0.01" class="list-input" v-model="o_price" />
- </view>
- <view class="box-1">
- <view class="box-left">
- 商品原价
- <text class="imp">*</text>
- :
- </view>
- <input type="digit" placeholder="请填写商品原价" step="0.01" value="" class="list-input" v-model="y_price" />
- </view>
- <view class="box-1">
- <view class="box-left">
- 佣金计算值
- <text class="imp">*</text>
- :
- </view>
- <input type="digit" placeholder="请填写佣金计算值" step="0.01" value="" class="list-input"
- v-model="breakprice" />
- </view>
- <view class="box-1">
- <view class="box-left">
- 库存
- <text class="imp">*</text>
- :
- </view>
- <input type="number" placeholder="请填写库存" value="" class="list-input" v-model="stock" />
- </view>
- <view class="batch-btn" @click="setup()">
- 批量设置
- </view>
- </view>
- <view class="batch" v-for="(item,index) in values" :key="index">
- <view v-for="(itm,ind) in header">
- <view class="box-1" v-if="itm.title != '操作' && itm.title != '图片'">
- <view class="box-left">
- {{itm.title}}
- </view>
- <input type="text" v-if="itm.slot && itm.title == '产品编号'" :placeholder="'请填写'+itm.title" value=""
- class="list-input" v-model="item[itm.slot]" />
- <input type="digit" v-if="itm.slot && itm.title != '产品编号'" :placeholder="'请填写'+itm.title" value=""
- class="list-input" v-model="item[itm.slot]" />
- <input type="text" v-if="itm.key" :placeholder="'请填写'+itm.title" value="" class="list-input"
- disabled="" v-model="item[itm.key]" />
- </view>
- <view class="box-1" v-if="itm.title == '图片'">
- <view class=" box-left">
- {{itm.title}}
- <text class="imp">*</text>
- :
- </view>
- <view class="box-image" @click="navCroper(400,400,index)">
- <image v-if="item[itm.slot]" :src="item[itm.slot]" mode=""></image>
- <image v-else src="../../../static/img/addP.png" mode=""></image>
- </view>
- </view>
- </view>
- <view class="batch-btn" @click="del(index)">
- 删除
- </view>
- </view>
- <uni-popup ref="choose" type="bottom">
- <view class="choose-main">
- <view class="choose-top flex">
- <view class="choose-font" @click="chooseclose()">
- 取消
- </view>
- </view>
- <scroll-view scroll-y="true" style="height: 600rpx;">
- <view class="choose-item flex" v-for="(item,index) in arrtmb" @click="chooseqd(item)"
- :key="item.rule_name">
- <view class="choose-item-left">
- {{item.rule_name}}
- </view>
- </view>
- </scroll-view>
- </view>
- </uni-popup>
- <uni-popup ref="arrt" type="bottom">
- <view class="choose-main">
- <view class="choose-top flex">
- <view class="choose-font" @click="close()">
- 取消
- </view>
- <view class="choose-del" v-if="tebindex|| tebindex===0" @click="dearrt()">
- 删除
- </view>
- <view class="choose-qd" @click="qd()">
- 确定
- </view>
- </view>
- <scroll-view scroll-y="true" style="height: 600rpx;">
- <view class="addarrt-box">
- <view class="box-1">
- <view class="box-left">
- 规格
- <text class="imp">*</text>
- :
- </view>
- <view class="list-input">
- <input v-if="isqd == 1" type="text" placeholder="请修改规格" value="" class="input"
- v-model="arrtname" @blur="jcarrtvalue" />
- <input v-if="isqd ==0" type="text" placeholder="请填写规格" value="" class="list-input"
- v-model="showarrtname" />
- <view class="delarrts" v-if="isqd ==0" @click="addarrtname()">
- 添加
- </view>
- </view>
- </view>
- <view class="box-1" v-for="(item,index) in addarrts">
- <view class="box-left">
- 修改规格值
- <text class="imp">*</text>
- :
- </view>
- <view class="list-input">
- <input type="text" placeholder="请修改规格值" class="input" v-model="addarrts[index]"
- @blur="jcarrtvalue" />
- <view class="delarrts" @click="delarrtvalue(index)">
- 删除
- </view>
- </view>
- </view>
- <view class="box-1" v-if="isqd == 1">
- <view class="box-left">
- 规格值
- <text class="imp">*</text>
- :
- </view>
- <view class="list-input">
- <input type="text" class="" placeholder="请填写规格值" value="" v-model="addarrt" />
- <view class="delarrts" @click="addarrtvalue">
- 添加
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import {
- is_format_attr,
- get_rule
- } from '@/api/upload.js'
- export default {
- props: {
- //分类选项
- baseURL: {
- type: String,
- default: ''
- },
- value: {
- type: Array,
- default: []
- },
- item: {
- type: Array,
- }
- },
- data() {
- return {
- values: this.value,
- items: this.item ? this.item : [],
- header: [], //规格头
- tebindex: '', //第几个规格
- arrts: [], //规格值
- showarrts: {
- value: '',
- detail: []
- }, //显示一条规格的东西
- isqd: 0, //是否添加完成规格0没有1开始修改
- showarrtname: '', //添加的规格
- arrtname: '', //添加的规格
- addarrts: [], //添加的规格值列表
- addarrt: '', //添加的规格值
- guige: '', //单规格图片
- price: '', //单规格售价
- o_price: '', //单规格成本价
- y_price: '', //单规格原价
- breakprice: '', //单规格佣金计算值
- stock: '', //单规格库存
- arrtmb: [], //规格模板
- choosearrt: '', //选择规格模板
- };
- },
- mounted() {
- console.log(this.values);
- if (this.items.length != 0) {
- this.arrts = this.items
- this.scarrt()
- }
- this.getArrtlist()
- },
- methods: {
- getArrtlist() {
- get_rule({}).then(({
- data
- }) => {
- this.arrtmb = data
- console.log(data, 'info');
- })
- },
- chooseopen() {
- this.$refs.choose.open()
- },
- open(opt, ind) {
- console.log(opt, ind, );
- if (opt) {
- this.arrtname = opt.value
- this.addarrts = opt.detail
- }
- if (ind != undefined) {
- this.tebindex = ind;
- console.log(this.tebindex);
- }
- this.$refs.arrt.open()
- },
- chooseclose() {
- this.$refs.choose.close()
- },
- chooseqd(opt) {
- console.log(opt);
- this.arrts = opt.rule_value
- this.choosearrt = opt
- this.chooseclose()
- },
- close() {
- this.isqd = 0
- this.showarrtname = ''
- this.tebindex = ''
- this.arrtname = '';
- this.addarrts = [];
- this.addarrt = '';
- this.$refs.arrt.close()
- },
- setup() {
- const obj = this
- this.values.forEach(e => {
- console.log(obj.guige, obj.price, obj.o_price, obj.y_price, obj.breakprice, obj.stock);
- if (obj.guige) {
- e.pic = obj.guige
- }
- if (obj.price) {
- e.price = obj.price * 1
- }
- if (obj.o_price) {
- e.cost = obj.o_price * 1
- }
- if (obj.y_price) {
- e.ot_price = obj.y_price * 1
- }
- if (obj.breakprice) {
- e.brokerage_origin = obj.breakprice
- }
- if (obj.stock) {
- e.stock = obj.stock
- }
- })
- },
- addarrtname() {
- if (this.showarrtname == '') {
- return this.$api.msg("请填写规则")
- }
- this.isqd = 1
- this.arrtname = this.showarrtname
- this.showarrtname = ''
- },
- succ() {
- console.log(this.items, '111');
- this.$emit('getarrts', this.values, this.items);
- },
- addarrtvalue(e) {
- if (this.addarrt) {
- this.addarrts.push(this.addarrt)
- this.addarrt = ''
- }
- },
- delarrtvalue(ind) {
- console.log(ind, '123456');
- if (this.arrts.length == 1) {
- return this.$api.msg('请设置至少一个规则值')
- }
- this.addarrts.splice(ind, 1)
- },
- dearrt() {
- this.arrts.splice(this.tebindex, 1)
- this.close()
- },
- del(index) {
- if (this.value.length == 1) {
- return this.$api.msg('请设置至少一个规则')
- }
- this.value.splice(index, 1)
- },
- jcarrtvalue(e, type) {
- if (!e.detail.value) {
- return this.$api.msg('规格值不能为空')
- }
- },
- qd() {
- if (this.addarrts.length == 0) {
- this.close();
- return this.$api.msg('规格值不能为空')
- }
- if (typeof(this.tebindex) != 'string') {
- console.log(this.tebindex);
- this.arrts[this.tebindex].value = this.arrtname;
- this.arrts[this.tebindex].detail = this.addarrts;
- } else {
- let data = {
- value: '',
- detail: [],
- attrHidden: '',
- detailValue: ''
- };
- data.value = this.arrtname;
- data.detail = this.addarrts;
- this.arrts.push(data);
- }
- this.close()
- },
- upLoad(path) {
- // #ifdef H5
- console.log(path, 'h5');
- // #endif
- uni.showLoading({
- title: '图片上传中',
- mask: true
- });
- return new Promise((resolve, error) => {
- uni.uploadFile({
- url: this.baseURL + '/api/upload/image', //仅为示例,非真实的接口地址
- filePath: path,
- name: 'file',
- header: {
- "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
- },
- success: (uploadFileRes) => {
- if ("string" === typeof uploadFileRes.data) {
- resolve(JSON.parse(uploadFileRes.data).data)
- } else {
- resolve(uploadFileRes.data.data)
- }
- },
- complete() {
- uni.hideLoading()
- }
- });
- })
- },
- navCroper(w, h, type) {
- let that = this;
- this.onImg().then((url) => {
- uni.navigateTo({
- url: `/pages/set/cropper?width=${w}&height=${h}`,
- events: {
- uploadSuccess(res) {
- that.upLoad(res).then((urldata) => {
- if (type == 'guige') {
- that.guige = urldata.url
- } else {
- that.value[type].pic = urldata.url
- }
- })
- }
- },
- success: function(res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('urlNext', {
- url
- })
- }
- })
- })
- },
- onImg(type) {
- const _this = this
- return new Promise((ok, erro) => {
- // 判断是否需要选择
- uni.showActionSheet({
- itemList: ['拍照', '选择一张照片'],
- success: function(res) {
- _this.chooseImage(res.tapIndex).then((url) => {
- ok(url)
- }).catch((res) => {
- erro(res)
- })
- },
- fail: function(res) {
- erro(res)
- console.log(res.errMsg);
- }
- });
- })
- },
- chooseImage: function(index) {
- const _this = this
- return new Promise((ok, error) => {
- // 从相册/相机选择
- // 如需直接开相机或直接选相册,请只使用一个选项
- const sourceType = index === 0 ? ['camera'] : ['album']
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: sourceType,
- success: function(res) {
- ok(res.tempFilePaths[0])
- },
- fail(e) {
- uni.showModal({
- title: '文件打开错误',
- content: '请设置授权文件存储权限',
- showCancel: false,
- });
- error(e)
- }
- });
- })
- },
- // 生成规格
- scarrt() {
- uni.showLoading({
- title: '生成中'
- })
- is_format_attr({
- attrs: this.arrts
- }).then(({
- data
- }) => {
- uni.hideLoading()
- this.items = data.attr
- this.header = data.header
- if (this.values.length == 0) {
- this.values = data.value
- }
- console.log(data);
- }).catch(err => {
- uni.hideLoading()
- })
- }
- }
- };
- </script>
- <style lang="scss">
- page,
- .content {
- min-height: 100%;
- height: auto;
- }
- .addarrt-box {
- padding: 20rpx;
- .btn {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 200rpx;
- height: 54rpx;
- background: #000000;
- border-radius: 38rpx;
- font-size: 34rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #ffffff;
- margin: 40rpx auto 20rpx;
- }
- }
- .box-1 {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 100%;
- padding-top: 20rpx;
- background: #ffffff;
- .box-left {
- padding-left: 2rpx;
- width: 30%;
- text-align: left;
- color: #000000;
- .imp {
- color: #e63931;
- }
- }
- input {
- height: 66rpx;
- line-height: 66rpx;
- // height: 88rpx;
- }
- .list-input {
- color: #9598a3;
- height: 66rpx;
- padding-left: 24rpx;
- font-size: 28rpx;
- display: flex;
- justify-content: flex-end;
- align-items: center;
- width: 75%;
- flex: 1;
- text-align: right;
- padding-right: 24rpx;
- .input {
- color: #9598a3;
- width: 100%;
- .input-placeholder {
- height: 70rpx;
- color: #959595;
- }
- }
- .delarrts {
- margin-left: 20rpx;
- flex-shrink: 0;
- line-height: 1;
- padding: 10rpx 20rpx;
- background: #ffffff;
- border-radius: 10rpx;
- font-size: 24rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #fd3b39;
- border: 1px solid #fd3b39;
- }
- }
- .box-image {
- height: 66rpx;
- width: 66rpx;
- image {
- width: 100%;
- height: 100%;
- }
- }
- }
- .showarrt-box {
- background: #ffffff;
- .showarrt-item {
- margin-top: 20rpx;
- height: 66rpx;
- .show-name {
- padding-left: 2rpx;
- width: 50%;
- text-align: left;
- color: #000000;
- }
- .show-info {
- width: 50%;
- font-size: 28rpx;
- color: #959595;
- text-align: right;
- padding-right: 24rpx;
- }
- }
- }
- .btn-box {
- background: #ffffff;
- padding: 20rpx 0;
- .addarrt-btn {
- color: #256fe7;
- }
- .shengchen {
- padding-left: 24rpx;
- background: #ffffff;
- padding: 20rpx 0;
- color: #e63931;
- }
- }
- .choose-main {
- background: #ffffff;
- }
- .choose-top {
- padding: 20rpx 40rpx 20rpx;
- font-size: 32rpx;
- .choose-font {
- color: #d4c7c2;
- }
- .choose-del {
- color: #256fe7;
- }
- .choose-qd {
- color: #e63931;
- }
- }
- .batch {
- border: 1px solid #000000;
- border-radius: 10rpx;
- margin-top: 20rpx;
- padding: 20rpx;
- background: #ffffff;
- .batch-title {
- font-size: 30rpx;
- text-align: center;
- }
- .batch-btn {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 400rpx;
- height: 76rpx;
- background: #000000;
- border-radius: 38rpx;
- font-size: 34rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #ffffff;
- margin: 40rpx auto 20rpx;
- }
- }
- .choose-main {
- background: #ffffff;
- }
- .choose-top {
- padding: 20rpx 40rpx 20rpx;
- font-size: 32rpx;
- .choose-font {
- color: #d4c7c2;
- }
- .choose-qd {
- color: #e63931;
- }
- }
- .choose-item {
- padding: 20rpx;
- .choose-item-left {
- font-size: 28rpx;
- }
- .current {
- color: #d4c7c2;
- }
- .choose-item-right {
- width: 40rpx;
- height: 40rpx;
- image {
- width: 100%;
- height: 100%;
- }
- }
- }
- </style>
|