FinishStep.vue 9.44 KB
<template>
  <view class="step">
    <MessageBox
      ref="formRef"
      @cancel="cancel"
      @confirm="submit"
      :cancelBtnText="`${step == 1? '取消' : '上一步'}`"
      :confirmBtnText="`${step == 1? '下一步' : '完成接待'}`"
      :title="`${step == 1? '客户信息完善' : '结果反馈'}`"
      :popupW="820"
      :maxHeight="820"
      :isAutoClose="false"
    >
      <view name="content">
        <template v-if="step == 1">
          <template v-if="!check(true)">
            <view
              class="error-tip"
              v-if="errorTip"
            >以下信息不能为空,请完善信息后保存</view>
            <view
              class="pop-tips"
              v-else
            >检测到“交车通知书”中未填写客户档案,请填写后再完成接待。</view>
          </template>
          <view class="form">
            <template v-for="(i, index) in formObject">
              <view
                class="form-item"
                :key="index"
              >
                <view class="label">{{ i.label }}</view>
                <view :class="['value', { error: showError(i.key) }]">
                  <template v-if="i.type == 'input'">
                    <input
                      :type="i.inputType"
                      :maxlength="i.maxlength"
                      v-model="formData[i.key]"
                      class="input"
                      :placeholder="i.placeholder"
                      placeholder-class="placeholder"
                    />
                  </template>
                  <template v-else>
                    <view
                      :class="['select',  `${formData[i.key]? '' : 'placeholder'}`]"
                      @click="showPopup(i.popKey)"
                    >
                      {{ formData[i.key] || i.placeholder }}
                      <uni-icons
                        class="arrow"
                        type="down"
                        :size="16"
                      ></uni-icons>
                    </view>
                  </template>
                </view>
              </view>
            </template>
          </view>
        </template>
        <template v-else>
          <view class="pop-tips">请完善本次接待结果</view>
          <view class="choose-box">
            <template v-for="(i,index) in resultList">
              <view
                :class="['choose-item', `${i.status == receptionStatus ? i.status == 1 ? 'success' : 'error' : ''}`]"
                :key="index"
                @click="chooseResult(i.status)"
              >
                <view :class="['sprite-icon' , `icon-face-${i.status == receptionStatus ? `${i.icon}-active` : i.icon }`]"></view>
                {{ i.text}}
              </view>
            </template>
          </view>
        </template>
      </view>
    </MessageBox>
    <car-brands
      ref="carBrandListVisible"
      @select="handleSelect($event,'carBrandListVisible')"
    />
    <employee
      ref="employeeBoxVisible"
      @select="handleSelect($event,'employeeBoxVisible')"
    />
    <uni-popup
      ref="successRef"
      type="message"
    >
      <uni-popup-message
        type="success"
        message="保存成功"
        :duration="1500"
      ></uni-popup-message>
    </uni-popup>
  </view>
</template>

<script type='text/ecmascript-6'>
import Employee from '@/components/Employee.vue'
import CarBrands from '@/components/CarBrands.vue'
import { mapMutations } from "vuex";
const phoneRex = /^[1]([3-9])[0-9]{9}$/;
export default {
  components: { Employee, CarBrands },
  name: 'FinishStep',
  props: {
  },
  data () {
    return {
      step: 1,
      formObject: [
        {
          label: "车主姓名",
          key: "customerName",
          type: "input",
          inputType: "text",
          maxlength: 50,
          placeholder: '请输入姓名'
        },
        {
          label: "车主电话",
          key: "phoneNumber",
          type: "input",
          inputType: "tel",
          maxlength: 11,
          placeholder: '请输入电话'
        },
        {
          label: "车型",
          key: "carModel",
          type: "select",
          popKey: "carBrandListVisible",
          placeholder: '请选择车型'
        },
        {
          label: "销售姓名",
          key: "staffName",
          type: "select",
          popKey: "employeeBoxVisible",
          placeholder: '请选择销售'
        },
      ],
      formData: {
        customerName: "",
        carModel: "",
        phoneNumber: "",
        salesUuid: "",
        staffName: "",
      },
      resultList: [
        {
          icon: 'success',
          text: '结果完美,成交了',
          status: 1

        },
        {
          icon: 'error',
          text: '仍需努力,战败了',
          status: 0
        }
      ],
      errorTip: false,
      receptionStatus: -1,
    }
  },
  computed: {
    watchStatus () {
      return this.$store.state.user.historyStatus
    },
  },
  watch: {
    watchStatus: {
      immediate: true,
      handler (newval) {
        this.receptionStatus = -1
        this.errorTip = false
        this.$refs?.formRef?.close()
      }
    },
  },
  mounted () {

  },
  methods: {
    ...mapMutations("audio", ["setReceptionStatus"]),
    showError (key) {
      let flag = !this.formData[key]
      if (key == 'phoneNumber' && this.formData[key]) flag = !phoneRex.test(this.formData[key])
      return this.errorTip && flag
    },
    showPopup (e) {
      this.$refs[e].open();
    },
    // 取消
    cancel () {
      if (this.step == 1) this.close()
      else this.step = 1
    },
    close () {
      this.errorTip = false
      this.receptionStatus = -1
      this.$refs.formRef.close()
    },
    check (all = false) {
      let flag = true
      try {
        Object.keys(this.formData).map(key => {
          if (!this.formData[key]) throw false
          if (!all && key == 'phoneNumber' && this.formData[key] && !phoneRex.test(this.formData[key])) throw false
        })
      } catch (error) {
        flag = error
      }
      return flag
    },
    // 保存
    submit () {
      if (this.step == 1) {
        this.errorTip = true;
        if (this.check()) this.step = 2
      } else {
        let { receptionStatus } = this
        if (receptionStatus == -1) return uni.showToast({
          title: '请完善本次接待结果',
          icon: 'none'
        })
        this.$refs.successRef.open();
        this.setReceptionStatus(receptionStatus);
        this.$emit('submit', receptionStatus)
      }

    },
    handleSelect (item, popkey) {
      this.$refs[popkey].close();
      if (popkey == "employeeBoxVisible") {
        this.formData.salesUuid = item.uuid;
        this.formData.staffName = item.staffName;
      } else {
        this.$refs.carBrandListVisible.close();
        this.formData.carModel = item.name;
      }
      this.$store.dispatch("setCustomerInfo", this.formData);
    },
    open () {
      this.$store.dispatch('getCustomerInfo').then((customerInfo) => {
        this.errorTip = false
        this.receptionStatus = -1
        this.formData = customerInfo
        let step = Object.values(customerInfo).every((value) => !!value) ? 2 : 1
        if (step == 2 && !this.check()) {
          this.errorTip = true
          step = 1
        }
        this.step = step
        this.$refs.formRef.open()
      })
    },
    chooseResult (val) {
      this.receptionStatus = val
    }
  }
}
</script>

<style scoped lang='scss'>
.pop-tips {
  background: rgba(44, 102, 247, 0.1);
  color: #2c66f7;
  font-size: 28rpx;
  padding: 24rpx 80rpx 24rpx;
  margin-top: 30rpx;
  text-align: center;
}
.error-tip {
  font-size: 28rpx;
  padding: 32rpx 60rpx 24rpx;
  margin-top: 30rpx;
  text-align: center;
  background-color: rgb(254, 237, 234);
  color: #f45c3d;
}
.form {
  display: flex;
  flex-wrap: wrap;
  gap: 24rpx 0;
  padding-top: 30rpx;
  &-item {
    // flex: 50%;
    display: flex;
    align-items: center;
    color: #6c6c70;
    font-size: 30rpx;
    box-sizing: border-box;
    margin: 0 auto;
    .label {
      position: relative;
      margin-left: auto;
      flex-shrink: 0;
      width: 124rpx;
      &::before {
        content: "*";
        color: #ff0000;
        position: absolute;
        left: -20rpx;
        top: 50%;
        transform: translate(0, -50%);
      }
    }
    .value {
      width: 520rpx;
      height: 80rpx;
      border: 2rpx solid #e8e8ea;
      background: #ffffff;
      margin-left: 32rpx;
      box-sizing: border-box;
      padding: 0 40rpx;
      border-radius: 8rpx;
      &.error {
        border: 2rpx solid #f24724;
        border-radius: 8rpx;
      }
      .input,
      .select {
        width: 100%;
        height: 100%;
        border: none !important;
        outline: none;
        padding: 0 !important;
      }
      .select {
        display: flex;
        align-items: center;
        .arrow {
          margin-left: auto;
        }
      }
      /deep/ .placeholder {
        font-size: 30rpx;
        color: #c9c9c9;
      }
    }
  }
}
.choose-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  .choose-item {
    width: 100%;
    height: 128rpx;
    border: 2rpx solid #e8e8e8;
    border-radius: 16rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 24rpx;
    .sprite-icon {
      margin-right: 16rpx;
    }
  }
  .success {
    background: #14cc681a;
    border-color: #14cc681a;
  }
  .error {
    background: #f247241a;
    border-color: #f247241a;
  }
}
</style>