detail.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <template>
  2. <view class="detail" @click="handleClickOutside">
  3. <u-navbar class="nav_bar" title="商品详情档案" :autoBack="true" :placeholder="true" rightIcon="more-dot-fill"
  4. v-hideNav></u-navbar>
  5. <u-swiper :list="imgsUrl" keyName="url" indicator indicatorMode="line" circular>
  6. <!-- <template v-slot:item="{ item, index }">
  7. <view style="width: 100%; height: 600rpx;">
  8. <image :src="item.url" mode="aspectFill" style="width: 100%; height: 100%; object-fit: cover;"></image>
  9. </view>
  10. </template> -->
  11. </u-swiper>
  12. <!-- 立即下架按钮 -->
  13. <view class="immediate_off_shelf">
  14. <u-button type="error" shape="circle" size="large" @click="handleOffShelf" :disabled="lockStatus === '1' || globalEditMode">
  15. <u-icon :name="downStatus == '0' ? 'arrow-upward' : 'arrow-downward'" size="38rpx"
  16. color="#ffffff"></u-icon>
  17. <text>{{ downStatus == '0' ? '立即上架' : '立即下架' }}</text>
  18. </u-button>
  19. </view>
  20. <!-- 轮播图下方操作按钮 -->
  21. <view class="swiper_actions">
  22. <view class="action_item" @click="handleDownload">
  23. <u-icon name="download" size="44rpx" color="#606266"></u-icon>
  24. <text class="action_text">下载图文</text>
  25. </view>
  26. <view class="action_item" @click="handleShare">
  27. <u-icon name="share" size="44rpx" color="#606266"></u-icon>
  28. <text class="action_text">分享</text>
  29. </view>
  30. <view class="action_item" @click="handleEditImgs">
  31. <u-icon name="camera" size="44rpx" color="#606266"></u-icon>
  32. <text class="action_text">编辑图片</text>
  33. <u-modal :show="showEditImgsModal" title="编辑图片" showCancelButton @confirm="confirmEditImgs" @cancel="cancelEditImgs">
  34. <imgs-row-scroll v-if="tempImgsUrl.length > 0" :isShowDeleteIcon="true" keyName="url"
  35. @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="tempImgsUrl"
  36. :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  37. <u-upload @afterRead="afterRead" multiple></u-upload>
  38. </u-modal>
  39. </view>
  40. <view class="action_item" @click="handleCutImg">
  41. <u-icon name="cut" size="44rpx" color="#606266"></u-icon>
  42. <text class="action_text">智能抠图</text>
  43. </view>
  44. </view>
  45. <!-- 核心信息区域 -->
  46. <view class="core_info">
  47. <view class="section_title">核心信息</view>
  48. <view class="info_row">
  49. <view class="info_label">品牌</view>
  50. <view class="info_value" @click.stop="showBrandlList()">
  51. <!-- <u-input v-if="editMode.dictLabel" v-model="tempValues.dictLabel" :autoFocus="true" @blur="!globalEditMode && saveEditField('dictLabel', tempValues.dictLabel, 'dictLabel')" /> -->
  52. <span>{{ coreInfo.dictLabel || '-' }}</span>
  53. <BrandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></BrandList>
  54. </view>
  55. </view>
  56. <view class="info_row">
  57. <view class="info_label">型号</view>
  58. <view class="info_value" @click.stop="toggleEditField('model', coreInfo.model)">
  59. <u-input v-if="editMode.model" v-model="tempValues.model" :autoFocus="true"
  60. @blur="!globalEditMode && saveEditField('model', tempValues.model, 'model')" />
  61. <span v-else>{{ coreInfo.model || '-' }}</span>
  62. </view>
  63. </view>
  64. <view class="info_row">
  65. <view class="info_label">独立编码</view>
  66. <view class="info_value code" @click.stop="toggleEditField('indentifyCode', coreInfo.indentifyCode)">
  67. <u-input v-if="editMode.indentifyCode" v-model="tempValues.indentifyCode" :autoFocus="true"
  68. @blur="!globalEditMode && saveEditField('indentifyCode', tempValues.indentifyCode, 'indentifyCode')" />
  69. <span v-else>{{ coreInfo.indentifyCode || '-' }}</span>
  70. </view>
  71. </view>
  72. <view class="info_row">
  73. <view class="info_label">是否入库</view>
  74. <view class="info_value">{{ stockStatusFormatter(coreInfo.stockStatus) }}</view>
  75. </view>
  76. <view class="info_row">
  77. <view class="info_label">入库日期</view>
  78. <view class="info_value">{{ coreInfo.createTime || '-' }}</view>
  79. </view>
  80. <view class="info_row">
  81. <view class="info_label">付款方式</view>
  82. <view class="info_value">{{ payTypeFormatter(coreInfo.payType) }}</view>
  83. </view>
  84. <view class="info_row col">
  85. <view class="info_label">备注信息</view>
  86. <view class="info_value note" @click.stop="toggleEditField('desc', coreInfo.desc)">
  87. <textarea v-if="editMode.desc" v-model="tempValues.desc" :autoFocus="true" rows="3"
  88. @blur="!globalEditMode && saveEditField('desc', tempValues.desc, 'desc')" />
  89. <span v-else>{{ coreInfo.desc || '-' }}</span>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 财务与价格区域 -->
  94. <view class="finance_price">
  95. <view class="section_title">财务与价格</view>
  96. <view class="price_group">
  97. <view class="price_item">
  98. <view class="price_label">总成本价</view>
  99. <view class="price_value original"
  100. @click.stop="toggleEditField('costPrice', coreInfo.costPrice)">
  101. <u-input v-if="editMode.costPrice" v-model="tempValues.costPrice" :autoFocus="true"
  102. @blur="!globalEditMode && saveEditField('costPrice', tempValues.costPrice, 'costPrice')" />
  103. <span v-else>¥{{ coreInfo.costPrice || '-' }}</span>
  104. </view>
  105. </view>
  106. <view class="price_item">
  107. <view class="price_label">同行价格</view>
  108. <view class="price_value additional"
  109. @click.stop="toggleEditField('peerPrice', coreInfo.peerPrice)">
  110. <u-input v-if="editMode.peerPrice" v-model="tempValues.peerPrice" :autoFocus="true"
  111. @blur="!globalEditMode && saveEditField('peerPrice', tempValues.peerPrice, 'peerPrice')" />
  112. <span v-else>¥{{ coreInfo.peerPrice || '-' }}</span>
  113. </view>
  114. </view>
  115. </view>
  116. <view class="price_group">
  117. <view class="price_item">
  118. <view class="price_label">代理价格</view>
  119. <view class="price_value agent" @click.stop="toggleEditField('agentPrice', coreInfo.agentPrice)">
  120. <u-input v-if="editMode.agentPrice" v-model="tempValues.agentPrice" :autoFocus="true"
  121. @blur="!globalEditMode && saveEditField('agentPrice', tempValues.agentPrice, 'agentPrice')" />
  122. <span v-else>¥{{ coreInfo.agentPrice || '-' }}</span>
  123. </view>
  124. </view>
  125. <view class="price_item">
  126. <view class="price_label">销售价格</view>
  127. <view class="price_value suggested"
  128. @click.stop="toggleEditField('salePrice', coreInfo.salePrice)">
  129. <u-input v-if="editMode.salePrice" v-model="tempValues.salePrice" :autoFocus="true"
  130. @blur="!globalEditMode && saveEditField('salePrice', tempValues.salePrice, 'salePrice')" />
  131. <span v-else>¥{{ coreInfo.salePrice || '-' }}</span>
  132. </view>
  133. </view>
  134. </view>
  135. <view class="price_group">
  136. <view class="price_item">
  137. <view class="price_label">官方指导价</view>
  138. <view class="price_value original" @click.stop="toggleEditField('price', coreInfo.price)">
  139. <u-input v-if="editMode.price" v-model="tempValues.price" :autoFocus="true"
  140. @blur="!globalEditMode && saveEditField('price', tempValues.price, 'price')" />
  141. <span v-else>¥{{ coreInfo.price || '-' }}</span>
  142. </view>
  143. </view>
  144. <view class="price_item"></view>
  145. </view>
  146. </view>
  147. <!-- 溯源与位置区域 -->
  148. <view class="traceability_productPosition">
  149. <view class="section_title">溯源与位置</view>
  150. <view class="info_row">
  151. <view class="info_label">商品位置</view>
  152. <view class="info_value" @click.stop="toggleEditField('productPosition', coreInfo.productPosition)">
  153. <u-input v-if="editMode.productPosition" v-model="tempValues.productPosition" :autoFocus="true"
  154. @blur="!globalEditMode && saveEditField('productPosition', tempValues.productPosition, 'productPosition')" />
  155. <span v-else>{{ coreInfo.productPosition || '-' }}</span>
  156. </view>
  157. </view>
  158. <view class="info_row">
  159. <view class="info_label">回收人员</view>
  160. <view class="info_value" @click.stop="showRecyclePersonPicker">
  161. <span>{{ coreInfo.recyclePerson || '-' }}</span>
  162. <personPicker ref="recyclePersonPickerRef" title="请选择回收人员"
  163. @selectPerson="handleSelectRecyclePerson">
  164. </personPicker>
  165. </view>
  166. </view>
  167. <view class="info_row">
  168. <view class="info_label">鉴定人员</view>
  169. <view class="info_value" @click.stop="showIdentifyingPersonPicker">
  170. <span>{{ coreInfo.identifyingPerson || '-' }}</span>
  171. <personPicker ref="identifyingPersonPickerRef" title="请选择鉴定人员"
  172. @selectPerson="handleSelectIdentifyingPerson"></personPicker>
  173. </view>
  174. </view>
  175. <view class="action_button">
  176. <u-button type="primary" plain size="mini" @click="viewLog">查看操作日志({{ coreInfo.logTotal ||
  177. '-'}}条)</u-button>
  178. <u-modal :show="logShow" title="日志" :closeOnClickOverlay="true" :showConfirmButton="false"
  179. @close="logShow = false">
  180. <view class="log_list">
  181. <view v-for="value in logList" :key="value.id" class="log_item">
  182. {{ value.createTime }}{{ value.name }}{{ value.operation }}
  183. </view>
  184. </view>
  185. </u-modal>
  186. </view>
  187. </view>
  188. <!-- 底部功能按钮栏 -->
  189. <view :class="['bottom_bar', { 'fourPart': coreInfo.stockStatus === '1', 'fivePart': coreInfo.stockStatus === '0' }]">
  190. <view class="bar_item" @click.stop="globalEditMode ? confirmGlobalEdit() : enterGlobalEdit()">
  191. <u-icon :name="globalEditMode ? 'checkbox-mark' : 'edit-pen'" size="46rpx"
  192. :color="globalEditMode ? '#10b981' : '#9ca3af'"></u-icon>
  193. <text class="bar_text">{{ globalEditMode ? '确定' : '编辑' }}</text>
  194. </view>
  195. <view :class="['bar_item', { 'disabled': globalEditMode}]" @click.stop="lockGoods">
  196. <u-icon :name="lockStatus === '1' ? 'lock-open' : 'lock'" size="46rpx" color="#9ca3af"></u-icon>
  197. <text class="bar_text">{{ lockStatus === '1' ? '解锁' : '锁单' }}</text>
  198. </view>
  199. <view :class="['bar_item', { 'disabled': globalEditMode}]">
  200. <image class="bar_icon" src="../../../static/icons/print.png" alt=""></image>
  201. <text class="bar_text">打印</text>
  202. </view>
  203. <view class="bar_item" v-if="coreInfo.stockStatus === '0'" @click.stop="handleConfirmStockIn">
  204. <view class="primary blue">
  205. <image class="bar_img" src="../../../static/icons/stockIn.png" alt=""></image>
  206. <text class="bar_text">确认入库</text>
  207. </view>
  208. </view>
  209. <view :class="['bar_item', { 'disabled': lockStatus === '1' || globalEditMode}]" @click="handleOpenOrder">
  210. <view class="primary orange">
  211. <u-icon name="bag" size="44rpx" color="#fff"></u-icon>
  212. <text class="bar_text">开单</text>
  213. </view>
  214. </view>
  215. </view>
  216. </view>
  217. </template>
  218. <script>
  219. import BrandList from '@/components/brand-list/index.vue'
  220. import personPicker from '@/components/person-picker/index.vue'
  221. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  222. export default {
  223. components: {
  224. BrandList,
  225. personPicker,
  226. imgsRowScroll,
  227. },
  228. data() {
  229. return {
  230. // 核心信息模拟数据
  231. coreInfo: {},
  232. // 编辑状态管理
  233. editMode: {
  234. model: false,
  235. indentifyCode: false,
  236. desc: false,
  237. costPrice: false,
  238. peerPrice: false,
  239. agentPrice: false,
  240. salePrice: false,
  241. price: false,
  242. productPosition: false,
  243. },
  244. // 全局编辑模式
  245. globalEditMode: false,
  246. // 临时存储编辑值
  247. tempValues: {},
  248. goodsId: '',
  249. logShow: false,
  250. logList: [],
  251. imgsUrl: [],
  252. lockStatus: '',//锁单状态 0:未锁单 1:已锁单
  253. downStatus: '',//下架状态 0:已下架 1:已上架
  254. showEditImgsModal: false,
  255. tempImgsUrl: [],
  256. }
  257. },
  258. onLoad(options) {
  259. this.goodsId = options.id;
  260. this.getGoodsDetail();
  261. },
  262. methods: {
  263. // 分享
  264. handleShare() {
  265. uni.showToast({
  266. title: '分享功能暂未开放',
  267. icon: 'none'
  268. })
  269. },
  270. // 智能抠图
  271. handleCutImg() {
  272. uni.showToast({
  273. title: '智能抠图功能暂未开放',
  274. icon: 'none'
  275. })
  276. },
  277. // 是否入库格式化
  278. stockStatusFormatter(val){
  279. switch (val) {
  280. case '1':
  281. return '已入库'
  282. case '0':
  283. return '未入库'
  284. default:
  285. return '-'
  286. }
  287. },
  288. payTypeFormatter(val){
  289. switch (val) {
  290. case '1':
  291. return '微信'
  292. case '2':
  293. return '支付宝'
  294. case '3':
  295. return '银行卡'
  296. case '4':
  297. return '现金'
  298. case '5':
  299. return '数字货币'
  300. case '6':
  301. return '挂账'
  302. default:
  303. return '-'
  304. }
  305. },
  306. // 锁单
  307. lockGoods() {
  308. if (this.globalEditMode) {
  309. uni.showToast({
  310. title: '编辑状态下不能操作',
  311. icon: 'none'
  312. })
  313. return
  314. }
  315. uni.$u.api.wareHouseLock({
  316. id: this.goodsId,
  317. lockStatus: this.lockStatus === '1' ? '0' : '1',
  318. }).then(res => {
  319. uni.showToast({
  320. type: "success",
  321. title: this.lockStatus === '1' ? '解锁成功' : '锁单成功',
  322. icon: 'success'
  323. })
  324. this.getGoodsDetail();
  325. }).catch((error) => {
  326. uni.showToast({
  327. title: error || '操作失败',
  328. icon: 'none'
  329. })
  330. })
  331. },
  332. showRecyclePersonPicker() {
  333. this.$refs.recyclePersonPickerRef.open();
  334. },
  335. // 处理选中回收人员
  336. handleSelectRecyclePerson(person) {
  337. this.coreInfo.recyclePerson = person.label;
  338. this.coreInfo.recyclePersonId = person.id;
  339. this.submitEdit(this.coreInfo)
  340. },
  341. // 显示鉴定人员选择器
  342. showIdentifyingPersonPicker() {
  343. this.$refs.identifyingPersonPickerRef.open();
  344. },
  345. // 处理选中鉴定人员
  346. handleSelectIdentifyingPerson(person) {
  347. this.coreInfo.identifyingPerson = person.label;
  348. this.coreInfo.identifyingPersonId = person.id;
  349. this.submitEdit(this.coreInfo)
  350. },
  351. // 显示品牌列表
  352. showBrandlList() {
  353. this.$refs.brandListRef.showBrandList();
  354. },
  355. // 处理选中品牌
  356. handleSelectedBrand(info) {
  357. this.coreInfo.dictLabel = info.dictLabel;
  358. this.coreInfo.dictValue = info.dictValue;
  359. this.submitEdit(this.coreInfo)
  360. },
  361. // 获取商品详情
  362. getGoodsDetail() {
  363. uni.$u.api.wareHouseDetail({
  364. id: this.goodsId,
  365. userId: this.$store.state.user.userInfo.userId,
  366. }).then(res => {
  367. this.coreInfo = res.data;
  368. this.imgsUrl = res.data.goodPicFileList || [];
  369. this.lockStatus = res.data.lockStatus;
  370. this.downStatus = res.data.downStatus;
  371. });
  372. },
  373. // 打开销售业务开单页面
  374. handleOpenOrder() {
  375. if (this.lockStatus === '1') {
  376. uni.showToast({
  377. title: '已锁单,不能开单',
  378. icon: 'none'
  379. })
  380. return
  381. }
  382. if (this.globalEditMode) {
  383. uni.showToast({
  384. title: '编辑状态下不能开单',
  385. icon: 'none'
  386. })
  387. return
  388. }
  389. const params = {
  390. id: this.goodsId,
  391. url: this.imgsUrl[0]?.url,
  392. dictLabel: this.coreInfo.dictLabel,
  393. dictValue: this.coreInfo.dictValue,
  394. model: this.coreInfo.model,
  395. agentPrice: this.coreInfo.agentPrice,
  396. price: this.coreInfo.price,
  397. recyclePerson: this.coreInfo.recyclePerson,
  398. recyclePersonId: this.coreInfo.recyclePersonId,
  399. createTime: this.coreInfo.createTime,
  400. }
  401. uni.navigateTo({
  402. url: '/pages/wareHouse/components/openOrder?params=' + JSON.stringify(params),
  403. });
  404. },
  405. handleConfirmStockIn(){
  406. this.coreInfo.stockStatus = '1';
  407. this.submitEdit(this.coreInfo)
  408. },
  409. viewLog() {
  410. uni.$u.api.wareHouseLog({
  411. id: this.goodsId,
  412. userId: this.$store.state.user.userInfo.userId,
  413. }).then(res => {
  414. this.logList = res.data;
  415. this.logShow = true;
  416. });
  417. },
  418. // 立即下架按钮
  419. handleOffShelf() {
  420. if (this.lockStatus === '1') {
  421. uni.showToast({
  422. title: '已锁单,不能下架',
  423. icon: 'none'
  424. })
  425. return
  426. }
  427. if (this.globalEditMode) {
  428. uni.showToast({
  429. title: '编辑状态下不能操作',
  430. icon: 'none'
  431. })
  432. return
  433. }
  434. uni.$u.api.wareHouseDown({
  435. id: this.goodsId,
  436. downStatus: this.downStatus === '1' ? '0' : '1',
  437. }).then(() => {
  438. uni.showToast({
  439. title: this.downStatus === '1' ? '下架成功' : '上架成功',
  440. icon: 'success'
  441. })
  442. this.getGoodsDetail();
  443. }).catch(() => {
  444. uni.showToast({
  445. title: '操作失败',
  446. icon: 'none'
  447. })
  448. })
  449. },
  450. // 切换单个字段的编辑状态
  451. toggleEditField(field, value) {
  452. // 如果不是全局编辑模式
  453. if (!this.globalEditMode) {
  454. // 重置所有编辑状态
  455. this.resetEditMode();
  456. // 设置当前字段为编辑状态
  457. this.editMode[field] = true;
  458. // 保存临时值
  459. this.tempValues[field] = value;
  460. }
  461. },
  462. // 保存单个字段的编辑值
  463. saveEditField(field, newValue, fieldName) {
  464. this.coreInfo[fieldName] = newValue;
  465. this.editMode[field] = false;
  466. delete this.tempValues[field];
  467. console.log(`保存${field}字段值: ${newValue}`);
  468. this.submitEdit(this.coreInfo);
  469. },
  470. // 进入全局编辑模式
  471. enterGlobalEdit() {
  472. this.globalEditMode = true;
  473. // 设置所有可编辑字段为编辑状态
  474. this.editMode = {
  475. model: true,
  476. indentifyCode: true,
  477. desc: true,
  478. costPrice: true,
  479. peerPrice: true,
  480. agentPrice: true,
  481. salePrice: true,
  482. price: true,
  483. productPosition: true,
  484. };
  485. // 保存所有字段的临时值
  486. this.tempValues = { ...this.coreInfo }
  487. },
  488. // 重置所有编辑状态
  489. resetEditMode() {
  490. Object.keys(this.editMode).forEach(key => {
  491. this.editMode[key] = false;
  492. });
  493. },
  494. submitEdit(info) {
  495. const data = {
  496. id: this.goodsId,
  497. goodPicFileList: this.imgsUrl,
  498. dictLabel: info.dictLabel,
  499. dictValue: info.dictValue,
  500. model: info.model,
  501. indentifyCode: info.indentifyCode,
  502. createTime: info.createTime,
  503. payType: info.payType,
  504. desc: info.desc,
  505. costPrice: info.costPrice,
  506. peerPrice: info.peerPrice,
  507. agentPrice: info.agentPrice,
  508. salePrice: info.salePrice,
  509. price: info.price,
  510. productPosition: info.productPosition,
  511. recyclePerson: info.recyclePerson,
  512. recyclePersonId: info.recyclePersonId,
  513. identifyingPerson: info.identifyingPerson,
  514. identifyingPersonId: info.identifyingPersonId,
  515. stockStatus: info.stockStatus,
  516. }
  517. uni.$u.api.wareHouseUpdate(data).then(res => {
  518. uni.showToast({
  519. title: '编辑成功',
  520. icon: 'success'
  521. });
  522. this.getGoodsDetail();
  523. this.$emit('editSuccess')
  524. }).catch(() => {
  525. uni.showToast({
  526. title: '操作失败',
  527. icon: 'none'
  528. })
  529. })
  530. },
  531. // 点击页面其他地方保存所有编辑
  532. handleClickOutside() {
  533. if (!this.globalEditMode) {
  534. // 保存当前正在编辑的字段
  535. Object.keys(this.editMode).forEach(key => {
  536. if (this.editMode[key]) {
  537. this.saveEditField(key, this.tempValues[key], key);
  538. }
  539. });
  540. }
  541. // 当globalEditMode为true时,不执行任何操作
  542. },
  543. // 确认全局编辑
  544. confirmGlobalEdit() {
  545. this.submitEdit(this.tempValues)
  546. // 重置全局编辑模式
  547. this.globalEditMode = false;
  548. // 退出所有编辑状态
  549. this.resetEditMode();
  550. // 清空临时值,恢复初始状态
  551. this.tempValues = {};
  552. },
  553. handleDownload() {
  554. if (this.imgsUrl.length == 0) {
  555. uni.showToast({
  556. title: '暂无图片',
  557. icon: 'none'
  558. })
  559. return;
  560. }
  561. uni.showModal({
  562. title: '保存图片',
  563. content: `是否将 ${this.imgsUrl.length} 张图片保存到本地相册?`,
  564. confirmText: '保存',
  565. success: (res) => {
  566. if (res.confirm) {
  567. this.saveImagesToLocal(this.imgsUrl);
  568. }
  569. }
  570. })
  571. },
  572. saveImagesToLocal(allUrls) {
  573. uni.showToast({
  574. title: '图片保存中...',
  575. icon: 'loading'
  576. })
  577. allUrls.forEach((item, index) => {
  578. uni.downloadFile({
  579. url: item.url,
  580. success: (res) => {
  581. if (res.statusCode === 200) {
  582. uni.saveImageToPhotosAlbum({
  583. filePath: res.tempFilePath,
  584. success() {
  585. uni.showToast({
  586. title: '保存成功'
  587. })
  588. },
  589. fail: (err) => {
  590. console.error('保存到相册失败:', err);
  591. // 如果是权限问题,尝试请求权限
  592. if (err.errMsg.includes('auth denied')) {
  593. uni.showModal({
  594. title: '权限不足',
  595. content: '需要访问相册权限来保存图片,是否去设置?',
  596. success: (modalRes) => {
  597. if (modalRes.confirm) {
  598. // 打开设置页面
  599. uni.openSetting({
  600. success: (settingRes) => {
  601. console.log('设置页面结果:', settingRes);
  602. }
  603. });
  604. }
  605. }
  606. });
  607. }
  608. reject(err);
  609. }
  610. })
  611. }
  612. }
  613. })
  614. })
  615. },
  616. handleEditImgs() {
  617. this.showEditImgsModal = true;
  618. this.tempImgsUrl = this.imgsUrl
  619. },
  620. getDeleteImgInfo(imgInfo) {
  621. this.tempImgsUrl = imgInfo.newImages
  622. },
  623. afterRead(info) {
  624. info.file.forEach(item=>{
  625. uni.$u.api.uploadFile(item.url).then((res) => {
  626. this.tempImgsUrl.push({url:res.data.url});
  627. uni.$u.toast("文件上传成功");
  628. }).catch(() => {
  629. uni.$u.toast("上传文件失败");
  630. })
  631. })
  632. },
  633. confirmEditImgs() {
  634. this.imgsUrl = this.tempImgsUrl
  635. this.submitEdit(this.coreInfo)
  636. this.showEditImgsModal = false;
  637. },
  638. cancelEditImgs() {
  639. this.tempImgsUrl = []
  640. this.showEditImgsModal = false;
  641. }
  642. }
  643. }
  644. </script>
  645. <style lang="scss" scoped>
  646. @import "../styles/detail.scss";
  647. </style>