goods.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <template>
  2. <view class="content-box">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" :title="title" background-color="#157A2C" color="#fff" @clickLeft="back"></uni-nav-bar>
  4. <view class="list_box">
  5. <u-list>
  6. <!-- 新增在制品按钮 -->
  7. <u-list-item v-if="type !== 'detail' && type !== 'receipt'">
  8. <view class="btn-group">
  9. <u-button type="success" class="btn-add" @click="addGoods">新增在制品</u-button>
  10. </view>
  11. </u-list-item>
  12. <!-- 货物列表 -->
  13. <u-list-item v-for="(item, index) in goodsList" :key="index">
  14. <view class="goods-item">
  15. <view class="goods-header">
  16. <text class="goods-name">{{ item.categoryName }}</text>
  17. <view class="goods-type">
  18. <text class="type-tag">{{ getTypeName(item.rootCategoryLevelId) }}</text>
  19. </view>
  20. </view>
  21. <view class="goods-row">
  22. <text class="label">牌号:</text>
  23. <text class="value">{{ item.brandNum }}</text>
  24. </view>
  25. <view class="goods-row">
  26. <text class="label">批次号:</text>
  27. <text class="value">{{ item.batchNo }}</text>
  28. </view>
  29. <view class="goods-row">
  30. <text class="label">数量:</text>
  31. <text class="value">{{ item.quantity }}{{ item.measuringUnit }}</text>
  32. </view>
  33. <view class="goods-row">
  34. <text class="label">重量:</text>
  35. <text class="value">{{ item.weight }}{{ item.weightUnit }}</text>
  36. </view>
  37. <view class="goods-row">
  38. <text class="label">生产工单号:</text>
  39. <text class="value">{{ item.workOrderCode }}</text>
  40. </view>
  41. <view class="goods-row">
  42. <text class="label">规格:</text>
  43. <text class="value">{{ item.specification }}</text>
  44. </view>
  45. <view class="goods-row">
  46. <text class="label">型号:</text>
  47. <text class="value">{{ item.modelType }}</text>
  48. </view>
  49. <view class="goods-row">
  50. <text class="label">编码:</text>
  51. <text class="value">{{ item.categoryCode }}</text>
  52. </view>
  53. <!-- 收货数量输入 -->
  54. <view v-if="type === 'receipt'" class="goods-row">
  55. <text class="label">接收数量:</text>
  56. <view class="input-wrapper">
  57. <input
  58. v-model="item.receiveQuantity"
  59. type="digit"
  60. :disabled="itemData.sendStatus == 4"
  61. class="quantity-input"
  62. placeholder="请输入接收数量"
  63. />
  64. <text class="unit">{{ item.measuringUnit }}</text>
  65. </view>
  66. </view>
  67. </view>
  68. </u-list-item>
  69. <u-list-item v-if="goodsList.length === 0">
  70. <view class="empty-wrapper">
  71. <u-empty iconSize="150" textSize="32" text="暂无货物信息"></u-empty>
  72. </view>
  73. </u-list-item>
  74. </u-list>
  75. </view>
  76. <!-- 底部按钮 -->
  77. <view v-if="type !== 'detail' && itemData.sendStatus != 4" class="footer-btns">
  78. <u-button class="btn-cancel" @click="handleCancel">取消</u-button>
  79. <u-button v-if="type === 'receipt'" type="error" class="btn-reject" @click="handleReject">驳回</u-button>
  80. <u-button type="success" class="btn-confirm" @click="handleConfirm">确定</u-button>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import {
  86. pleaseEntrustDetail,
  87. pleaseEntrustGoodsDetail,
  88. pleaseEntrustSaveDetail,
  89. pleaseTReceiveGoods
  90. } from '@/api/entrust/index';
  91. export default {
  92. data() {
  93. return {
  94. type: 'add',
  95. title: '发货单',
  96. itemData: {},
  97. goodsList: [],
  98. id: ''
  99. };
  100. },
  101. onLoad(options) {
  102. this.type = options.type || 'add';
  103. this.id = options.id;
  104. this.title = this.type !== 'receipt' ? '发货单' : '收货单';
  105. if (this.id) {
  106. this.getDetailData();
  107. }
  108. },
  109. methods: {
  110. async getDetailData() {
  111. try {
  112. // 先获取请托详情
  113. const detailRes = await pleaseEntrustDetail(this.id);
  114. this.itemData = detailRes || {};
  115. // 再获取货物详情
  116. await this.getGoodsDetail();
  117. } catch (error) {
  118. uni.showToast({
  119. title: '加载失败',
  120. icon: 'none'
  121. });
  122. }
  123. },
  124. async getGoodsDetail() {
  125. try {
  126. const detailType = this.type === 'receipt' ? 2 : 1;
  127. const res = await pleaseEntrustGoodsDetail({
  128. id: this.id,
  129. detailType
  130. });
  131. this.goodsList = [];
  132. if (res && res.length > 0) {
  133. res.forEach((item) => {
  134. if (this.type === 'receipt' && this.itemData.sendStatus != 4) {
  135. item.receiveQuantity = item.quantity;
  136. }
  137. this.goodsList.push({ ...item });
  138. });
  139. }
  140. } catch (error) {
  141. uni.showToast({
  142. title: '加载失败',
  143. icon: 'none'
  144. });
  145. }
  146. },
  147. getTypeName(type) {
  148. const typeMap = {
  149. 1: '原材料',
  150. 2: '半成品',
  151. 3: '成品',
  152. 4: '辅料',
  153. 5: '包材'
  154. };
  155. return typeMap[type] || '';
  156. },
  157. addGoods() {
  158. const existingIds = encodeURIComponent(JSON.stringify(this.goodsList));
  159. uni.navigateTo({
  160. url: `/pages/pda/entrust/selectGoods/selectGoods?id=${this.id}&existingIds=${existingIds}`
  161. });
  162. },
  163. receiveGoods(selectedList) {
  164. // 接收选择的在制品数据
  165. this.goodsList = selectedList.map(item => ({ ...item }));
  166. },
  167. handleCancel() {
  168. uni.navigateBack();
  169. },
  170. handleReject() {
  171. uni.showModal({
  172. title: '驳回原因',
  173. editable: true,
  174. placeholderText: '请输入驳回原因',
  175. success: (res) => {
  176. if (res.confirm && res.content) {
  177. // 处理驳回逻辑
  178. uni.showToast({
  179. title: '已驳回',
  180. icon: 'success'
  181. });
  182. setTimeout(() => {
  183. uni.navigateBack();
  184. }, 1500);
  185. }
  186. }
  187. });
  188. },
  189. async handleConfirm() {
  190. if (this.type !== 'receipt') {
  191. // 发货
  192. if (this.goodsList.length === 0) {
  193. uni.showToast({
  194. title: '请先新增一条在制品数据',
  195. icon: 'none'
  196. });
  197. return;
  198. }
  199. uni.showLoading({ title: '发货中...' });
  200. try {
  201. await pleaseEntrustSaveDetail(this.goodsList);
  202. uni.hideLoading();
  203. uni.showToast({
  204. title: '发货成功',
  205. icon: 'success'
  206. });
  207. setTimeout(() => {
  208. // 通知上一页刷新
  209. const pages = getCurrentPages();
  210. const prevPage = pages[pages.length - 2];
  211. if (prevPage && prevPage.$vm.getDetail) {
  212. prevPage.$vm.getDetail();
  213. }
  214. uni.navigateBack();
  215. }, 1500);
  216. } catch (error) {
  217. uni.hideLoading();
  218. uni.showToast({
  219. title: '发货失败',
  220. icon: 'none'
  221. });
  222. }
  223. } else {
  224. // 收货
  225. uni.showLoading({ title: '收货中...' });
  226. try {
  227. await pleaseTReceiveGoods(this.goodsList);
  228. uni.hideLoading();
  229. uni.showToast({
  230. title: '收货成功',
  231. icon: 'success'
  232. });
  233. setTimeout(() => {
  234. // 通知上一页刷新
  235. const pages = getCurrentPages();
  236. const prevPage = pages[pages.length - 2];
  237. if (prevPage && prevPage.$vm.getDetail) {
  238. prevPage.$vm.getDetail();
  239. }
  240. uni.navigateBack();
  241. }, 1500);
  242. } catch (error) {
  243. uni.hideLoading();
  244. uni.showToast({
  245. title: '收货失败',
  246. icon: 'none'
  247. });
  248. }
  249. }
  250. }
  251. }
  252. };
  253. </script>
  254. <style lang="scss" scoped>
  255. .content-box {
  256. height: 100vh;
  257. overflow: hidden;
  258. display: flex;
  259. flex-direction: column;
  260. background-color: $page-bg;
  261. }
  262. .list_box {
  263. flex: 1;
  264. overflow: hidden;
  265. padding: 16rpx 0;
  266. .u-list {
  267. height: 100% !important;
  268. }
  269. }
  270. .btn-group {
  271. padding: 0 24rpx 20rpx;
  272. .btn-add {
  273. width: 100%;
  274. height: 70rpx;
  275. border-radius: 35rpx;
  276. font-size: 28rpx;
  277. }
  278. }
  279. .goods-item {
  280. background-color: #fff;
  281. border-radius: 12rpx;
  282. padding: 24rpx;
  283. margin: 0 24rpx 20rpx;
  284. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  285. .goods-header {
  286. display: flex;
  287. justify-content: space-between;
  288. align-items: center;
  289. margin-bottom: 20rpx;
  290. padding-bottom: 20rpx;
  291. border-bottom: 1rpx solid #f0f0f0;
  292. .goods-name {
  293. font-size: 32rpx;
  294. font-weight: bold;
  295. color: #333;
  296. }
  297. .type-tag {
  298. display: inline-block;
  299. padding: 4rpx 16rpx;
  300. background-color: rgba(21, 122, 44, 0.1);
  301. color: $theme-color;
  302. border-radius: 4rpx;
  303. font-size: 24rpx;
  304. }
  305. }
  306. .goods-row {
  307. display: flex;
  308. align-items: center;
  309. margin-bottom: 16rpx;
  310. font-size: 28rpx;
  311. .label {
  312. color: #999;
  313. min-width: 180rpx;
  314. }
  315. .value {
  316. flex: 1;
  317. color: #333;
  318. word-break: break-all;
  319. }
  320. .input-wrapper {
  321. flex: 1;
  322. display: flex;
  323. align-items: center;
  324. .quantity-input {
  325. flex: 1;
  326. padding: 12rpx 16rpx;
  327. border: 1rpx solid #e0e0e0;
  328. border-radius: 6rpx;
  329. font-size: 28rpx;
  330. }
  331. .unit {
  332. margin-left: 8rpx;
  333. color: #999;
  334. }
  335. }
  336. }
  337. }
  338. .empty-wrapper {
  339. display: flex;
  340. align-items: center;
  341. justify-content: center;
  342. padding-top: 25vh;
  343. }
  344. .footer-btns {
  345. display: flex;
  346. gap: 20rpx;
  347. padding: 20rpx 32rpx;
  348. background-color: #fff;
  349. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.08);
  350. padding-bottom: constant(safe-area-inset-bottom);
  351. padding-bottom: env(safe-area-inset-bottom);
  352. /deep/ .u-button {
  353. flex: 1;
  354. height: 80rpx;
  355. border-radius: 40rpx;
  356. font-size: 30rpx;
  357. }
  358. .btn-cancel {
  359. background-color: #fff;
  360. color: #666;
  361. border: 1rpx solid #e0e0e0;
  362. }
  363. }
  364. </style>