detail.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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" v-if="isWareHouser">
  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 original" @click.stop="toggleEditField('price', coreInfo.price)">
  128. <u-input v-if="editMode.price" v-model="tempValues.price" :autoFocus="true"
  129. @blur="!globalEditMode && saveEditField('price', tempValues.price, 'price')" />
  130. <span v-else>¥{{ coreInfo.price || '-' }}</span>
  131. </view>
  132. </view>
  133. </view>
  134. <view class="price_group" v-if="isWareHouser">
  135. <view class="price_item">
  136. <view class="price_label">销售价格</view>
  137. <view class="price_value suggested"
  138. @click.stop="toggleEditField('salePrice', coreInfo.salePrice)">
  139. <u-input v-if="editMode.salePrice" v-model="tempValues.salePrice" :autoFocus="true"
  140. @blur="!globalEditMode && saveEditField('salePrice', tempValues.salePrice, 'salePrice')" />
  141. <span v-else>¥{{ coreInfo.salePrice || '-' }}</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. import { permissionCheck } from '@/utils/util.js'
  223. export default {
  224. components: {
  225. BrandList,
  226. personPicker,
  227. imgsRowScroll,
  228. },
  229. data() {
  230. return {
  231. // 核心信息模拟数据
  232. coreInfo: {},
  233. // 编辑状态管理
  234. editMode: {
  235. model: false,
  236. indentifyCode: false,
  237. desc: false,
  238. costPrice: false,
  239. peerPrice: false,
  240. agentPrice: false,
  241. salePrice: false,
  242. price: false,
  243. productPosition: false,
  244. },
  245. // 全局编辑模式
  246. globalEditMode: false,
  247. // 临时存储编辑值
  248. tempValues: {},
  249. goodsId: '',
  250. logShow: false,
  251. logList: [],
  252. imgsUrl: [],
  253. lockStatus: '',//锁单状态 0:未锁单 1:已锁单
  254. downStatus: '',//下架状态 0:已下架 1:已上架
  255. showEditImgsModal: false,
  256. tempImgsUrl: [],
  257. isWareHouser: permissionCheck('WAREHOUSER',false),
  258. }
  259. },
  260. onLoad(options) {
  261. this.goodsId = options.id;
  262. this.getGoodsDetail();
  263. },
  264. methods: {
  265. // 分享
  266. handleShare() {
  267. uni.showToast({
  268. title: '分享功能暂未开放',
  269. icon: 'none'
  270. })
  271. },
  272. // 智能抠图
  273. handleCutImg() {
  274. uni.showToast({
  275. title: '智能抠图功能暂未开放',
  276. icon: 'none'
  277. })
  278. },
  279. // 是否入库格式化
  280. stockStatusFormatter(val){
  281. switch (val) {
  282. case '1':
  283. return '已入库'
  284. case '0':
  285. return '未入库'
  286. default:
  287. return '-'
  288. }
  289. },
  290. payTypeFormatter(val){
  291. switch (val) {
  292. case '1':
  293. return '微信'
  294. case '2':
  295. return '支付宝'
  296. case '3':
  297. return '银行卡'
  298. case '4':
  299. return '现金'
  300. case '5':
  301. return '数字货币'
  302. case '6':
  303. return '挂账'
  304. default:
  305. return '-'
  306. }
  307. },
  308. // 锁单
  309. lockGoods() {
  310. if (this.globalEditMode) {
  311. uni.showToast({
  312. title: '编辑状态下不能操作',
  313. icon: 'none'
  314. })
  315. return
  316. }
  317. uni.$u.api.wareHouseLock({
  318. id: this.goodsId,
  319. lockStatus: this.lockStatus === '1' ? '0' : '1',
  320. }).then(res => {
  321. uni.showToast({
  322. type: "success",
  323. title: this.lockStatus === '1' ? '解锁成功' : '锁单成功',
  324. icon: 'success'
  325. })
  326. this.getGoodsDetail();
  327. }).catch((error) => {
  328. uni.showToast({
  329. title: error || '操作失败',
  330. icon: 'none'
  331. })
  332. })
  333. },
  334. showRecyclePersonPicker() {
  335. this.$refs.recyclePersonPickerRef.open();
  336. },
  337. // 处理选中回收人员
  338. handleSelectRecyclePerson(person) {
  339. this.coreInfo.recyclePerson = person.label;
  340. this.coreInfo.recyclePersonId = person.id;
  341. this.submitEdit(this.coreInfo)
  342. },
  343. // 显示鉴定人员选择器
  344. showIdentifyingPersonPicker() {
  345. this.$refs.identifyingPersonPickerRef.open();
  346. },
  347. // 处理选中鉴定人员
  348. handleSelectIdentifyingPerson(person) {
  349. this.coreInfo.identifyingPerson = person.label;
  350. this.coreInfo.identifyingPersonId = person.id;
  351. this.submitEdit(this.coreInfo)
  352. },
  353. // 显示品牌列表
  354. showBrandlList() {
  355. if(!permissionCheck('WAREHOUSER')) return false
  356. this.$refs.brandListRef.showBrandList();
  357. },
  358. // 处理选中品牌
  359. handleSelectedBrand(info) {
  360. this.coreInfo.dictLabel = info.dictLabel;
  361. this.coreInfo.dictValue = info.dictValue;
  362. this.submitEdit(this.coreInfo)
  363. },
  364. // 获取商品详情
  365. getGoodsDetail() {
  366. uni.$u.api.wareHouseDetail({
  367. id: this.goodsId,
  368. userId: this.$store.state.user.userInfo.userId,
  369. }).then(res => {
  370. this.coreInfo = res.data;
  371. this.imgsUrl = res.data.goodPicFileList || [];
  372. this.lockStatus = res.data.lockStatus;
  373. this.downStatus = res.data.downStatus;
  374. });
  375. },
  376. // 打开销售业务开单页面
  377. handleOpenOrder() {
  378. if (this.lockStatus === '1') {
  379. uni.showToast({
  380. title: '已锁单,不能开单',
  381. icon: 'none'
  382. })
  383. return
  384. }
  385. if (this.globalEditMode) {
  386. uni.showToast({
  387. title: '编辑状态下不能开单',
  388. icon: 'none'
  389. })
  390. return
  391. }
  392. const params = {
  393. id: this.goodsId,
  394. url: this.imgsUrl[0]?.url,
  395. dictLabel: this.coreInfo.dictLabel,
  396. dictValue: this.coreInfo.dictValue,
  397. model: this.coreInfo.model,
  398. agentPrice: this.coreInfo.agentPrice,
  399. price: this.coreInfo.price,
  400. recyclePerson: this.coreInfo.recyclePerson,
  401. recyclePersonId: this.coreInfo.recyclePersonId,
  402. createTime: this.coreInfo.createTime,
  403. }
  404. uni.navigateTo({
  405. url: '/pages/wareHouse/components/openOrder?params=' + JSON.stringify(params),
  406. });
  407. },
  408. handleConfirmStockIn(){
  409. this.coreInfo.stockStatus = '1';
  410. this.submitEdit(this.coreInfo)
  411. },
  412. viewLog() {
  413. uni.$u.api.wareHouseLog({
  414. id: this.goodsId,
  415. userId: this.$store.state.user.userInfo.userId,
  416. }).then(res => {
  417. this.logList = res.data;
  418. this.logShow = true;
  419. });
  420. },
  421. // 立即下架按钮
  422. handleOffShelf() {
  423. if (this.lockStatus === '1') {
  424. uni.showToast({
  425. title: '已锁单,不能下架',
  426. icon: 'none'
  427. })
  428. return
  429. }
  430. if (this.globalEditMode) {
  431. uni.showToast({
  432. title: '编辑状态下不能操作',
  433. icon: 'none'
  434. })
  435. return
  436. }
  437. uni.$u.api.wareHouseDown({
  438. id: this.goodsId,
  439. downStatus: this.downStatus === '1' ? '0' : '1',
  440. }).then(() => {
  441. uni.showToast({
  442. title: this.downStatus === '1' ? '下架成功' : '上架成功',
  443. icon: 'success'
  444. })
  445. this.getGoodsDetail();
  446. }).catch(() => {
  447. uni.showToast({
  448. title: '操作失败',
  449. icon: 'none'
  450. })
  451. })
  452. },
  453. // 切换单个字段的编辑状态
  454. toggleEditField(field, value) {
  455. if(!permissionCheck('WAREHOUSER')) return false
  456. // 如果不是全局编辑模式
  457. if (!this.globalEditMode) {
  458. // 重置所有编辑状态
  459. this.resetEditMode();
  460. // 设置当前字段为编辑状态
  461. this.editMode[field] = true;
  462. // 保存临时值
  463. this.tempValues[field] = value;
  464. }
  465. },
  466. // 保存单个字段的编辑值
  467. saveEditField(field, newValue, fieldName) {
  468. this.coreInfo[fieldName] = newValue;
  469. this.editMode[field] = false;
  470. delete this.tempValues[field];
  471. console.log(`保存${field}字段值: ${newValue}`);
  472. this.submitEdit(this.coreInfo);
  473. },
  474. // 进入全局编辑模式
  475. enterGlobalEdit() {
  476. if(!permissionCheck('WAREHOUSER')) return false
  477. this.globalEditMode = true;
  478. // 设置所有可编辑字段为编辑状态
  479. this.editMode = {
  480. model: true,
  481. indentifyCode: true,
  482. desc: true,
  483. costPrice: true,
  484. peerPrice: true,
  485. agentPrice: true,
  486. salePrice: true,
  487. price: true,
  488. productPosition: true,
  489. };
  490. // 保存所有字段的临时值
  491. this.tempValues = { ...this.coreInfo }
  492. },
  493. // 重置所有编辑状态
  494. resetEditMode() {
  495. Object.keys(this.editMode).forEach(key => {
  496. this.editMode[key] = false;
  497. });
  498. },
  499. submitEdit(info) {
  500. const data = {
  501. id: this.goodsId,
  502. goodPicFileList: this.imgsUrl,
  503. dictLabel: info.dictLabel,
  504. dictValue: info.dictValue,
  505. model: info.model,
  506. indentifyCode: info.indentifyCode,
  507. createTime: info.createTime,
  508. payType: info.payType,
  509. desc: info.desc,
  510. costPrice: info.costPrice,
  511. peerPrice: info.peerPrice,
  512. agentPrice: info.agentPrice,
  513. salePrice: info.salePrice,
  514. price: info.price,
  515. productPosition: info.productPosition,
  516. recyclePerson: info.recyclePerson,
  517. recyclePersonId: info.recyclePersonId,
  518. identifyingPerson: info.identifyingPerson,
  519. identifyingPersonId: info.identifyingPersonId,
  520. stockStatus: info.stockStatus,
  521. }
  522. uni.$u.api.wareHouseUpdate(data).then(res => {
  523. uni.showToast({
  524. title: '编辑成功',
  525. icon: 'success'
  526. });
  527. this.getGoodsDetail();
  528. this.$emit('editSuccess')
  529. }).catch(() => {
  530. uni.showToast({
  531. title: '操作失败',
  532. icon: 'none'
  533. })
  534. })
  535. },
  536. // 点击页面其他地方保存所有编辑
  537. handleClickOutside() {
  538. if (!this.globalEditMode) {
  539. // 保存当前正在编辑的字段
  540. Object.keys(this.editMode).forEach(key => {
  541. if (this.editMode[key]) {
  542. this.saveEditField(key, this.tempValues[key], key);
  543. }
  544. });
  545. }
  546. // 当globalEditMode为true时,不执行任何操作
  547. },
  548. // 确认全局编辑
  549. confirmGlobalEdit() {
  550. this.submitEdit(this.tempValues)
  551. // 重置全局编辑模式
  552. this.globalEditMode = false;
  553. // 退出所有编辑状态
  554. this.resetEditMode();
  555. // 清空临时值,恢复初始状态
  556. this.tempValues = {};
  557. },
  558. handleDownload() {
  559. if (this.imgsUrl.length == 0) {
  560. uni.showToast({
  561. title: '暂无图片',
  562. icon: 'none'
  563. })
  564. return;
  565. }
  566. uni.showModal({
  567. title: '保存图片',
  568. content: `是否将 ${this.imgsUrl.length} 张图片保存到本地相册?`,
  569. confirmText: '保存',
  570. success: (res) => {
  571. if (res.confirm) {
  572. this.saveImagesToLocal(this.imgsUrl);
  573. }
  574. }
  575. })
  576. },
  577. saveImagesToLocal(allUrls) {
  578. uni.showToast({
  579. title: '图片保存中...',
  580. icon: 'loading'
  581. })
  582. allUrls.forEach((item, index) => {
  583. uni.downloadFile({
  584. url: item.url,
  585. success: (res) => {
  586. if (res.statusCode === 200) {
  587. uni.saveImageToPhotosAlbum({
  588. filePath: res.tempFilePath,
  589. success() {
  590. uni.showToast({
  591. title: '保存成功'
  592. })
  593. },
  594. fail: (err) => {
  595. console.error('保存到相册失败:', err);
  596. // 如果是权限问题,尝试请求权限
  597. if (err.errMsg.includes('auth denied')) {
  598. uni.showModal({
  599. title: '权限不足',
  600. content: '需要访问相册权限来保存图片,是否去设置?',
  601. success: (modalRes) => {
  602. if (modalRes.confirm) {
  603. // 打开设置页面
  604. uni.openSetting({
  605. success: (settingRes) => {
  606. console.log('设置页面结果:', settingRes);
  607. }
  608. });
  609. }
  610. }
  611. });
  612. }
  613. reject(err);
  614. }
  615. })
  616. }
  617. }
  618. })
  619. })
  620. },
  621. handleEditImgs() {
  622. if(!permissionCheck('WAREHOUSER')) return false
  623. this.showEditImgsModal = true;
  624. this.tempImgsUrl = this.imgsUrl
  625. },
  626. getDeleteImgInfo(imgInfo) {
  627. this.tempImgsUrl = imgInfo.newImages
  628. },
  629. afterRead(info) {
  630. info.file.forEach(item=>{
  631. uni.$u.api.uploadFile(item.url).then((res) => {
  632. this.tempImgsUrl.push({url:res.data.url});
  633. uni.$u.toast("文件上传成功");
  634. }).catch(() => {
  635. uni.$u.toast("上传文件失败");
  636. })
  637. })
  638. },
  639. confirmEditImgs() {
  640. this.imgsUrl = this.tempImgsUrl
  641. this.submitEdit(this.coreInfo)
  642. this.showEditImgsModal = false;
  643. },
  644. cancelEditImgs() {
  645. this.tempImgsUrl = []
  646. this.showEditImgsModal = false;
  647. }
  648. }
  649. }
  650. </script>
  651. <style lang="scss" scoped>
  652. @import "../styles/detail.scss";
  653. </style>