Skip to content
spces.ts 3.17 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component} from '@angular/core';
import {NavParams, ViewController} from "ionic-angular";
wangqinghua's avatar
wangqinghua committed
import {ServeService} from "../../pages/serve-pages/serve.service";
wangqinghua's avatar
wangqinghua committed
import {CommonService} from "../../provide/common.service";
wangqinghua's avatar
wangqinghua committed

@Component({
    selector: 'spces',
    templateUrl: 'spces.html'
})
export class SpcesComponent {

    goods;
wangqinghua's avatar
wangqinghua committed
    goodsId;
wangqinghua's avatar
wangqinghua committed
    choose = {
        amount: <any>'1',
        brand: '',
        officeId: '',
wangqinghua's avatar
wangqinghua committed
        id: '',
wangqinghua's avatar
wangqinghua committed
        model: '',
        specs1: '',
        specs2: '',
        specs3: '',
        specs4: '',
        specs5: '',
    };

wangqinghua's avatar
wangqinghua committed
    goodsDetail;

wangqinghua's avatar
wangqinghua committed
    constructor(private viewCtrl: ViewController, private params: NavParams,
wangqinghua's avatar
wangqinghua committed
                private serveSer: ServeService, private commonSer: CommonService) {
wangqinghua's avatar
wangqinghua committed
        this.goodsId = this.params.get('goodsId');
wangqinghua's avatar
wangqinghua committed
        this.goodsDetail = this.params.get('data');
        if (this.goodsDetail) {
            this.choose.amount = this.goodsDetail.amount;
            this.choose.specs1 = this.goodsDetail.specs1;
            this.choose.specs2 = this.goodsDetail.specs2;
            this.choose.specs3 = this.goodsDetail.specs3;
            this.choose.specs4 = this.goodsDetail.specs4;
            this.choose.specs5 = this.goodsDetail.specs5;
wangqinghua's avatar
wangqinghua committed
        }
        this.serveSer.supplyDetail(this.goodsId).subscribe(
            (res) => {
                this.goods = res;
            }
        )
wangqinghua's avatar
wangqinghua committed
    }

    close() {
        this.viewCtrl.dismiss();
    }

    stop(e) {
        e.stopPropagation();
    }

    //增加
    add() {
        this.choose.amount++;
    }

    //减少
    reduce() {
        if (this.choose.amount > 1) {
            this.choose.amount--;
        }
    }

    //提交
    submit() {
        this.choose.brand = this.goods.brand;
        this.choose.officeId = this.goods.id;
wangqinghua's avatar
wangqinghua committed
        if (this.goodsDetail) this.choose.id = this.goods.id;  //购物车编辑
wangqinghua's avatar
wangqinghua committed
        this.choose.model = this.goods.model;
wangqinghua's avatar
wangqinghua committed
        console.log(this.choose);
wangqinghua's avatar
wangqinghua committed
        if (this.goods.specs1List && this.goods.specs1List.length > 0 && !this.choose.specs1) {
wangqinghua's avatar
wangqinghua committed
            this.commonSer.toast('请选择规格!');
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        if (this.goods.specs2List && this.goods.specs2List.length > 0 && !this.choose.specs2) {
wangqinghua's avatar
wangqinghua committed
            this.commonSer.toast('请选择规格!');
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        if (this.goods.specs3List && this.goods.specs3List.length > 0 && !this.choose.specs3) {
wangqinghua's avatar
wangqinghua committed
            this.commonSer.toast('请选择规格!');
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        if (this.goods.specs4List && this.goods.specs4List.length > 0 && !this.choose.specs4) {
wangqinghua's avatar
wangqinghua committed
            this.commonSer.toast('请选择规格!');
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        if (this.goods.specs5List && this.goods.specs5List.length > 0 && !this.choose.specs5) {
wangqinghua's avatar
wangqinghua committed
            this.commonSer.toast('请选择规格!');
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        this.viewCtrl.dismiss(this.choose);
    }

    getSpecs(index, item) {
        if (index == 1) this.choose.specs1 = item;
        if (index == 2) this.choose.specs2 = item;
        if (index == 3) this.choose.specs3 = item;
        if (index == 4) this.choose.specs4 = item;
        if (index == 5) this.choose.specs5 = item;
    }
}