octopus-add-effect.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <view class="container">
  3. <view class="page-header">
  4. <text class="page-title">感恩记录</text>
  5. </view>
  6. <!-- 成交金额 -->
  7. <view class="form-section">
  8. <text class="section-label">成交金额(元) <text class="required-mark">*</text></text>
  9. <input class="amount-input" v-model="effectAmount" type="digit" placeholder="如 2500.00" />
  10. </view>
  11. <!-- 成交来源描述 -->
  12. <view class="form-section">
  13. <text class="section-label">成交来源描述(选填)</text>
  14. <textarea class="desc-input" v-model="effectDesc" placeholder="简述成交来源,如:家长转介绍、社区活动等" maxlength="200"></textarea>
  15. </view>
  16. <!-- 发生时间 -->
  17. <view class="form-section">
  18. <text class="section-label">发生时间(选填)</text>
  19. <view class="datetime-row">
  20. <picker mode="date" :value="happenedDate" @change="onDateChange">
  21. <view class="form-picker">{{ happenedDate || '选择日期' }}</view>
  22. </picker>
  23. <text class="datetime-sep">·</text>
  24. <picker mode="time" :value="happenedTime" @change="onTimeChange">
  25. <view class="form-picker">{{ happenedTime || '选择时间' }}</view>
  26. </picker>
  27. </view>
  28. </view>
  29. <!-- 关联关键人(可多选 + 角色标记) -->
  30. <view class="form-section">
  31. <view class="kp-header">
  32. <text class="section-label">关联关键人(可多选)</text>
  33. <text class="kp-add-link" @tap="goAddKeyPerson">+ 新建</text>
  34. </view>
  35. <view class="kp-list" v-if="keyPersons.length > 0">
  36. <view class="kp-item" v-for="kp in keyPersons" :key="kp.id"
  37. :class="{selected: selectedMap[kp.id]}"
  38. @click="toggleKeyPerson(kp.id)">
  39. <view class="kp-info">
  40. <text class="kp-name">{{ kp.name }}</text>
  41. <text class="kp-org">{{ kp.organization || kp.title || '' }}</text>
  42. </view>
  43. <!-- 已有联系方式 → 可匹配系统用户 -->
  44. <text class="kp-match-btn" v-if="kp.contactInfo" @click.stop="onMatchByPhone(kp)">匹配用户</text>
  45. <text class="kp-sys-badge" v-if="kp.matched">✓ 系统用户</text>
  46. <!-- 角色选择(选中时显示) -->
  47. <view class="kp-role" v-if="selectedMap[kp.id]" @click.stop>
  48. <text class="role-tag" :class="{active: roleMap[kp.id] === 1}" @click="setRole(kp.id, 1)">引荐</text>
  49. <text class="role-tag" :class="{active: roleMap[kp.id] === 2}" @click="setRole(kp.id, 2)">决策</text>
  50. <text class="role-tag" :class="{active: roleMap[kp.id] === 3}" @click="setRole(kp.id, 3)">其他</text>
  51. </view>
  52. </view>
  53. </view>
  54. <text class="empty-hint" v-else>暂无关键人,点击「+ 新建」添加</text>
  55. </view>
  56. <!-- 按手机号快速建关键人 -->
  57. <view class="form-section">
  58. <text class="section-label">手机号匹配(选填)</text>
  59. <view class="phone-match-row">
  60. <input class="phone-input" v-model="matchPhone" placeholder="输入手机号自动匹配" maxlength="11" type="number" />
  61. <text class="phone-match-btn" @tap="doPhoneMatch">匹配</text>
  62. </view>
  63. <text class="phone-match-result" v-if="matchResult">{{ matchResult }}</text>
  64. </view>
  65. <!-- 提交按钮 -->
  66. <view class="submit-bar">
  67. <button class="btn-submit" @click="onSubmit" :disabled="!canSubmit">保存感恩记录</button>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import { addOctopusEffect, getOctopusKeyPersons, matchOctopusKeyPersonByPhone, bindOctopusKeyPersonSystemUser } from '../../utils/api.js'
  73. export default {
  74. data() {
  75. var now = new Date()
  76. var y = now.getFullYear()
  77. var m = String(now.getMonth() + 1).padStart(2, '0')
  78. var d = String(now.getDate()).padStart(2, '0')
  79. var h = String(now.getHours()).padStart(2, '0')
  80. var min = String(now.getMinutes()).padStart(2, '0')
  81. return {
  82. effectAmount: '',
  83. effectDesc: '',
  84. happenedDate: y + '-' + m + '-' + d,
  85. happenedTime: h + ':' + min,
  86. keyPersons: [],
  87. selectedMap: {}, // kpId -> true
  88. roleMap: {}, // kpId -> role (1引荐/2决策/3其他)
  89. _onLoadFired: false,
  90. matchPhone: '',
  91. matchResult: ''
  92. }
  93. },
  94. computed: {
  95. canSubmit() {
  96. return this.effectAmount.trim()
  97. }
  98. },
  99. onLoad() {
  100. this.loadKeyPersons()
  101. this._onLoadFired = true
  102. },
  103. onShow() {
  104. if (this._onLoadFired) {
  105. this._onLoadFired = false
  106. } else {
  107. this.loadKeyPersons()
  108. }
  109. },
  110. methods: {
  111. async loadKeyPersons() {
  112. try {
  113. var res = await getOctopusKeyPersons()
  114. if (res.code === 200 && Array.isArray(res.data)) {
  115. this.keyPersons = res.data
  116. }
  117. } catch (e) { /* 静默 */ }
  118. },
  119. /** 按关键人联系方式匹配系统用户 */
  120. onMatchByPhone: function(kp) {
  121. if (!kp.contactInfo) return
  122. this.doPhoneMatchInternal(kp.contactInfo, kp.id)
  123. },
  124. /** 手机号匹配输入框触发 */
  125. doPhoneMatch: function() {
  126. var phone = this.matchPhone.trim()
  127. if (!phone) {
  128. this.matchResult = '请输入手机号'
  129. return
  130. }
  131. this.matchResult = '匹配中...'
  132. this.doPhoneMatchInternal(phone, null)
  133. },
  134. async doPhoneMatchInternal(phone, kpId) {
  135. try {
  136. var res = await matchOctopusKeyPersonByPhone({ phone: phone })
  137. if (res.code === 200 && res.data && res.data.matched) {
  138. var matchedName = res.data.nickname || res.data.realName || res.data.memberName || ''
  139. var extra = res.data.memberId ? ' (memberId:' + res.data.memberId + ')' : ''
  140. this.matchResult = '已匹配: ' + matchedName + extra
  141. if (kpId && res.data.systemUserId) {
  142. // 持久化:将关键人与系统用户绑定
  143. var bindRes = await bindOctopusKeyPersonSystemUser({ keyPersonId: kpId, systemUserId: res.data.systemUserId })
  144. if (bindRes.code === 200) {
  145. this.$set(this.keyPersons[this.keyPersons.findIndex(function(k) { return k.id === kpId })], 'matched', true)
  146. this.matchResult = '已匹配并保存: ' + matchedName + extra
  147. }
  148. }
  149. } else {
  150. this.matchResult = res.message || '未找到该手机号对应的用户'
  151. }
  152. } catch (e) {
  153. this.matchResult = '匹配失败,请稍后重试'
  154. }
  155. },
  156. goAddKeyPerson() {
  157. uni.navigateTo({ url: '/pages/action-detail/octopus-add-key-person' })
  158. },
  159. toggleKeyPerson(id) {
  160. if (this.selectedMap[id]) {
  161. this.$set(this.selectedMap, id, false)
  162. this.$delete(this.roleMap, id)
  163. } else {
  164. this.$set(this.selectedMap, id, true)
  165. this.$set(this.roleMap, id, 1) // 默认引荐
  166. }
  167. },
  168. setRole(id, role) {
  169. this.$set(this.roleMap, id, role)
  170. },
  171. onDateChange(e) {
  172. this.happenedDate = e.detail.value
  173. },
  174. onTimeChange(e) {
  175. this.happenedTime = e.detail.value
  176. },
  177. async onSubmit() {
  178. if (!this.effectAmount.trim()) {
  179. uni.showToast({ title: '请填写成交金额', icon: 'none' })
  180. return
  181. }
  182. var data = {
  183. effectAmount: this.effectAmount,
  184. effectDesc: this.effectDesc.trim(),
  185. happenedAt: this.happenedDate + 'T' + this.happenedTime + ':00'
  186. }
  187. // 组装关键人列表
  188. var kpList = []
  189. var ids = Object.keys(this.selectedMap).filter(function(k) { return this.selectedMap[k] }, this)
  190. ids.forEach(function(k) {
  191. kpList.push({ keyPersonId: Number(k), role: this.roleMap[k] || 3 })
  192. }, this)
  193. if (kpList.length > 0) data.keyPersons = kpList
  194. try {
  195. var res = await addOctopusEffect(data)
  196. if (res.code === 200) {
  197. uni.showToast({ title: '保存成功', icon: 'success' })
  198. setTimeout(() => uni.navigateBack(), 1500)
  199. } else {
  200. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  201. }
  202. } catch (e) { uni.showToast({ title: '保存失败', icon: 'none' }) }
  203. }
  204. }
  205. }
  206. </script>
  207. <style scoped>
  208. .container {
  209. min-height: 100vh;
  210. background: #f5f5f5;
  211. padding: 24rpx;
  212. }
  213. .page-header {
  214. padding: 20rpx 0 30rpx;
  215. }
  216. .page-title {
  217. font-size: 36rpx;
  218. font-weight: bold;
  219. color: #333;
  220. }
  221. .form-section {
  222. background: #fff;
  223. border-radius: 16rpx;
  224. padding: 24rpx;
  225. margin-bottom: 20rpx;
  226. }
  227. .section-label {
  228. font-size: 28rpx;
  229. color: #333;
  230. font-weight: 500;
  231. display: block;
  232. margin-bottom: 16rpx;
  233. }
  234. .required-mark {
  235. color: #F97316;
  236. }
  237. .amount-input {
  238. width: 100%;
  239. height: 88rpx;
  240. background: #fafafa;
  241. border-radius: 12rpx;
  242. padding: 0 20rpx;
  243. font-size: 28rpx;
  244. box-sizing: border-box;
  245. }
  246. .desc-input {
  247. width: 100%;
  248. height: 160rpx;
  249. background: #fafafa;
  250. border-radius: 12rpx;
  251. padding: 20rpx;
  252. font-size: 28rpx;
  253. box-sizing: border-box;
  254. }
  255. /* 关键人选择 */
  256. .kp-header {
  257. display: flex;
  258. align-items: center;
  259. justify-content: space-between;
  260. }
  261. .kp-header .section-label {
  262. margin-bottom: 0;
  263. }
  264. .kp-add-link {
  265. font-size: 26rpx;
  266. color: #F97316;
  267. }
  268. .kp-list {
  269. margin-top: 16rpx;
  270. }
  271. .kp-item {
  272. padding: 16rpx 20rpx;
  273. border: 2rpx solid #e0e0e0;
  274. border-radius: 12rpx;
  275. background: #fafafa;
  276. margin-bottom: 12rpx;
  277. }
  278. .kp-item.selected {
  279. border-color: #F97316;
  280. background: #FFF7ED;
  281. }
  282. .kp-info {
  283. display: flex;
  284. align-items: center;
  285. justify-content: space-between;
  286. }
  287. .kp-name {
  288. font-size: 28rpx;
  289. color: #333;
  290. }
  291. .kp-org {
  292. font-size: 22rpx;
  293. color: #999;
  294. }
  295. .kp-match-btn {
  296. font-size: 22rpx;
  297. color: #0EA5E9;
  298. padding: 4rpx 12rpx;
  299. border: 1rpx solid #0EA5E9;
  300. border-radius: 8rpx;
  301. background: #F0F9FF;
  302. flex-shrink: 0;
  303. }
  304. .kp-sys-badge {
  305. font-size: 20rpx;
  306. color: #10B981;
  307. background: #ECFDF5;
  308. padding: 2rpx 12rpx;
  309. border-radius: 6rpx;
  310. margin-left: 8rpx;
  311. }
  312. .kp-role {
  313. display: flex;
  314. margin-top: 12rpx;
  315. gap: 12rpx;
  316. }
  317. .role-tag {
  318. font-size: 22rpx;
  319. padding: 6rpx 20rpx;
  320. border-radius: 8rpx;
  321. border: 2rpx solid #e0e0e0;
  322. color: #666;
  323. }
  324. .role-tag.active {
  325. border-color: #F97316;
  326. background: #F97316;
  327. color: #fff;
  328. }
  329. .empty-hint {
  330. font-size: 26rpx;
  331. color: #999;
  332. }
  333. .submit-bar {
  334. margin-top: 40rpx;
  335. }
  336. .btn-submit {
  337. width: 100%;
  338. background: #F97316;
  339. color: #fff;
  340. border: none;
  341. border-radius: 12rpx;
  342. padding: 24rpx 0;
  343. font-size: 32rpx;
  344. }
  345. .btn-submit[disabled] {
  346. background: #ccc;
  347. }
  348. .form-picker {
  349. width: 45%;
  350. height: 88rpx;
  351. background: #fafafa;
  352. border-radius: 12rpx;
  353. padding: 0 20rpx;
  354. font-size: 28rpx;
  355. color: #333;
  356. display: flex;
  357. align-items: center;
  358. box-sizing: border-box;
  359. }
  360. .datetime-row {
  361. display: flex;
  362. align-items: center;
  363. gap: 16rpx;
  364. }
  365. .datetime-sep {
  366. font-size: 28rpx;
  367. color: #ccc;
  368. }
  369. /* 手机号匹配 */
  370. .phone-match-row {
  371. display: flex;
  372. align-items: center;
  373. gap: 16rpx;
  374. }
  375. .phone-input {
  376. flex: 1;
  377. height: 88rpx;
  378. background: #fafafa;
  379. border-radius: 12rpx;
  380. padding: 0 20rpx;
  381. font-size: 28rpx;
  382. box-sizing: border-box;
  383. }
  384. .phone-match-btn {
  385. padding: 0 28rpx;
  386. height: 88rpx;
  387. line-height: 88rpx;
  388. background: #0EA5E9;
  389. color: #fff;
  390. border-radius: 12rpx;
  391. font-size: 28rpx;
  392. flex-shrink: 0;
  393. }
  394. .phone-match-result {
  395. font-size: 24rpx;
  396. color: #0EA5E9;
  397. margin-top: 12rpx;
  398. display: block;
  399. }
  400. </style>