PageOne.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <template>
  2. <view class="page-one-container">
  3. <!-- 图片资料标题 -->
  4. <view class="page-header">
  5. <view class="detail-image-header">
  6. <text class="detail-image-title">图片资料</text>
  7. <view class="copy-btn" @click="handleSaveAllImages">
  8. <text>一键下载实物图到相册</text>
  9. </view>
  10. </view>
  11. </view>
  12. <!-- 聊天记录/通话记录/跟进卡片 -->
  13. <view class="card-wrap">
  14. <view class="card-title">
  15. <text :class="{ 'active': recordType === 'chat' }" @click="recordType = 'chat'">
  16. 聊天记录
  17. </text>
  18. <text class="divider">|</text>
  19. <text :class="{ 'active': recordType === 'call' }" @click="recordType = 'call'">
  20. 通话记录
  21. </text>
  22. <text class="divider">|</text>
  23. <text :class="{ 'active': recordType === 'frontendFollow' }" @click="recordType = 'frontendFollow'">
  24. 前端跟进
  25. </text>
  26. <text class="divider">|</text>
  27. <text :class="{ 'active': recordType === 'followRecord' }" @click="recordType = 'followRecord'">
  28. 跟进记录
  29. </text>
  30. </view>
  31. <!-- 聊天记录 -->
  32. <view v-if="recordType === 'chat'" class="image-upload-container">
  33. <view class="image-list">
  34. <view v-for="(item, index) in chatRecordsList" :key="`chat-${index}`" class="image-item">
  35. <PicComp :src="item.fileUrl" @needPreviewPic="previewImage" />
  36. <view class="delete-btn" @click="handleDeleteImage(item)">×</view>
  37. </view>
  38. <view class="upload-btn" @click="handleUploadImage('chatRecords')">
  39. <u-icon name="plus" size="40" color="#999" />
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 通话录音 -->
  44. <view v-if="recordType === 'call'" class="call-records-container">
  45. <sound-recorder v-for="item in soundRecordList" :key="item.fileName" :data="item"
  46. @handleDelectThisSoundRecord="handleDeleteSoundRecord" />
  47. </view>
  48. <!-- 前端跟进 -->
  49. <follow-card v-if="recordType === 'frontendFollow'" :key="'frontendFollow'" :clue-id="currentClueId" type="4" />
  50. <!-- 跟进记录 -->
  51. <follow-card v-if="recordType === 'followRecord'" :key="'followRecord'" :clue-id="currentClueId" type="5" />
  52. </view>
  53. <!-- 实物图卡片 -->
  54. <view class="card-wrap">
  55. <view class="card-title">实物图</view>
  56. <view class="image-upload-container">
  57. <view class="image-list">
  58. <view v-for="(item, index) in truePicList" :key="`truePic-${index}`" class="image-item">
  59. <PicComp :src="item.fileUrl" @needPreviewPic="previewTrueImage" />
  60. <view class="delete-btn" @click="handleDeleteImage(item)">×</view>
  61. </view>
  62. <view class="upload-btn" @click="handleUploadImage('truePic')">
  63. <u-icon name="plus" size="40" color="#999" />
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 基本信息卡片 -->
  69. <view class="info-card">
  70. <view class="info-card-title">基本信息</view>
  71. <u-row class="info-row">
  72. <u-col span="6">
  73. <view class="info-label">发单人</view>
  74. <view class="info-value">{{ orderDetail.createNickName || '未填写' }}</view>
  75. </u-col>
  76. <u-col span="6">
  77. <view class="info-label">型号</view>
  78. <view class="info-value">{{ orderDetail.model || '未填写' }}</view>
  79. </u-col>
  80. </u-row>
  81. <u-row class="info-row">
  82. <u-col span="6">
  83. <view class="info-label">上门时间</view>
  84. <view class="info-value">{{ orderDetail.visitTime || '未填写' }}</view>
  85. </u-col>
  86. <u-col span="6">
  87. <view class="info-label">地址</view>
  88. <view class="info-value">{{ orderDetail.address || '未填写' }}</view>
  89. </u-col>
  90. </u-row>
  91. </view>
  92. <!-- 联系方式卡片 -->
  93. <view class="contact-card">
  94. <view class="contact-item phone-card" @click="handlePhoneClick">
  95. <u-icon name="phone" size="40" color="#07C160" />
  96. <view class="contact-title">电话</view>
  97. <view v-if="orderDetail.phone" class="red-dot"></view>
  98. </view>
  99. <view class="contact-item wechat-card" @click="handleWechatClick">
  100. <u-icon name="chat" size="40" color="#07C160" />
  101. <view class="contact-title">微信</view>
  102. <view v-if="orderDetail.wechat" class="red-dot"></view>
  103. </view>
  104. </view>
  105. <!-- 下一步按钮 -->
  106. <view class="space-block"></view>
  107. <u-button class="next-btn" @click="handleNext" type="primary" size="middle">
  108. 下一步
  109. </u-button>
  110. </view>
  111. </template>
  112. <script>
  113. import PicComp from './PicComp.vue'
  114. import soundRecorder from '@/components/soundRecorder/soundRecorder.vue'
  115. import FollowCard from './FollowCard.vue'
  116. import imageUpload from '../utils/imageUpload.js'
  117. export default {
  118. name: 'PageOne',
  119. components: {
  120. PicComp,
  121. soundRecorder,
  122. FollowCard
  123. },
  124. props: {
  125. orderDetail: {
  126. type: Object,
  127. default: () => ({})
  128. },
  129. orderId: {
  130. type: String,
  131. default: ''
  132. },
  133. currentReceipt: {
  134. type: Object,
  135. default: () => ({})
  136. }
  137. },
  138. data() {
  139. return {
  140. recordType: 'chat', // 'chat' | 'call' | 'frontendFollow' | 'followRecord'
  141. chatRecordsList: [],
  142. truePicList: [],
  143. soundRecordList: []
  144. }
  145. },
  146. computed: {
  147. currentClueId() {
  148. return (this.currentReceipt && this.currentReceipt.clueId) || (this.orderDetail && this.orderDetail.clueId) || ''
  149. }
  150. },
  151. watch: {
  152. currentReceipt: {
  153. handler(newVal) {
  154. if (newVal && newVal.id) {
  155. this.loadImageList()
  156. this.loadCallRecords()
  157. }
  158. },
  159. immediate: true,
  160. deep: true
  161. }
  162. },
  163. methods: {
  164. /**
  165. * 加载图片列表
  166. */
  167. async loadImageList() {
  168. if (!this.currentReceipt.id || !this.orderDetail.itemBrand) return
  169. try {
  170. // 加载聊天记录
  171. const chatList = await imageUpload.getFileList(
  172. '2',
  173. '1',
  174. this.currentReceipt.id,
  175. this.orderDetail.itemBrand,
  176. this.currentReceipt.clueId
  177. )
  178. this.chatRecordsList = chatList || []
  179. // 加载实物图
  180. const truePicList = await imageUpload.getFileList(
  181. '2',
  182. '2',
  183. this.currentReceipt.id,
  184. this.orderDetail.itemBrand,
  185. this.currentReceipt.clueId
  186. )
  187. this.truePicList = truePicList || []
  188. } catch (error) {
  189. console.error('加载图片列表失败:', error)
  190. }
  191. },
  192. /**
  193. * 加载通话记录
  194. */
  195. async loadCallRecords() {
  196. if (!this.currentReceipt.clueId) return
  197. try {
  198. const { data } = await uni.$u.api.getCallClueFileByClueId({
  199. clueId: this.currentReceipt.clueId
  200. })
  201. this.soundRecordList = data || []
  202. } catch (error) {
  203. console.error('加载通话记录失败:', error)
  204. }
  205. },
  206. /**
  207. * 上传图片
  208. */
  209. async handleUploadImage(type) {
  210. try {
  211. const filePaths = await imageUpload.chooseImage(9)
  212. const uploadResults = await imageUpload.uploadFiles(filePaths)
  213. // 绑定订单文件
  214. const orderFileType = type === 'truePic' ? '2' : '1'
  215. await imageUpload.bindOrderFile(
  216. this.currentReceipt.clueId,
  217. this.currentReceipt.id,
  218. orderFileType,
  219. uploadResults
  220. )
  221. // 刷新列表
  222. this.loadImageList()
  223. } catch (error) {
  224. console.error('上传图片失败:', error)
  225. }
  226. },
  227. /**
  228. * 删除图片
  229. */
  230. async handleDeleteImage(item) {
  231. uni.showModal({
  232. title: '提示',
  233. content: '确定要删除这张图片吗?',
  234. success: async (res) => {
  235. if (res.confirm) {
  236. try {
  237. await imageUpload.deleteFile(item.id)
  238. this.loadImageList()
  239. } catch (error) {
  240. console.error('删除图片失败:', error)
  241. }
  242. }
  243. }
  244. })
  245. },
  246. /**
  247. * 删除录音
  248. */
  249. async handleDeleteSoundRecord({ id }) {
  250. uni.showModal({
  251. title: '提示',
  252. content: '是否确定删除?',
  253. success: async (res) => {
  254. if (res.confirm) {
  255. try {
  256. await uni.$u.api.deleteClueFile([id])
  257. uni.showToast({
  258. title: '删除成功',
  259. icon: 'success'
  260. })
  261. this.loadCallRecords()
  262. } catch (error) {
  263. uni.showToast({
  264. title: '删除失败',
  265. icon: 'error'
  266. })
  267. }
  268. }
  269. }
  270. })
  271. },
  272. /**
  273. * 预览图片
  274. */
  275. previewImage(src) {
  276. const urlList = this.chatRecordsList.map(item => item.fileUrl)
  277. uni.previewImage({
  278. urls: urlList,
  279. current: src
  280. })
  281. },
  282. /**
  283. * 预览实物图
  284. */
  285. previewTrueImage(src) {
  286. const urlList = this.truePicList.map(item => item.fileUrl)
  287. uni.previewImage({
  288. urls: urlList,
  289. current: src
  290. })
  291. },
  292. //一键复制
  293. handleSaveAllImages() {
  294. // 合并所有图片
  295. const allImages = [...this.truePicList]
  296. //取出所有图的url
  297. const allUrls = allImages.map(item => item.fileUrl)
  298. if (allUrls.length > 0) {
  299. // 显示保存图片确认弹窗
  300. uni.showModal({
  301. title: '保存图片',
  302. content: `是否将 ${allUrls.length} 张图片保存到本地相册?`,
  303. confirmText: '保存',
  304. // cancelText: '仅复制链接',
  305. success: (res) => {
  306. if (res.confirm) {
  307. // 用户选择保存图片
  308. this.saveImagesToLocal(allUrls)
  309. } else if (res.cancel) {
  310. // 用户选择仅复制链接
  311. this.copyImageUrls(allUrls)
  312. }
  313. }
  314. })
  315. } else {
  316. uni.showToast({
  317. title: '没有图片可保存',
  318. icon: 'none'
  319. })
  320. }
  321. },
  322. // 保存图片到本地相册
  323. async saveImagesToLocal(imageUrls) {
  324. try {
  325. uni.showLoading({
  326. title: '正在保存图片...',
  327. mask: true
  328. })
  329. const savedImages = []
  330. const failedImages = []
  331. // 逐个保存图片
  332. for (let i = 0; i < imageUrls.length; i++) {
  333. const url = imageUrls[i]
  334. try {
  335. await this.saveSingleImage(url)
  336. savedImages.push(url)
  337. } catch (error) {
  338. console.error(`保存图片失败: ${url}`, error)
  339. failedImages.push(url)
  340. }
  341. // 更新进度
  342. uni.showLoading({
  343. title: `正在保存图片... (${i + 1}/${imageUrls.length})`,
  344. mask: true
  345. })
  346. }
  347. uni.hideLoading()
  348. // 显示结果
  349. let message = `成功保存 ${savedImages.length} 张图片`
  350. if (failedImages.length > 0) {
  351. message += `,${failedImages.length} 张保存失败`
  352. }
  353. uni.showToast({
  354. title: message,
  355. icon: 'none',
  356. duration: 3000
  357. })
  358. // 如果有失败的图片,也复制链接作为备选
  359. if (failedImages.length > 0) {
  360. const allUrls = [...savedImages, ...failedImages]
  361. this.copyImageUrls(allUrls)
  362. }
  363. } catch (error) {
  364. uni.hideLoading()
  365. console.error('保存图片过程中发生错误:', error)
  366. uni.showToast({
  367. title: '保存图片失败',
  368. icon: 'error'
  369. })
  370. }
  371. },
  372. // 保存单张图片
  373. saveSingleImage(url) {
  374. return new Promise((resolve, reject) => {
  375. // 先下载图片
  376. uni.downloadFile({
  377. url: url,
  378. success: (res) => {
  379. if (res.statusCode === 200) {
  380. // 保存到相册
  381. uni.saveImageToPhotosAlbum({
  382. filePath: res.tempFilePath,
  383. success: () => {
  384. console.log('图片保存成功:', url)
  385. resolve()
  386. },
  387. fail: (err) => {
  388. console.error('保存到相册失败:', err)
  389. // 如果是权限问题,尝试请求权限
  390. if (err.errMsg.includes('auth denied')) {
  391. uni.showModal({
  392. title: '权限不足',
  393. content: '需要访问相册权限来保存图片,是否去设置?',
  394. success: (modalRes) => {
  395. if (modalRes.confirm) {
  396. // 打开设置页面
  397. uni.openSetting({
  398. success: (settingRes) => {
  399. console.log('设置页面结果:', settingRes)
  400. }
  401. })
  402. }
  403. }
  404. })
  405. }
  406. reject(err)
  407. }
  408. })
  409. } else {
  410. reject(new Error('下载失败'))
  411. }
  412. },
  413. fail: (err) => {
  414. console.error('下载图片失败:', err)
  415. reject(err)
  416. }
  417. })
  418. })
  419. },
  420. // 复制图片链接
  421. copyImageUrls(urls) {
  422. uni.setClipboardData({
  423. data: JSON.stringify(urls),
  424. success: () => {
  425. uni.showToast({
  426. title: '图片链接已复制',
  427. icon: 'none'
  428. })
  429. }
  430. })
  431. },
  432. /**
  433. * 电话点击
  434. */
  435. handlePhoneClick() {
  436. if (!this.orderDetail.phone) {
  437. uni.showToast({
  438. title: '该订单暂时没有电话号码',
  439. icon: 'none'
  440. })
  441. return
  442. }
  443. uni.makePhoneCall({
  444. phoneNumber: this.orderDetail.phone,
  445. success: () => {
  446. this.$store.commit('call/SET_FORM', {
  447. clueId: this.orderDetail.clueId,
  448. type: '3',
  449. callee: this.orderDetail.phone
  450. })
  451. }
  452. })
  453. },
  454. /**
  455. * 微信点击
  456. */
  457. handleWechatClick() {
  458. if (!this.orderDetail.wechat) {
  459. uni.showToast({
  460. title: '该订单暂时没有微信号',
  461. icon: 'none'
  462. })
  463. return
  464. }
  465. uni.setClipboardData({
  466. data: this.orderDetail.wechat,
  467. success: () => {
  468. uni.showToast({
  469. title: '微信号已复制',
  470. icon: 'none'
  471. })
  472. }
  473. })
  474. },
  475. /**
  476. * 下一步
  477. */
  478. handleNext() {
  479. this.$emit('next', {
  480. nowPage: 'formOne',
  481. form: {}
  482. })
  483. }
  484. }
  485. }
  486. </script>
  487. <style scoped lang="scss">
  488. @import '../styles/common.scss';
  489. .page-one-container {
  490. @extend .page-container;
  491. padding-bottom: 100rpx;
  492. }
  493. .page-header {
  494. display: flex;
  495. justify-content: space-between;
  496. align-items: center;
  497. margin-bottom: 20rpx;
  498. }
  499. .page-title {
  500. @include font-styles($size: title, $weight: bold, $color: primary);
  501. }
  502. .save-all-btn {
  503. border-radius: 20rpx;
  504. border-color: #007AFF;
  505. color: #007AFF;
  506. }
  507. .card-wrap {
  508. @extend .card-wrap;
  509. margin-top: 20rpx;
  510. }
  511. .card-title {
  512. padding: 20rpx 15rpx;
  513. border-bottom: 1rpx solid map-get($colors, border);
  514. display: flex;
  515. align-items: center;
  516. white-space: nowrap;
  517. overflow-x: auto;
  518. -webkit-overflow-scrolling: touch;
  519. text {
  520. padding: 0 6rpx;
  521. cursor: pointer;
  522. font-size: 26rpx;
  523. white-space: nowrap;
  524. flex-shrink: 0;
  525. &.active {
  526. color: map-get($colors, primary);
  527. font-weight: bold;
  528. }
  529. }
  530. .divider {
  531. margin: 0 4rpx;
  532. color: #ddd;
  533. font-size: 24rpx;
  534. flex-shrink: 0;
  535. }
  536. }
  537. .image-upload-container {
  538. padding: 20rpx;
  539. }
  540. .image-list {
  541. display: flex;
  542. flex-wrap: wrap;
  543. gap: 20rpx;
  544. }
  545. .image-item {
  546. position: relative;
  547. width: 200rpx;
  548. height: 200rpx;
  549. box-sizing: border-box;
  550. }
  551. .delete-btn {
  552. position: absolute;
  553. top: -10rpx;
  554. right: -10rpx;
  555. width: 40rpx;
  556. height: 40rpx;
  557. background-color: #ff4d4f;
  558. color: #fff;
  559. border-radius: 50%;
  560. display: flex;
  561. align-items: center;
  562. justify-content: center;
  563. font-size: 30rpx;
  564. font-weight: bold;
  565. z-index: 10;
  566. cursor: pointer;
  567. }
  568. .upload-btn {
  569. width: 200rpx;
  570. height: 200rpx;
  571. border: 8rpx dashed #ddd;
  572. border-radius: 30rpx;
  573. display: flex;
  574. align-items: center;
  575. justify-content: center;
  576. background-color: #f9f9f9;
  577. box-sizing: border-box;
  578. cursor: pointer;
  579. }
  580. .call-records-container {
  581. padding: 20rpx;
  582. }
  583. .info-card {
  584. @extend .card-wrap;
  585. padding: 20rpx;
  586. margin-top: 20rpx;
  587. box-sizing: border-box;
  588. width: 100%;
  589. max-width: 100%;
  590. }
  591. .info-card-title {
  592. @include font-styles($size: title, $weight: bold, $color: primary);
  593. margin-bottom: 25rpx;
  594. padding-bottom: 15rpx;
  595. border-bottom: 1rpx solid map-get($colors, border);
  596. }
  597. .info-row {
  598. margin-bottom: 20rpx;
  599. }
  600. .info-label {
  601. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  602. margin-bottom: 8rpx;
  603. }
  604. .info-value {
  605. @include font-styles($size: small, $weight: regular, $color: secondary);
  606. word-break: break-all;
  607. }
  608. .contact-card {
  609. display: flex;
  610. justify-content: space-between;
  611. margin: 20rpx 0;
  612. gap: 20rpx;
  613. }
  614. .contact-item {
  615. flex: 1;
  616. @extend .card-wrap;
  617. padding: 20rpx;
  618. display: flex;
  619. flex-direction: column;
  620. align-items: center;
  621. position: relative;
  622. cursor: pointer;
  623. }
  624. .contact-title {
  625. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  626. margin-top: 10rpx;
  627. }
  628. .red-dot {
  629. position: absolute;
  630. top: 15rpx;
  631. right: 15rpx;
  632. width: 25rpx;
  633. height: 25rpx;
  634. background-color: #ff4d4f;
  635. border-radius: 50%;
  636. box-shadow: 0 0 4rpx rgba(255, 77, 79, 0.3);
  637. }
  638. .space-block {
  639. height: 100rpx;
  640. }
  641. .next-btn {
  642. position: fixed;
  643. bottom: 10rpx;
  644. left: 2.5%;
  645. width: 95%;
  646. height: 80rpx;
  647. line-height: 80rpx;
  648. text-align: center;
  649. border-radius: 20rpx;
  650. }
  651. .detail-image-header {
  652. display: flex;
  653. justify-content: space-between;
  654. align-items: center;
  655. width: 100%;
  656. border-bottom: 1rpx solid map-get($colors, border);
  657. }
  658. .detail-image-title {
  659. @include font-styles($size: content, $weight: bold, $color: primary);
  660. }
  661. .copy-btn {
  662. border-radius: 20rpx;
  663. border: 1rpx solid #007AFF;
  664. background-color: transparent;
  665. color: #007AFF;
  666. padding: 0 24rpx;
  667. height: 64rpx;
  668. line-height: 64rpx;
  669. cursor: pointer;
  670. }
  671. </style>