pageOne.vue 18 KB

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