|
@@ -0,0 +1,472 @@
|
|
|
+<template>
|
|
|
+ <div class="order-schema-form-container">
|
|
|
+ <SchemaFormRenderer
|
|
|
+ ref="schemaForm"
|
|
|
+ :schema="schema"
|
|
|
+ :state="value"
|
|
|
+ @input="onInput"
|
|
|
+ :rules="rules"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import SchemaFormRenderer from '@/components/common/form-schema-renderer.vue'
|
|
|
+import { createSchema } from './schema'
|
|
|
+import { mapState, mapMutations } from 'vuex'
|
|
|
+import { schemaKeyMap } from '@/views/create-order/data'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'SchemaForm',
|
|
|
+ components: {
|
|
|
+ SchemaFormRenderer
|
|
|
+ },
|
|
|
+ props: {
|
|
|
+ productType: {
|
|
|
+ type: String,
|
|
|
+ default: 'cjdy'
|
|
|
+ },
|
|
|
+ productInfo: {
|
|
|
+ type: Object,
|
|
|
+ default() {
|
|
|
+ return {}
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 产品卡片的索引
|
|
|
+ index: {
|
|
|
+ type: [String, Number],
|
|
|
+ default: '0'
|
|
|
+ },
|
|
|
+ value: {
|
|
|
+ type: Object,
|
|
|
+ default() {
|
|
|
+ return {}
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ schema: [
|
|
|
+ // {
|
|
|
+ // label: '约定支付方式',
|
|
|
+ // key: 'payWay',
|
|
|
+ // className: 'pay-way-form-item',
|
|
|
+ // component: {}, // component和slot二选一,component优先级高
|
|
|
+ // slot: 'slotName',
|
|
|
+ // required: false,
|
|
|
+ // props: {},
|
|
|
+ // hooks: {},
|
|
|
+ // }
|
|
|
+ ],
|
|
|
+ rules: {},
|
|
|
+ selectedRelatedOrder: {},
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState({
|
|
|
+ schemaKey: state => state.order.schemaKey,
|
|
|
+ pageForm: state => state.order.pageForm,
|
|
|
+ productInfoList: state => state.order.orderInfo.productInfoList,
|
|
|
+ }),
|
|
|
+ thisProductInfoListItem() {
|
|
|
+ return this.productInfoList[this.index]
|
|
|
+ }
|
|
|
+ // ...mapGetters(),
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ productType: {
|
|
|
+ immediate: true,
|
|
|
+ handler(n) {
|
|
|
+ this.getOrderProductInfo(n)
|
|
|
+ this.beforeGetUserPower()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ schemaKey() {
|
|
|
+ this.getOrderProductInfo(this.productType)
|
|
|
+ this.beforeGetUserPower()
|
|
|
+ setTimeout(() => {
|
|
|
+ this.$refs.schemaForm.clearValidate()
|
|
|
+ }, 0)
|
|
|
+ },
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapMutations('order', [
|
|
|
+ 'refreshOrderProductItemCard',
|
|
|
+ 'removeOrderProductItem',
|
|
|
+ ]),
|
|
|
+ async validate() {
|
|
|
+ return this.$refs.schemaForm.validate()
|
|
|
+ },
|
|
|
+ onInput(e) {
|
|
|
+ this.$emit('input', e)
|
|
|
+ this.afterInput() // 用于动态修改用户限制选中项
|
|
|
+ },
|
|
|
+ onInitSchema() {
|
|
|
+ this.$emit('initd')
|
|
|
+ },
|
|
|
+ refreshValue(obj = {}) {
|
|
|
+ const r = Object.assign({}, this.value, obj)
|
|
|
+ this.onInput(r)
|
|
|
+ },
|
|
|
+ getOrderProductInfo(type) {
|
|
|
+ // rules和schema可以根据productType、productInfo、form生成
|
|
|
+ const { schemaList, value, rules } = createSchema({
|
|
|
+ type: type || this.productType,
|
|
|
+ info: this.productInfo,
|
|
|
+ state: this.value,
|
|
|
+ index: this.index,
|
|
|
+ })
|
|
|
+ this.schema = schemaList
|
|
|
+ this.rules = rules
|
|
|
+ this.onInput(value)
|
|
|
+ this.onInitSchema()
|
|
|
+ },
|
|
|
+ async beforeGetUserPower(ent = false) {
|
|
|
+ // 判断购买主体是企业还是个人
|
|
|
+ const { buySubject, accountTel, companyName } = this.pageForm
|
|
|
+ if (buySubject === 1) {
|
|
|
+ // 个人
|
|
|
+ if (accountTel) {
|
|
|
+ await this.getUserService()
|
|
|
+ }
|
|
|
+ } else if (buySubject === 2 && ent) {
|
|
|
+ if (accountTel && companyName) {
|
|
|
+ this.getUserService()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.afterInput()
|
|
|
+ },
|
|
|
+ async getUserService() {
|
|
|
+ const payload = {
|
|
|
+ phone: this.pageForm.accountTel,
|
|
|
+ entName: this.pageForm.companyName,
|
|
|
+ buySubject: this.pageForm.buySubject + '',
|
|
|
+ productType: this.productType,
|
|
|
+ }
|
|
|
+ if (!payload.productType) return
|
|
|
+ const r = await this.$store.dispatch('order/getUserService', payload)
|
|
|
+ this.refreshOrderProductItemCard({
|
|
|
+ key: 'productUserService',
|
|
|
+ index: this.index,
|
|
|
+ data: r,
|
|
|
+ })
|
|
|
+ if (r.willEffect) {
|
|
|
+ this.$alert('已存在未生效订单', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ callback: action => {
|
|
|
+ if (action === 'confirm') {
|
|
|
+ this.removeOrderProductItem(this.index)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return r
|
|
|
+ },
|
|
|
+ getSchemaItemWithKey(key) {
|
|
|
+ return this.schema.find(item => item.key === key)
|
|
|
+ },
|
|
|
+ // 处理并分发各个产品卡片操作的限制
|
|
|
+ afterInput() {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ // this.changeSchemaCommon()
|
|
|
+ if (this.productType === 'cjdy') {
|
|
|
+ this.groupCjdySchema()
|
|
|
+ } else if (this.productInfo === 'dhy') {
|
|
|
+ this.changeDhySchema()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log(this.thisProductInfoListItem, this.schema)
|
|
|
+ },
|
|
|
+ // 工具:动态修改选中可用的类型
|
|
|
+ utilChangeAvailablePayment() {
|
|
|
+ const ma = this.getSchemaItemWithKey(schemaKeyMap.payment)
|
|
|
+ const options = ma.props.options
|
|
|
+ // 获取当前
|
|
|
+ const paymentValue = this.value[schemaKeyMap.payment]
|
|
|
+ let changed = false
|
|
|
+
|
|
|
+ const target = options.find(item => item.value === paymentValue)
|
|
|
+ if (target && !target.disabled) {
|
|
|
+ // do something
|
|
|
+ } else {
|
|
|
+ // 被禁用或者,不存在都需要修改选中
|
|
|
+ const enableArr = options.filter(r => !r.disabled)
|
|
|
+ if (enableArr.length > 0) {
|
|
|
+ const v = enableArr[0].value
|
|
|
+ this.refreshValue({ [schemaKeyMap.payment]: v })
|
|
|
+ changed = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return changed
|
|
|
+ },
|
|
|
+ // 工具:检查是否可以升级,并动态禁用启用付费类型相关选项
|
|
|
+ utilCheckAndEnabledUpgradeRenew() {
|
|
|
+ let canRenewUpgrade = false
|
|
|
+ const ma = this.getSchemaItemWithKey(schemaKeyMap.payment)
|
|
|
+ if (this.thisProductInfoListItem?.productUserService) {
|
|
|
+ const us = this.thisProductInfoListItem.productUserService
|
|
|
+ if (Array.isArray(us.serviceArrMap) && us.serviceArrMap.length > 0) {
|
|
|
+ if (us.serviceArrMap[0].vipExist) {
|
|
|
+ // 可以续费
|
|
|
+ canRenewUpgrade = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改options
|
|
|
+ ma.props.options.forEach(item => {
|
|
|
+ // 续费或升级
|
|
|
+ if (item.value === 2 || item.value === 3) {
|
|
|
+ item.disabled = !canRenewUpgrade
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 如果被禁用的项被选中,则自动调整选中项
|
|
|
+ const changed = this.utilChangeAvailablePayment()
|
|
|
+ return {
|
|
|
+ canRenewUpgrade,
|
|
|
+ changed,
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 工具:检查当前是否是商品属性
|
|
|
+ utilCheckIsVipService() {
|
|
|
+ // 产品属性 1会员服务 2 资源包 3实物 4其他
|
|
|
+ return this.thisProductInfoListItem?.productCardInfo?.info?.attribute === 1
|
|
|
+ },
|
|
|
+ // 工具:检查当前属性是否是资源包
|
|
|
+ utilCheckIsSourcePack() {
|
|
|
+ // 产品属性 1会员服务 2 资源包 3实物 4其他
|
|
|
+ return this.thisProductInfoListItem?.productCardInfo?.info?.attribute === 2
|
|
|
+ },
|
|
|
+ // common: 通用修改付费类型相关逻辑
|
|
|
+ commonChangePaymentSchema() {
|
|
|
+ const { buySubject } = this.pageForm
|
|
|
+ // 1. 付费类型相关调整
|
|
|
+ // 根据UserService限制用户可以选择的付费类型
|
|
|
+ // const ma = this.getSchemaItemWithKey(schemaKeyMap.payment)
|
|
|
+ // 产品属性为会员服务且
|
|
|
+ if (this.utilCheckIsVipService()) {
|
|
|
+ if (buySubject === 1) {
|
|
|
+ // 1.1 个人: serviceArrMap不能位空,且,vipExist为true。此时可以续费(升级),否则不可以续费(升级)
|
|
|
+ this.utilCheckAndEnabledUpgradeRenew()
|
|
|
+ } else if (buySubject === 2) {
|
|
|
+ // 1.2 企业: 选择关联订单后再次查询。然后做1.1相关判断
|
|
|
+ // 此处判断在关联订单选择完成后判断
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // common: 通用关联订单相关逻辑
|
|
|
+ commonChangeRelateOrderSchema() {
|
|
|
+ const { buySubject } = this.pageForm
|
|
|
+ // 付费类型为“续费”、“升级”则为必填
|
|
|
+ const relatedOrders = this.getSchemaItemWithKey('relatedOrders')
|
|
|
+ if (Array.isArray(this.thisProductInfoListItem?.productUserService?.serviceArrMap)) {
|
|
|
+ const opt = this.thisProductInfoListItem?.productUserService?.serviceArrMap || []
|
|
|
+ relatedOrders.props.options = opt.map(t => {
|
|
|
+ return {
|
|
|
+ ...t,
|
|
|
+ phone: this.pageForm.accountTel,
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (this.value[schemaKeyMap.payment] === 2 || this.value[schemaKeyMap.payment] === 3) {
|
|
|
+ // 续费或升级
|
|
|
+ relatedOrders.required = true
|
|
|
+ } else {
|
|
|
+ relatedOrders.required = false
|
|
|
+ }
|
|
|
+ relatedOrders.props.required = relatedOrders.required
|
|
|
+
|
|
|
+ this.$set(relatedOrders.hooks, 'confirm', async (p) => {
|
|
|
+ if (p.selected[0]) {
|
|
|
+ this.selectedRelatedOrder = p.selected[0]
|
|
|
+ }
|
|
|
+ // 企业下,根据选中的权益判断是否可以进行续费和升级
|
|
|
+ if (buySubject === 2) {
|
|
|
+ // 重新调用
|
|
|
+ await this.getUserService()
|
|
|
+ this.utilCheckAndEnabledUpgradeRenew()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // common: 升级内容
|
|
|
+ commonChangeUpgradeContentSchema() {
|
|
|
+ const { buySubject } = this.pageForm
|
|
|
+ // 付费类型为“续费”、“升级”则为必填
|
|
|
+ const uc = this.getSchemaItemWithKey(schemaKeyMap.upgradeContent)
|
|
|
+ // 1.展示:仅当产品属性为“会员服务”且付费类型为“升级”才展示,否则不展示;
|
|
|
+ uc.show = this.utilCheckIsVipService() && this.value[schemaKeyMap.payment] === 3
|
|
|
+ // 2.可选:增购子账号、补充服务(如若只有1个可选,则作为默认值);
|
|
|
+ if (uc.show) {
|
|
|
+ // 3.增购子账号,展示条件:仅当购买主体为“企业”或“产品类型”为“大会员”才展示,否则不展示。
|
|
|
+ const showValidator = buySubject === 2 || this.productType === 'dhy'
|
|
|
+ if (!showValidator) {
|
|
|
+ uc.props.options = uc.props.options.filter(c => !c.subCount)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 账号数量、主账号/子账号数量
|
|
|
+ commonChangeAccountNumberSchema() {
|
|
|
+ const { buySubject } = this.pageForm
|
|
|
+ const { subAccountNumbers, [schemaKeyMap.payment]: payment } = this.value
|
|
|
+ const main = this.getSchemaItemWithKey('mainAccountNumbers')
|
|
|
+ const sub = this.getSchemaItemWithKey('subAccountNumbers')
|
|
|
+
|
|
|
+ // 1.子账号展示:满足以下任意条件即展示:
|
|
|
+ const hasAddSubAccount = true // 是否勾选了增购子账号
|
|
|
+ // (1)产品属性为“会员服务”且购买主体为“企业”且付费类型不是升级;
|
|
|
+ const entNotUpgrade = this.utilCheckIsVipService() && buySubject === 2 && payment !== 3
|
|
|
+ // (2)产品属性为“会员服务”且购买主体为“企业”且付费类型是升级且升级内容有“增购子账号”;
|
|
|
+ const entUpgradeAddSubAccount = this.utilCheckIsVipService() && buySubject === 2 && payment === 3 && hasAddSubAccount
|
|
|
+ // (3)产品类型为大会员且付费类型不是升级;
|
|
|
+ const bigNotUpgrade = this.productType === 'dhy' && payment !== 3
|
|
|
+ // (4)产品类型为大会员且付费类型是升级且升级内容有“增购子账号”。
|
|
|
+ const bigNotUpgradeAddSubAccount = this.productType === 'dhy' && payment === 3 && hasAddSubAccount
|
|
|
+
|
|
|
+ const show = entNotUpgrade || entUpgradeAddSubAccount || bigNotUpgrade || bigNotUpgradeAddSubAccount
|
|
|
+ main.show = show
|
|
|
+ sub.show = show
|
|
|
+
|
|
|
+ // 2.账号展示规则
|
|
|
+ // (1)主账号默认为1个;
|
|
|
+ // (2)子账号付费:仅可输入≥1的正整数;如若未填写则提示“请输入付费账号数量”;
|
|
|
+ // (3)子账号赠送:非必填,仅可输入≥0的正整数;
|
|
|
+ // (4)合计=付费+赠送,如若未填写则按照0计算
|
|
|
+ // 特殊情况说明如下:付费类型为续费,则反显关联订单付费和赠送账号数量,不支持修改,历史数据0元订单,默认为赠送,非0元订单,都默认为付费。
|
|
|
+
|
|
|
+ // 计算主账号1个+子账号+赠送账号的和
|
|
|
+ const mainAccountCount = 1
|
|
|
+ let allTotal = 0
|
|
|
+ allTotal += mainAccountCount
|
|
|
+ if (subAccountNumbers) {
|
|
|
+ allTotal += subAccountNumbers.payCount
|
|
|
+ allTotal += subAccountNumbers.freeCount
|
|
|
+ }
|
|
|
+ main.props.text = `付费${mainAccountCount}个 合计:<span class="text-color-main">${allTotal}</span>个`
|
|
|
+ },
|
|
|
+ // 服务周期
|
|
|
+ commonChangeValidityPeriod() {
|
|
|
+ const { saleGifts, [schemaKeyMap.payment]: payment } = this.value
|
|
|
+ const m = this.getSchemaItemWithKey('validityPeriod')
|
|
|
+
|
|
|
+ // 2.产品属性为“会员服务”:
|
|
|
+ if (this.utilCheckIsVipService()) {
|
|
|
+ m.show = true
|
|
|
+ // (1)销售策略为“售卖”:
|
|
|
+ if (saleGifts === 1) {
|
|
|
+ // 1)付费类型为购买、试用,展示如下图:
|
|
|
+ // 1 付费:文本框,非必填,仅可输入1和正整数,单位可选:月(初始值)、天
|
|
|
+ // 2 赠送:文本框,非必填,仅可输入0和正整数,单位同付费,不支持选择。
|
|
|
+ // 3 合计:付费+赠送,初始值为-,单位同付费,如若为0,则提示“请输入有效周期”;
|
|
|
+ this.$set(m.props, 'showPayUnit', ['月', '日'])
|
|
|
+ this.$set(m.props, 'freeUnitDisabled', true)
|
|
|
+ this.$set(m.props, 'showPayInput', true)
|
|
|
+ this.$set(m.props, 'sameUnit', true)
|
|
|
+ if (payment === 1 || payment === 4) {
|
|
|
+ // 购买、试用
|
|
|
+ // do something...
|
|
|
+ this.$set(m.props, 'showOpenOnPaymentDay', true)
|
|
|
+ this.$set(m.props, 'showButtonTip', false)
|
|
|
+ } else if (payment === 2) {
|
|
|
+ // 续费
|
|
|
+ // 不展示自动开通模块
|
|
|
+ this.$set(m.props, 'showOpenOnPaymentDay', false)
|
|
|
+ // 显示底部提示
|
|
|
+ this.$set(m.props, 'showButtonTip', true)
|
|
|
+ } else {
|
|
|
+ // 升级
|
|
|
+ m.show = false
|
|
|
+ }
|
|
|
+ } else if (saleGifts === 2) {
|
|
|
+ // 赠送
|
|
|
+ this.$set(m.props, 'showPayUnit', ['月', '日'])
|
|
|
+ this.$set(m.props, 'freeUnitDisabled', true)
|
|
|
+ this.$set(m.props, 'showPayInput', false)
|
|
|
+ // this.$set(m.props, 'sameUnit', true)
|
|
|
+ if (payment === 1 || payment === 4) {
|
|
|
+ // 购买、试用
|
|
|
+ // do something...
|
|
|
+ this.$set(m.props, 'showOpenOnPaymentDay', true)
|
|
|
+ this.$set(m.props, 'showButtonTip', false)
|
|
|
+ } else if (payment === 2) {
|
|
|
+ // 续费
|
|
|
+ // 不展示自动开通模块
|
|
|
+ this.$set(m.props, 'showOpenOnPaymentDay', false)
|
|
|
+ // 显示底部提示
|
|
|
+ this.$set(m.props, 'showButtonTip', true)
|
|
|
+ } else {
|
|
|
+ // 升级
|
|
|
+ m.show = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (this.utilCheckIsSourcePack()) {
|
|
|
+ // 【产品属性为资源包】且【该产品类型支持系统自动开通权限】
|
|
|
+ // 并且仅展示自动开通
|
|
|
+ // m.show = false // 有自动开通权限【展示】
|
|
|
+ this.$set(m.props, 'showPayInput', false)
|
|
|
+ this.$set(m.props, 'showFreeInput', false)
|
|
|
+ this.$set(m.props, 'showOpenOnPaymentDay', true)
|
|
|
+ this.$set(m.props, 'showButtonTip', false)
|
|
|
+ } else {
|
|
|
+ m.show = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 合同金额
|
|
|
+ commonChangeContractAmount() {
|
|
|
+ const { saleGifts } = this.value
|
|
|
+ const m = this.getSchemaItemWithKey('contractAmount')
|
|
|
+ if (saleGifts === 1) {
|
|
|
+ // 售卖
|
|
|
+ this.$set(m.props, 'showContractMoney', true)
|
|
|
+ } else if (saleGifts === 2) {
|
|
|
+ // 赠送
|
|
|
+ // 不展示合同金额
|
|
|
+ this.$set(m.props, 'showContractMoney', false)
|
|
|
+ }
|
|
|
+
|
|
|
+ // const price = this.getPrice()
|
|
|
+ // this.$set(m.props, 'noStandardMoney', price === -1)
|
|
|
+ // this.$set(m.props, 'standardMoney', price)
|
|
|
+
|
|
|
+ // const rate = discountRate()
|
|
|
+ // this.$set(m.props, 'discountRate', rate)
|
|
|
+ },
|
|
|
+ // 组合以及定制:超级订阅规则
|
|
|
+ groupCjdySchema() {
|
|
|
+ // 付费类型相关调整
|
|
|
+ this.commonChangePaymentSchema()
|
|
|
+ // 关联订单
|
|
|
+ this.commonChangeRelateOrderSchema()
|
|
|
+ // 升级内容
|
|
|
+ this.commonChangeUpgradeContentSchema()
|
|
|
+ // 产品规格
|
|
|
+ this.commonChangeSpecificationSchema()
|
|
|
+ this.cjdyChangeSpecificationSchema()
|
|
|
+ // 账号数量
|
|
|
+ this.commonChangeAccountNumberSchema()
|
|
|
+ // 服务周期
|
|
|
+ this.commonChangeValidityPeriod()
|
|
|
+ // 合同金额
|
|
|
+ this.commonChangeContractAmount()
|
|
|
+ },
|
|
|
+ commonChangeSpecificationSchema() {
|
|
|
+ const { buySubject } = this.pageForm
|
|
|
+ const { [schemaKeyMap.payment]: payment } = this.value
|
|
|
+ const ma = this.getSchemaItemWithKey(schemaKeyMap.payment)
|
|
|
+ // 1付费类型为“续费”,默认为关联订单的产品规格,不支持修改;
|
|
|
+ // 2付费类型为“升级”且“升级内容”仅为“增购子账号”,默认为关联订单的产品规格,其他产品规格不展示;
|
|
|
+ // 3付费类型为“升级”且“升级内容”有“补充服务”或为空,仅可选择不低于关联订单的产品规格(注:特殊处理,大会员自定义版默认展示),其他产品规格不展示。
|
|
|
+ ma.show = ma.props.options.length > 1
|
|
|
+ },
|
|
|
+ cjdyChangeSpecificationSchema() {
|
|
|
+ // const { buySubject } = this.pageForm
|
|
|
+ // const { [schemaKeyMap.payment]: payment } = this.value
|
|
|
+ // const ma = this.getSchemaItemWithKey(schemaKeyMap.payment)
|
|
|
+ },
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+
|
|
|
+</style>
|