pageOne.vue 16 KB

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