pageOne.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <view class="page-itemOne">
  3. <u-row justify="space-between" customStyle="margin-bottom: 10px">
  4. <u-col span="3">
  5. <div class="page-itemOne-title">图片资料</div>
  6. </u-col>
  7. <u-col span="3.5">
  8. <u-button size="small" @click="copyAllImages"
  9. style="border-radius: 20rpx;border-color: #007AFF;color: #007AFF;">保存全部图片</u-button>
  10. </u-col>
  11. </u-row>
  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 class="image-item" v-for="(item, index) in trueUploadList" :key="'truePic-' + index">
  18. <pic-comp @needPreviewPic='previewImageTrue' :src="item.fileUrl"></pic-comp>
  19. <view class="delete-btn" @click="deleteImage(item)">×</view>
  20. </view>
  21. <view class="upload-btn" @click="uploadImage('truePic', currentReceipt.id)">
  22. <u-icon name="plus" size="40" color="#999"></u-icon>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 聊天记录卡片 -->
  28. <view class="card_wrap">
  29. <view class="card-title">
  30. <text @click="chatRecordOrCallRecord = 'chatRecords'">聊天记录</text>
  31. <text style="margin: 0 10rpx;">|</text>
  32. <text @click="chatRecordOrCallRecord = 'callRecords'">通话记录</text>
  33. </view>
  34. <!-- 聊天记录卡片 -->
  35. <view class="image-upload-container" v-if="chatRecordOrCallRecord === 'chatRecords'">
  36. <view class="image-list">
  37. <view class="image-item" v-for="(item, index) in chatRecordsUploadList"
  38. :key="'chatRecords-' + index">
  39. <pic-comp @needPreviewPic='previewImageChat' :src="item.fileUrl"></pic-comp>
  40. <view class="delete-btn" @click="deleteImage(item)">×</view>
  41. </view>
  42. <view class="upload-btn" @click="uploadImage('chatRecords', currentReceipt.id)">
  43. <u-icon name="plus" size="40" color="#999"></u-icon>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 通话录音卡片 -->
  48. <view class="image-upload-container" v-if="chatRecordOrCallRecord === 'callRecords'">
  49. <view>
  50. <sound-recorder v-for="item in soundRecordList" :key="item.fileName" :data="item"
  51. @handleDelectThisSoundRecord='handleDelectThisSoundRecord'></sound-recorder>
  52. <!-- <view class="add-btn" @click="addCallRecord">添加通话记录</view> -->
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 基本信息卡片 -->
  57. <view class="info-card">
  58. <view class="info-card-title">基本信息</view>
  59. <u-row class="info-row">
  60. <u-col span="6">
  61. <view class="info-label">发单人</view>
  62. <view class="info-value">{{ orderDetail.createNickName || '未填写' }}</view>
  63. </u-col>
  64. <u-col span="6">
  65. <view class="info-label">型号</view>
  66. <view class="info-value">{{ orderDetail.model || '未填写' }}</view>
  67. </u-col>
  68. </u-row>
  69. <u-row class="info-row">
  70. <u-col span="6">
  71. <view class="info-label">上门时间</view>
  72. <view class="info-value">{{ orderDetail.visitTime || '未填写' }}</view>
  73. </u-col>
  74. <u-col span="6">
  75. <view class="info-label">地址</view>
  76. <view class="info-value">{{ orderDetail.address || '未填写' }}</view>
  77. </u-col>
  78. </u-row>
  79. </view>
  80. <!-- 联系方式卡片 -->
  81. <view class="connect">
  82. <view class="connect-card phone-card" @click="handlePhoneClick">
  83. <u-icon name="phone" size="40" color="#07C160" style="margin-bottom: 10rpx;"></u-icon>
  84. <view class="connect-title">电话</view>
  85. <!-- 小红点 -->
  86. <view v-if="orderDetail.phone" class="red-dot"></view>
  87. </view>
  88. <view class="connect-card wechat-card" @click="handleWechatClick">
  89. <u-icon name="chat" size="40" color="#07C160" style="margin-bottom: 10rpx;"></u-icon>
  90. <view class="connect-title">微信</view>
  91. <!-- 小红点 -->
  92. <view v-if="orderDetail.wechat" class="red-dot"></view>
  93. </view>
  94. </view>
  95. <view class="space-block">
  96. </view>
  97. <u-button class='next-btn' @click="handleNextClick" type="primary" size="middle"
  98. style="border-radius: 20rpx;">下一步</u-button>
  99. </view>
  100. </template>
  101. <script>
  102. import picComp from './picComp.vue'
  103. import imgUploadAndDownLoad from '../mixin/imgUploadAndDownLoad.js'
  104. import soundRecorder from '@/components/soundRecorder/soundRecorder.vue'
  105. export default {
  106. mixins: [imgUploadAndDownLoad],
  107. props: {
  108. orderDetail: {
  109. type: Object,
  110. default: () => { },
  111. },
  112. orderId: {
  113. type: String,
  114. default: '',
  115. },
  116. currentReceipt: {
  117. type: Object,
  118. default: () => { },
  119. },
  120. },
  121. components: {
  122. picComp, soundRecorder
  123. },
  124. data() {
  125. return {
  126. //展示的图片列表
  127. trueUploadList: [],
  128. chatRecordsUploadList: [],
  129. // 待绑定的图片列表
  130. bindList: [],
  131. chatRecordOrCallRecord: 'chatRecords',
  132. soundRecordList: [],//录音记录
  133. }
  134. },
  135. watch: {
  136. // 监听 props 变化,触发请求
  137. orderDetail: {
  138. handler(newVal) {
  139. if (newVal) {
  140. console.log('orderDetail 变化了', newVal);
  141. }
  142. }
  143. },
  144. currentReceipt: {
  145. handler(newVal) {
  146. console.log('currentReceipt 变化了', newVal);
  147. if (newVal) {
  148. //刷新图片列表
  149. setTimeout(() => {
  150. this.getList('2', '1', newVal.id, this.orderDetail.itemBrand);
  151. this.getList('2', '2', newVal.id, this.orderDetail.itemBrand);
  152. this.getCallRecords();
  153. }, 100)
  154. }
  155. }
  156. },
  157. },
  158. methods: {
  159. // 电话卡片点击事件
  160. handlePhoneClick() {
  161. console.log('电话卡片被点击', '电话号码:', this.orderDetail.phone)
  162. if (this.orderDetail.phone) {
  163. uni.makePhoneCall({
  164. phoneNumber: this.orderDetail.phone,
  165. success: () => {
  166. this.$store.commit("call/SET_FORM", {
  167. clueId: this.orderDetail.clueId,
  168. type: "3",
  169. callee: this.orderDetail.phone,
  170. });
  171. console.log('this.currentReceipt333', this.$store.state.call.form.callee)
  172. },
  173. });
  174. //先暂时复制电话号码
  175. // uni.setClipboardData({
  176. // data: this.orderDetail.phone,
  177. // success: () => {
  178. // uni.showToast({
  179. // title: '电话号码已复制',
  180. // icon: 'none'
  181. // })
  182. // }
  183. // })
  184. } else {
  185. uni.showToast({
  186. title: '该订单暂时没有电话号码',
  187. icon: 'none'
  188. })
  189. }
  190. },
  191. // 微信卡片点击事件
  192. handleWechatClick() {
  193. console.log('微信卡片被点击', '微信号:', this.orderDetail.wechat)
  194. if (this.orderDetail.wechat) {
  195. //复制微信号
  196. uni.setClipboardData({
  197. data: this.orderDetail.wechat,
  198. success: () => {
  199. uni.showToast({
  200. title: '微信号已复制',
  201. icon: 'none'
  202. })
  203. }
  204. })
  205. } else {
  206. uni.showToast({
  207. title: '该订单暂时没有微信号',
  208. icon: 'none'
  209. })
  210. }
  211. },
  212. // 下一步
  213. handleNextClick() {
  214. // 校验表单
  215. // if (!this.form.truePic.length) {
  216. // uni.showToast({
  217. // title: '请上传实物图',
  218. // icon: 'none'
  219. // })
  220. // return
  221. // }
  222. // if (!this.form.chatRecords.length) {
  223. // uni.showToast({
  224. // title: '请上传聊天记录',
  225. // icon: 'none'
  226. // })
  227. // return
  228. // }
  229. this.$emit('handleNextClick', {
  230. nowPage: 'formOne',
  231. form: this.form,
  232. })
  233. },
  234. //一键复制
  235. copyAllImages() {
  236. // 合并所有图片
  237. const allImages = [...this.trueUploadList];
  238. //取出所有图的url
  239. const allUrls = allImages.map(item => item.fileUrl);
  240. if (allUrls.length > 0) {
  241. // 显示保存图片确认弹窗
  242. uni.showModal({
  243. title: '保存图片',
  244. content: `是否将 ${allUrls.length} 张图片保存到本地相册?`,
  245. confirmText: '保存',
  246. // cancelText: '仅复制链接',
  247. success: (res) => {
  248. if (res.confirm) {
  249. // 用户选择保存图片
  250. this.saveImagesToLocal(allUrls);
  251. } else if (res.cancel) {
  252. // 用户选择仅复制链接
  253. this.copyImageUrls(allUrls);
  254. }
  255. }
  256. })
  257. } else {
  258. uni.showToast({
  259. title: '没有图片可保存',
  260. icon: 'none'
  261. })
  262. }
  263. },
  264. // 保存图片到本地相册
  265. async saveImagesToLocal(imageUrls) {
  266. try {
  267. uni.showLoading({
  268. title: '正在保存图片...',
  269. mask: true
  270. });
  271. const savedImages = [];
  272. const failedImages = [];
  273. // 逐个保存图片
  274. for (let i = 0; i < imageUrls.length; i++) {
  275. const url = imageUrls[i];
  276. try {
  277. await this.saveSingleImage(url);
  278. savedImages.push(url);
  279. } catch (error) {
  280. console.error(`保存图片失败: ${url}`, error);
  281. failedImages.push(url);
  282. }
  283. // 更新进度
  284. uni.showLoading({
  285. title: `正在保存图片... (${i + 1}/${imageUrls.length})`,
  286. mask: true
  287. });
  288. }
  289. uni.hideLoading();
  290. // 显示结果
  291. let message = `成功保存 ${savedImages.length} 张图片`;
  292. if (failedImages.length > 0) {
  293. message += `,${failedImages.length} 张保存失败`;
  294. }
  295. uni.showToast({
  296. title: message,
  297. icon: 'none',
  298. duration: 3000
  299. });
  300. // 如果有失败的图片,也复制链接作为备选
  301. if (failedImages.length > 0) {
  302. const allUrls = [...savedImages, ...failedImages];
  303. this.copyImageUrls(allUrls);
  304. }
  305. } catch (error) {
  306. uni.hideLoading();
  307. console.error('保存图片过程中发生错误:', error);
  308. uni.showToast({
  309. title: '保存图片失败',
  310. icon: 'error'
  311. });
  312. }
  313. },
  314. // 保存单张图片
  315. saveSingleImage(url) {
  316. return new Promise((resolve, reject) => {
  317. // 先下载图片
  318. uni.downloadFile({
  319. url: url,
  320. success: (res) => {
  321. if (res.statusCode === 200) {
  322. // 保存到相册
  323. uni.saveImageToPhotosAlbum({
  324. filePath: res.tempFilePath,
  325. success: () => {
  326. console.log('图片保存成功:', url);
  327. resolve();
  328. },
  329. fail: (err) => {
  330. console.error('保存到相册失败:', err);
  331. // 如果是权限问题,尝试请求权限
  332. if (err.errMsg.includes('auth denied')) {
  333. uni.showModal({
  334. title: '权限不足',
  335. content: '需要访问相册权限来保存图片,是否去设置?',
  336. success: (modalRes) => {
  337. if (modalRes.confirm) {
  338. // 打开设置页面
  339. uni.openSetting({
  340. success: (settingRes) => {
  341. console.log('设置页面结果:', settingRes);
  342. }
  343. });
  344. }
  345. }
  346. });
  347. }
  348. reject(err);
  349. }
  350. });
  351. } else {
  352. reject(new Error('下载失败'));
  353. }
  354. },
  355. fail: (err) => {
  356. console.error('下载图片失败:', err);
  357. reject(err);
  358. }
  359. });
  360. });
  361. },
  362. // 复制图片链接
  363. copyImageUrls(urls) {
  364. uni.setClipboardData({
  365. data: JSON.stringify(urls),
  366. success: () => {
  367. uni.showToast({
  368. title: '图片链接已复制',
  369. icon: 'none'
  370. })
  371. }
  372. })
  373. },
  374. // 预览真实图片
  375. previewImageTrue(src) {
  376. const urlList = this.trueUploadList.map(item => item.fileUrl);
  377. uni.previewImage({
  378. urls: urlList,
  379. current: src
  380. })
  381. },
  382. previewImageChat(src) {
  383. const urlList = this.chatRecordsUploadList.map(item => item.fileUrl);
  384. uni.previewImage({
  385. urls: urlList,
  386. current: src
  387. })
  388. },
  389. //获取通话记录
  390. async getCallRecords() {
  391. console.log('这里是参数', this.currentReceipt.clueId);
  392. const { data } = await uni.$u.api.getCallClueFileByClueId({ clueId: this.currentReceipt.clueId });
  393. // const { data } = await uni.$u.api.getCallClueFileByClueId({ clueId: '1998278069905854466' });
  394. console.log('通话记录:', data);
  395. this.soundRecordList = data;
  396. },
  397. //删除录音
  398. handleDelectThisSoundRecord({ id }) {
  399. console.log('当前需要删除的录音的id是', id)
  400. uni.showModal({
  401. title: '提示',
  402. content: '是否确定删除?',
  403. confirmColor: '#6cc040',
  404. success: async (res) => {
  405. if (res.confirm) {
  406. try {
  407. await uni.$u.api.deleteClueFile([id])
  408. uni.showToast({
  409. title: '删除成功',
  410. icon: 'success',
  411. duration: 2000
  412. })
  413. this.getData()
  414. } catch (error) {
  415. uni.showToast({
  416. title: '删除失败',
  417. icon: 'error',
  418. duration: 2000
  419. })
  420. }
  421. }
  422. }
  423. })
  424. },
  425. },
  426. }
  427. </script>
  428. <style scoped lang="scss">
  429. // 导入公共样式
  430. @import './common.scss';
  431. // 主样式
  432. .page-itemOne {
  433. @extend .page-container;
  434. }
  435. .page-itemOne-title {
  436. @include font-styles($size: title, $weight: bold, $color: primary);
  437. }
  438. .page-itemOne-form {
  439. @include font-styles($size: tiny, $weight: semi-bold, $color: secondary);
  440. text-wrap: nowrap;
  441. }
  442. .image-upload-container {
  443. padding: map-get($sizes, padding-sm) map-get($sizes, padding);
  444. }
  445. .image-list {
  446. display: flex;
  447. flex-wrap: wrap;
  448. gap: 20rpx;
  449. }
  450. .image-item {
  451. position: relative;
  452. width: 200rpx;
  453. height: 200rpx;
  454. box-sizing: border-box;
  455. }
  456. .delete-btn {
  457. position: absolute;
  458. top: -10rpx;
  459. right: -10rpx;
  460. width: 40rpx;
  461. height: 40rpx;
  462. background-color: #ff4d4f;
  463. color: #fff;
  464. border-radius: 50%;
  465. display: flex;
  466. align-items: center;
  467. justify-content: center;
  468. @include font-styles($size: tiny, $weight: bold);
  469. z-index: 10;
  470. }
  471. .upload-btn {
  472. width: 200rpx;
  473. height: 200rpx;
  474. border: 8rpx dashed #ddd;
  475. border-radius: 30rpx;
  476. display: flex;
  477. align-items: center;
  478. justify-content: center;
  479. background-color: #f9f9f9;
  480. box-sizing: border-box;
  481. }
  482. /* 基本信息卡片样式 */
  483. .info-card {
  484. @include card;
  485. margin-top: 20rpx;
  486. margin-bottom: 20rpx;
  487. padding: map-get($sizes, padding-sm) map-get($sizes, padding);
  488. &:hover {
  489. @include shadow(2);
  490. }
  491. }
  492. .info-card-title {
  493. @include font-styles($size: title, $weight: bold, $color: primary);
  494. margin-bottom: 25rpx;
  495. padding-bottom: 15rpx;
  496. border-bottom: 1rpx solid map-get($colors, border);
  497. }
  498. .info-row {
  499. margin-bottom: 20rpx;
  500. }
  501. .info-label {
  502. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  503. margin-bottom: 8rpx;
  504. }
  505. .info-value {
  506. @include font-styles($size: small, $weight: regular, $color: secondary, $line-height: small);
  507. word-break: break-all;
  508. }
  509. /* 联系方式卡片样式 */
  510. .connect {
  511. display: flex;
  512. justify-content: space-between;
  513. margin: 20rpx 0;
  514. gap: 20rpx;
  515. }
  516. .connect-card {
  517. flex: 1;
  518. @include card;
  519. padding: 10rpx;
  520. display: flex;
  521. flex-direction: column;
  522. align-items: center;
  523. box-sizing: border-box;
  524. position: relative;
  525. &:hover {
  526. @include shadow(2);
  527. }
  528. }
  529. .connect-title {
  530. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  531. margin-bottom: 8rpx;
  532. }
  533. .connect-value {
  534. @include font-styles($size: small, $weight: medium, $color: secondary);
  535. }
  536. /* 小红点样式 */
  537. .red-dot {
  538. position: absolute;
  539. top: 15rpx;
  540. right: 15rpx;
  541. width: 25rpx;
  542. height: 25rpx;
  543. background-color: #ff4d4f;
  544. border-radius: 50%;
  545. box-shadow: 0 0 4rpx rgba(255, 77, 79, 0.3);
  546. }
  547. .next-btn {
  548. position: fixed;
  549. bottom: 10rpx;
  550. left: 2.5%;
  551. width: 95%;
  552. height: 80rpx;
  553. line-height: 80rpx;
  554. text-align: center;
  555. @include font-styles($size: medium, $weight: bold, $color: #fff);
  556. border-radius: 0rpx 0rpx 20rpx 20rpx;
  557. }
  558. .space-block {
  559. height: 80rpx;
  560. }
  561. </style>