|
@@ -0,0 +1,456 @@
|
|
|
+<template>
|
|
|
+ <div class="add-order-wrapper" v-if="product !== ''">
|
|
|
+ <h-header :title="title"></h-header>
|
|
|
+ <div class="row">
|
|
|
+ <img :src="product.pics[0].url" alt="">
|
|
|
+ <div class="extra-wrapper">
|
|
|
+ <div v-if="product.extra.length > 0" v-for="(extra, index) in product.extra" @click="selectExtra(extra,index)" :class="{'active':active.index === index}" class="extra">
|
|
|
+ {{extra.type}}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <!-- options -->
|
|
|
+ <div class="option-wrapper">
|
|
|
+ <!-- 选择数量 -->
|
|
|
+ <div class="cell border-top-1px">
|
|
|
+ <div class="title">
|
|
|
+ 选择数量
|
|
|
+ </div>
|
|
|
+ <div class="content one">
|
|
|
+ <cube-button @click="cut" :inline="true" :outline="true">-</cube-button>
|
|
|
+ <cube-input class="border-top-1px border-bottom-1px" type="number" @blur="blur" v-model="num"></cube-input>
|
|
|
+ <cube-button @click="add" :inline="true" :outline="true">+</cube-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <!-- 服务时间 -->
|
|
|
+ <div class="cell border-top-1px">
|
|
|
+
|
|
|
+ <div class="title">
|
|
|
+ 服务时间
|
|
|
+ </div>
|
|
|
+ <div class="content" @click="showDatePicker">
|
|
|
+ {{time.text}}<i class="cubeic-arrow"></i>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <!-- 服务地址 -->
|
|
|
+ <div class="cell border-top-1px">
|
|
|
+ <div class="title">
|
|
|
+ 选择地址
|
|
|
+ </div>
|
|
|
+ <div class="content two" @click="selectAddress">
|
|
|
+ <div class="address-wrapper">
|
|
|
+ <div class="address" v-if="address !==''">
|
|
|
+ <p><span>{{order.name}}</span><span>{{address.mobile}}</span></p>
|
|
|
+ <p><span>{{address.address.city}}</span><span>{{address.address.area}}</span><span>{{address.address.detail}}</span></p>
|
|
|
+ </div>
|
|
|
+ <span v-else>请选择服务地址</span>
|
|
|
+ <i class="cubeic-arrow"></i>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <!-- 备注 -->
|
|
|
+ <div class="cell border-top-1px">
|
|
|
+ <div class="title">
|
|
|
+ 备注:
|
|
|
+ </div>
|
|
|
+ <div class="content">
|
|
|
+ <cube-input placeholder="可填写附加内容" v-model="remarks"></cube-input>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <!-- 服务协议 -->
|
|
|
+ <!-- <div class="cell border-top-1px">-->
|
|
|
+ <!-- <div class="title">-->
|
|
|
+ <!-- 协议:-->
|
|
|
+ <!-- </div>-->
|
|
|
+ <!-- <div class="content">-->
|
|
|
+
|
|
|
+ <!-- </div>-->
|
|
|
+ <!-- </div>-->
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="btn-wrapper border-top-1px">
|
|
|
+ <div class="order-amount">
|
|
|
+ 费用总计:<span>{{price}}</span>
|
|
|
+ </div>
|
|
|
+ <cube-button :primary="true" @click="addOrder">立即下单</cube-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+ import http from 'api';
|
|
|
+ import ApiSetting from 'lib/baseUrl';
|
|
|
+
|
|
|
+ export default {
|
|
|
+ name: 'addOrder',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ title: '',
|
|
|
+ product: '',
|
|
|
+ active: {
|
|
|
+ index: -1,
|
|
|
+ extra: ''
|
|
|
+ },
|
|
|
+ order: {},
|
|
|
+ time: {
|
|
|
+ text: '',
|
|
|
+ other: {
|
|
|
+ date: '',
|
|
|
+ selectedVal: '',
|
|
|
+ selectedText: '',
|
|
|
+ }
|
|
|
+ },
|
|
|
+ address: '',
|
|
|
+ num: 0,
|
|
|
+ remarks: '',
|
|
|
+ price: 0
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ if (JSON.stringify(this.$store.state.product) === '{}') {
|
|
|
+ this.$router.go(-2);
|
|
|
+ } else {
|
|
|
+ this.product = this.$store.state.product;
|
|
|
+ this.title = this.product.name;
|
|
|
+ this.init();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ active: {
|
|
|
+ // eslint-disable-next-line
|
|
|
+ handler: function (val, old) {
|
|
|
+ this.price = this.num * window.Number.parseInt(this.active.extra.price);
|
|
|
+ this.order.active = this.active;
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ },
|
|
|
+ // eslint-disable-next-line
|
|
|
+ num: function (val, old) {
|
|
|
+ if (val < 0) {
|
|
|
+ this.num = 0;
|
|
|
+ }
|
|
|
+ this.order.num = val;
|
|
|
+ if (this.active.extra !== '') {
|
|
|
+ this.price = this.num * window.Number.parseInt(this.active.extra.price);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ time: {
|
|
|
+ // eslint-disable-next-line
|
|
|
+ handler: function (val, old) {
|
|
|
+ if (val !== '') {
|
|
|
+ this.order.time = val;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ },
|
|
|
+ // eslint-disable-next-line
|
|
|
+ remarks: function (val, old) {
|
|
|
+ this.order.remarks = val;
|
|
|
+ },
|
|
|
+ order: {
|
|
|
+ // eslint-disable-next-line
|
|
|
+ handler: function (val, oldVal) {
|
|
|
+ this.$store.state.order = this.order;
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ selectExtra(extra, index) {
|
|
|
+ this.active.index = index;
|
|
|
+ this.active.extra = extra;
|
|
|
+ },
|
|
|
+ selectAddress() {
|
|
|
+ this.$router.push({ name: 'address' });
|
|
|
+ },
|
|
|
+ // 页面跳转之后数据绑定
|
|
|
+ init() {
|
|
|
+ this.order = this.$store.state.order;
|
|
|
+ if (JSON.stringify(this.order) !== '{}') {
|
|
|
+ // active
|
|
|
+ if (this.order.active !== undefined) {
|
|
|
+ this.active = this.order.active;
|
|
|
+ }
|
|
|
+ // num
|
|
|
+ if (this.order.num !== undefined) {
|
|
|
+ this.num = this.order.num;
|
|
|
+ }
|
|
|
+ // time
|
|
|
+ this.time = this.order.time;
|
|
|
+ // address
|
|
|
+ if (this.order.address !== undefined) {
|
|
|
+ this.address = this.order.address;
|
|
|
+ }
|
|
|
+ // remarks
|
|
|
+ this.remarks = this.order.remarks;
|
|
|
+ }
|
|
|
+ // 放置初始化最底层
|
|
|
+ if (this.time.text === '') {
|
|
|
+ this.time.text = '请选择上门服务时间';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ add() {
|
|
|
+ this.num += 1;
|
|
|
+ },
|
|
|
+ cut() {
|
|
|
+ this.num -= 1;
|
|
|
+ },
|
|
|
+ blur() {
|
|
|
+ console.log(this.num);
|
|
|
+ if (this.num < 0 || this.num === '') {
|
|
|
+ this.num = 0;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 立即下单
|
|
|
+ addOrder() {
|
|
|
+ if (this.orderTest()) {
|
|
|
+ // 检测用户地址是否在服务范围内
|
|
|
+ http(ApiSetting.checkAddress, {
|
|
|
+ user_id: this.$store.state.userInfo.id,
|
|
|
+ address_id: this.order.address.address_id
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ this.$store.state.order.station = res.station;
|
|
|
+ const state = this.$store.state;
|
|
|
+ console.log(state.order);
|
|
|
+ console.log(state.userInfo);
|
|
|
+ console.log(state.product);
|
|
|
+ const json = {
|
|
|
+ balance: state.userInfo.balance,
|
|
|
+ products: JSON.stringify({
|
|
|
+ product_id: state.product.id,
|
|
|
+ count: state.order.num
|
|
|
+ }),
|
|
|
+ memo: state.order.remarks !== undefined ? state.order.remarks : '',
|
|
|
+ precedence: '0',
|
|
|
+ booking_time: `${state.order.time.other.selectedVal[0]}-${state.order.time.other.selectedVal[1]}-${state.order.time.other.selectedVal[2]} ${state.order.time.other.selectedVal[3] === 9 ? '09' : state.order.time.other.selectedVal[3]}:00`,
|
|
|
+ address_id: state.order.address.address_id,
|
|
|
+ station: state.order.station,
|
|
|
+ type: state.product.type,
|
|
|
+ counts: state.order.num,
|
|
|
+ extra: `[${JSON.stringify(state.order.active.extra)}]`,
|
|
|
+ order_channel: 'wx_pub',
|
|
|
+ user_id: ''
|
|
|
+ };
|
|
|
+ console.log(json);
|
|
|
+ });
|
|
|
+ /* {
|
|
|
+ balance: state.userInfo.balance,
|
|
|
+ products: JSON.stringify({
|
|
|
+ product_id:state.product.id.
|
|
|
+ count: state.order.num
|
|
|
+ }),
|
|
|
+ memo: this.order.remarks!==undefined?this.order.remarks:'',
|
|
|
+ precedence: '0',
|
|
|
+ booking_time: this.bookingDate + ' ' + this.bookingTime + ':00',
|
|
|
+ address_id: this.order.address.address_id,
|
|
|
+ coupons: JSON.stringify(coupons),
|
|
|
+ station: this.stationID,
|
|
|
+ type: this.productType,
|
|
|
+ counts: this.productCount,
|
|
|
+ extra: extraJson,
|
|
|
+ tech_id: this.beautician.id,
|
|
|
+ user_id: userID,
|
|
|
+ order_channel: channel
|
|
|
+ } */
|
|
|
+ this.$store.dispatch('addOrder');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 选择时间
|
|
|
+ showDatePicker() {
|
|
|
+ // 当前日期加2天
|
|
|
+ const minD = new Date();
|
|
|
+ // eslint-disable-next-line
|
|
|
+ minD.setTime(minD.getTime() + 24 * 2 * 60 * 60 * 1000);
|
|
|
+ const maxD = new Date();
|
|
|
+ // eslint-disable-next-line
|
|
|
+ maxD.setTime(maxD.getTime() + 24 * 32 * 60 * 60 * 1000);
|
|
|
+ if (!this.datePicker) {
|
|
|
+ this.datePicker = this.$createDatePicker({
|
|
|
+ title: '服务时间',
|
|
|
+ min: new Date(minD.getFullYear(), minD.getMonth(), minD.getDate()),
|
|
|
+ max: new Date(maxD.getFullYear(), maxD.getMonth(), maxD.getDate()),
|
|
|
+ value: new Date(),
|
|
|
+ format: {
|
|
|
+ year: 'YYYY年',
|
|
|
+ month: 'MM月',
|
|
|
+ date: 'D日',
|
|
|
+ hour: 'h点',
|
|
|
+ minute: 'mm分'
|
|
|
+ },
|
|
|
+ columnCount: 4,
|
|
|
+ onSelect: this.selectHandle,
|
|
|
+ onCancel: this.cancelHandle
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.datePicker.show();
|
|
|
+ },
|
|
|
+ // eslint-disable-next-line
|
|
|
+ selectHandle(date, selectedVal, selectedText) {
|
|
|
+ console.log(selectedVal[3]);
|
|
|
+ if (selectedVal[3] < 9 || selectedVal[3] > 18) {
|
|
|
+ this.$createDialog({
|
|
|
+ type: 'alert',
|
|
|
+ title: '抱歉',
|
|
|
+ content: '我们的服务时间为早上9点到晚上7点,其他时间段暂不提供服务!',
|
|
|
+ time: 2500
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.time.text = `${selectedText[0]}${selectedText[1]}${selectedText[2]}${selectedText[3]}`;
|
|
|
+ this.time.other.date = date;
|
|
|
+ this.time.other.selectedVal = selectedVal;
|
|
|
+ this.time.other.selectedText = selectedText;
|
|
|
+ },
|
|
|
+ cancelHandle() {
|
|
|
+ this.$createToast({
|
|
|
+ type: 'correct',
|
|
|
+ txt: '取消时间选择',
|
|
|
+ time: 1000
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+ },
|
|
|
+ // 订单检测
|
|
|
+ orderTest() {
|
|
|
+ // 判断服务是否选择
|
|
|
+ if (this.product.extra.length > 0 && this.active.index < 0) {
|
|
|
+ this.$createDialog({
|
|
|
+ type: 'alert',
|
|
|
+ title: '抱歉',
|
|
|
+ content: '你还没有选择服务类型!',
|
|
|
+ time: 2500
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 商品数量不为0
|
|
|
+ if (this.num === 0) {
|
|
|
+ this.$createDialog({
|
|
|
+ type: 'alert',
|
|
|
+ title: '抱歉',
|
|
|
+ content: '你还没有选择服务数量!',
|
|
|
+ time: 2500
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 时间必选
|
|
|
+ if (this.time.text === '请选择上门服务时间') {
|
|
|
+ this.$createDialog({
|
|
|
+ type: 'alert',
|
|
|
+ title: '抱歉',
|
|
|
+ content: '请选择上门服务时间!',
|
|
|
+ time: 2500
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 地址不为空
|
|
|
+ if (this.address === '') {
|
|
|
+ this.$createDialog({
|
|
|
+ type: 'alert',
|
|
|
+ title: '抱歉',
|
|
|
+ content: '您还没有选择地址',
|
|
|
+ time: 2500
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+</script>
|
|
|
+<style lang="stylus">
|
|
|
+ .add-order-wrapper
|
|
|
+ height: 60vh
|
|
|
+ .row
|
|
|
+ height calc(100vh - 94px)
|
|
|
+ overflow scroll
|
|
|
+ .extra-wrapper
|
|
|
+ display grid
|
|
|
+ padding: 10px 20px
|
|
|
+ grid-template-columns repeat(2, 1fr)
|
|
|
+ .extra
|
|
|
+ flex 1
|
|
|
+ padding: 8px
|
|
|
+ font-size otherSize
|
|
|
+ transition-duration: 300ms;
|
|
|
+ color #929292
|
|
|
+ margin: 5px 20px
|
|
|
+ border: 1px solid #000;
|
|
|
+ &.active
|
|
|
+ background-color black
|
|
|
+ color #fff
|
|
|
+ .option-wrapper
|
|
|
+ .cell
|
|
|
+ font-size h3
|
|
|
+ display flex
|
|
|
+ padding 15px 25px
|
|
|
+ i.cubeic-arrow
|
|
|
+ .title
|
|
|
+ flex 0 0 80px
|
|
|
+ text-align left
|
|
|
+ .content
|
|
|
+ flex 1
|
|
|
+ text-align right
|
|
|
+ &.one
|
|
|
+ display flex
|
|
|
+ justify-content flex-end
|
|
|
+ .cube-input
|
|
|
+ height h3
|
|
|
+ width: h1
|
|
|
+ input
|
|
|
+ text-align center
|
|
|
+ padding: 0
|
|
|
+ button
|
|
|
+ padding 0 5px
|
|
|
+ height: h3
|
|
|
+ width: h3
|
|
|
+ &.two
|
|
|
+ display flex
|
|
|
+ justify-content flex-end
|
|
|
+ i.cubeic-arrow
|
|
|
+ line-height 1
|
|
|
+ flex 0 0 20px
|
|
|
+ .address-wrapper
|
|
|
+ flex 1
|
|
|
+ display flex
|
|
|
+ justify-content flex-end
|
|
|
+ .address
|
|
|
+ flex 1
|
|
|
+ p
|
|
|
+ font-size inputTitle
|
|
|
+ span
|
|
|
+ margin-right: 5px
|
|
|
+ &:nth-child(2)
|
|
|
+ padding-top: 5px
|
|
|
+ font-size inputSize
|
|
|
+ span:nth-child(3)
|
|
|
+ display inline-block
|
|
|
+ width 80px
|
|
|
+ text-align left
|
|
|
+ vertical-align bottom
|
|
|
+ overflow: hidden;
|
|
|
+ white-space: nowrap;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ i.cubeic-arrow
|
|
|
+ flex 0 0 20px
|
|
|
+ img
|
|
|
+ display block
|
|
|
+ width: 100%
|
|
|
+ .btn-wrapper
|
|
|
+ position fixed
|
|
|
+ display flex
|
|
|
+ bottom: 0
|
|
|
+ right: 0
|
|
|
+ left: 0
|
|
|
+ .order-amount
|
|
|
+ flex 1
|
|
|
+ line-height 20px
|
|
|
+ text-align left
|
|
|
+ padding: 15px
|
|
|
+ span
|
|
|
+ color red
|
|
|
+ button
|
|
|
+ flex 0 0 150px
|
|
|
+</style>
|