123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698 |
- <template>
- <app-layout>
- <view :class="is_service ? 'preventTouchMove' : ' '">
- <view class='title'>基本信息</view>
- <view class='goods-img'>
- <view class='label'>
- <text>商品图片</text>
- <text class="label-info">(最多9张,可拖拽改变顺序)</text>
- </view>
- <view class='goods-list'>
- <movable-area style="height: auto; width: 100%;" class="flex-wrap">
- <view @touchend.stop='touchend' @touchmove.stop='touchm' @longpress.stop='_longtap(item.pic_url,index,$event)' class='goods-item' v-for="(item,index) in img" :key="index">
- <image mode="aspectFill" class='goods-cover move-img' :data-index="index" :src="item.pic_url"></image>
- <image @click.stop='del_img(index)' v-if="!beMove" class='del-btn' src='./../image/delete.png'></image>
- <view v-if="index == 0 && !beMove" class='main-img'>主图</view>
- </view>
- <view v-if="img.length < 9" @click.stop='addImg' class='add-goods-img'>
- <image src='./../image/add-goods.png'></image>
- <view>添加</view>
- </view>
- <movable-view :data-index="beginIndex" :x="x" :y="y" direction="all" :damping="5000" :friction="1" :disabled="disabled">
- <image :hidden='imgHidden' mode="aspectFill" class="goods-cover img-border" :src='img_src'></image>
- </movable-view>
- </movable-area>
- </view>
- </view>
- <view class='goods-info'>
- <view class='info-item goods-name cross-center dir-left-nowrap'>
- <view class="form-label">商品名称</view>
- <view @click="nameBlur" v-if="inputName" :class="form.name.length > 0 ? 'input' : 'input placeholder'">{{form.name ? form.name :'请输入商品名称'}}</view>
- <input :focus="!inputName" @blur="nameBlur" v-else class='input' placeholder-style="color: #cdcdcd" placeholder="请输入商品名称" v-model='form.name'></input>
- </view>
- <view class='info-item cross-center main-between'>
- <view class="form-label">商品分类</view>
- <view @click="chooseCat">
- <view class='cat-info dir-right-nowrap cross-center'>
- <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
- <text v-if="form.cats.length > 0">编辑</text>
- <text style="color: #cdcdcd" v-else>未选择</text>
- </view>
- </view>
- </view>
- <view class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">单位</view>
- <view class='dir-left-nowrap cross-center'>
- <input maxlength="4" placeholder-style="color: #cdcdcd" placeholder="请输入商品单位" v-model='unit' class='input'></input>
- </view>
- </view>
- </view>
- <view class='title'>规格、价格及库存</view>
- <view class='goods-info'>
- <view class='info-item main-between'>
- <view>多规格</view>
- <switch style="transform:scale(0.7)" :checked="set_attr" @change="set_attr = !set_attr"></switch>
- </view>
- <view v-if="set_attr" class='info-item cross-center main-between'>
- <view class="form-label">商品规格</view>
- <view @click="chooseAttr">
- <view class='cat-info dir-right-nowrap cross-center'>
- <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
- <text v-if="attr">已设置</text>
- <text style="color: #cdcdcd" v-else>未设置,点击设置</text>
- </view>
- </view>
- </view>
- <view v-if="!set_attr" class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">规格</view>
- <view class='dir-left-nowrap cross-center price-input'>
- <view class="default-attr">默认规格</view>
- </view>
- </view>
- <view class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">成本价</view>
- <view class='dir-left-nowrap price-input cross-center main-between'>
- <input @change="costChange" placeholder-style="color: #cdcdcd" placeholder="请输入成本价" type='digit' class='input' v-model="form.cost_price"></input>
- <view>元</view>
- </view>
- </view>
- <view class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">原价</view>
- <view class='dir-left-nowrap price-input cross-center main-between'>
- <input @change="originalChange" placeholder-style="color: #cdcdcd" placeholder="请输入原价" type='digit' class='input' v-model="form.original_price"></input>
- <view>元</view>
- </view>
- </view>
- <view class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">售价</view>
- <view class='dir-left-nowrap price-input cross-center main-between'>
- <input @change="priceChange" placeholder-style="color: #cdcdcd" placeholder="请输入售价" type='digit' class='input' v-model="form.price"></input>
- <view>元</view>
- </view>
- </view>
- <view v-if="!set_attr" class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">库存</view>
- <view class='dir-left-nowrap price-input cross-center main-between'>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入库存" type='number' v-model="form.goods_num" class='input unit'></input>
- <view class="unit-width">{{unit}}</view>
- </view>
- </view>
- <view v-if="!set_attr" class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">货号</view>
- <view class='dir-left-nowrap price-input cross-center'>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入货号" type='number' class='input' v-model="form.goods_no"></input>
- </view>
- </view>
- <view v-if="!set_attr" class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">重量</view>
- <view class='dir-left-nowrap cross-center price-input'>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入重量" type='number' v-model='form.goods_weight' class='input'></input>
- <view>g</view>
- </view>
- </view>
- </view>
- <view class='title'>运费、包邮及限购</view>
- <view class='goods-info'>
- <view class='info-item cross-center main-between'>
- <view class="form-label">运费设置</view>
- <view @click="chooseExpress">
- <view class='cat-info dir-right-nowrap cross-center'>
- <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
- <text v-if="bePostage.id > 0">{{bePostage.name}}</text>
- <text v-else>未选择</text>
- </view>
- </view>
- </view>
- <view class='express-setting'>
- <view class='express-input cross-center'>
- <view class="integral">满件包邮</view>
- <view class='dir-left-nowrap cross-center input-item'>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入包邮件数" type='number' v-model='form.pieces' class='input'></input>
- <view>件</view>
- </view>
- </view>
- <view class='express-etc'>如果设置0或空,则不支持满件包邮</view>
- </view>
- <view class='express-setting'>
- <view class='express-input cross-center'>
- <view class="integral">满额包邮</view>
- <view class='dir-left-nowrap cross-center input-item'>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入包邮金额" type='digit' v-model='form.forehead' class='input'></input>
- <view>元</view>
- </view>
- </view>
- <view class='express-etc'>如果设置0或空,则不支持满额包邮</view>
- </view>
- <view class='info-item main-between'>
- <view>限购</view>
- <switch style="transform:scale(0.7)" :checked="confine" @change="confine=!confine"></switch>
- </view>
- <view v-if="confine" class='info-item cross-center dir-left-nowrap'>
- <view class="form-label">限购数量</view>
- <view class='dir-left-nowrap cross-center price-input'>
- <view class='dir-left-nowrap cross-center price-input'>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入限购数量" type='number' v-model='form.confine_count' class='input'></input>
- <view>件</view>
- </view>
- </view>
- </view>
- </view>
- <view class='title'>商品图文描述</view>
- <view class='goods-info'>
- <view class='info-item cross-center main-between'>
- <view class="form-label">商品图文描述</view>
- <view @click="toGoodsDetail">
- <view class='cat-info dir-right-nowrap cross-center'>
- <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
- <text v-if="goods_detail.length > 0">已添加</text>
- <text v-else>未添加</text>
- </view>
- </view>
- </view>
- </view>
- <view class='title'>积分设置</view>
- <view class='goods-info integral-info'>
- <view class='express-setting'>
- <view class='express-input cross-center'>
- <view class="integral">积分赠送</view>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入积分赠送数量或比例" v-model='give_integral' class='input'></input>
- </view>
- <view class='express-etc'>会员购物赠送积分,如果不填或填0,则默认为不赠送,如果带%则为按成交价格的比例计算积分。</view>
- </view>
- <view class='express-setting'>
- <view class='express-input cross-center'>
- <view class="integral">积分抵扣</view>
- <input placeholder-style="color: #cdcdcd" placeholder="请输入积分抵扣数量或比例" v-model='forehead_integral' class='input'></input>
- </view>
- <view class='express-etc'>如果不填或填0,则不支持积分抵扣;如果带%则为按成交价格的比例计算抵扣多少元。</view>
- </view>
- </view>
- <view class='title'>卡券</view>
- <view class='goods-info'>
- <view class='info-item cross-center main-between'>
- <view class="form-label">卡券</view>
- <view @click="chooseCard">
- <view class='cat-info dir-right-nowrap cross-center'>
- <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
- <text v-if="goods_card.length > 0">已选择</text>
- <text v-else>未选择</text>
- </view>
- </view>
- </view>
- </view>
- <view class='title'>服务内容</view>
- <view class='goods-info'>
- <view class='info-item cross-center main-between'>
- <view class="form-label">服务内容</view>
- <view @click="chooseService">
- <view class='cat-info dir-right-nowrap cross-center'>
- <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
- <text v-if="beService.length > 0">已选择</text>
- <text v-else-if="service.length > 0">未选择</text>
- <text v-else>未设置</text>
- </view>
- </view>
- </view>
- </view>
- <view class="main-between form-button">
- <view @click="submit(0)">
- <view class='save'>保存</view>
- </view>
- <view @click="submit(1)">
- <view class='send'>上架</view>
- </view>
- </view>
- <view :class="['dialog', `${iphone_x?'iphone_x':''}`]" v-if="dialog">
- <view class="picker-list">
- <view class="main-between picker-header">
- <view @click="toggle">取消</view>
- <view @click="toggle(1)">确定</view>
- </view>
- <picker-view :value="[set_postage?postageIndex:-1]" class="picker" @change="bindChange">
- <picker-view-column>
- <view v-for="(item,idx) in postage" :key="item.id"
- :class="[`cross-center picker-text`,{
- 'sure-color': newIndex === idx,
- 'cardinal-color': newIndex === idx + 1 || newIndex === idx - 1,
- 'even-color': newIndex === idx + 2 || newIndex === idx - 2,
- }]">{{item.name}}</view>
- </picker-view-column>
- </picker-view>
- </view>
- </view>
- </view>
- <view class='dialog' v-if="is_service">
- <view class='dialog-item'>
- <view class='dialog-title'>服务内容</view>
- <view class="type-list">
- <view v-if="is_service" v-for="(item,index) in service" :key="index" @click='choose(item)' class="dir-left-nowrap type-choose" >
- <image v-if="item.isChoose" class="active-status" src='./../image/active.png'></image>
- <image v-else class="active-status" src='/static/image/icon/form-er.png'></image>
- <view :class="[`${item.isChoose ? 'active':''}`]">{{item.name}}</view>
- </view>
- </view>
- <view class="main-center btn-area">
- <view class="submit-btn" @click='cancelService'>取消</view>
- <view class="line"></view>
- <view class="submit-btn be-submit" @click='submitService'>确认</view>
- </view>
- </view>
- </view>
- <view class='dialog' v-if="modal">
- <view class='dialog-item'>
- <view class='dialog-title'>提示</view>
- <view class="error-info" v-if="set_cat">您暂未设置分类</view>
- <view class="error-info" v-if="set_postage && postage.length == 0">您暂未设置运费模板</view>
- <view class="error-info" v-if="set_service && service.length == 0">您暂未设置服务内容</view>
- <view class="error-info" v-if="set_card && card.length == 0">您暂未设置卡券</view>
- <view class="error-info">请前往商城后台设置</view>
- <view class="main-center btn-area">
- <view class="submit-btn be-submit" @click='close'>确认</view>
- </view>
- </view>
- </view>
- <view class='dialog' v-if="error">
- <view class='dialog-item'>
- <view class='dialog-title'>提示</view>
- <view class="error-info">{{error}}</view>
- <view class="main-center btn-area">
- <view class="submit-btn be-submit" @click='close'>确认</view>
- </view>
- </view>
- </view>
- <view class='dialog' v-if="beSubmit">
- <view class='dialog-item'>
- <view class='dialog-title'>提示</view>
- <view class="submit-info">是否确认要上架此商品</view>
- <view class="main-center btn-area">
- <view class="submit-btn" @click='close'>取消</view>
- <view class="line"></view>
- <view class="submit-btn be-submit" @click='toSubmit'>确认</view>
- </view>
- </view>
- </view>
- </app-layout>
- </template>
- <script>
- import { mapState } from "vuex";
- export default {
- data() {
- return {
- postageIndex: -1,
- height: 0,
- give_integral: 0,
- forehead_integral: 0,
- beSubmit: false,
- inputName: true,
- form: {
- cats: [],
- name: '',
- cost_price: '',
- price: '',
- original_price: ''
- },
- cats: [],
- forehead: -1,
- unit: '件',
- iphone_x: false,
- set_attr: false,
- modal: false,
- error: false,
- set_cat: false,
- set_postage: false,
- set_service: false,
- confine: false,
- is_service: false,
- goods_card: [],
- img: [],
- card: [],
- goods_detail: [],
- beMove: false,
- service: [],
- postage: [],
- bePostage: '',
- beService: [],
- default_service: [],
- newIndex: '0',
- index: '0',
- attr: false,
- have_children: false,
- disabled: true,
- imgHidden: true,
- flag: false,
- x: 0,
- y: 0,
- id: 0,
- first_service: true,
- choose_list: [],
- elements: [],
- img_src: '',
- loading: false,
- dialog: false,
- loading: false
- }
- },
- computed: {
- ...mapState({
- theme: state => state.mallConfig.theme,
- userInfo: state => state.user.info,
- adminImg: state => state.mallConfig.__wxapp_img.app_admin,
- })
- },
- methods: {
- money(val) {
- let num = val.toString(); //先转换成字符串类型
- if (num.indexOf('.') == 0) { //第一位就是 .
- num = '0' + num
- }
- num = num.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
- num = num.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
- num = num.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
- num = num.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
- if (num.indexOf(".") < 0 && num != "") {
- num = parseFloat(num);
- }
- return +num
- },
- costChange(e) {
- this.form.cost_price = this.money(e.detail.value)
- },
- originalChange(e) {
- this.form.original_price = this.money(e.detail.value)
- },
- priceChange(e) {
- this.form.price = this.money(e.detail.value)
- },
- nameBlur() {
- this.inputName = !this.inputName;
- },
- catchTouchMove() {
- return false;
- },
- toSubmit() {
- let that = this;
- if(that.loading) {
- return false
- }
- uni.showLoading({
- title: '提交中...'
- });
- that.loading = true;
- that.beSubmit = false;
- that.$request({
- url: that.$api.app_admin.edit,
- data: {
- form: JSON.stringify(that.form)
- },
- method: 'post'
- }).then(response=>{
- that.loading = false;
- that.$hideLoading();
- uni.hideLoading();
- that.loading = false;
- if(response.code == 0) {
- if(response.code == 0) {
- uni.showToast({
- title: response.msg,
- duration: 1000
- });
- uni.setStorage({
- key: "goods_status",
- data: '保存成功'
- })
- setTimeout(function() {
- uni.navigateBack();
- }, 500)
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.loading = false;
- that.$hideLoading();
- uni.hideLoading();
- });
- },
- submit(status) {
- let pass = false;
- let that = this;
- let form = that.form;
- let cats = [];
- if (that.img.length > 0) {
- form.pic_url = that.img;
- } else {
- that.error = '请上传商品图片';
- return false
- }
- if (!form.name) {
- that.error = '请设置商品名称';
- return false
- }
- if (that.cats.length == 0) {
- that.error = '请设置商品分类';
- return false
- }else {
- for(let i in that.cats) {
- cats.push(that.cats[i].value)
- }
- }
- if (!that.unit) {
- that.error = '请设置商品单位';
- return false
- } else {
- if (!form.unit) {
- form.unit = that.unit
- }
- }
- if (!form.cost_price) {
- that.error = '请设置商品成本价';
- return false
- }
- if (form.cost_price < 0) {
- that.error = '成本价不得小于零';
- return false
- }
- if (!form.original_price) {
- that.error = '请设置商品原价';
- return false
- }
- if (form.original_price < 0) {
- that.error = '商品原价不得小于零';
- return false
- }
- if (!form.price) {
- that.error = '请设置商品售价';
- return false
- }
- if (form.price < 0.01) {
- that.error = '商品售价不得小于零';
- return false
- }
- if(!that.set_attr) {
- form.use_attr = 0;
- form.attr = [];
- if (!form.goods_num) {
- that.error = '商品库存不得为空';
- return false
- } else if (form.goods_num < 0) {
- that.error = '商品库存不得小于零';
- return false
- } else {
- pass = true;
- }
- }else {
- form.use_attr = 1;
- form.goods_num = 0;
- if (!form.attr_groups || form.attr_groups.length == 0) {
- that.error = '请设置商品规格';
- return false
- }else {
- pass = true
- }
- }
- form.cards = that.goods_card;
- form.services = [];
- if (that.beService.length > 0) {
- form.services = that.beService;
- }
- let service_num = 0;
- if(that.beService.length == that.default_service.length) {
- for(let i in that.beService) {
- if(that.beService[i] == that.default_service[i]) {
- service_num++;
- }
- }
- }
- form.is_default_services = 1;
- if(that.beService.length == 0 || service_num != that.beService.length) {
- form.is_default_services = 0;
- }
- form.status = status;
- form.virtual_sales = 0;
- form.cover_pic = '';
- form.sort = 100;
- form.accumulative = 1;
- form.member_price = {};
- form.mchCats = [];
- if (that.goods_detail.length > 0) {
- form.detail = '';
- for(let i in that.goods_detail) {
- if(that.goods_detail[i].type == "img") {
- form.detail += '<p><img src="' + that.goods_detail[i].pic_url + '"/></p>'
- }else if(that.goods_detail[i].type == "line") {
- form.detail += '<p><img src="' + that.adminImg.line + '"/></p>'
- }else if(that.goods_detail[i].type == "text") {
- form.detail += '<p>' + that.goods_detail[i].text + '</p>'
- }
- }
- } else {
- that.error = '请设置图文描述';
- return false
- }
- if (that.forehead_integral) {
- if (that.forehead_integral > 0) {
- form.forehead_integral_type = 1;
- } else {
- form.forehead_integral_type = 2;
- form.forehead_integral = that.forehead_integral.replace('%', '')
- }
- }
- if (that.give_integral) {
- if (that.give_integral > 0) {
- form.give_integral_type = 1;
- form.give_integral = that.give_integral;
- } else {
- form.give_integral_type = 2;
- form.give_integral = that.give_integral.replace('%', '')
- }
- }
- form.freight_id = that.bePostage.id;
- form.freight = that.bePostage;
- form.individual_share = 0;
- form.is_level = 0;
- form.individual_share = 0;
- form.video_url = '';
- if (pass) {
- that.form = form;
- that.form.cats = cats;
- if(that.id > 0) {
- that.form.id = that.id;
- }
- if(status == 0) {
- that.toSubmit();
- }else {
- that.beSubmit = true;
- }
- }
- },
- close() {
- this.error = null;
- this.modal = false;
- this.beSubmit = false;
- },
- inputAttr(index) {
- this.attr[index].attr_list[0].attr_id = (+index + 2).toString();
- },
- _longtap: function (img_src,index,e) {
- let that = this;
- var query = uni.createSelectorQuery();
- var nodesRef = query.selectAll(".move-img");
- nodesRef.fields({
- dataset: true,
- rect: true
- }, (result) => {
- that.elements = result;
- }).exec()
- const detail = e.detail;
- that.img[index].pic_url = '';
- that.x = e.currentTarget.offsetLeft;
- that.y = e.currentTarget.offsetTop;
- that.imgHidden = false;
- that.flag = true;
- that.beMove = true;
- that.img_src = img_src;
- that.beginIndex = index;
- },
- //触摸结束
- touchend: function (e) {
- let that = this;
- if (!that.flag) {
- return;
- }
- const x = e.changedTouches[0].pageX
- const y = e.changedTouches[0].pageY
- const list = that.elements;
- let data = that.img
- const beginIndex = that.beginIndex;
- for (var j = 0; j < list.length; j++) {
- const item = list[j];
- if (x > item.left && x < item.right && y > item.top && y < item.bottom) {
- const endIndex = item.dataset.index;
- //向后移动
- if (beginIndex < endIndex) {
- let tem = data[beginIndex];
- for (let i = beginIndex; i < endIndex; i++) {
- data[i] = data[i + 1]
- }
- data[endIndex] = tem;
- }
- //向前移动
- if (beginIndex > endIndex) {
- let tem = data[beginIndex];
- for (let i = beginIndex; i > endIndex; i--) {
- data[i] = data[i - 1]
- }
- data[endIndex] = tem;
- }
- data[endIndex].pic_url = that.img_src;
- that.img = data;
- }
- }
- if (!that.img[beginIndex].pic_url) {
- that.img[beginIndex].pic_url = that.img_src;
- }
- that.imgHidden = true;
- that.flag = false;
- that.beMove = false;
- that.beginIndex = null;
- },
- //滑动
- touchm: function (e) {
- if (this.flag) {
- const x = e.touches[0].pageX
- const y = e.touches[0].pageY
- this.x = x - 60;
- this.y = y - 129;
- }
- },
- cancelService() {
- let beService = this.beService;
- let service = this.service;
- if (beService.length > 0) {
- service.forEach(function(res, index) {
- res.isChoose = false;
- beService.forEach(function(row) {
- if (row.id == res.id) {
- res.isChoose = true;
- }
- })
- })
- } else {
- service.forEach(function(res, index) {
- res.isChoose = false;
- })
- }
- this.beService = beService;
- this.service = service;
- this.set_service = false;
- this.is_service = false;
- setTimeout(v=>{
- uni.pageScrollTo({
- scrollTop: 45550,
- duration: 0
- });
- },0)
- },
- submitService() {
- let beService = [];
- this.service.forEach(function(row) {
- if (row.isChoose) {
- beService.push(row)
- }
- })
- this.beService = beService;
- this.set_service = false;
- this.is_service = false;
- setTimeout(v=>{
- uni.pageScrollTo({
- scrollTop: 45550,
- duration: 0
- });
- },0)
- },
- choose(item) {
- let that = this;
- that.service.forEach(function(row) {
- if (row.id == item.id) {
- row.isChoose = !row.isChoose;
- that.$forceUpdate();
- }
- })
- },
- toGoodsDetail() {
- uni.navigateTo({
- url: '/pages/app_admin/goods-detail/goods-detail'
- })
- },
- addImg() {
- let that = this;
- let num = 9 - that.img.length;
- uni.chooseImage({
- count: num,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success(res) {
- // tempFilePath可以作为img标签的src属性显示图片
- const tempFilePaths = res.tempFilePaths;
- let img = that.img;
- tempFilePaths.forEach(function (row, index) {
- uni.showLoading({
- title: '上传中...'
- });
- let fileName = '';
- // #ifdef MP-BAIDU
- fileName = row.substr(row.lastIndexOf('/') + 1);
- // #endif
- uni.uploadFile({
- url: that.$api.upload.file,
- filePath: row,
- name: 'file',
- fileType: 'image',
- formData: {
- file: row,
- file_name: fileName
- },
- success(res) {
- // #ifndef MP-BAIDU
- const imgInfo = JSON.parse(res.data);
- // #endif
- // #ifdef MP-BAIDU
- const imgInfo = res.data;
- // #endif
- let para = {
- pic_url: imgInfo.data.url,
- id: imgInfo.data.id
- }
- if (imgInfo.code == 0) {
- img.push(para)
- }
- that.img = img;
- if (index == tempFilePaths.length - 1) {
- uni.hideLoading();
- }
- },
- fail(e) {
- console.log('upload fail:', e);
- if (e && e.errMsg) {
- uni.showModal({
- title: '错误',
- content: e.errMsg,
- showCancel: false,
- });
- }
- }
- })
- })
- }
- })
- },
- del_img(index) {
- this.img.splice(index, 1);
- },
- chooseCat() {
- uni.navigateTo({
- url: '/pages/app_admin/goods-cat/goods-cat'
- })
- },
- chooseAttr() {
- let that = this;
- uni.navigateTo({
- url: '/pages/app_admin/goods-attr/goods-attr'
- })
- uni.setStorage({
- key: "goods_unit",
- data: that.unit
- })
- },
- bindChange(e) {
- this.newIndex = e.detail.value[0]
- },
- toggle(status) {
- this.choose_list = [];
- this.dialog = false;
- this.set_cat = false;
- if (status == 1) {
- if (this.set_postage) {
- this.bePostage = this.postage[this.newIndex]
- }
- }else {
- this.set_postage = false;
- }
- },
- chooseService() {
- let that = this;
- if(that.first_service) {
- that.$request({
- url: that.$api.app_admin.service,
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0) {
- that.service = response.data.list;
- if (response.data.list.length == 0) {
- that.modal = true;
- } else {
- that.is_service = true;
- }
- let beService = [];
- response.data.list.forEach(function (row) {
- row.isChoose = false
- if (row.is_default == 1) {
- beService.push(row);
- row.isChoose = true
- }
- })
- that.set_service = true;
- that.beService = beService;
- that.default_service = beService;
- that.first_service = false;
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- }else {
- if (that.service.length == 0) {
- that.modal = true;
- } else {
- that.is_service = true;
- }
- }
- },
- chooseCard() {
- let that = this;
- that.$request({
- url: that.$api.app_admin.card,
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0) { true;
- that.card = response.data.list;
- if(response.data.list.length == 0) {
- that.set_card = true;
- that.modal = true;
- }else {
- uni.navigateTo({
- url: '/pages/app_admin/goods-card/goods-card'
- })
- }
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- chooseExpress() {
- let that = this;
- that.$request({
- url: that.$api.app_admin.postage,
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0) {
- if (response.data.list.length == 0) {
- that.set_postage = true;
- that.modal = true;
- that.postage = response.data.list;
- } else {
- let arr = [];
- response.data.list.forEach(function (row, index) {
- arr.push(response.data.list[index].id)
- })
- let index = arr.indexOf(that.bePostage.id);
- if(index > -1) {
- that.postageIndex = index;
- that.newIndex = index;
- }else {
- that.bePostage = ''
- }
- that.set_postage = true;
- that.dialog = true;
- that.postage = response.data.list;
- }
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- getService(id) {
- let that = this;
- that.$request({
- url: that.$api.app_admin.service,
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0) {
- that.service = response.data.list;
- for(let i in that.service) {
- that.service[i].isChoose = false;
- }
- if(id > 0) {
- for(let j in that.beService) {
- for(let i in that.service) {
- if(that.service[i].id == that.beService[j].id) {
- that.service[i].isChoose = true;
- that.first_service = false;
- }
- }
- }
- }else {
- console.log(2)
- that.beService = [];
- response.data.list.forEach(function(row) {
- row.isChoose = false
- if (row.is_default == 1) {
- that.beService.push(row);
- row.isChoose = true
- }
- })
- }
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- getPostage(id) {
- let that = this;
- that.$request({
- url: that.$api.app_admin.postage,
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0) {
- that.postage = response.data.list;
- if(id > 0) {
- return
- }else {
- that.bePostage = '';
- response.data.list.forEach(function(row) {
- if (row.status == 1) {
- that.bePostage = row;
- }
- })
- }
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- getCard() {
- let that = this;
- that.$request({
- url: that.$api.app_admin.card,
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0) {
- that.card = response.data.list;
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- getDetail(id) {
- let that = this;
- that.$request({
- url: that.$api.app_admin.goods_edit,
- data: {
- id: id
- }
- }).then(response=>{
- that.$hideLoading();
- that.getService(id);
- that.getPostage(id);
- if(response.code == 0) {
- that.form = response.data.detail;
- that.img = that.form.pic_url;
- that.cats = that.form.cats;
- that.set_attr = that.form.use_attr;
- that.beService = that.form.services;
- that.bePostage = that.form.freight;
- that.goods_card = that.form.cards;
- that.forehead_integral = +that.form.forehead_integral;
- if(that.form.forehead_integral_type == 2) {
- that.forehead_integral = that.form.forehead_integral + '%';
- }
- that.give_integral = +that.form.give_integral;
- if(that.form.give_integral_type == 2) {
- that.give_integral = that.form.give_integral + '%';
- }
- if(that.form.attr_groups.length > 0 && that.form.attr.length > 0) {
- that.attr = true;
- uni.setStorage({
- key: "goods_attr_groups",
- data: that.form.attr_groups
- })
- uni.setStorage({
- key: "goods_attr",
- data: that.form.attr
- })
- }
- let detail = that.form.detail.split(/<\/p>|<br\/>|<img /);
- let good_detail = [];
- let para;
- console.log(detail)
- for(let i in detail) {
- detail[i] = detail[i].replace(/<p>/g, '').replace(/<\/p>/g, '');
- para = {type: ''};
- if(detail[i].indexOf('src') > -1) {
- para.type = 'img'
- para.id = ''
- para.pic_url = detail[i].slice(5, detail[i].length -3)
- }else {
- para.type = 'text'
- para.text = detail[i]
- }
- good_detail[i] = para;
- }
- for(let i in good_detail) {
- if(good_detail[i].text == '') {
- good_detail.splice(i,1);
- }
- }
- that.goods_detail = good_detail;
- uni.setStorage({
- key: "goods_card",
- data: that.form.cards
- })
- uni.setStorage({
- key: "goods_cat",
- data: that.cats
- })
- uni.setStorage({
- key: "goods_detail",
- data: good_detail
- })
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- }
- },
- onLoad(options) {
- let that = this;
- uni.getSystemInfo({
- success: function (res) {
- if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
- that.iphone_x = true;
- }
- }
- })
- uni.getSystemInfo({
- success: function (res) {
- let clientHeight = res.windowHeight;
- let clientWidth = res.windowWidth;
- let ratio = 750 / clientWidth;
- that.height = clientHeight * ratio;
- }
- });
- that.getCard();
- uni.removeStorage({
- key: 'goods_card',
- success(res) {
- that.goods_card = [];
- }
- })
- uni.removeStorage({
- key: 'goods_cat',
- success(res) {
- console.log(res)
- }
- })
- uni.removeStorage({
- key: 'goods_unit',
- success(res) {
- console.log(res)
- }
- })
- uni.removeStorage({
- key: 'goods_attr_groups',
- success(res) {
- console.log(res)
- }
- })
- uni.removeStorage({
- key: 'goods_attr',
- success(res) {
- console.log(res)
- }
- })
- uni.removeStorage({
- key: 'temp_attr',
- success(res) {
- console.log(res)
- }
- })
- uni.removeStorage({
- key: 'temp_attr_info',
- success(res) {
- console.log(res)
- }
- })
- uni.removeStorage({
- key: 'goods_detail',
- success(res) {
- that.goods_detail = [];
- }
- })
- if(options.id > 0) {
- that.$showLoading({
- type: 'global',
- text: '加载中...'
- });
- that.id = options.id;
- setTimeout(v=>{
- uni.setNavigationBarTitle({
- title: '编辑商品',
- });
- that.getDetail(options.id);
- },500)
- }else {
- that.getService();
- that.getPostage();
- }
- },
- onShow() {
- let that = this;
- uni.getStorage({
- key: 'goods_card',
- success(res) {
- that.goods_card = res.data;
- }
- })
- uni.getStorage({
- key: 'goods_cat',
- success(res) {
- that.cats = res.data;
- }
- })
- uni.getStorage({
- key: 'goods_detail',
- success(res) {
- that.goods_detail = res.data;
- }
- })
- uni.getStorage({
- key: 'goods_attr_groups',
- success(res) {
- that.form.attr_groups = res.data;
- that.attr = true;
- }
- })
- uni.getStorage({
- key: 'goods_attr',
- success(res) {
- that.form.attr = res.data;
- }
- })
- uni.removeStorage({
- key: 'temp_attr',
- success(res) {
- console.log(res)
- }
- })
- uni.removeStorage({
- key: 'temp_attr_info',
- success(res) {
- console.log(res)
- }
- })
- }
- }
- </script>
- <style scoped lang="scss">
- .preventTouchMove{
- bottom: 0;
- left: 0;
- width: 100%;
- overflow: hidden;
- position: fixed;
- z-index: 0;
- }
- .title {
- font-size: #{28rpx};
- color: #999;
- margin: #{30rpx} #{24rpx} #{13rpx};
- }
- .goods-img {
- background-color: #fff;
- padding: #{32rpx} #{24rpx};
- }
- .goods-list {
- margin-top: #{8rpx};
- margin-left: #{-24rpx};
- }
- .goods-item {
- position: relative;
- margin-left: #{24rpx};
- margin-top: #{24rpx};
- height: #{218rpx};
- width: #{218rpx};
- }
- .label {
- font-size: #{28rpx};
- color: #999;
- }
- .goods-cover {
- height: #{218rpx};
- width: #{218rpx};
- }
- .del-btn {
- height: #{40rpx};
- width: #{40rpx};
- position: absolute;
- right: #{-8rpx};
- top: #{-16rpx};
- }
- .main-img {
- height: #{40rpx};
- line-height: #{40rpx};
- width: #{218rpx};
- text-align: center;
- font-size: #{24rpx};
- color: #fff;
- background-color: rgba(68, 109, 253, 0.5);
- position: absolute;
- bottom: 0;
- left: 0;
- }
- .add-goods-img {
- background-color: #f4f5f9;
- position: relative;
- margin-left: #{24rpx};
- margin-top: #{24rpx};
- height: #{218rpx};
- width: #{218rpx};
- font-size: #{24rpx};
- color: #999;
- z-index: 10;
- text-align: center;
- }
- .add-goods-img image {
- height: #{40rpx};
- width: #{40rpx};
- margin: #{70rpx} auto #{10rpx};
- }
- .goods-info {
- background-color: #fff;
- padding: 0 #{24rpx};
- .info-item:first-of-type {
- border-top: 0;
- }
- .info-item.goods-name {
- border-top: #{1rpx} solid #e2e2e2;
- }
- }
- .form-label {
- width: #{176rpx};
- }
- .info-item {
- border-top: #{1rpx} solid #e2e2e2;
- height: #{88rpx};
- line-height: #{88rpx};
- font-size: #{28rpx};
- color: #353535;
- }
- view.input {
- height: #{80rpx};
- line-height: #{80rpx};
- white-space: nowrap;
- overflow: auto;
- }
- view.input.placeholder {
- color: #cdcdcd;
- }
- .input {
- width: #{476rpx};
- background-color: #fff;
- padding-left: #{25rpx};
- font-size: #{28rpx};
- }
- .input.unit {
- width: #{396rpx};
- }
- .unit-width {
- width: #{112rpx};
- text-align: right;
- }
- .cat-info {
- width: #{526rpx};
- color: #666;
- }
- .to-more {
- height: #{24rpx};
- width: #{12rpx};
- margin-left: #{10rpx};
- }
- .price-input {
- position: relative;
- color: #666;
- height: #{88rpx};
- .default-attr {
- padding-left: #{25rpx};
- }
- }
- .money {
- position: absolute;
- height: #{88rpx};
- line-height: #{88rpx};
- width: #{20rpx};
- left: 0;
- top: 0;
- }
- .attr-info {
- background-color: #fff;
- padding: 0 #{24rpx};
- margin-top: #{20rpx};
- }
- .attr-input {
- width: #{638rpx};
- }
- .attr-input .input {
- color: #666;
- width: #{412rpx};
- }
- .attr-input .input.unit {
- width: #{330rpx};
- }
- .express-setting {
- height: #{136rpx};
- padding: #{16rpx} 0 #{20rpx};
- border-top: #{1rpx} solid #e2e2e2;
- }
- .express-input {
- position: relative;
- .input-item {
- font-size: #{28rpx};
- color: #353535;
- .input {
- width: #{650rpx};
- }
- }
- }
- .express-input .input {
- width: #{702rpx};
- padding-left: #{216rpx};
- }
- .express-input .integral {
- position: absolute;
- left: 0;
- z-index: 2;
- }
- .express-etc {
- color: #999;
- font-size: #{24rpx};
- margin-top: #{16rpx};
- }
- .form-button {
- width: #{656rpx};
- margin: 0 auto;
- }
- .save {
- height: #{80rpx};
- line-height: #{80rpx};
- text-align: center;
- width: #{300rpx};
- margin: #{80rpx} 0;
- font-size: #{28rpx};
- color: #446dfd;
- border: #{2rpx} solid #446dfd;
- background-color: #FFFFFF;
- border-radius: #{40rpx};
- }
- .send {
- height: #{80rpx};
- line-height: #{80rpx};
- text-align: center;
- width: #{300rpx};
- margin: #{80rpx} #{24rpx};
- font-size: #{28rpx};
- color: #fff;
- background-color: #446dfd;
- border-radius: #{40rpx};
- }
- .dialog {
- position: fixed;
- height: 100%;
- width: 100%;
- bottom: 0;
- left: 0;
- z-index: 10;
- background-color: rgba(0, 0, 0, .3);
- }
- .dialog.iphone_x .picker-list{
- padding-bottom: #{50rpx};
- }
- .picker {
- width: 100%;
- height: #{440rpx};
- color: #999999;
- }
- .dialog.iphone_x .picker{
- height:#{490rpx};
- }
- .picker-list {
- background-color: #fff;
- padding-top: #{20rpx};
- position: fixed;
- bottom: 0;
- left: 0;
- width: 100%;
- }
- .picker-header {
- padding: 0 #{24rpx};
- color: #446dfd;
- font-size: #{32rpx};
- }
- .is_cat {
- padding: #{50rpx} 0 0 #{24rpx};
- color: #666666;
- font-size: #{28rpx};
- border-bottom: #{1rpx} solid #e2e2e2;
- }
- .is_cat text {
- margin-right: #{48rpx};
- display: inline-block;
- max-width: #{130rpx};
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .is_cat text:last-of-type {
- padding-bottom: #{24rpx};
- color: #446dfd;
- border-bottom: #{2rpx} solid #446dfd;
- }
- .type-list {
- max-height: #{400rpx};
- overflow: auto;
- }
- .type-choose {
- padding: 0 #{24rpx} 0 #{72rpx};
- height: #{36rpx};
- line-height: #{36rpx};
- color: #353535;
- font-size: #{32rpx};
- text-align: left;
- margin: #{35rpx} 0 #{50rpx};
- }
- .type-choose .active {
- color: #446dfd;
- }
- .active-status {
- width: #{36rpx};
- height: #{36rpx};
- display: block;
- margin-right: #{24rpx};
- }
- .attr-btn-item {
- padding-left: #{88rpx};
- background-color: #fff;
- }
- .dialog-item {
- padding-top: #{20rpx};
- position: fixed;
- top: 25%;
- left: 0;
- right: 0;
- margin: 0 auto;
- width: #{620rpx};
- border-radius: #{16rpx};
- background-color: #fff;
- }
- .btn-area {
- height: #{88rpx};
- position: relative;
- border-top: #{1rpx} solid #e2e2e2;
- }
- .btn-area .line {
- height: #{32rpx};
- width: #{1rpx};
- background-color: #e2e2e2;
- position: absolute;
- top: #{28rpx};
- left: 0;
- right: 0;
- margin: 0 auto;
- }
- .submit-btn {
- height: #{88rpx};
- line-height: #{88rpx};
- font-size: #{32rpx};
- color: #666;
- width: #{310rpx};
- text-align: center;
- }
- .submit-btn.be-submit {
- color: #446dfd;
- }
- .dialog-title {
- text-align: center;
- margin: #{15rpx} 0 #{50rpx};
- }
- .img-border {
- height: #{250rpx};
- width: #{250rpx};
- margin-top: #{-16rpx};
- margin-left: #{-16rpx};
- }
- .screen {
- height: 100%;
- overflow: hidden;
- }
- .error-info {
- text-align: center;
- margin: #{50rpx};
- }
- .submit-info {
- text-align:center;
- margin-bottom: #{60rpx};
- }
- .picker-text {
- line-height: #{88rpx};
- color: #446dfd;
- font-size: #{32rpx};
- padding-left: #{24rpx};
- }
- .picker-text.sure-color {
- color: #446dfd;
- }
- .picker-text.cardinal-color {
- color: #999999;
- }
- .picker-text.even-color {
- color: #cdcdcd;
- }
- .integral {
- font-size: #{28rpx};
- color: #353535;
- }
- .integral-info .express-setting {
- height: #{164rpx};
- }
- .integral-info .express-setting:first-of-type {
- border-top:0
- }
- .label-info {
- font-size: #{24rpx};
- color: #999999;
- }
- </style>
|