journey-card.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="jc-wrap" v-if="intent">
  3. <view class="jc-header">
  4. <text class="jc-title">{{ domainLabel }}</text>
  5. <text class="jc-stage-label">{{ stageLabel }}</text>
  6. </view>
  7. <view class="jc-progress">
  8. <view class="jc-bar">
  9. <view class="jc-bar-fill" :style="'width:' + progressPct + '%'"></view>
  10. </view>
  11. <text class="jc-pct">{{ progressPct }}%</text>
  12. </view>
  13. <view class="jc-steps" v-if="intentType === 'C'">
  14. <view class="jc-step" v-for="(s, i) in cSteps" :key="s.key" :class="{ 'jc-step-done': i <= stage, 'jc-step-cur': i === stage }">
  15. <view class="jc-step-dot" :class="{ 'jc-step-dot-done': i <= stage }">
  16. <text class="jc-step-num" v-if="i < stage">✓</text>
  17. <text class="jc-step-num" v-else>{{ i + 1 }}</text>
  18. </view>
  19. <text class="jc-step-label">{{ s }}</text>
  20. </view>
  21. </view>
  22. <view class="jc-action" v-if="nextAction && nextAction !== 'done'" @click="onAction">
  23. <text class="jc-action-text">{{ nextLabel }}</text>
  24. <text class="jc-action-arrow">›</text>
  25. </view>
  26. <view class="jc-done" v-else-if="nextAction === 'done'">
  27. <text class="jc-done-text">✅ 全部完成,奖励已发放!</text>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import { getProblemDomainList } from '../utils/api.js'
  33. var C_STEPS = ['选问题域', '看流程', '调研', '选购方案', '物流', '出报告', '确认方案', '任务完成']
  34. var A_STEPS = ['选购', '出报告', '确认方案', '任务完成']
  35. var B_STEPS = ['问卷', '推荐']
  36. var C_ACTIONS = ['flow-intro', 'survey', 'package', 'logistics', 'report', 'plan-confirm', 'tasks', 'done']
  37. var A_ACTIONS = ['purchase', 'report', 'plan-confirm', 'tasks', 'done']
  38. var B_ACTIONS = ['survey', 'recommend', 'done']
  39. var C_LABELS = ['查看服务流程', '填写调研', '选购方案', '查看物流', '等待报告', '确认方案', '查看任务', '已完成']
  40. var A_LABELS = ['去选购', '查看报告', '确认方案', '查看任务', '已完成']
  41. var B_LABELS = ['填写问卷', '查看推荐', '已完成']
  42. export default {
  43. name: 'JourneyCard',
  44. props: {
  45. intent: {
  46. type: Object,
  47. default: null
  48. }
  49. },
  50. data() {
  51. return {
  52. domainMap: {}
  53. }
  54. },
  55. computed: {
  56. intentType() {
  57. return this.intent && this.intent.intentType
  58. },
  59. stage() {
  60. return this.intent ? (this.intent.journeyStage || 0) : 0
  61. },
  62. maxStage() {
  63. if (this.intentType === 'C') return 7
  64. if (this.intentType === 'A') return 4
  65. if (this.intentType === 'B') return 2
  66. return 0
  67. },
  68. progressPct() {
  69. if (this.maxStage === 0) return 0
  70. return Math.round((this.stage / this.maxStage) * 100)
  71. },
  72. steps() {
  73. if (this.intentType === 'C') return C_STEPS
  74. if (this.intentType === 'A') return A_STEPS
  75. if (this.intentType === 'B') return B_STEPS
  76. return []
  77. },
  78. actions() {
  79. if (this.intentType === 'C') return C_ACTIONS
  80. if (this.intentType === 'A') return A_ACTIONS
  81. if (this.intentType === 'B') return B_ACTIONS
  82. return []
  83. },
  84. labels() {
  85. if (this.intentType === 'C') return C_LABELS
  86. if (this.intentType === 'A') return A_LABELS
  87. if (this.intentType === 'B') return B_LABELS
  88. return []
  89. },
  90. cSteps() {
  91. if (this.intentType !== 'C') return []
  92. var sliced = this.steps.slice(0, Math.max(this.stage + 1, 3))
  93. return sliced.map(function(s, i) {
  94. return { key: 's' + i, label: s }
  95. })
  96. },
  97. stageLabel() {
  98. var idx = Math.min(this.stage, this.steps.length - 1)
  99. if (this.stage >= this.steps.length) return '已完成'
  100. return '第' + (this.stage + 1) + '步:' + this.steps[idx]
  101. },
  102. nextAction() {
  103. var idx = Math.min(this.stage, this.actions.length - 1)
  104. return this.actions[idx] || 'done'
  105. },
  106. nextLabel() {
  107. var idx = Math.min(this.stage, this.labels.length - 1)
  108. return this.labels[idx] || '已完成'
  109. },
  110. domainLabel() {
  111. var code = this.intent && this.intent.problemDomainCode
  112. if (code && this.domainMap[code]) {
  113. return this.domainMap[code]
  114. }
  115. if (this.intentType === 'A') return 'A类 · 随便看看'
  116. if (this.intentType === 'B') return 'B类 · 问卷'
  117. if (this.intentType === 'C') return 'C类 · 解决问题'
  118. return ''
  119. }
  120. },
  121. created() {
  122. this.loadDomainMap()
  123. },
  124. methods: {
  125. loadDomainMap() {
  126. var self = this
  127. getProblemDomainList().then(function(res) {
  128. var list = res && res.data
  129. if (Array.isArray(list)) {
  130. var map = {}
  131. list.forEach(function(d) {
  132. map[d.code] = d.name
  133. })
  134. self.domainMap = map
  135. }
  136. }).catch(function() {
  137. // 静默失败
  138. })
  139. },
  140. onAction() {
  141. this.$emit('action', {
  142. action: this.nextAction,
  143. code: this.intent && this.intent.problemDomainCode
  144. })
  145. }
  146. }
  147. }
  148. </script>
  149. <style scoped>
  150. .jc-wrap {
  151. background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
  152. border-radius: 24rpx;
  153. padding: 28rpx 30rpx;
  154. margin: 20rpx 24rpx 0;
  155. box-shadow: 0 4rpx 20rpx rgba(249, 115, 22, 0.12);
  156. }
  157. .jc-header {
  158. display: flex;
  159. justify-content: space-between;
  160. align-items: center;
  161. margin-bottom: 16rpx;
  162. }
  163. .jc-title {
  164. font-size: 30rpx;
  165. font-weight: bold;
  166. color: #333;
  167. }
  168. .jc-stage-label {
  169. font-size: 22rpx;
  170. color: #F97316;
  171. background: rgba(249, 115, 22, 0.12);
  172. padding: 4rpx 14rpx;
  173. border-radius: 20rpx;
  174. }
  175. .jc-progress {
  176. display: flex;
  177. align-items: center;
  178. margin-bottom: 20rpx;
  179. }
  180. .jc-bar {
  181. flex: 1;
  182. height: 12rpx;
  183. background: #FED7AA;
  184. border-radius: 6rpx;
  185. overflow: hidden;
  186. }
  187. .jc-bar-fill {
  188. height: 100%;
  189. background: linear-gradient(90deg, #F97316, #FB923C);
  190. border-radius: 6rpx;
  191. transition: width 0.3s;
  192. }
  193. .jc-pct {
  194. font-size: 22rpx;
  195. color: #F97316;
  196. margin-left: 12rpx;
  197. min-width: 48rpx;
  198. text-align: right;
  199. }
  200. .jc-steps {
  201. display: flex;
  202. flex-wrap: nowrap;
  203. overflow-x: auto;
  204. margin-bottom: 20rpx;
  205. padding-bottom: 8rpx;
  206. }
  207. .jc-step {
  208. display: flex;
  209. flex-direction: column;
  210. align-items: center;
  211. margin-right: 24rpx;
  212. flex-shrink: 0;
  213. }
  214. .jc-step:last-child {
  215. margin-right: 0;
  216. }
  217. .jc-step-dot {
  218. width: 36rpx;
  219. height: 36rpx;
  220. border-radius: 50%;
  221. background: #FED7AA;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. margin-bottom: 8rpx;
  226. }
  227. .jc-step-dot-done {
  228. background: #F97316;
  229. }
  230. .jc-step-num {
  231. font-size: 20rpx;
  232. color: #fff;
  233. font-weight: bold;
  234. }
  235. .jc-step-label {
  236. font-size: 20rpx;
  237. color: #999;
  238. white-space: nowrap;
  239. }
  240. .jc-step-cur .jc-step-label {
  241. color: #F97316;
  242. font-weight: 600;
  243. }
  244. .jc-step-done .jc-step-label {
  245. color: #666;
  246. }
  247. .jc-action {
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. background: #F97316;
  252. border-radius: 40rpx;
  253. padding: 22rpx 0;
  254. margin-top: 8rpx;
  255. }
  256. .jc-action:active {
  257. opacity: 0.9;
  258. }
  259. .jc-action-text {
  260. color: #fff;
  261. font-size: 30rpx;
  262. font-weight: 600;
  263. }
  264. .jc-action-arrow {
  265. color: #fff;
  266. font-size: 36rpx;
  267. margin-left: 8rpx;
  268. }
  269. .jc-done {
  270. text-align: center;
  271. padding: 16rpx 0;
  272. margin-top: 8rpx;
  273. }
  274. .jc-done-text {
  275. font-size: 28rpx;
  276. color: #16A34A;
  277. }
  278. </style>