pageOne.vue 19 KB

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