index.vue 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  1. <template>
  2. <div class="container">
  3. <van-nav-bar
  4. title="退货登记"
  5. left-arrow
  6. @click-left="goBack"
  7. @click-right="init"
  8. >
  9. <template #left>
  10. <van-icon name="arrow-left" size="25" />
  11. <div class="left-btn">返回</div>
  12. </template>
  13. <template #right>
  14. <div class="nav-right right-btn">重置</div>
  15. </template>
  16. </van-nav-bar>
  17. <div class="content">
  18. <div v-if="showInitialPage" class="init-container">
  19. <div class="content-tips">
  20. <div style="flex: 1">
  21. <van-notice-bar left-icon="volume-o">请扫描退回单号</van-notice-bar>
  22. </div>
  23. </div>
  24. <div class="scan-returned-content">
  25. <div class="input-group">
  26. <van-field
  27. ref="scan-express-no-input"
  28. autofocus
  29. v-model="expressNo"
  30. autocomplete="off"
  31. placeholder="输入快递单号"
  32. clearable
  33. @keydown.enter="inputExpressNo"
  34. >
  35. </van-field>
  36. </div>
  37. <div class="button-group">
  38. <van-button
  39. @click="inputExpressNo"
  40. style="width: 100%"
  41. type="primary"
  42. class="confirm-btn"
  43. >确认
  44. </van-button>
  45. </div>
  46. </div>
  47. </div>
  48. <div v-else>
  49. <van-tabs>
  50. <van-tab title="退货信息">
  51. <div>
  52. <div class="content-tips">
  53. <div style="flex: 1">
  54. <van-notice-bar color="#1989fa" background="#ecf9ff"
  55. >{{ ownerQualityInspection }}
  56. </van-notice-bar>
  57. </div>
  58. </div>
  59. </div>
  60. <van-cell-group inset style="margin-top: 10px">
  61. <van-field
  62. v-model="params.returnNo"
  63. label="快递单号"
  64. readonly
  65. placeholder="请输入快递单号"
  66. />
  67. <van-field
  68. readonly
  69. clickable
  70. label="承运商"
  71. placeholder="选择承运商"
  72. v-model="params.logisticsName"
  73. @click="logisticPickerShow = true"
  74. />
  75. <van-popup
  76. v-model:show="logisticPickerShow"
  77. position="bottom"
  78. destroy-on-close
  79. >
  80. <van-picker
  81. :columns="logistics"
  82. @cancel="logisticPickerShow = false"
  83. @confirm="selectedLogistic"
  84. />
  85. </van-popup>
  86. <van-field
  87. readonly
  88. clickable
  89. label="仓库"
  90. placeholder="选择仓库"
  91. :model-value="getWarehouseName(warehouse)"
  92. v-model="params.warehouseCode"
  93. @click="warehousePickerShow = true"
  94. />
  95. <van-popup
  96. v-model:show="warehousePickerShow"
  97. position="bottom"
  98. destroy-on-close
  99. >
  100. <van-picker
  101. :columns="warehouses"
  102. @cancel="warehousePickerShow = false"
  103. @confirm="selectedWarehouse"
  104. />
  105. </van-popup>
  106. <van-field
  107. readonly
  108. clickable
  109. label="货主"
  110. placeholder="选择货主"
  111. :model-value="getOwnerName(params.ownerCode)"
  112. @click="ownerPickerShow = true"
  113. />
  114. <van-popup
  115. v-model:show="ownerPickerShow"
  116. position="bottom"
  117. destroy-on-close
  118. >
  119. <van-picker
  120. :columns="owners"
  121. @cancel="ownerPickerShow = false"
  122. @confirm="selectedOwner"
  123. />
  124. </van-popup>
  125. <van-field
  126. readonly
  127. clickable
  128. label="店铺"
  129. placeholder="选择店铺"
  130. v-model="params.storeName"
  131. @click="storePickerShow = true"
  132. />
  133. <van-popup
  134. v-model:show="storePickerShow"
  135. position="bottom"
  136. destroy-on-close
  137. >
  138. <van-picker
  139. :columns="storeOptions"
  140. @cancel="storePickerShow = false"
  141. @confirm="selectedStore"
  142. />
  143. </van-popup>
  144. <van-field
  145. v-model="params.orderUpstream"
  146. label="上游平台"
  147. placeholder="上游平台"
  148. />
  149. <van-field
  150. v-model="params.arrivalPayment"
  151. label="到付费用"
  152. placeholder="到付费用"
  153. />
  154. <van-field
  155. v-model="params.remark"
  156. rows="1"
  157. autosize
  158. label="备注"
  159. type="textarea"
  160. placeholder="备注"
  161. />
  162. </van-cell-group>
  163. <van-cell-group inset style="margin-top: 10px">
  164. <van-field
  165. :model-value="params.originalNo"
  166. label="是否原单"
  167. readonly
  168. placeholder="是否原单"
  169. />
  170. <van-field
  171. v-model="params.upstreamNo"
  172. label="客户订单号"
  173. placeholder="客户订单号"
  174. />
  175. <van-field
  176. v-model="params.asnNo"
  177. label="ASN单号"
  178. readonly
  179. placeholder="ASN单号"
  180. />
  181. <van-field
  182. v-model="params.buyerName"
  183. label="客户姓名"
  184. readonly
  185. placeholder="客户姓名"
  186. />
  187. <van-field
  188. v-model="params.buyerPhone"
  189. label="电话号码"
  190. readonly
  191. placeholder="电话号码"
  192. />
  193. </van-cell-group>
  194. <van-cell-group inset style="margin-top: 20px; margin-bottom: 50px">
  195. <van-button type="primary" block @click="submit">提交</van-button>
  196. </van-cell-group>
  197. </van-tab>
  198. <van-tab title="商品信息" class="returned-detail-list">
  199. <div>
  200. <div class="content-tips">
  201. <div style="flex: 1">
  202. <van-notice-bar color="#1989fa" background="#ecf9ff"
  203. >{{ ownerQualityInspection }}
  204. </van-notice-bar>
  205. </div>
  206. </div>
  207. </div>
  208. <template v-if="!params.details || params.details.length === 0">
  209. <van-empty description="暂无信息请进行录入" />
  210. </template>
  211. <template v-for="(item, index) in params.details">
  212. <div class="card-div">
  213. <div class="card-div-content">
  214. <div class="info-row">
  215. <div class="info-label">sku</div>
  216. <div class="info-value">{{ item.barCode }}</div>
  217. <div class="info-label">质量状态</div>
  218. <div class="info-value">
  219. <van-tag :color="getTagColor(item.qualityStatus)">
  220. {{ item.qualityStatus }}
  221. </van-tag>
  222. </div>
  223. </div>
  224. <div class="info-row">
  225. <div class="info-label">商品编号</div>
  226. <div class="info-value">{{ item.barCode }}</div>
  227. <div class="info-label">商品名称</div>
  228. <div class="info-value">
  229. <van-text-ellipsis
  230. :content="item.tradeName"
  231. rows="1"
  232. expand-text="展开"
  233. collapse-text="收起"
  234. />
  235. </div>
  236. </div>
  237. <div class="info-row">
  238. <div class="info-label">生产日期</div>
  239. <div class="info-value">
  240. {{ item.manufactureTime }}
  241. </div>
  242. <div class="info-label">失效日期</div>
  243. <div class="info-value">{{ item.validityTime }}</div>
  244. </div>
  245. <div class="info-row">
  246. <div class="info-label">批次号</div>
  247. <div class="info-value">{{ item.batchNumber }}</div>
  248. <div class="info-label">数量</div>
  249. <div class="info-value">{{ item.number }}</div>
  250. </div>
  251. </div>
  252. <div class="card-div-footer">
  253. <div class="product-description">
  254. {{ item.remark }}
  255. </div>
  256. </div>
  257. <template v-if="hasBoxItems(item)">
  258. <div>
  259. <van-divider content-position="left">外箱图</van-divider>
  260. <van-row>
  261. <template v-for="(i, imgIndex) in getBoxItems(item)">
  262. <van-col span="4">
  263. <van-image
  264. :key="`box-photos-${index}-${imgIndex}`"
  265. width="100%"
  266. height="50"
  267. :src="i.src"
  268. />
  269. </van-col>
  270. </template>
  271. </van-row>
  272. </div>
  273. </template>
  274. <template v-if="hasProductItems(item)">
  275. <div>
  276. <van-divider content-position="left">内物图</van-divider>
  277. <van-row>
  278. <template v-for="(i, imgIndex) in getProductItems(item)">
  279. <van-col span="4">
  280. <van-image
  281. :key="`product-photos-${index}-${imgIndex}`"
  282. width="100%"
  283. height="50"
  284. :src="i.src"
  285. />
  286. </van-col>
  287. </template>
  288. </van-row>
  289. </div>
  290. </template>
  291. <div class="card-div-footer-options">
  292. <div class="options-row">
  293. <div class="info-value">
  294. <van-button
  295. size="mini"
  296. type="danger"
  297. block
  298. plain
  299. @click="removeDetails(index)"
  300. >删除
  301. </van-button>
  302. </div>
  303. <div class="info-value">
  304. <van-button
  305. size="mini"
  306. type="default"
  307. block
  308. plain
  309. @click="editDetails(index)"
  310. >编辑
  311. </van-button>
  312. </div>
  313. </div>
  314. </div>
  315. </div>
  316. </template>
  317. <van-floating-bubble
  318. axis="xy"
  319. icon="add"
  320. magnetic="x"
  321. @click="showScancode"
  322. />
  323. </van-tab>
  324. <van-dialog
  325. v-model:show="scancodeDialog"
  326. title="扫描条码"
  327. @open="openScanCode"
  328. @confirm="showQualityStatus"
  329. show-cancel-button
  330. >
  331. <van-field
  332. ref="scancodeInputRef"
  333. v-model="scancode"
  334. label="商品条码"
  335. autocomplete="off"
  336. @keyup.enter="showQualityStatus"
  337. placeholder="商品条码"
  338. />
  339. </van-dialog>
  340. <van-dialog
  341. v-model:show="qualityStatusDialog"
  342. title="质量状态"
  343. @confirm="queryBarcode"
  344. show-cancel-button
  345. >
  346. <van-radio-group v-model="qualityStatus">
  347. <template v-for="(item, index) in qualityStatusOptions">
  348. <van-cell
  349. :title="item.text"
  350. clickable
  351. @click="qualityStatus = item.value"
  352. >
  353. <template #right-icon>
  354. <van-radio :name="item.value" />
  355. </template>
  356. </van-cell>
  357. </template>
  358. </van-radio-group>
  359. </van-dialog>
  360. <van-dialog
  361. v-model:show="returnedDetailDialog"
  362. title="商品详情"
  363. show-cancel-button
  364. :show-confirm-button="checkUploadImages()"
  365. @confirm="addDetails"
  366. >
  367. <div style="max-height: 70vh; overflow-y: auto">
  368. <van-field
  369. v-model="selectDetail.sku"
  370. placeholder="SKU"
  371. clearable
  372. />
  373. <van-field
  374. readonly
  375. v-model="selectDetail.barCode"
  376. placeholder="商品条码"
  377. clearable
  378. />
  379. <van-field
  380. v-model="selectDetail.tradeName"
  381. placeholder="商品名称"
  382. readonly
  383. />
  384. <van-field
  385. readonly
  386. clickable
  387. label="质量状态"
  388. placeholder="质量状态"
  389. v-model="selectDetail.qualityStatus"
  390. @click="selectedDetailQualityStatus = true"
  391. />
  392. <van-popup
  393. v-model:show="selectedDetailQualityStatus"
  394. position="bottom"
  395. destroy-on-close
  396. >
  397. <van-picker
  398. :columns="qualityStatusOptions"
  399. @cancel="selectedDetailQualityStatus = false"
  400. @confirm="selectedDetailQualityStatusFunc"
  401. />
  402. </van-popup>
  403. <van-field
  404. is-link
  405. readonly
  406. name="datePicker"
  407. label="生产日期"
  408. :placeholder="
  409. selectDetail.manufactureTime ? '' : '请选择生产日期'
  410. "
  411. :model-value="formatDateDisplay(selectDetail.manufactureTime)"
  412. @click="showManufactureTime = true"
  413. />
  414. <van-popup
  415. v-model:show="showManufactureTime"
  416. destroy-on-close
  417. position="bottom"
  418. >
  419. <van-date-picker
  420. :model-value="parseDateValue(selectDetail.manufactureTime)"
  421. @confirm="manufactureTimeConfirm"
  422. @cancel="showManufactureTime = false"
  423. />
  424. </van-popup>
  425. <van-field
  426. :model-value="formatDateDisplay(selectDetail.validityTime)"
  427. is-link
  428. readonly
  429. name="datePicker"
  430. label="失效日期"
  431. :placeholder="selectDetail.validityTime ? '' : '请选择失效日期'"
  432. @click="showValidityTime = true"
  433. />
  434. <van-popup
  435. v-model:show="showValidityTime"
  436. destroy-on-close
  437. position="bottom"
  438. >
  439. <van-date-picker
  440. :model-value="parseDateValue(selectDetail.validityTime)"
  441. @confirm="validityTimeConfirm"
  442. @cancel="showValidityTime = false"
  443. />
  444. </van-popup>
  445. <van-field
  446. autocomplete="off"
  447. v-model="selectDetail.batchNumber"
  448. placeholder="批次号"
  449. clearable
  450. />
  451. <van-field
  452. v-model="selectDetail.number"
  453. type="digit"
  454. placeholder="数量"
  455. clearable
  456. />
  457. <van-field
  458. v-model="selectDetail.remark"
  459. label="备注"
  460. placeholder="备注"
  461. label-align="top"
  462. />
  463. <van-row v-if="showAccessories">
  464. <div style="font-size: 12px;">
  465. <template v-for="(item,index) in accessories">
  466. <p>
  467. 配件条码:
  468. [<span style="color: #2ca547">{{ item.accessory }}</span>]
  469. [<span style="color: #277b39 ">{{ item.descrC }}</span>]
  470. 数量:
  471. [<span style="color: #2ca547">{{ item.qty }}</span>]件
  472. </p>
  473. </template>
  474. <p style="font-size: 12px">
  475. 请检查商品:
  476. 【<span style="color: #ff2020">{{ selectDetail.sku}}</span>】
  477. {{ selectDetail.tradeName }} 配件
  478. </p>
  479. </div>
  480. </van-row>
  481. <template
  482. v-if="
  483. selectDetail.boxPhotos && selectDetail.boxPhotos.length > 0
  484. "
  485. >
  486. <van-divider content-position="left" style="margin: 0px">外箱图</van-divider>
  487. <van-row>
  488. <template
  489. v-if="
  490. selectDetail.boxPhotos &&
  491. selectDetail.boxPhotos.length > 0
  492. "
  493. >
  494. <template v-for="(item, index) in selectDetail.boxPhotos">
  495. <van-col span="4">
  496. <van-image
  497. :key="`box-photos-${index}`"
  498. width="100%"
  499. height="50"
  500. :src="getImageUrl(item, '外箱图')"
  501. @click="showBoxImagePreview(index)"
  502. />
  503. </van-col>
  504. </template>
  505. <van-image-preview
  506. v-model:show="showBoxPreview"
  507. :images="detailBoxImages"
  508. :start-position="startBoxPosition"
  509. @change="onBoxPreviewChange"
  510. closeable
  511. >
  512. <template #index>
  513. <div class="custom-toolbar">
  514. <span
  515. >{{ startPhotosPosition + 1 }}/{{
  516. selectDetail.boxPhotos.length
  517. }}</span
  518. >
  519. <van-button
  520. icon="delete"
  521. type="danger"
  522. @click.stop="handleBoxDelete"
  523. size="mini"
  524. >删除
  525. </van-button>
  526. </div>
  527. </template>
  528. </van-image-preview>
  529. </template>
  530. </van-row>
  531. </template>
  532. <template
  533. v-if="
  534. selectDetail.productPhotos &&
  535. selectDetail.productPhotos.length > 0
  536. "
  537. >
  538. <van-divider content-position="left" style="margin: 0px">内物图</van-divider>
  539. <van-row>
  540. <template v-for="(item, index) in selectDetail.productPhotos">
  541. <van-col span="4">
  542. <van-image
  543. :key="`product-photos-${index}`"
  544. width="100%"
  545. height="50"
  546. :src="getImageUrl(item, '内物图')"
  547. @click="showPhotosImagePreview(index)"
  548. />
  549. </van-col>
  550. </template>
  551. </van-row>
  552. <van-image-preview
  553. v-model:show="showPhotosPreview"
  554. :images="detailProductImages"
  555. :start-position="startPhotosPosition"
  556. @change="onPhotosPreviewChange"
  557. closeable
  558. >
  559. <template #index>
  560. <div class="custom-toolbar">
  561. <span>
  562. {{ startPhotosPosition + 1 }}/{{
  563. selectDetail.productPhotos.length
  564. }}
  565. </span>
  566. <van-button
  567. icon="delete"
  568. type="danger"
  569. @click.stop="handlePhotosDelete"
  570. size="mini"
  571. >删除
  572. </van-button>
  573. </div>
  574. </template>
  575. </van-image-preview>
  576. </template>
  577. <van-row>
  578. <van-col span="12">
  579. <van-button
  580. type="primary"
  581. block
  582. @click="invokeCameraToCapture('外箱图')"
  583. >外箱图录入
  584. </van-button>
  585. </van-col>
  586. <van-col span="12">
  587. <van-button
  588. type="primary"
  589. block
  590. @click="invokeCameraToCapture('内物图')"
  591. >内物图录入
  592. </van-button>
  593. </van-col>
  594. </van-row>
  595. <input
  596. type="file"
  597. id="outer-carton-box-input"
  598. capture="user"
  599. accept="image/*"
  600. hidden
  601. :onchange="outerCartonInput"
  602. />
  603. <input
  604. type="file"
  605. id="inner-contents-input"
  606. capture="user"
  607. accept="image/*"
  608. hidden
  609. :onchange="innerContentsInput"
  610. />
  611. </div>
  612. </van-dialog>
  613. </van-tabs>
  614. </div>
  615. </div>
  616. <van-popup
  617. v-model:show="showOwnerSelect"
  618. destroy-on-close
  619. round
  620. position="bottom"
  621. >
  622. <van-picker
  623. :model-value="getOwnerName(params.ownerCode)"
  624. :columns="ownerSelectedOptions"
  625. @cancel="showOwnerSelect = false"
  626. @confirm="selectOwner"
  627. />
  628. </van-popup>
  629. </div>
  630. </template>
  631. <script setup>
  632. import { ref, computed, nextTick, onMounted } from 'vue'
  633. import {
  634. showFailToast,
  635. showSuccessToast,
  636. showNotify,
  637. showLoadingToast,
  638. closeToast,
  639. showConfirmDialog,
  640. showToast,
  641. } from 'vant'
  642. import { getHeader, goBack } from '@/utils/android'
  643. import {
  644. deleteDetails,
  645. getQualityInspection,
  646. getQualityInspectionBy,
  647. getQualityStatus,
  648. getReturnedByExpress,
  649. getTagColorBy,
  650. listAsn,
  651. matchAsnBy,
  652. matchCarrierCode,
  653. matchOrderBy,
  654. register,
  655. searchBarcode,
  656. searchOwnerBarcode,
  657. shops,
  658. validateDate,
  659. } from '@/api/returned/index.ts'
  660. import { carrierOptions, getOwner, getWarehouse } from '@/api/basic/index.ts'
  661. import { useStore } from '@/store/modules/user'
  662. import { getStatus } from '@/utils/returned.ts'
  663. try {
  664. getHeader()
  665. } catch (error) {
  666. console.log(error)
  667. }
  668. const showInitialPage = ref(true)
  669. const expressNo = ref(null)
  670. const warehouse = ref(useStore.warehouse)
  671. // 当前选择的货主
  672. const title = computed(() => {
  673. if (expressNo.value && showInitialPage.value === false) {
  674. return '退货登记:' + params.value.returnNo
  675. }
  676. return '退货登记'
  677. })
  678. const qualityStatusOptions = ref([])
  679. // 货主
  680. const owners = ref([])
  681. // 仓库
  682. const warehouses = ref([])
  683. // 承运商
  684. const logistics = ref([])
  685. // 店铺
  686. const storeOptions = ref([])
  687. // 选中相关信息的下标
  688. const selectDetailIndex = ref(-1)
  689. const ownerMap = ref({})
  690. const warehousesMap = ref({})
  691. const logisticsMap = ref({})
  692. const asnList = ref({})
  693. // 外箱图
  694. const boxFiles = ref([])
  695. // 内物图
  696. const productFiles = ref([])
  697. onMounted(() => {
  698. getOwner().then((res) => {
  699. const { data } = res
  700. owners.value = data.map((item) => {
  701. return { value: item.code, text: item.name }
  702. })
  703. const map = {}
  704. data.forEach((item) => {
  705. map[item.code] = item.name
  706. })
  707. ownerMap.value = map
  708. })
  709. getQualityStatus().then((res) => {
  710. const { data } = res
  711. qualityStatusOptions.value = data.map((item) => {
  712. return { value: item, text: item }
  713. })
  714. })
  715. getWarehouse().then((res) => {
  716. const { data } = res
  717. warehouses.value = data.map((item) => {
  718. return { value: item.code, text: item.name }
  719. })
  720. const map = {}
  721. data.forEach((item) => {
  722. map[item.code] = item.name
  723. })
  724. warehousesMap.value = map
  725. })
  726. carrierOptions().then((res) => {
  727. const { data } = res
  728. logistics.value = data.map((item) => {
  729. return { value: item.id, text: item.name }
  730. })
  731. const map = {}
  732. data.forEach((item) => {
  733. map[item.name] = item.id
  734. })
  735. logisticsMap.value = map
  736. })
  737. try {
  738. getHeader()
  739. } catch (error) {}
  740. })
  741. // 商品外箱图
  742. function hasBoxItems(detail) {
  743. const { boxPhotos } = detail
  744. if (!boxPhotos || boxPhotos.length === 0) {
  745. return false
  746. }
  747. return boxFiles.value.some((item) => {
  748. return boxPhotos.includes(item.fileName)
  749. })
  750. }
  751. // 商品外箱图
  752. function getBoxItems(detail) {
  753. const { boxPhotos } = detail
  754. if (!boxPhotos || boxPhotos.length === 0) {
  755. return []
  756. }
  757. boxFiles.value.forEach((item) => {
  758. console.log(item)
  759. console.log(boxPhotos.includes(item.fileName))
  760. })
  761. console.log(boxFiles.value.filter((_) => true))
  762. return boxFiles.value.filter((item) => boxPhotos.includes(item.fileName))
  763. }
  764. // 商品外箱图
  765. function hasProductItems(detail) {
  766. const { productPhotos } = detail
  767. if (!productPhotos || productPhotos.length === 0) {
  768. return false
  769. }
  770. return productFiles.value.some((item) => {
  771. return productPhotos.includes(item.fileName)
  772. })
  773. }
  774. // 商品内物图
  775. function getProductItems(detail) {
  776. const { productPhotos } = detail
  777. if (!productPhotos || productPhotos.length === 0) {
  778. return []
  779. }
  780. console.log(
  781. productFiles.value.filter((item) => {
  782. return productPhotos.includes(item.fileName)
  783. }),
  784. )
  785. return productFiles.value.filter((item) => {
  786. return productPhotos.includes(item.fileName)
  787. })
  788. }
  789. // 获取对应的店铺信息
  790. async function getStoreOptionsBy(owner) {
  791. const results = await shops(owner)
  792. const { data } = results
  793. if (!data || data.length === 0) {
  794. storeOptions.value = []
  795. return
  796. }
  797. storeOptions.value = data.map((item) => {
  798. return { value: item, text: item }
  799. })
  800. }
  801. const qualityInspection = ref(null)
  802. // 初始化质检状态
  803. function initQualityInspection(owner) {
  804. console.log(owner)
  805. getQualityInspection(owner).then((res) => {
  806. qualityInspection.value = res.data
  807. })
  808. }
  809. const ownerQualityInspection = computed(() => {
  810. return getQualityInspectionBy(qualityInspection.value)
  811. })
  812. // 扫描商品条码
  813. const scancode = ref('')
  814. // 商品质量状态
  815. const qualityStatus = ref('')
  816. // 提交的商品信息
  817. const params = ref({
  818. id: null,
  819. returnNo: null,
  820. warehouseCode: null,
  821. logisticsName: null,
  822. storeName: null,
  823. upstreamNo: null,
  824. ownerCode: null,
  825. orderUpstream: null,
  826. orderUpSteam: null,
  827. arrivalPayment: null,
  828. buyerName: null,
  829. asnNo: null,
  830. buyerPhone: null,
  831. originalNo: null,
  832. remark: null,
  833. details: [],
  834. })
  835. // 商品信息
  836. const selectDetail = ref({
  837. id: null,
  838. rejectHeadId: null,
  839. rejectPushTaskNo: null,
  840. status: null,
  841. detailStatus: null,
  842. isGenuine: null,
  843. qualityMark: null,
  844. sku: '',
  845. barCode: '',
  846. tradeName: '',
  847. qualityStatus: '',
  848. manufactureTime: '',
  849. validityTime: '',
  850. batchNumber: '',
  851. remark: '',
  852. asnNo: null,
  853. number: 0,
  854. warehouse: null,
  855. warehouseBin: null,
  856. boxPhotos: [],
  857. productPhotos: [],
  858. files: null,
  859. pieceTag: null,
  860. createTime: null,
  861. creatorId: null,
  862. updateTime: null,
  863. updaterId: null,
  864. deleteTime: null,
  865. version: null,
  866. repairableType: null,
  867. repairableTypes: null,
  868. operatorId: null,
  869. operatorName: null,
  870. operatorTime: null,
  871. skuImage: null,
  872. orginSkuImage: null,
  873. })
  874. function initDetail() {
  875. selectDetail.value = {
  876. id: null,
  877. rejectHeadId: null,
  878. rejectPushTaskNo: null,
  879. status: null,
  880. detailStatus: null,
  881. isGenuine: null,
  882. qualityMark: null,
  883. sku: '',
  884. barCode: '',
  885. tradeName: '',
  886. qualityStatus: '',
  887. manufactureTime: '',
  888. validityTime: '',
  889. batchNumber: '',
  890. remark: '',
  891. asnNo: null,
  892. number: null,
  893. warehouse: null,
  894. warehouseBin: null,
  895. boxPhotos: [],
  896. productPhotos: [],
  897. files: null,
  898. pieceTag: null,
  899. createTime: null,
  900. creatorId: null,
  901. updateTime: null,
  902. updaterId: null,
  903. deleteTime: null,
  904. version: null,
  905. repairableType: null,
  906. repairableTypes: null,
  907. operatorId: null,
  908. operatorName: null,
  909. operatorTime: null,
  910. skuImage: null,
  911. orginSkuImage: null,
  912. }
  913. }
  914. // 承运商选择
  915. const logisticPickerShow = ref(false)
  916. const selectedLogistic = (row) => {
  917. const { selectedOptions } = row
  918. logisticPickerShow.value = false
  919. params.value.logisticsName = selectedOptions[0].text
  920. }
  921. // 货主选择
  922. const ownerPickerShow = ref(false)
  923. const ownerName = ref('')
  924. const selectedOwner = (row) => {
  925. const { selectedValues, selectedOptions } = row
  926. ownerPickerShow.value = false
  927. params.value.ownerCode = selectedOptions[0].value
  928. ownerName.value = selectedOptions[0].text
  929. initQualityInspection(params.value.ownerCode)
  930. }
  931. // 仓库选择
  932. const warehousePickerShow = ref(false)
  933. const warehouseName = ref('')
  934. const selectedWarehouse = (row) => {
  935. const { selectedValues, selectedOptions } = row
  936. warehousePickerShow.value = false
  937. params.value.warehouseCode = selectedValues
  938. warehouseName.value = selectedOptions[0].text
  939. }
  940. // 店铺选择
  941. const storePickerShow = ref(false)
  942. const selectedStore = (row) => {
  943. const { selectedOptions } = row
  944. storePickerShow.value = false
  945. params.value.storeName = selectedOptions[0].text
  946. }
  947. // 货主名
  948. function getOwnerName(owner) {
  949. return ownerMap.value[owner]
  950. }
  951. // 仓库名
  952. function getWarehouseName(code) {
  953. return warehousesMap.value[code]
  954. }
  955. // 输入快递单号
  956. function inputExpressNo() {
  957. const no = expressNo.value
  958. const isSuccess = checkExpressNo(no)
  959. if (!isSuccess) {
  960. return
  961. }
  962. const express_no = initExpressNo(no)
  963. if (!express_no || express_no.length === 0) {
  964. showFailToast('快递单号异常')
  965. return
  966. }
  967. params.value.returnNo = express_no
  968. params.value.warehouseCode = warehouse.value
  969. listAsn(express_no).then((res) => {
  970. if (res.data) {
  971. asnList.value = res.data
  972. }
  973. })
  974. matchReturned(express_no)
  975. expressNo.value = null
  976. showInitialPage.value = false
  977. }
  978. function matchReturned(expressNo) {
  979. getReturnedByExpress(expressNo).then((res) => {
  980. const { data } = res
  981. if (!data) {
  982. matchOrder(expressNo)
  983. return
  984. }
  985. const { id, headStatus, returnNo, warehouseCode } = data
  986. if (!id) {
  987. console.log('没有退件记录')
  988. matchOrder(expressNo)
  989. return
  990. }
  991. if (id) {
  992. if (['已入仓', '已拆包'].includes(headStatus)) {
  993. showNotify({
  994. type: 'primary',
  995. message: `当前退回单号${returnNo}--${headStatus}`,
  996. })
  997. init(false)
  998. params.value.id = id
  999. params.value.returnNo = returnNo
  1000. params.value.warehouseCode = warehouseCode
  1001. params.value.warehousingStatus = null
  1002. selectDetailIndex.value = -1
  1003. matchOrder(expressNo)
  1004. }
  1005. }
  1006. })
  1007. }
  1008. // 匹配原单信息
  1009. function matchOrder(expressNo) {
  1010. matchOrderBy(expressNo).then((res) => {
  1011. const { data } = res
  1012. if (!data) {
  1013. console.log('未匹配到订单信息')
  1014. matchAsn(expressNo)
  1015. return
  1016. }
  1017. console.log('匹配到订单信息')
  1018. if (data) {
  1019. const {
  1020. upstreamNo,
  1021. shopName,
  1022. ownerCode,
  1023. recipientName,
  1024. phone,
  1025. logisticName,
  1026. details,
  1027. } = data
  1028. showNotify({ type: 'success', message: '匹配到原单信息' })
  1029. params.value.upstreamNo = upstreamNo
  1030. params.value.ownerCode = ownerCode
  1031. params.value.warehouseCode = warehouse.value
  1032. params.value.storeName = shopName
  1033. params.value.logisticsName = logisticName
  1034. params.value.buyerName = handlerLongText(recipientName)
  1035. params.value.buyerPhone = handlerLongText(phone)
  1036. params.value.originalNo = '原单退回'
  1037. params.value.sendNo = null
  1038. initQualityInspection(params.value.ownerCode)
  1039. if (!details || details.length === 0) {
  1040. return
  1041. }
  1042. const list = []
  1043. details.forEach((item) => {
  1044. const {
  1045. sku,
  1046. barCode,
  1047. detailAmount,
  1048. name,
  1049. productionDate,
  1050. expirationDate,
  1051. batchNumber,
  1052. quality,
  1053. attributeBin,
  1054. } = item
  1055. let qualityStatus
  1056. if (quality) {
  1057. if (quality === 'ZP') {
  1058. qualityStatus = '正品'
  1059. qualityStatus = '正品'
  1060. } else if (quality === 'CP') {
  1061. qualityStatus = '次品'
  1062. } else {
  1063. qualityStatus = '正品'
  1064. }
  1065. } else {
  1066. qualityStatus = '正品'
  1067. }
  1068. list.push({
  1069. sku: sku,
  1070. tradeName: name,
  1071. barCode: barCode,
  1072. number: detailAmount,
  1073. manufactureTime: productionDate,
  1074. validityTime: expirationDate,
  1075. batchNumber: batchNumber,
  1076. warehouse: attributeBin,
  1077. qualityStatus: qualityStatus,
  1078. isOriginal: true,
  1079. })
  1080. params.value.details = list
  1081. matchCarrier(expressNo)
  1082. })
  1083. } else {
  1084. matchAsn(expressNo)
  1085. }
  1086. })
  1087. }
  1088. function matchCarrier(expressNo) {
  1089. matchCarrierCode(expressNo).then((res) => {
  1090. const { data } = res
  1091. if (!data || data.length === 0) {
  1092. showNotify({
  1093. type: 'primary',
  1094. message: '请手动选择承运商',
  1095. })
  1096. } else {
  1097. params.value.logisticsName = data
  1098. }
  1099. })
  1100. }
  1101. // 转化加密
  1102. function handlerLongText(text) {
  1103. return text && text.length > 15 ? '加密' : text ? text : null
  1104. }
  1105. // 匹配对应的ASN
  1106. function matchAsn(expressNo) {
  1107. matchAsnBy(expressNo).then((res) => {
  1108. const { data } = res
  1109. if (!data) {
  1110. console.log('未匹配asn单信息')
  1111. matchCarrier(expressNo)
  1112. return
  1113. }
  1114. const {
  1115. ownerCode,
  1116. phone,
  1117. shopName,
  1118. recipientName,
  1119. logisticName,
  1120. upstreamNo,
  1121. } = data
  1122. params.value.returnNo = expressNo
  1123. params.value.upstreamNo = upstreamNo
  1124. params.value.ownerCode = ownerCode
  1125. params.value.warehouseCode = warehouse.value
  1126. params.value.storeName = shopName
  1127. params.value.logisticsName = logisticName
  1128. params.value.buyerName = handlerLongText(recipientName)
  1129. params.value.buyerPhone = handlerLongText(phone)
  1130. params.value.originalNo = ''
  1131. params.value.sendNo = null
  1132. matchCarrier(expressNo)
  1133. params.value.details = []
  1134. initDetail()
  1135. initQualityInspection(params.value.ownerCode)
  1136. })
  1137. }
  1138. // 校验快递单号格式
  1139. function checkExpressNo(no) {
  1140. if (!no || no.length === 0) {
  1141. showFailToast('单号长度异常')
  1142. return false
  1143. }
  1144. if (no.startsWith('http')) {
  1145. showFailToast('扫描到了错误的条码')
  1146. return false
  1147. }
  1148. if (no.endsWith('.com')) {
  1149. showFailToast('扫描到了错误的条码')
  1150. return false
  1151. }
  1152. const length = no.length
  1153. if (length > 30 || length < 5) {
  1154. showFailToast('单号长度异常')
  1155. return false
  1156. }
  1157. return true
  1158. }
  1159. // 处理快递单号相关问题
  1160. function initExpressNo(no) {
  1161. // 处理扫描快递单号
  1162. if (!no) {
  1163. return no
  1164. }
  1165. if (no.includes('-')) {
  1166. no = no.substring(0, no.indexOf('-')) // 京东快递异常
  1167. }
  1168. return no
  1169. .replaceAll('-', '')
  1170. .replaceAll(' ', '')
  1171. .replaceAll('R02Z', '')
  1172. .replaceAll('R02T', '') // 圆通退回单号异常
  1173. }
  1174. // 重置提交 恢复到扫描快递单号页面
  1175. function init(showInputPage = true) {
  1176. warehouseName.value = null
  1177. ownerName.value = null
  1178. params.value = {
  1179. orderUpstream: null,
  1180. returnNo: null,
  1181. warehouseCode: null,
  1182. logisticsName: null,
  1183. storeName: null,
  1184. orderUpSteam: null,
  1185. arrivalPayment: null,
  1186. buyerName: null,
  1187. asnNo: null,
  1188. upstreamNo: null,
  1189. buyerPhone: null,
  1190. originalNo: null,
  1191. remark: null,
  1192. details: [],
  1193. }
  1194. expressNo.value = null
  1195. showInitialPage.value = showInputPage
  1196. initDetail()
  1197. }
  1198. // 扫码弹框
  1199. const scancodeDialog = ref(false)
  1200. const scancodeInputRef = ref(false)
  1201. const qualityStatusDialog = ref(false)
  1202. // 扫描条码dialog
  1203. function showScancode() {
  1204. scancodeDialog.value = true
  1205. }
  1206. function openScanCode() {
  1207. nextTick(() => {
  1208. setTimeout(() => {
  1209. const input = scancodeInputRef.value?.$el?.querySelector('input')
  1210. input?.focus()
  1211. input?.setSelectionRange(0, input.value.length)
  1212. }, 150)
  1213. })
  1214. }
  1215. // 选择质量状态
  1216. function showQualityStatus() {
  1217. const barcode = scancode.value
  1218. if (!barcode) {
  1219. showFailToast('商品条码异常')
  1220. scancodeDialog.value = true
  1221. return
  1222. }
  1223. qualityStatusDialog.value = true
  1224. qualityStatus.value = '正品'
  1225. }
  1226. // 查询商品
  1227. async function queryBarcode() {
  1228. showLoadingToast({
  1229. duration: 0,
  1230. forbidClick: true,
  1231. message: '查询商品信息中.....',
  1232. })
  1233. const barcode = scancode.value
  1234. const { ownerCode } = params.value
  1235. if (ownerCode) {
  1236. const result = await queryOwnerBarcode(ownerCode, barcode)
  1237. if (result) {
  1238. scancodeDialog.value = false
  1239. qualityStatusDialog.value = false
  1240. closeToast()
  1241. return
  1242. }
  1243. }
  1244. const { details } = params.value
  1245. if (!details || details.length === 0) {
  1246. await queryBarcodeBy(barcode)
  1247. scancodeDialog.value = false
  1248. qualityStatusDialog.value = false
  1249. closeToast()
  1250. }
  1251. }
  1252. /**
  1253. * 更具货主查询商品条码
  1254. * @param ownerCode
  1255. * @param barcode
  1256. * @returns {Promise<boolean>}
  1257. */
  1258. async function queryOwnerBarcode(ownerCode, barcode) {
  1259. try {
  1260. console.log('queryOwnerBarcode')
  1261. const results = await searchOwnerBarcode({ ownerCode, barcode })
  1262. const {
  1263. data: { basSku },
  1264. } = results
  1265. console.log(results)
  1266. if (!basSku) {
  1267. return false
  1268. }
  1269. addDetailByBasSku(basSku)
  1270. return true
  1271. } catch (err) {
  1272. console.log(err.message)
  1273. }
  1274. return false
  1275. }
  1276. /**
  1277. * 查询对应的
  1278. * @param barcode
  1279. * @returns {Promise<boolean>}
  1280. */
  1281. async function queryBarcodeBy(barcode) {
  1282. try {
  1283. const results = await searchBarcode({ barcode })
  1284. const { data } = results
  1285. const { basSku, ownerCodes } = data
  1286. if (ownerCodes && ownerCodes.length > 1) {
  1287. showOwnerSelectDialog(ownerCodes)
  1288. return null
  1289. }
  1290. if (!basSku) {
  1291. return null
  1292. }
  1293. addDetailByBasSku(basSku)
  1294. return null
  1295. } catch (err) {
  1296. console.log(err.message)
  1297. }
  1298. return null
  1299. }
  1300. // 添加详情
  1301. function addDetailByBasSku(basSku) {
  1302. const { sku, barCode, ownerCode, tradeName, accessories } = basSku
  1303. selectDetailIndex.value = -1
  1304. selectDetail.value.sku = sku
  1305. if (!params.value.ownerCode) {
  1306. params.value.ownerCode = ownerCode
  1307. initQualityInspection(params.value.ownerCode)
  1308. }
  1309. selectDetail.value.barCode = barCode
  1310. selectDetail.value.qualityStatus = qualityStatus.value
  1311. selectDetail.value.tradeName = tradeName
  1312. selectDetail.value.number = 1
  1313. scancodeDialog.value = false
  1314. qualityStatusDialog.value = false
  1315. returnedDetailDialog.value = true
  1316. // 显示
  1317. showAccessoriesItems(accessories)
  1318. }
  1319. const accessories = ref([])
  1320. const showAccessories = ref(false)
  1321. function showAccessoriesItems(items) {
  1322. console.log(items)
  1323. console.log(!items || items.length === 0)
  1324. if (!items || items.length === 0) {
  1325. accessories.value = []
  1326. showAccessories.value = false
  1327. return
  1328. }
  1329. accessories.value = items
  1330. showAccessories.value = true
  1331. }
  1332. // 质量状态
  1333. const returnedDetailDialog = ref(false)
  1334. const selectedDetailQualityStatus = ref(false)
  1335. const selectedDetailQualityStatusFunc = (row) => {
  1336. const { selectedOptions } = row
  1337. selectedDetailQualityStatus.value = false
  1338. selectDetail.value.qualityStatus = selectedOptions[0].text
  1339. }
  1340. // 辅助函数:格式化日期显示(可选)
  1341. const formatDateDisplay = (dateString) => {
  1342. if (!dateString) return ''
  1343. return dateString.replace(/-/g, '/') // 将 2023-05-01 显示为 2023/05/01
  1344. }
  1345. // 辅助函数:将日期字符串转换为数组格式 [年, 月, 日]
  1346. const parseDateValue = (dateString) => {
  1347. if (!dateString) return []
  1348. const [year, month, day] = dateString.split('-')
  1349. return [year, month, day]
  1350. }
  1351. // 生产日期
  1352. const showManufactureTime = ref(false)
  1353. const manufactureTimeConfirm = async (result) => {
  1354. if (!result.selectedValues) {
  1355. showManufactureTime.value = false
  1356. return
  1357. }
  1358. // 正确解构参数
  1359. const { selectedValues } = result
  1360. const [year, month, day] = selectedValues
  1361. const formattedMonth = month.padStart(2, '0')
  1362. const formattedDay = day.padStart(2, '0')
  1363. const manufactureTime = `${year}-${formattedMonth}-${formattedDay}`
  1364. const { sku } = selectDetail.value
  1365. const { owner: ownerCode } = params.value
  1366. const isValid = await checkValidateDate(
  1367. ownerCode,
  1368. sku,
  1369. manufactureTime,
  1370. 'manufactureTime',
  1371. )
  1372. if (!isValid) {
  1373. console.log('检验出现异常')
  1374. return
  1375. }
  1376. selectDetail.value.manufactureTime = manufactureTime
  1377. showManufactureTime.value = false
  1378. }
  1379. // 失效日期
  1380. const showValidityTime = ref(false)
  1381. const validityTimeConfirm = async (result) => {
  1382. if (!result.selectedValues) {
  1383. showValidityTime.value = false
  1384. return
  1385. }
  1386. // 正确解构参数
  1387. const { selectedValues } = result
  1388. const [year, month, day] = selectedValues
  1389. const formattedMonth = month.padStart(2, '0')
  1390. const formattedDay = day.padStart(2, '0')
  1391. const validityTime = `${year}-${formattedMonth}-${formattedDay}`
  1392. const { sku } = selectDetail.value
  1393. const { owner: ownerCode } = params.value
  1394. const isValid = await checkValidateDate(
  1395. ownerCode,
  1396. sku,
  1397. validityTime,
  1398. 'validityTime',
  1399. )
  1400. if (!isValid) {
  1401. return
  1402. }
  1403. selectDetail.value.validityTime = `${year}-${formattedMonth}-${formattedDay}`
  1404. showValidityTime.value = false
  1405. }
  1406. // 质量状态标签
  1407. function getTagColor(qualityStatus) {
  1408. return getTagColorBy(qualityStatus)
  1409. }
  1410. const addDetails = async () => {
  1411. const isCheck = checkUploadImages()
  1412. if (!isCheck) {
  1413. returnedDetailDialog.value = true
  1414. return false
  1415. }
  1416. const index = selectDetailIndex.value
  1417. const detail = JSON.parse(JSON.stringify(selectDetail.value))
  1418. if (index > -1) {
  1419. params.value.details[index] = detail
  1420. initDetail()
  1421. return true
  1422. }
  1423. // 查找对应的详情进行合并
  1424. params.value.details.push(detail)
  1425. // 重置详情
  1426. initDetail()
  1427. return true
  1428. }
  1429. // 删除对应的详情
  1430. function removeDetails(index) {
  1431. if (null === index) {
  1432. showFailToast('未找到对应的详情')
  1433. return
  1434. }
  1435. const { id } = params.value.details[index]
  1436. if (!id) {
  1437. params.value.details.splice(index, 1)
  1438. showSuccessToast('删除成功')
  1439. } else {
  1440. deleteDetails(id).then((res) => {
  1441. if (res.data) {
  1442. params.value.details.splice(index, 1)
  1443. showSuccessToast('删除成功')
  1444. } else {
  1445. showFailToast('删除失败')
  1446. }
  1447. })
  1448. }
  1449. }
  1450. function selectOwner({ selectedValues }) {
  1451. const ownerCode = selectedValues[0].value
  1452. params.value.ownerCode = selectedValues[0]
  1453. showOwnerSelect.value = false
  1454. ownerSelectedOptions.value = []
  1455. const barcode = scancode.value
  1456. searchOwnerBarcode({ ownerCode, barcode })
  1457. getStoreOptionsBy(ownerCode)
  1458. // 货主
  1459. }
  1460. const showOwnerSelect = ref(false)
  1461. const ownerSelectedOptions = ref([])
  1462. // 多货主选择
  1463. function showOwnerSelectDialog(items) {
  1464. if (!items || items.length === 0) {
  1465. ownerSelectedOptions.value = owners.value.map((item) => {
  1466. JSON.parse(JSON.stringify(item))
  1467. })
  1468. showOwnerSelect.value = true
  1469. return
  1470. }
  1471. ownerSelectedOptions.value = owners.value
  1472. .filter((item) => {
  1473. const { value } = item
  1474. return items.includes(value)
  1475. })
  1476. .map((item) => JSON.parse(JSON.stringify(item)))
  1477. showOwnerSelect.value = true
  1478. }
  1479. // 校验日期
  1480. async function checkValidateDate(ownerCode, sku, newDate, fieldName) {
  1481. if (['NOSKU', 'NOBARCODE'].includes(sku)) {
  1482. return true
  1483. }
  1484. const type = fieldName === 'manufactureTime' ? '生产日期' : '失效日期'
  1485. try {
  1486. await validateDate({
  1487. newDate: newDate,
  1488. fieldName: fieldName,
  1489. ownerCode: ownerCode,
  1490. sku: sku,
  1491. })
  1492. showNotify({
  1493. type: 'success',
  1494. message: `${type} 状态校验成功 `,
  1495. })
  1496. return true
  1497. } catch (error) {
  1498. showNotify({
  1499. type: 'warning',
  1500. message: `校验${type}出现异常`,
  1501. })
  1502. return false
  1503. }
  1504. }
  1505. function blobToBase64(blob) {
  1506. return new Promise((resolve, reject) => {
  1507. const fileReader = new FileReader()
  1508. fileReader.onload = (e) => {
  1509. resolve(e.target.result)
  1510. }
  1511. fileReader.readAsDataURL(blob)
  1512. fileReader.onerror = () => {
  1513. reject(new Error('blobToBase64 error'))
  1514. }
  1515. })
  1516. }
  1517. // 编辑等级详情
  1518. function editDetails(index) {
  1519. selectDetailIndex.value = index
  1520. const { details } = params.value
  1521. selectDetail.value = JSON.parse(JSON.stringify(details[index]))
  1522. returnedDetailDialog.value = true
  1523. }
  1524. // 写入当前商品详情
  1525. function pushImageItem(event, type) {
  1526. const file = event.target.files[0]
  1527. if (!file) return
  1528. if (!file.type.startsWith('image/')) {
  1529. alert('请选择图片文件!')
  1530. return
  1531. }
  1532. const filename = file.name
  1533. const item = {
  1534. src: URL.createObjectURL(file),
  1535. file: file,
  1536. fileName: filename,
  1537. type,
  1538. }
  1539. if (type === '外箱图') {
  1540. if (!selectDetail.value.boxPhotos) {
  1541. selectDetail.value.boxPhotos = []
  1542. }
  1543. blobToBase64(file).then((_) => {
  1544. const some = boxFiles.value.some((item) => {
  1545. return filename === item.fileName
  1546. })
  1547. if (some) {
  1548. showFailToast('录入重复图片')
  1549. } else {
  1550. boxFiles.value.push(item)
  1551. selectDetail.value.boxPhotos.push(filename)
  1552. }
  1553. })
  1554. } else if (type === '内物图') {
  1555. if (!selectDetail.value.productPhotos) {
  1556. selectDetail.value.productPhotos = []
  1557. }
  1558. blobToBase64(file).then((_) => {
  1559. const some = productFiles.value.some((item) => {
  1560. return filename === item.fileName
  1561. })
  1562. if (some) {
  1563. showFailToast('录入重复图片')
  1564. } else {
  1565. productFiles.value.push(item)
  1566. selectDetail.value.productPhotos.push(filename)
  1567. }
  1568. })
  1569. }
  1570. }
  1571. // 触发拍照
  1572. function invokeCameraToCapture(type) {
  1573. const { sku } = selectDetail.value
  1574. if (!sku) {
  1575. showFailToast('当前没有可录入的商品信息')
  1576. return
  1577. }
  1578. if (type === '外箱图') {
  1579. document.getElementById('outer-carton-box-input').click()
  1580. } else if (type === '内物图') {
  1581. document.getElementById('inner-contents-input').click()
  1582. }
  1583. }
  1584. function getImageUrl(filename, type) {
  1585. let list = []
  1586. if (type === '外箱图') {
  1587. list = boxFiles.value
  1588. } else if (type === '内物图') {
  1589. list = productFiles.value
  1590. }
  1591. for (let i = 0; i < list.length; i++) {
  1592. const item = list[i]
  1593. const { src, fileName } = item
  1594. if (fileName === fileName) {
  1595. return src
  1596. }
  1597. }
  1598. return null
  1599. }
  1600. // 外箱图事件
  1601. function outerCartonInput(event) {
  1602. pushImageItem(event, '外箱图')
  1603. }
  1604. // 内物图异常
  1605. function innerContentsInput(event) {
  1606. pushImageItem(event, '内物图')
  1607. }
  1608. function submit() {
  1609. const { ownerCode, logisticsName, returnNo, warehouseCode } = params.value
  1610. if (!ownerCode || ownerCode.length === 0) {
  1611. showNotify({
  1612. type: 'warning',
  1613. message: '没有对应的退件详情!请录入对应的退件详情',
  1614. })
  1615. return
  1616. } else if (!logisticsName || logisticsName.length === 0) {
  1617. showNotify({
  1618. type: 'warning',
  1619. message: '请录入承运商',
  1620. })
  1621. return
  1622. } else if (!returnNo || ownerCode.length === 0) {
  1623. showNotify({
  1624. type: 'warning',
  1625. message: '请录入退件单号',
  1626. })
  1627. return
  1628. } else if (!warehouseCode || warehouseCode.length === 0) {
  1629. showNotify({
  1630. type: 'warning',
  1631. message: '请选择登记仓库',
  1632. })
  1633. return
  1634. }
  1635. console.log('checkDetailNumber')
  1636. if (checkDetailNumber()) {
  1637. return
  1638. }
  1639. const formData = new FormData()
  1640. const boxItems = boxFiles && boxFiles.value ? boxFiles.value : []
  1641. const productItems =
  1642. productFiles && productFiles.value ? productFiles.value : []
  1643. const files = [...boxItems, ...productItems]
  1644. const filenames = []
  1645. if (files && files.length > 0) {
  1646. files.forEach((item) => {
  1647. const { file, fileName } = item
  1648. if (!filenames.includes(fileName)) {
  1649. formData.append('files', file)
  1650. filenames.push(fileName)
  1651. }
  1652. })
  1653. }
  1654. handleDetails(params.value.details)
  1655. formData.append('body', JSON.stringify(params.value))
  1656. console.log(formData)
  1657. showLoadingToast({
  1658. duration: 0,
  1659. forbidClick: true,
  1660. message: '提交登记中.....',
  1661. })
  1662. register(formData)
  1663. .then((res) => {
  1664. const { data } = res
  1665. const { accumulateTaskMap } = data
  1666. closeToast()
  1667. if (data) {
  1668. if (accumulateTaskMap && accumulateTaskMap.length > 0) {
  1669. let messages = []
  1670. const ownerName = getOwnerName(params.value.ownerCode)
  1671. for (let i = 0; i < accumulateTaskMap.length; i++) {
  1672. const { quality, taskCode } = accumulateTaskMap[i]
  1673. messages.push(`进入${ownerName}新的${quality}攒单任务号${taskCode}`)
  1674. }
  1675. showConfirmDialog({
  1676. title: '提交成功',
  1677. message: messages.join('\r\n'),
  1678. theme: 'round-button',
  1679. })
  1680. } else {
  1681. showNotify({
  1682. type: 'success',
  1683. message: '成功提交',
  1684. })
  1685. }
  1686. init()
  1687. params.value.ownerCode = ownerCode
  1688. }
  1689. })
  1690. .catch(() => {
  1691. closeToast()
  1692. })
  1693. }
  1694. function checkDetailNumber() {
  1695. const { details } = params.value
  1696. if (!details || details.length === 0) {
  1697. showNotify({
  1698. type: 'warning',
  1699. message: '登记详情不能为空',
  1700. })
  1701. return true
  1702. }
  1703. const check = details.some((item) => {
  1704. const { number } = item
  1705. return Number.isNaN(number) || Number(number) <= 0
  1706. })
  1707. if (check) {
  1708. showNotify({
  1709. type: 'warning',
  1710. message: '登记数量不能为 0 和 空 ',
  1711. })
  1712. }
  1713. return check
  1714. }
  1715. function handleDetails(details) {
  1716. for (let i = 0; i < details.length; i++) {
  1717. const { qualityStatus } = details[i]
  1718. console.log(qualityStatus)
  1719. const { isGenuineValue, qualityMark } = getStatus(qualityStatus)
  1720. details[i].isGenuine = isGenuineValue
  1721. details[i].qualityMark = qualityMark
  1722. }
  1723. }
  1724. const showPhotosPreview = ref(false)
  1725. const startPhotosPosition = ref(0)
  1726. const showPhotosImagePreview = (index) => {
  1727. startPhotosPosition.value = index
  1728. showPhotosPreview.value = true
  1729. }
  1730. const onPhotosPreviewChange = (index) => {
  1731. startPhotosPosition.value = index
  1732. }
  1733. const handlePhotosDelete = () => {
  1734. showConfirmDialog({
  1735. title: '提示',
  1736. message: '确定要删除这张图片吗?',
  1737. })
  1738. .then(() => {
  1739. selectDetail.value.productPhotos.splice(startBoxPosition.value, 1)
  1740. showToast('删除成功')
  1741. if (selectDetail.value.productPhotos.length === 0) {
  1742. showPhotosPreview.value = false
  1743. } else if (
  1744. startPhotosPosition.value >= selectDetail.value.productPhotos.length
  1745. ) {
  1746. startPhotosPosition.value = selectDetail.value.productPhotos.length - 1
  1747. }
  1748. // 这里可以添加实际删除图片的API调用
  1749. // deleteImageAPI(deletedImage).then(...)
  1750. })
  1751. .catch(() => {
  1752. // 取消删除
  1753. })
  1754. }
  1755. const showBoxPreview = ref(false)
  1756. const startBoxPosition = ref(0)
  1757. const showBoxImagePreview = (index) => {
  1758. startBoxPosition.value = index
  1759. showBoxPreview.value = true
  1760. }
  1761. const onBoxPreviewChange = (index) => {
  1762. startBoxPosition.value = index
  1763. }
  1764. const handleBoxDelete = () => {
  1765. showConfirmDialog({
  1766. title: '提示',
  1767. message: '确定要删除这张图片吗?',
  1768. })
  1769. .then(() => {
  1770. selectDetail.value.boxPhotos.splice(startBoxPosition.value, 1)
  1771. showToast('删除成功')
  1772. if (selectDetail.value.boxPhotos.length === 0) {
  1773. showBoxPreview.value = false
  1774. } else if (
  1775. startBoxPosition.value >= selectDetail.value.boxPhotos.length
  1776. ) {
  1777. startBoxPosition.value = selectDetail.value.boxPhotos.length - 1
  1778. }
  1779. // 这里可以添加实际删除图片的API调用
  1780. // deleteImageAPI(deletedImage).then(...)
  1781. })
  1782. .catch(() => {
  1783. // 取消删除
  1784. })
  1785. }
  1786. const detailBoxImages = computed(() => {
  1787. const items = selectDetail.value.boxPhotos
  1788. if (!items || items.length === 0) {
  1789. return []
  1790. }
  1791. return boxFiles.value
  1792. .filter((item) => {
  1793. return items.includes(item.fileName)
  1794. })
  1795. .map((item) => item.src)
  1796. })
  1797. const detailProductImages = computed(() => {
  1798. const items = selectDetail.value.productPhotos
  1799. if (!items || items.length === 0) {
  1800. return []
  1801. }
  1802. return boxFiles.value
  1803. .filter((item) => {
  1804. return items.includes(item.fileName)
  1805. })
  1806. .map((item) => item.src)
  1807. })
  1808. // 校验是否上次图片
  1809. function checkUploadImages() {
  1810. const status = ['次品', '待修复']
  1811. const { productPhotos, boxPhotos, qualityStatus } = selectDetail.value
  1812. if (!status.includes(qualityStatus)) {
  1813. return true
  1814. }
  1815. const boxPhotoIsNull = !boxPhotos || boxPhotos.length === 0
  1816. const productPhotoIsNull = !productPhotos || productPhotos.length === 0
  1817. if (boxPhotoIsNull) {
  1818. showNotify({
  1819. type: 'warning',
  1820. message: '请传入对应的外箱图',
  1821. })
  1822. return false
  1823. }
  1824. if (productPhotoIsNull) {
  1825. showNotify({
  1826. type: 'warning',
  1827. message: '请传入对应的内物图',
  1828. })
  1829. return false
  1830. }
  1831. return true
  1832. }
  1833. window.onRefresh = async () => {
  1834. console.log('window.onRefresh')
  1835. }
  1836. </script>
  1837. <style scoped lang="sass">
  1838. .van-nav-bar
  1839. .left-btn
  1840. color: #fff
  1841. height: 46px
  1842. padding-right: 20px
  1843. line-height: 46px
  1844. .right-btn
  1845. color: #fff
  1846. .container
  1847. .init-container
  1848. width: 100%
  1849. .scan-returned-content
  1850. padding: 10px
  1851. .input-group
  1852. padding: 5px
  1853. .button-group
  1854. padding: 5px
  1855. .content
  1856. width: 100%
  1857. .scan-returned-no
  1858. align-items: center
  1859. padding: 15px
  1860. .returned-detail-list
  1861. .card-div
  1862. background: #fff
  1863. border-radius: 12px
  1864. overflow: hidden
  1865. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05)
  1866. margin: 5px 0
  1867. padding: 5px 0
  1868. .card-div-content
  1869. padding: 3px
  1870. .info-row
  1871. display: flex
  1872. margin-bottom: 12px
  1873. font-size: 12px
  1874. .info-label
  1875. width: 100px
  1876. color: #969799
  1877. .info-value
  1878. flex: 1
  1879. color: #333333
  1880. font-weight: 500
  1881. .card-div-footer
  1882. padding: 5px
  1883. background: #fafafa
  1884. border-top: 1px solid #f5f5f5
  1885. color: #646566
  1886. font-size: 14px
  1887. line-height: 1.5
  1888. .card-div-footer-images
  1889. padding: 5px
  1890. background: #fafafa
  1891. border-top: 1px solid #f5f5f5
  1892. color: #646566
  1893. font-size: 14px
  1894. line-height: 1.5
  1895. .card-div-footer-options
  1896. background: #fafafa
  1897. border-top: 1px solid #f5f5f5
  1898. color: #646566
  1899. font-size: 14px
  1900. .options-row
  1901. display: flex
  1902. font-size: 12px
  1903. .info-label
  1904. width: 100px
  1905. color: #969799
  1906. .info-value
  1907. flex: 1
  1908. color: #333333
  1909. font-weight: 500
  1910. .returned-details
  1911. .van-field
  1912. padding: 0
  1913. </style>