AddInventory.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. <u-form-item required label="盘点日期" prop="buyerName">
  10. <picker mode="date" @change="bindDateChange">
  11. <view style="width: 510rpx;text-align: right;margin-right: 10rpx;display: inline-block;">
  12. <text v-if="add_form.stocktakingTime">{{ $u.timeFormat(add_form.stocktakingTime, 'yyyy-mm-dd') }}</text>
  13. <text style="color:#B8C0C8;" v-else>请选择</text>
  14. </view>
  15. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  16. </picker>
  17. </u-form-item>
  18. </view>
  19. <view class="form-model-view">
  20. <u-form-item required label="商品清单">
  21. <view @click="selGoodsPage" class="form-value add-btn-go">
  22. <u-icon name="plus" size="24"></u-icon>
  23. <text>选择商品</text>
  24. </view>
  25. </u-form-item>
  26. <view class="goods-ul" v-if="goods_list.length">
  27. <block v-for="(item, index) in goods_list" :key="index">
  28. <view class="goods-li clearfix">
  29. <view class="goods-img float_left" @click="delGoods(item, index)"><u-icon size="40" name="minus-circle-fill" color="#fa3534"></u-icon></view>
  30. <view class="float_left info">
  31. <view class="goods-name ellipsis">{{ item.materielName }}</view>
  32. <view class="goods-code">{{ item.materielCode }}</view>
  33. <view class="goods-num clearfix">
  34. <view class="float_left">{{ item.unitName }};{{ item.skuName }}</view>
  35. <view class="float_right">账目库存: {{ $utils.formatNub(item.documentInventoryNum) }}</view>
  36. </view>
  37. <view class="num-ul">
  38. <view class="num-li">
  39. <view class="label">实盘库存</view>
  40. <input @blur="editNumChange(index)" type="digit" placeholder="请输入" v-model="item.currentInventoryNum" />
  41. </view>
  42. <view class="num-li" v-if="item.isEq === 5">
  43. <view class="label">其他单位</view>
  44. <input type="digit" placeholder="请输入" v-model="item.otherNum" />
  45. </view>
  46. <view class="num-li">
  47. <view class="label">盈亏数量</view>
  48. <input type="digit" class="input-dis" disabled :value="item.diffNum > 0 ? `+${item.diffNum}` : item.diffNum" />
  49. </view>
  50. <view class="num-li" v-if="enableLocationManagement === 5">
  51. <view class="label">库区库位</view>
  52. <input
  53. @click="openLocation(index, item)"
  54. disabled
  55. type="text"
  56. placeholder="请选择"
  57. :value="item.storageLocationName ? item.areaName + '-' + item.storageLocationName : ''"
  58. />
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </block>
  64. </view>
  65. </view>
  66. <view class="form-model-view">
  67. <u-form-item label="备注" label-position="top"><u-input type="textarea" v-model="add_form.remark" /></u-form-item>
  68. </view>
  69. </u-form>
  70. <view class="detail-bottom"><u-button class="handel-btn" @click="submit" :loading="sub_load" :ripple="true" type="primary">提交</u-button></view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. sub_load: false,
  78. rules: {
  79. warehouseName: [
  80. {
  81. required: true,
  82. message: '请选择仓库',
  83. trigger: ['change', 'blur']
  84. }
  85. ]
  86. },
  87. goods_id: [],
  88. werahouseData: '',
  89. warehouseGoods: '',
  90. goods_num: '',
  91. add_form: {
  92. warehouseId: '',
  93. warehouseName: '',
  94. operatorName: '',
  95. remark: '',
  96. stocktakingTime: '',
  97. details: []
  98. },
  99. goods_list: [],
  100. del_goods_id: [],
  101. goods_index: 0,
  102. areaBysku: ''
  103. };
  104. },
  105. computed: {
  106. userName() {
  107. return this.$store.state.userInfo.name;
  108. },
  109. enableLocationManagement() {
  110. return parseInt(this.$store.state.basicSet.enableLocationManagement);
  111. }
  112. },
  113. watch: {
  114. werahouseData(val) {
  115. if (val) {
  116. this.add_form.warehouseId = val.id;
  117. this.add_form.warehouseName = val.warehouseName;
  118. }
  119. },
  120. // 选择商品资料页面返回
  121. warehouseGoods(list) {
  122. if (list) {
  123. this.selGoods(list);
  124. }
  125. },
  126. areaBysku(val) {
  127. if (val) {
  128. const target = this.$u.deepClone(this.goods_list);
  129. target[this.goods_index] = {
  130. ...target[this.goods_index],
  131. areaId: val.areaId,
  132. areaName: val.areaName,
  133. areaCode: val.areaCode,
  134. storageLocationId: val.storageLocationId,
  135. storageLocationName: val.storageLocationName,
  136. storageLocationCode: val.storageLocationCode
  137. };
  138. this.goods_list = target;
  139. }
  140. }
  141. },
  142. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  143. onReady() {
  144. this.$refs.uForm.setRules(this.rules);
  145. },
  146. onLoad(options) {
  147. if (options.id) {
  148. this.invenrory_id = options.id;
  149. uni.setNavigationBarTitle({
  150. title: '编辑盘点单'
  151. });
  152. this.getStocktakingInfo();
  153. } else {
  154. this.add_form.stocktakingTime = parseInt(new Date().getTime() / 1000);
  155. }
  156. },
  157. methods: {
  158. // 去选择库区库位页面
  159. openLocation(index, row) {
  160. this.goods_index = index;
  161. this.goPage(`/pagesT/stock/WarehouseRegionBySku?basicGoodsId=${row.materielId}&skuId=${row.skuId}&warehouseId=${this.add_form.warehouseId}`);
  162. },
  163. delGoods(row, index) {
  164. if (row.id) {
  165. this.del_goods_id.push(row.id);
  166. }
  167. this.goods_list.splice(index, 1);
  168. },
  169. selGoodsPage() {
  170. if (!this.add_form.warehouseId) {
  171. this.$u.toast('请选择仓库');
  172. return;
  173. }
  174. uni.setStorageSync('warehouseGoods', this.goods_list);
  175. this.goPage('/pagesT/goods/GoodsbyWarehouse?id=' + this.add_form.warehouseId);
  176. },
  177. // 详情
  178. getStocktakingInfo() {
  179. this.$u.api.getStocktakingInfo(this.invenrory_id).then(({ data }) => {
  180. this.add_form = {
  181. warehouseId: data.warehouseId,
  182. warehouseName: data.warehouseName,
  183. operatorName: data.operatorName,
  184. remark: data.remark,
  185. stocktakingTime: data.stocktakingTime,
  186. details: data.details
  187. };
  188. // 商品
  189. this.goods_list = data.details.map(item => {
  190. return {
  191. id: item.id,
  192. buyNum: 1,
  193. materielId: item.materielId,
  194. materielName: item.materielName,
  195. materielCode: item.materielCode,
  196. skuId: item.skuId,
  197. skuName: item.skuName,
  198. unitName: item.unitName,
  199. diffNum: item.differenceStatus === 4 ? 0 - item.differenceNum : item.differenceNum - 0,
  200. remark: item.remark,
  201. costUnitPrice: item.costUnitPrice || 0,
  202. documentInventoryNum: Number(item.documentInventoryNum), // 账面库存
  203. currentInventoryNum: Number(item.currentInventoryNum), // 实盘库存
  204. otherNum: Number(item.otherNum), // 其他单位
  205. areaId: item.areaId,
  206. areaName: item.areaName,
  207. areaCode: item.areaCode,
  208. storageLocationName: item.storageLocationName,
  209. storageLocationId: item.storageLocationId,
  210. storageLocationCode: item.storageLocationCode
  211. };
  212. });
  213. });
  214. },
  215. bindDateChange(e) {
  216. this.add_form.stocktakingTime = this.$utils.timeByTimestamp(e.detail.value + ' 00:00:00');
  217. },
  218. // 改变数量
  219. editNumChange(index) {
  220. let target = this.$u.deepClone(this.goods_list);
  221. target[index].diffNum = this.$NP.minus(target[index].currentInventoryNum, target[index].documentInventoryNum);
  222. this.goods_list = target;
  223. },
  224. // 多选商品确定
  225. selGoods(list) {
  226. this.goods_list = list.map(item => {
  227. return {
  228. isEq: item.isEq,
  229. otherNum: Number(item.otherNum) || '',
  230. materielId: item.materielId,
  231. materielCode: item.materielCode,
  232. materielName: item.materielName,
  233. warehouseName: this.add_form.warehouseName,
  234. skuName: item.skuName,
  235. skuId: item.skuId,
  236. unitName: item.unitName,
  237. currentInventoryNum: Number(item.inventoryNum), // 实盘库存
  238. costUnitPrice: Number(item.costPrice),
  239. diffNum: 0,
  240. remark: '',
  241. buyNum: 1,
  242. documentInventoryNum: item.allNum, // 账面库存
  243. areaId: '',
  244. areaName: '',
  245. areaCode: '',
  246. storageLocationName: '',
  247. storageLocationId: '',
  248. storageLocationCode: ''
  249. };
  250. });
  251. },
  252. submit() {
  253. this.$refs.uForm.validate(valid => {
  254. if (valid) {
  255. if (!this.goods_list.length) {
  256. this.$u.toast('请选择商品');
  257. return;
  258. }
  259. const details = this.$u.deepClone(this.goods_list).map(item => {
  260. delete item.diffNum;
  261. delete item.buyerNum;
  262. return item;
  263. });
  264. const params = {
  265. ...this.add_form,
  266. operatorName: this.userName,
  267. details: details
  268. };
  269. this.sub_load = true;
  270. if (this.invenrory_id) {
  271. this.$u.api
  272. .updateStocktaking(this.invenrory_id, {
  273. ...params,
  274. deleteArray: this.del_goods_id
  275. })
  276. .then(res => {
  277. this.sub_load = false;
  278. this.$u.toast('修改成功');
  279. setTimeout(() => {
  280. uni.navigateBack();
  281. }, 2000);
  282. })
  283. .catch(err => {
  284. this.sub_load = false;
  285. });
  286. } else {
  287. this.$u.api
  288. .addStocktaking(params)
  289. .then(res => {
  290. this.sub_load = false;
  291. this.$u.toast('新建成功');
  292. setTimeout(() => {
  293. uni.navigateBack();
  294. }, 2000);
  295. })
  296. .catch(err => {
  297. this.sub_load = false;
  298. });
  299. }
  300. }
  301. });
  302. }
  303. }
  304. };
  305. </script>
  306. <style lang="scss" scoped>
  307. .goods-ul {
  308. padding-bottom: 20rpx;
  309. .more-goods {
  310. line-height: 80rpx;
  311. border-top: 1px solid #eeeeee;
  312. text-align: center;
  313. font-size: 24rpx;
  314. }
  315. .goods-title {
  316. margin-bottom: 20rpx;
  317. line-height: 80rpx;
  318. font-size: 24rpx;
  319. border-bottom: 1px solid #eeeeee;
  320. .float_right {
  321. color: $uni-color-primary;
  322. }
  323. }
  324. .goods-li {
  325. line-height: 32rpx;
  326. margin-top: 20rpx;
  327. .goods-img {
  328. margin-right: 20rpx;
  329. image {
  330. width: 150rpx;
  331. height: 150rpx;
  332. border-radius: 8rpx;
  333. display: block;
  334. }
  335. }
  336. .info {
  337. width: 640rpx;
  338. .num-ul {
  339. display: flex;
  340. padding-top: 20rpx;
  341. .num-li {
  342. font-size: 24rpx;
  343. line-height: 36rpx;
  344. flex: 3;
  345. text-align: center;
  346. position: relative;
  347. font-weight: bold;
  348. padding: 0 16rpx;
  349. .label {
  350. font-weight: 400;
  351. color: #999999;
  352. }
  353. input {
  354. text-align: center;
  355. border-bottom: 1px solid $uni-color-primary;
  356. &.input-dis {
  357. border-bottom: 1px solid #eeeeee;
  358. }
  359. }
  360. &::after {
  361. display: block;
  362. content: '';
  363. position: absolute;
  364. width: 1px;
  365. height: 60rpx;
  366. top: 50%;
  367. transform: translateY(-50%);
  368. right: 0;
  369. background-color: #eeeeee;
  370. }
  371. &:last-child {
  372. &::after {
  373. display: block;
  374. content: '';
  375. position: absolute;
  376. width: 1px;
  377. height: 50rpx;
  378. top: 50%;
  379. transform: translateY(-50%);
  380. right: 0;
  381. background-color: transparent;
  382. }
  383. }
  384. }
  385. }
  386. .goods-name {
  387. width: 640rpx;
  388. height: 34rpx;
  389. line-height: 34rpx;
  390. }
  391. .goods-code {
  392. font-size: 24rpx;
  393. padding-top: 10rpx;
  394. }
  395. .goods-num {
  396. padding-top: 10rpx;
  397. font-size: 24rpx;
  398. .price {
  399. font-size: 28rpx;
  400. font-weight: bold;
  401. color: $uni-color-error;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. </style>