PageOne.vue 18 KB

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