AddLoss.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view class="detail-view">
  3. <u-form label-width="160" :model="add_form" ref="uForm">
  4. <view class="form-model-view">
  5. <u-form-item required label="报损仓库" prop="warehouseName">
  6. <u-input @click="goPage('/pagesT/werahouse/selWerahouse')" class="dis-input" disabled v-model="add_form.warehouseName" placeholder="请选择" />
  7. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  8. </u-form-item>
  9. </view>
  10. <view class="form-model-view">
  11. <u-form-item required label="商品清单">
  12. <view @click="selGoodsPage" class="form-value add-btn-go">
  13. <u-icon name="plus" size="24"></u-icon>
  14. <text>选择商品</text>
  15. </view>
  16. </u-form-item>
  17. <view class="goods-ul" v-if="goods_list.length">
  18. <block v-for="(item, index) in goods_list" :key="index">
  19. <view class="goods-li clearfix">
  20. <view class="goods-img float_left" @click="delGoods(item, index)"><u-icon size="40" name="minus-circle-fill" color="#fa3534"></u-icon></view>
  21. <view class="float_left info">
  22. <view class="goods-name ellipsis">{{ item.materielName }}</view>
  23. <view class="goods-code">{{ item.materielCode }}</view>
  24. <view class="goods-num clearfix">
  25. <view class="float_left">{{ item.unitName }};{{ item.skuName }}</view>
  26. <view class="float_right">账目库存: {{ $utils.formatNub(item.inventoryNum) }}</view>
  27. </view>
  28. <view class="num-ul">
  29. <view class="num-li">
  30. <view class="label">当前成本</view>
  31. <input type="digit" disabled v-model="item.lossAmount" />
  32. </view>
  33. <view class="num-li">
  34. <view class="label">报损数量</view>
  35. <input type="digit" placeholder="请输入" v-model="item.num" />
  36. </view>
  37. <view class="num-li" v-if="item.isEq === 5">
  38. <view class="label">其他单位</view>
  39. <input type="digit" placeholder="请输入" v-model="item.otherNum" />
  40. </view>
  41. <view class="num-li">
  42. <view class="label">报损金额</view>
  43. <input type="digit" disabled :value="$utils.formatNub($NP.times(item.lossAmount, item.num))" />
  44. </view>
  45. <view class="num-li" v-if="enableLocationManagement === 5">
  46. <view class="label">库区库位</view>
  47. <input
  48. @click="openLocation(index, item)"
  49. disabled
  50. type="text"
  51. placeholder="请选择"
  52. :value="item.storageLocationName ? item.areaName + '-' + item.storageLocationName : ''"
  53. />
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </block>
  59. </view>
  60. </view>
  61. <view class="form-model-view">
  62. <u-form-item label="备注" label-position="top"><u-input type="textarea" v-model="add_form.remark" /></u-form-item>
  63. </view>
  64. </u-form>
  65. <view class="detail-bottom"><u-button class="handel-btn" @click="submit" :loading="sub_load" :ripple="true" type="primary">提交</u-button></view>
  66. </view>
  67. </template>
  68. <script>
  69. export default {
  70. data() {
  71. return {
  72. rules: {
  73. warehouseName: [
  74. {
  75. required: true,
  76. message: '请选择所属仓库',
  77. trigger: ['change', 'blur']
  78. }
  79. ]
  80. },
  81. werahouseData: '',
  82. warehouseGoods: '',
  83. add_form: {
  84. warehouseName: '',
  85. warehouseId: '',
  86. operatorName: '',
  87. remark: ''
  88. },
  89. goods_list: [],
  90. sub_load: false,
  91. goods_index: 0,
  92. areaBysku: ''
  93. };
  94. },
  95. computed: {
  96. userName() {
  97. return this.$store.state.userInfo.name;
  98. },
  99. enableLocationManagement() {
  100. return parseInt(this.$store.state.basicSet.enableLocationManagement);
  101. }
  102. },
  103. watch: {
  104. werahouseData(val) {
  105. if (val) {
  106. this.add_form.warehouseId = val.id;
  107. this.add_form.warehouseName = val.warehouseName;
  108. this.goods_list = [];
  109. }
  110. },
  111. // 选择商品页面返回
  112. warehouseGoods(list) {
  113. if (list) {
  114. this.selGoods(list);
  115. }
  116. },
  117. areaBysku(val) {
  118. if (val) {
  119. const target = this.$u.deepClone(this.goods_list);
  120. target[this.goods_index] = {
  121. ...target[this.goods_index],
  122. areaId: val.areaId,
  123. areaName: val.areaName,
  124. areaCode: val.areaCode,
  125. storageLocationId: val.storageLocationId,
  126. storageLocationName: val.storageLocationName,
  127. storageLocationCode: val.storageLocationCode
  128. };
  129. this.goods_list = target;
  130. }
  131. }
  132. },
  133. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  134. onReady() {
  135. this.$refs.uForm.setRules(this.rules);
  136. },
  137. onLoad(options) {},
  138. methods: {
  139. // 去选择库区库位页面
  140. openLocation(index, row) {
  141. this.goods_index = index;
  142. this.goPage(`/pagesT/stock/WarehouseRegionBySku?basicGoodsId=${row.materielId}&skuId=${row.skuId}&warehouseId=${this.add_form.warehouseId}`);
  143. },
  144. delGoods(row, index) {
  145. this.goods_list.splice(index, 1);
  146. },
  147. selGoodsPage() {
  148. if (!this.add_form.warehouseId) {
  149. this.$u.toast('请选择仓库');
  150. return;
  151. }
  152. uni.setStorageSync('warehouseGoods', this.goods_list);
  153. this.goPage('/pagesT/goods/GoodsbyWarehouse?id=' + this.add_form.warehouseId);
  154. },
  155. // 多选商品确定
  156. selGoods(list) {
  157. this.goods_list = list.map(item => {
  158. return {
  159. isEq: item.isEq,
  160. otherNum: '',
  161. materielId: item.materielId,
  162. materielCode: item.materielCode,
  163. materielName: item.materielName,
  164. warehouseName: this.add_form.warehouseName,
  165. skuName: item.skuName,
  166. skuId: item.skuId,
  167. unitName: item.unitName,
  168. inventoryNum: Number(item.inventoryNum),
  169. lossAmount: Number(item.costPrice),
  170. num: item.buyNum,
  171. areaId: '',
  172. areaName: '',
  173. areaCode: '',
  174. storageLocationName: '',
  175. storageLocationId: '',
  176. storageLocationCode: ''
  177. };
  178. });
  179. },
  180. submit() {
  181. this.$refs.uForm.validate(valid => {
  182. if (valid) {
  183. if (!this.goods_list.length) {
  184. this.$u.toast('请选择商品');
  185. return;
  186. }
  187. const isbuyerNum = this.goods_list.every(item => item.num > 0);
  188. if (!isbuyerNum) {
  189. this.$u.toast('报损数量必须大于0');
  190. return;
  191. }
  192. let goodsData = this.goods_list.map(item => {
  193. let goods = {
  194. materielId: item.materielId,
  195. materielName: item.materielName,
  196. materielCode: item.materielCode,
  197. skuId: item.skuId,
  198. unitName: item.unitName,
  199. skuName: item.skuName,
  200. num: item.num,
  201. inventoryNum: item.inventoryNum,
  202. lossAmount: item.lossAmount,
  203. otherNum: item.otherNum,
  204. areaId: item.areaId,
  205. areaName: item.areaName,
  206. areaCode: item.areaCode,
  207. storageLocationName: item.storageLocationName,
  208. storageLocationId: item.storageLocationId,
  209. storageLocationCode: item.storageLocationCode
  210. };
  211. return goods;
  212. });
  213. const params = {
  214. warehouseId: this.add_form.warehouseId,
  215. warehouseName: this.add_form.warehouseName,
  216. remark: this.add_form.remark,
  217. operatorName: this.userName,
  218. details: goodsData
  219. };
  220. this.sub_load = true;
  221. this.$u.api
  222. .addReportLoss(params)
  223. .then(res => {
  224. this.sub_load = false;
  225. this.$u.toast('新建成功');
  226. setTimeout(() => {
  227. uni.navigateBack();
  228. }, 2000);
  229. })
  230. .catch(err => {
  231. this.sub_load = false;
  232. });
  233. }
  234. });
  235. }
  236. }
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. .goods-ul {
  241. padding-bottom: 20rpx;
  242. .goods-title {
  243. margin-bottom: 20rpx;
  244. line-height: 80rpx;
  245. font-size: 24rpx;
  246. border-bottom: 1px solid #eeeeee;
  247. .float_right {
  248. color: $uni-color-primary;
  249. }
  250. }
  251. .goods-li {
  252. line-height: 32rpx;
  253. margin-top: 20rpx;
  254. .goods-img {
  255. margin-right: 20rpx;
  256. image {
  257. width: 150rpx;
  258. height: 150rpx;
  259. border-radius: 8rpx;
  260. display: block;
  261. }
  262. }
  263. .info {
  264. width: 640rpx;
  265. .num-ul {
  266. display: flex;
  267. padding-top: 20rpx;
  268. .num-li {
  269. font-size: 24rpx;
  270. line-height: 36rpx;
  271. flex: 3;
  272. text-align: center;
  273. position: relative;
  274. font-weight: bold;
  275. padding: 0 16rpx;
  276. .label {
  277. font-weight: 400;
  278. color: #999999;
  279. }
  280. input {
  281. text-align: center;
  282. border-bottom: 1px solid $uni-color-primary;
  283. &.input-dis {
  284. border-bottom: 1px solid #eeeeee;
  285. }
  286. }
  287. &::after {
  288. display: block;
  289. content: '';
  290. position: absolute;
  291. width: 1px;
  292. height: 60rpx;
  293. top: 50%;
  294. transform: translateY(-50%);
  295. right: 0;
  296. background-color: #eeeeee;
  297. }
  298. &:last-child {
  299. &::after {
  300. display: block;
  301. content: '';
  302. position: absolute;
  303. width: 1px;
  304. height: 50rpx;
  305. top: 50%;
  306. transform: translateY(-50%);
  307. right: 0;
  308. background-color: transparent;
  309. }
  310. }
  311. }
  312. }
  313. .goods-name {
  314. width: 640rpx;
  315. height: 34rpx;
  316. line-height: 34rpx;
  317. }
  318. .goods-code {
  319. font-size: 24rpx;
  320. padding-top: 10rpx;
  321. }
  322. .goods-num {
  323. padding-top: 10rpx;
  324. font-size: 24rpx;
  325. .price {
  326. font-size: 28rpx;
  327. font-weight: bold;
  328. color: $uni-color-error;
  329. }
  330. }
  331. }
  332. }
  333. }
  334. </style>