stockCountAdd.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div class="app-container">
  3. <el-form ref="dataForm" :model="dataForm" :rules="rules" label-width="120px" inline>
  4. <h3>盘点单</h3>
  5. <el-form-item label="盘点时间" prop="serialDate">
  6. <el-date-picker v-model="dataForm.serialDate" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
  7. placeholder="选择日期时间" style="width:200px" :disabled="type === 'detail'">
  8. </el-date-picker>
  9. </el-form-item>
  10. <el-form-item label="仓库" prop="warehouseId">
  11. <el-select v-model="dataForm.warehouseId" clearable placeholder="请选择" style="width: 200px;"
  12. :disabled="type === 'detail'">
  13. <el-option :key="item.id" v-for="item in warehouseList" :label="item.warehouseName"
  14. :value="item.id">
  15. </el-option>
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="盘点人" prop="addHandlerId">
  19. <el-select v-model="dataForm.addHandlerId" clearable filterable placeholder="请选择" style="width: 200px"
  20. :disabled="type === 'detail'">
  21. <el-option :key="item.loginId" v-for="item in userSelsctList"
  22. :label="item.deptName + '_' + item.userName" :value="item.loginId">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <div class="mx">
  27. <h3>盘点明细</h3>
  28. <el-button size="small" type="primary" v-if="type !== 'detail'" @click="handleSelectGoods('inventoryEntryInfos')"
  29. icon="el-icon-plus">商品/物料</el-button>
  30. </div>
  31. <el-table size="small" :data="dataForm.inventoryEntryInfos" border :cell-style="{ textAlign: 'center' }"
  32. :header-cell-style="{ textAlign: 'center' }" style="width: 100%">
  33. <el-table-column label="商品编号">
  34. <template slot-scope="scope">
  35. {{ scope.row.productCode }}
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="商品名称">
  39. <template slot-scope="scope">
  40. {{ scope.row.productName }}
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="单价(¥)">
  44. <template slot-scope="scope">
  45. {{ scope.row.createPrice.toFixed(2) }}
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="库存数量">
  49. <template slot-scope="scope">
  50. {{ scope.row.createProductNumber }}
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="盘点数量">
  54. <template slot-scope="scope">
  55. <el-form-item v-if="type !== 'detail'"
  56. :prop="'inventoryEntryInfos.' + scope.$index + '.updateNumber'"
  57. :rules="{ required: true, message: '盘点数量不能为空', trigger: 'blur' }" class="tableFormItem">
  58. <el-input-number v-model="scope.row.updateNumber" @change="handleChange(scope.row)"
  59. size="small" :min="1" :max="10000"></el-input-number>
  60. </el-form-item>
  61. <span v-else>{{ scope.row.updateNumber }}</span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="差异">
  65. <template slot-scope="scope">
  66. {{ scope.row.sumPrice }}
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="备注">
  70. <template slot-scope="scope">
  71. <el-input v-if="type !== 'detail'" :maxlength="99" v-model="scope.row.remarks" />
  72. <span v-else>{{ scope.row.remarks }}</span>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="操作" width="150" v-if="type !== 'detail'">
  76. <template slot-scope="scope">
  77. <el-button size="mini" type="danger"
  78. @click="dataForm.inventoryEntryInfos.splice(scope.$index, 1)">删除</el-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. </el-form>
  83. <div class="footer">
  84. <el-button type="primary" @click="submitForm" v-if="type !== 'detail'">保存
  85. </el-button>
  86. <el-button @click="roBack()">返回
  87. </el-button>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import { createStockCount, updateStockCount, readStockCount } from "@/api/stockCount";
  93. import { supplierList } from "@/api/supplier";
  94. import { warehouseList } from "@/api/warehouse";
  95. import { allUserList } from "@/api/public";
  96. import waves from "@/directive/waves"; // 水波纹指令
  97. export default {
  98. directives: { waves },
  99. data() {
  100. return {
  101. userSelsctList: [],
  102. supplierList: [],
  103. warehouseList: [],
  104. id: '',
  105. type: '',
  106. /** 表单*/
  107. dataForm: {
  108. serialDate: '',
  109. warehouseId: undefined,
  110. addHandlerId: undefined,
  111. remarks: undefined,
  112. inventoryEntryInfos: [],
  113. inventoryOutInfos: []
  114. },
  115. rules: {
  116. serialDate: [
  117. { required: true, message: '请选择盘点时间', trigger: 'blur' }
  118. ],
  119. warehouseId: [
  120. { required: true, message: '请选择仓库', trigger: 'blur' }
  121. ],
  122. remarks: [
  123. { required: true, message: '请填写盘点原因', trigger: 'blur' }
  124. ],
  125. addHandlerId: [
  126. { required: true, message: '请选择盘点人', trigger: 'blur' }
  127. ],
  128. },
  129. }
  130. },
  131. watch: {
  132. $route: {
  133. immediate: true,
  134. handler(newVal) {
  135. if (this.$route.name === 'stockCountAdd') {
  136. this.dataForm = {
  137. serialDate: '',
  138. warehouseId: undefined,
  139. addHandlerId: undefined,
  140. remarks: undefined,
  141. inventoryEntryInfos: [],
  142. inventoryOutInfos: []
  143. }
  144. } else if (this.$route.name === 'stockCountDetail') {
  145. this.type = 'detail'
  146. }
  147. if (this.$route.params.id) {
  148. this.id = this.$route.params.id
  149. this.getDataFormDetail()
  150. }
  151. }
  152. }
  153. },
  154. mounted() {
  155. this.getSupplierList();
  156. this.getStoreList();
  157. this.getAllUserList();
  158. },
  159. methods: {
  160. /** 获取供应商列表数据 */
  161. getSupplierList() {
  162. supplierList().then(response => {
  163. this.supplierList = response.data.data;
  164. }).catch(() => { });
  165. },
  166. /** 获取仓库列表数据 */
  167. getStoreList() {
  168. warehouseList().then(response => {
  169. this.warehouseList = response.data.data;
  170. }).catch(() => { });
  171. },
  172. /** 获取人员列表数据 */
  173. getAllUserList() {
  174. allUserList().then(response => {
  175. this.userSelsctList = response.data.data;
  176. }).catch(() => { });
  177. },
  178. /** 获取详情页面数据 */
  179. getDataFormDetail() {
  180. readStockCount({ id: this.id }).then(response => {
  181. let dataForm = response.data.data;
  182. dataForm.inventoryEntryInfos = dataForm.inventoryEntryInfos == null ? [] : dataForm.inventoryEntryInfos
  183. dataForm.inventoryOutInfos = dataForm.inventoryOutInfos == null ? [] : dataForm.inventoryOutInfos
  184. this.dataForm = dataForm;
  185. }).catch(() => { })
  186. },
  187. // 选择商品
  188. async handleSelectGoods(val) {
  189. if (!this.dataForm.warehouseId) {
  190. this.$message.error('请先选择仓库!')
  191. return
  192. } else {
  193. let selectedIds = val=='inventoryEntryInfos' ? this.dataForm.inventoryEntryInfos.map(item => item.productId) : this.dataForm.inventoryOutInfos.map(item => item.productId);
  194. const Goods = await this.$EnPickerGoods({
  195. // goodsApi: '/warehouse-entry/info/inventory',
  196. selectedIds: selectedIds,
  197. goodsApiParams: { warehouseId: this.dataForm.warehouseId }
  198. })
  199. if (!Goods.length) return
  200. if(val=='inventoryEntryInfos'){
  201. const inventoryEntryInfos = Goods.map(item => {
  202. item.updateNumber = 1
  203. item.sumPrice = item.createProductNumber - 1
  204. return item
  205. })
  206. this.dataForm.inventoryEntryInfos = this.dataForm.inventoryEntryInfos && this.dataForm.inventoryEntryInfos.length ? this.dataForm.inventoryEntryInfos.concat(inventoryEntryInfos) : this.dataForm.inventoryEntryInfos = inventoryEntryInfos
  207. }else{
  208. const inventoryOutInfos = Goods.map(item => {
  209. item.updateNumber = 1
  210. item.sumPrice = item.createProductNumber - 1
  211. return item
  212. })
  213. this.dataForm.inventoryOutInfos = this.dataForm.inventoryOutInfos && this.dataForm.inventoryOutInfos.length ? this.dataForm.inventoryOutInfos.concat(inventoryOutInfos) : this.dataForm.inventoryOutInfos = inventoryOutInfos
  214. }
  215. }
  216. },
  217. submitForm() {
  218. this.$refs["dataForm"].validate((valid) => {
  219. if (valid) {
  220. if (this.dataForm.inventoryEntryInfos.length == 0 || this.dataForm.inventoryOutInfos.length == 0) {
  221. this.$message.error('请选择商品/物料!')
  222. return
  223. } else {
  224. if (this.id) {
  225. updateStockCount(this.dataForm).then(() => {
  226. this.$notify({
  227. title: '成功',
  228. message: '更新成功',
  229. type: 'success',
  230. duration: 2000
  231. })
  232. this.roBack();
  233. })
  234. } else {
  235. createStockCount(this.dataForm).then(() => {
  236. this.$notify({
  237. title: "成功",
  238. message: "创建成功",
  239. type: "success",
  240. duration: 2000,
  241. });
  242. this.roBack();
  243. })
  244. }
  245. }
  246. }
  247. });
  248. },
  249. handleChange(row) {
  250. row.sumPrice = row.createProductNumber - row.updateNumber
  251. },
  252. roBack() {
  253. // const { callback } = this.$route.params
  254. // if (typeof callback === 'function') callback()
  255. this.$store.dispatch('delVisitedViews', this.$route).then((views) => {
  256. const latestView = views.slice(-1)[0]
  257. if (latestView) {
  258. this.$router.push(latestView.path)
  259. } else {
  260. this.$router.push('/')
  261. }
  262. })
  263. // this.$router.push({ name: 'stockCount' })
  264. }
  265. }
  266. }
  267. </script>
  268. <style>
  269. /** 底部步骤 */
  270. .footer {
  271. width: 100%;
  272. padding: 10px;
  273. bottom: 0px;
  274. text-align: center;
  275. z-index: 999;
  276. }
  277. .mx {
  278. display: flex;
  279. align-items: center;
  280. justify-content: space-between;
  281. }
  282. /** 表格中输入框样式 */
  283. .tableFormItem {
  284. width: 100%;
  285. margin-bottom: 0;
  286. }
  287. </style>