detail.vue 25 KB

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