|
@@ -0,0 +1,231 @@
|
|
|
+import { computed, ref, getCurrentInstance } from 'vue'
|
|
|
+import { useStore } from '@/store'
|
|
|
+import { useMonitorModel, useMonitorTipDialog } from './base'
|
|
|
+
|
|
|
+/**
|
|
|
+ * 文案项目配置
|
|
|
+ */
|
|
|
+const TextConfig = {
|
|
|
+ default: '监控',
|
|
|
+ follow: '已监控'
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 弹窗相关配置表
|
|
|
+ */
|
|
|
+const DialogDataMap = {
|
|
|
+ 'success-monitor': {
|
|
|
+ title: '监控成功',
|
|
|
+ content:
|
|
|
+ '您可前往“工作台-商机-项目进度监控”查看项目最新招标/采购进度。为保证您能及时获取新增监控信息推送,请前往开启推送提醒。',
|
|
|
+ footerActions: [
|
|
|
+ {
|
|
|
+ label: '暂不开启',
|
|
|
+ class: 'cancel'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '去开启',
|
|
|
+ class: 'confirm',
|
|
|
+ action: 'doOpenPushSetting'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ 'max-monitor': {
|
|
|
+ title: '监控项目个数已达上限',
|
|
|
+ content: '您最多可监控$1个项目,可联系客服,申请监控更多项目',
|
|
|
+ footerActions: [
|
|
|
+ {
|
|
|
+ label: '我再想想',
|
|
|
+ class: 'cancel'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '联系客服',
|
|
|
+ class: 'confirm',
|
|
|
+ action: 'doOpenCustomer'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ 'apply-monitor': {
|
|
|
+ title: '申请监控更多项目',
|
|
|
+ content: '您可联系客服,申请升级产品套餐,监控更多项目',
|
|
|
+ footerActions: [
|
|
|
+ {
|
|
|
+ label: '我再想想',
|
|
|
+ class: 'cancel'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '联系客服',
|
|
|
+ class: 'confirm',
|
|
|
+ action: 'doOpenCustomer'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ 'cancel-monitor': {
|
|
|
+ title: '确定不再监控?',
|
|
|
+ content: '取消监控,将错过项目最新动态推送',
|
|
|
+ footerActions: [
|
|
|
+ {
|
|
|
+ label: '确认取消',
|
|
|
+ class: 'cancel',
|
|
|
+ action: 'doRemoveFollow'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '我再想想',
|
|
|
+ class: 'confirm'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ 'success-toast': '监控成功,您可前往“工作台-商机-项目进度监控”查看'
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 弹窗相关事件 Emit
|
|
|
+ */
|
|
|
+// 打开推送提醒设置
|
|
|
+function doOpenPushSetting() {}
|
|
|
+
|
|
|
+function useProjectQuickMonitorModel({ type, id }) {
|
|
|
+ const that = getCurrentInstance().proxy
|
|
|
+ const collectElement = ref(null)
|
|
|
+ const { dialogConfig, doOpenDialog, doCloseDialog } =
|
|
|
+ useMonitorTipDialog(DialogDataMap)
|
|
|
+ const HasPowerBigmemberOrEnt = computed(() => {
|
|
|
+ const store = useStore()
|
|
|
+ return store.getters['user/entniche'] || store.getters['user/bigmember']
|
|
|
+ })
|
|
|
+ const loading = ref(false)
|
|
|
+ const { model, doChange, doFetch } = useMonitorModel({ type, id })
|
|
|
+ const monitorPopoverConfig = computed(() => {
|
|
|
+ return {
|
|
|
+ showTip: !model.value.follow,
|
|
|
+ showMore: model.value.follow,
|
|
|
+ showList: true,
|
|
|
+ showCancel: model.value.follow,
|
|
|
+ alreadyNum: model.value.expands.used,
|
|
|
+ remainNum: model.value.expands.surplus,
|
|
|
+ textType: type
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 打开留资弹窗
|
|
|
+ function doOpenCollectDialog(key) {
|
|
|
+ collectElement.value?.noCallApiFn(key || 'pc_article_project_more', false)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 联系客服
|
|
|
+ function doOpenCustomer() {
|
|
|
+ that?.contactCustomer(that)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 监控操作业务流程
|
|
|
+ * 0. 前置权益判断
|
|
|
+ * 0.1 判断是否非大会员、非商机管理用户
|
|
|
+ * > 否,留资弹窗
|
|
|
+ * 1. 监控成功
|
|
|
+ * 1.1 判断是否开启推送提醒
|
|
|
+ * > 是,提醒开启推送提醒 success-monitor
|
|
|
+ * > 否,toast 提醒监控成功 success-toast
|
|
|
+ * 2. 监控失败
|
|
|
+ * 2.1 超出可监控项目个数
|
|
|
+ * 2.1.1 判断是否非大会员、非商机管理用户
|
|
|
+ * > 是,弹窗提醒 max-monitor
|
|
|
+ * > 否,留资弹窗
|
|
|
+ * 2.2 其他错误,toast 提醒
|
|
|
+ * @return {Promise<void>}
|
|
|
+ */
|
|
|
+ async function doAddFollow() {
|
|
|
+ if (loading.value) return
|
|
|
+ loading.value = true
|
|
|
+ // 业务流程
|
|
|
+ if (!model.value.follow) {
|
|
|
+ await doChange().then((res) => {
|
|
|
+ if (res.success) {
|
|
|
+ // 判断是否开启推送提醒
|
|
|
+ if (!res.data?.msg_open) {
|
|
|
+ doOpenDialog('success-monitor')
|
|
|
+ } else {
|
|
|
+ that.$toast(DialogDataMap['success-toast'])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 判断是否超出可监控项目个数
|
|
|
+ if (res.data?.limit_status) {
|
|
|
+ if (HasPowerBigmemberOrEnt.value) {
|
|
|
+ doOpenDialog('max-monitor', { count: res.data?.limit_status })
|
|
|
+ } else {
|
|
|
+ doOpenCollectDialog('pc_article_project_limit')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.$toast(res.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ loading.value = false
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统一处理 dialog, popover emit 事件
|
|
|
+ * @param {string} type
|
|
|
+ * // popover 事务
|
|
|
+ * - more 查看监控动态
|
|
|
+ * - list 查看监控列表
|
|
|
+ * - apply 申请监控更多
|
|
|
+ * - cancel 取消监控确认弹窗
|
|
|
+ * // dialog 事务
|
|
|
+ * - doCloseDialog 关闭弹窗
|
|
|
+ * - doRemoveFollow 提交取消监控事务
|
|
|
+ * - doOpenCustomer 联系客服
|
|
|
+ * - doOpenPushSetting 打开推送提醒设置
|
|
|
+ */
|
|
|
+ function doClickMonitorActions(type) {
|
|
|
+ switch (type) {
|
|
|
+ case 'doCloseDialog':
|
|
|
+ doCloseDialog()
|
|
|
+ break
|
|
|
+ case 'doOpenCustomer':
|
|
|
+ doOpenCustomer()
|
|
|
+ break
|
|
|
+ case 'doOpenPushSetting':
|
|
|
+ doOpenPushSetting()
|
|
|
+ break
|
|
|
+ case 'doRemoveFollow':
|
|
|
+ doChange().then((res) => {
|
|
|
+ that.$toast(res.msg)
|
|
|
+ doCloseDialog()
|
|
|
+ })
|
|
|
+ break
|
|
|
+ case 'cancel':
|
|
|
+ doOpenDialog('cancel-monitor')
|
|
|
+ break
|
|
|
+ case 'apply':
|
|
|
+ if (HasPowerBigmemberOrEnt.value) {
|
|
|
+ doOpenDialog('apply-monitor')
|
|
|
+ } else {
|
|
|
+ doOpenCollectDialog('pc_article_project_more')
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 'more':
|
|
|
+ break
|
|
|
+ case 'list':
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ // 基础展示信息
|
|
|
+ model,
|
|
|
+ doFetch,
|
|
|
+ doAddFollow,
|
|
|
+ TextConfig,
|
|
|
+ // popover 悬浮信息
|
|
|
+ monitorPopoverConfig,
|
|
|
+ doClickMonitorActions,
|
|
|
+ // dialog 提示弹窗
|
|
|
+ dialogConfig,
|
|
|
+ // 留资
|
|
|
+ collectElement
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export default useProjectQuickMonitorModel
|