PageOne.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. 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. // phoneNumber:'13813737524',//开发者测试手机号
  446. success: () => {
  447. this.$store.commit('call/SET_FORM', {
  448. clueId: this.orderDetail.clueId,
  449. type: '3',
  450. callee: this.orderDetail.phone
  451. })
  452. }
  453. })
  454. },
  455. /**
  456. * 微信点击
  457. */
  458. handleWechatClick() {
  459. if (!this.orderDetail.wechat) {
  460. uni.showToast({
  461. title: '该订单暂时没有微信号',
  462. icon: 'none'
  463. })
  464. return
  465. }
  466. uni.setClipboardData({
  467. data: this.orderDetail.wechat,
  468. success: () => {
  469. uni.showToast({
  470. title: '微信号已复制',
  471. icon: 'none'
  472. })
  473. }
  474. })
  475. },
  476. /**
  477. * 下一步
  478. */
  479. handleNext() {
  480. this.$emit('next', {
  481. nowPage: 'formOne',
  482. form: {}
  483. })
  484. }
  485. }
  486. }
  487. </script>
  488. <style scoped lang="scss">
  489. @import '../styles/common.scss';
  490. .page-one-container {
  491. @extend .page-container;
  492. padding-bottom: 100rpx;
  493. }
  494. .page-header {
  495. display: flex;
  496. justify-content: space-between;
  497. align-items: center;
  498. margin-bottom: 20rpx;
  499. }
  500. .page-title {
  501. @include font-styles($size: title, $weight: bold, $color: primary);
  502. }
  503. .save-all-btn {
  504. border-radius: 20rpx;
  505. border-color: #007AFF;
  506. color: #007AFF;
  507. }
  508. .card-wrap {
  509. @extend .card-wrap;
  510. margin-top: 20rpx;
  511. }
  512. .card-title {
  513. padding: 20rpx 15rpx;
  514. border-bottom: 1rpx solid map-get($colors, border);
  515. display: flex;
  516. align-items: center;
  517. white-space: nowrap;
  518. overflow-x: auto;
  519. -webkit-overflow-scrolling: touch;
  520. text {
  521. padding: 0 6rpx;
  522. cursor: pointer;
  523. font-size: 26rpx;
  524. white-space: nowrap;
  525. flex-shrink: 0;
  526. &.active {
  527. color: map-get($colors, primary);
  528. font-weight: bold;
  529. }
  530. }
  531. .divider {
  532. margin: 0 4rpx;
  533. color: #ddd;
  534. font-size: 24rpx;
  535. flex-shrink: 0;
  536. }
  537. }
  538. .image-upload-container {
  539. padding: 20rpx;
  540. }
  541. .image-list {
  542. display: flex;
  543. flex-wrap: wrap;
  544. gap: 20rpx;
  545. }
  546. .image-item {
  547. position: relative;
  548. width: 200rpx;
  549. height: 200rpx;
  550. box-sizing: border-box;
  551. }
  552. .delete-btn {
  553. position: absolute;
  554. top: -10rpx;
  555. right: -10rpx;
  556. width: 40rpx;
  557. height: 40rpx;
  558. background-color: #ff4d4f;
  559. color: #fff;
  560. border-radius: 50%;
  561. display: flex;
  562. align-items: center;
  563. justify-content: center;
  564. font-size: 30rpx;
  565. font-weight: bold;
  566. z-index: 10;
  567. cursor: pointer;
  568. }
  569. .upload-btn {
  570. width: 200rpx;
  571. height: 200rpx;
  572. border: 8rpx dashed #ddd;
  573. border-radius: 30rpx;
  574. display: flex;
  575. align-items: center;
  576. justify-content: center;
  577. background-color: #f9f9f9;
  578. box-sizing: border-box;
  579. cursor: pointer;
  580. }
  581. .call-records-container {
  582. padding: 20rpx;
  583. }
  584. .info-card {
  585. @extend .card-wrap;
  586. padding: 20rpx;
  587. margin-top: 20rpx;
  588. box-sizing: border-box;
  589. width: 100%;
  590. max-width: 100%;
  591. }
  592. .info-card-title {
  593. @include font-styles($size: title, $weight: bold, $color: primary);
  594. margin-bottom: 25rpx;
  595. padding-bottom: 15rpx;
  596. border-bottom: 1rpx solid map-get($colors, border);
  597. }
  598. .info-row {
  599. margin-bottom: 20rpx;
  600. }
  601. .info-label {
  602. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  603. margin-bottom: 8rpx;
  604. }
  605. .info-value {
  606. @include font-styles($size: small, $weight: regular, $color: secondary);
  607. word-break: break-all;
  608. }
  609. .contact-card {
  610. display: flex;
  611. justify-content: space-between;
  612. margin: 20rpx 0;
  613. gap: 20rpx;
  614. }
  615. .contact-item {
  616. flex: 1;
  617. @extend .card-wrap;
  618. padding: 20rpx;
  619. display: flex;
  620. flex-direction: column;
  621. align-items: center;
  622. position: relative;
  623. cursor: pointer;
  624. }
  625. .contact-title {
  626. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  627. margin-top: 10rpx;
  628. }
  629. .red-dot {
  630. position: absolute;
  631. top: 15rpx;
  632. right: 15rpx;
  633. width: 25rpx;
  634. height: 25rpx;
  635. background-color: #ff4d4f;
  636. border-radius: 50%;
  637. box-shadow: 0 0 4rpx rgba(255, 77, 79, 0.3);
  638. }
  639. .space-block {
  640. height: 100rpx;
  641. }
  642. .next-btn {
  643. position: fixed;
  644. bottom: 10rpx;
  645. left: 2.5%;
  646. width: 95%;
  647. height: 80rpx;
  648. line-height: 80rpx;
  649. text-align: center;
  650. border-radius: 20rpx;
  651. }
  652. .detail-image-header {
  653. display: flex;
  654. justify-content: space-between;
  655. align-items: center;
  656. width: 100%;
  657. border-bottom: 1rpx solid map-get($colors, border);
  658. }
  659. .detail-image-title {
  660. @include font-styles($size: content, $weight: bold, $color: primary);
  661. }
  662. .copy-btn {
  663. border-radius: 20rpx;
  664. border: 1rpx solid #007AFF;
  665. background-color: transparent;
  666. color: #007AFF;
  667. padding: 0 24rpx;
  668. height: 64rpx;
  669. line-height: 64rpx;
  670. cursor: pointer;
  671. }
  672. </style>