detail.vue 31 KB

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