pageOne.vue 19 KB

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