checkModal.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <div>
  3. <a-modal @cancel="handleCancel" :visible="stockVisible" :title="title" width="90%">
  4. <a-spin :spinning="confirmLoading">
  5. <edit-form
  6. :spinnerList="spinnerList"
  7. :depotList="deoptData"
  8. :form="form"
  9. :rules="rules"
  10. :stockVisible="stockVisible"
  11. ref="editForm"
  12. :total="dataSource.length || 0"
  13. openType="detail"
  14. :stockType="stockType"
  15. @getForm="getForm"
  16. @clear="onClearList"
  17. ></edit-form>
  18. <a-divider />
  19. <div>
  20. <div>
  21. <a-form :form="queryParam" ref="form">
  22. <a-row class="form-row" :gutter="24">
  23. <a-col :lg="6" :md="12" :sm="24" class="form-col">
  24. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="商品类别">
  25. <!-- <a-input disabled placeholder="请输入" v-model="queryParam.categoryId" /> -->
  26. <a-tree-select
  27. style="width: 100%"
  28. :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
  29. allow-clear
  30. :treeData="categoryTree"
  31. v-model="queryParam.categoryId"
  32. placeholder="请选择商品类别"
  33. >
  34. </a-tree-select>
  35. </a-form-item>
  36. </a-col>
  37. <a-col :lg="6" :md="12" :sm="24" class="form-col">
  38. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="商品名称">
  39. <a-input placeholder="请输入" v-model="queryParam.name" />
  40. </a-form-item>
  41. </a-col>
  42. <a-col :lg="6" :md="12" :sm="24" class="form-col">
  43. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="批次号">
  44. <a-input placeholder="请输入" v-model="queryParam.batchNumber" />
  45. </a-form-item>
  46. </a-col>
  47. <a-col :lg="6" :md="12" :sm="24" class="form-col">
  48. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="仓位货架">
  49. <a-input placeholder="请输入" v-model="queryParam.position" />
  50. </a-form-item>
  51. </a-col>
  52. <a-col :lg="6" :md="12" :sm="24" class="form-col">
  53. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="是否存在数量差异">
  54. <a-select placeholder="请选择" v-model="form.isDifference" :options="isDifferenceData"> </a-select>
  55. </a-form-item>
  56. </a-col>
  57. <span>
  58. <a-col :md="6" :sm="24">
  59. <a-button type="primary" @click="onSearch">查询</a-button>
  60. <a-button style="margin-left: 8px" @click="onReset">重置</a-button>
  61. </a-col>
  62. </span>
  63. </a-row>
  64. </a-form>
  65. </div>
  66. <a-table
  67. ref="table"
  68. size="middle"
  69. bordered
  70. rowKey="id"
  71. :columns="columns"
  72. :dataSource="dataSource"
  73. :pagination="ipagination"
  74. :loading="loading"
  75. @change="handleTableChange"
  76. >
  77. <!-- <template v-for="col in colList" :slot="col" slot-scope="text, record">
  78. <div :key="col">
  79. <a-input v-if="editableData[record.id]" v-model="editableData[record.id][col]" style="margin: -5px 0" />
  80. <template v-else>
  81. {{ col }}
  82. </template>
  83. </div>
  84. </template> -->
  85. <span slot="action" v-if="openType !== 'detail'" slot-scope="text, record">
  86. <a type="text" @click="handleEdit(record)">编辑</a>
  87. </span>
  88. <template slot="inventory" slot-scope="value, record">
  89. {{ parseInt(value) }}
  90. </template>
  91. </a-table>
  92. </div>
  93. </a-spin>
  94. <template slot="footer">
  95. <a-button @click="handleCancel">取消</a-button>
  96. <a-button v-if="isShowBtn" @click="handleOk">完成盘点</a-button>
  97. <a-button v-if="isShowBtn" @click="handleUpdate" type="primary">确定更新盘点数据</a-button>
  98. </template>
  99. </a-modal>
  100. <j-select-material-modal
  101. @ok="getGoods"
  102. @all="findAllSelect"
  103. ref="selectModal"
  104. :multi="true"
  105. :isStock="true"
  106. ></j-select-material-modal>
  107. <a-modal @cancel="editVisible = false" @ok="onSubmitGoods" :visible="editVisible" title="编辑" width="50%">
  108. <a-form-model :model="editForm" :rules="editFormRules" ref="editFormModel">
  109. <a-form-model-item label="盘点任务名称" :labelCol="{ span: 4 }" :wrapperCol="{ span: 14 }" prop="name">
  110. <a-input disabled v-model="editForm.name" placeholder="请输入"></a-input>
  111. </a-form-model-item>
  112. <a-form-model-item label="批次号" :labelCol="{ span: 4 }" :wrapperCol="{ span: 14 }" prop="batchNumber">
  113. <a-input disabled v-model="editForm.batchNumber" placeholder="请输入"></a-input>
  114. </a-form-model-item>
  115. <a-form-model-item label="实际库存" :labelCol="{ span: 4 }" :wrapperCol="{ span: 14 }" prop="newInventory">
  116. <a-input-number placeholder="请输入" v-model="editForm.newInventory" @change="handleChangeNewInventory" :min="0" style="width:100%" />
  117. </a-form-model-item>
  118. <a-form-model-item label="实际仓位货架" :labelCol="{ span: 4 }" :wrapperCol="{ span: 14 }" prop="newPosition">
  119. <a-input v-model="editForm.newPosition" placeholder="请输入"></a-input>
  120. </a-form-model-item>
  121. <a-form-model-item :labelCol="{ span: 4 }" :wrapperCol="{ span: 14 }" prop="differenceCount">
  122. <template slot="label">
  123. 差异数量
  124. <span>
  125. <a-tooltip>
  126. <template slot="title">
  127. 盘盈是正数,盘亏是负数
  128. </template>
  129. <a-icon type="question-circle" />
  130. </a-tooltip>
  131. </span>
  132. </template>
  133. <span :class="editForm.differenceCount!==0?'red-num':''">{{editForm.differenceCount}}</span>
  134. </a-form-model-item>
  135. <a-form-model-item label="差异原因" :labelCol="{ span: 4 }" :wrapperCol="{ span: 14 }" prop="differenceReason">
  136. <a-input v-model="editForm.differenceReason" placeholder="请输入"></a-input>
  137. </a-form-model-item>
  138. </a-form-model>
  139. </a-modal>
  140. </div>
  141. </template>
  142. <script>
  143. import { findBySelectOrgan, queryMaterialCategoryTreeList, getAllOrganizationTreeByUser } from '@/api/api'
  144. import editForm from './editForm.vue'
  145. import table from '../utils/table'
  146. import JSelectMaterialModal from '../../../components/jeecgbiz/modal/JSelectMaterialModal.vue'
  147. import { getAction, postAction } from '@/api/manage'
  148. import { getMaterialByBatchNumber } from '@/api/api'
  149. import { newTableMixin } from '@/mixins/newTableMixin'
  150. import { Modal } from 'ant-design-vue'
  151. // import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  152. // import { Form } from 'ant-design-vue'
  153. // const useForm = Form.useForm
  154. export default {
  155. components: { editForm, JSelectMaterialModal },
  156. mixins: [newTableMixin],
  157. props: {
  158. rules: {
  159. type: Object,
  160. default: () => {
  161. return {}
  162. },
  163. },
  164. stockVisible: {
  165. type: Boolean,
  166. default: false,
  167. },
  168. title: {
  169. type: String,
  170. default: '新增',
  171. },
  172. spinnerList: {
  173. type: Array,
  174. default: () => [],
  175. },
  176. deoptData: {
  177. type: Array,
  178. default: () => [],
  179. },
  180. taskId: {
  181. type: String,
  182. default: '',
  183. },
  184. openType: {
  185. type: String,
  186. default: 'add',
  187. },
  188. },
  189. data() {
  190. return {
  191. width: '1600px',
  192. visible: false,
  193. confirmLoading: false,
  194. prefixNo: '',
  195. loading: false,
  196. dataSource: [],
  197. columns: table.checkGoodsColumns,
  198. url: {
  199. add: '/stocktaking/add',
  200. update: '/stocktaking/detailUpdate',
  201. edit: '/stocktaking/itemUpdate',
  202. updateStock: '/stocktaking/taskUpdateStock/',
  203. taskCom: ' /stocktaking/taskComplete/',
  204. detail: '/stocktaking/detail/',
  205. },
  206. form: {},
  207. isShow: false,
  208. stockType: 'check',
  209. queryParam: { categoryId: '', materialName: '', batchNumber: '', position: '', isDifference: null },
  210. isDifferenceData: [
  211. {
  212. label: '是',
  213. value: '1',
  214. },
  215. {
  216. label: '否',
  217. value: '2',
  218. },
  219. ],
  220. categoryTree: [],
  221. labelCol: {
  222. xs: { span: 24 },
  223. sm: { span: 8 },
  224. },
  225. wrapperCol: {
  226. xs: { span: 24 },
  227. sm: { span: 16 },
  228. },
  229. editForm: {},
  230. editVisible: false,
  231. editFormRules:{
  232. newInventory:[
  233. { required: true, message: '请输入实际库存' },
  234. { pattern: /^[0-9]*$/, message: '只能输入数字' }
  235. ]
  236. }
  237. }
  238. },
  239. watch: {
  240. stockVisible(val) {
  241. this.loadCategoryTreeData()
  242. if (val) {
  243. if (this.taskId) {
  244. this.$nextTick(() => {
  245. this.getDetailList(this.taskId)
  246. })
  247. return
  248. }
  249. } else {
  250. this.dataSource = []
  251. this.ipagination.current = 1
  252. this.loading = false
  253. }
  254. },
  255. editVisible(val) {
  256. if (!val) {
  257. this.editForm = {}
  258. // this.form.resetFields()
  259. }
  260. },
  261. },
  262. computed: {
  263. isShowBtn() {
  264. console.log('==================', this.form.taskStatus)
  265. if (this.openType === 'detail') return false
  266. if (this.form.taskStatus !== 1) return false
  267. return true
  268. },
  269. },
  270. methods: {
  271. handleEdit(data) {
  272. this.editForm = { ...data }
  273. this.editVisible = true
  274. this.handleChangeNewInventory(data.newInventory)
  275. },
  276. onSubmitGoods() {
  277. this.$refs.editFormModel.validate((valid) => {
  278. if (valid) {
  279. postAction(this.url.edit, this.editForm).then((res) => {
  280. this.$message.success('操作成功')
  281. this.editVisible = false
  282. })
  283. } else {
  284. return false
  285. }
  286. })
  287. },
  288. loadCategoryTreeData() {
  289. let params = {}
  290. params.id = ''
  291. queryMaterialCategoryTreeList(params).then((res) => {
  292. if (res) {
  293. this.categoryTree = []
  294. for (let i = 0; i < res.length; i++) {
  295. let temp = res[i]
  296. this.categoryTree.push(temp)
  297. }
  298. }
  299. })
  300. },
  301. handleCancel() {
  302. this.$emit('update:stockVisible', false)
  303. },
  304. //更新盘点数据
  305. handleUpdate() {
  306. let that = this
  307. const url = this.url.updateStock + this.taskId
  308. Modal.confirm({
  309. title: '是否确定更新盘点数据,确定后商品库存将按照当前的盘点数据进行更新',
  310. onOk() {
  311. getAction(url)
  312. .then((res) => {
  313. that.$message.success('操作成功')
  314. that.handleCancel()
  315. })
  316. .catch((err) => {
  317. this.$message.error('操作失败')
  318. })
  319. },
  320. onCancel() {
  321. console.log('Cancel')
  322. },
  323. })
  324. },
  325. handleOk() {
  326. getAction(this.url.taskCom + this.taskId)
  327. .then((res) => {
  328. this.$message.success('操作成功')
  329. })
  330. .catch((err) => {
  331. this.$message.error('操作失败')
  332. })
  333. this.handleCancel()
  334. },
  335. onChangeGoods() {
  336. this.$refs.selectModal.queryParam.depotId = this.form.depotId
  337. this.$refs.selectModal.showModal()
  338. },
  339. getDetailList(id) {
  340. const url = this.url.detail + id
  341. const form = this.$refs['editForm'].form
  342. getAction(url).then((res) => {
  343. const {
  344. depotId,
  345. taskName,
  346. taskStatus,
  347. taskType,
  348. createTime,
  349. createByName,
  350. materialCount,
  351. positionRange,
  352. creator,
  353. id,
  354. operBy,
  355. operTime,
  356. } = res.data
  357. form.setFieldsValue({
  358. depotId,
  359. taskName,
  360. taskStatus,
  361. taskType,
  362. createTime,
  363. createByName,
  364. materialCount,
  365. positionRange,
  366. creator,
  367. id,
  368. operBy,
  369. operTime,
  370. })
  371. this.getList(id)
  372. })
  373. },
  374. getList(id) {
  375. const url2 = '/stocktaking/detailByItemList'
  376. const form = this.$refs['editForm'].form
  377. const params = { ...this.queryParam, taskStocktakingId: id || this.taskId }
  378. const url = url2 + '?pageNum=' + this.ipagination.current + '&pageSize=' + this.ipagination.pageSize
  379. postAction(url, params).then((res) => {
  380. this.dataSource = res.data
  381. this.ipagination.total = this.dataSource.length
  382. const materialExtendIdList = this.dataSource.map((item) => item.batchNumber)
  383. form.setFieldsValue({
  384. materialExtendIdList,
  385. })
  386. this.getForm(form.getFieldsValue())
  387. })
  388. },
  389. getGoods(rows, ids) {
  390. const str = ids
  391. .split(',')
  392. .filter((item) => item)
  393. .join(',')
  394. this.getBatchData(str)
  395. },
  396. findAllSelect() {
  397. const params = { ...this.$refs.selectModal.queryParam }
  398. getAction('/material/findBatchNumbersBySelect', params).then((res) => {
  399. this.$refs.selectModal.close()
  400. this.getBatchData(res.data)
  401. })
  402. },
  403. getBatchData(val) {
  404. const batchStr = val
  405. .split(',')
  406. .filter((item) => item)
  407. .join(',')
  408. const params = {
  409. batchNumber: batchStr,
  410. organId: '',
  411. mpList: '',
  412. prefixNo: '',
  413. }
  414. getMaterialByBatchNumber(params).then((res) => {
  415. this.dataSource.push(...res.data)
  416. this.dataSource = this.dataSource.reduce((acc, cur) => {
  417. const hasDuplicate = acc.some((item) => item.batchNumber === cur.batchNumber)
  418. if (!hasDuplicate) {
  419. acc.push(cur)
  420. }
  421. return acc
  422. }, [])
  423. })
  424. },
  425. getForm(val) {
  426. this.form = val
  427. this.$refs['editForm'].model = val
  428. },
  429. //删除
  430. handleDelete(record) {
  431. this.dataSource = this.dataSource.filter((item) => item.batchNumber !== record.batchNumber)
  432. },
  433. onClearList(val) {
  434. this.dataSource = []
  435. this.getForm(val)
  436. if (val.taskType === 1) {
  437. this.findAllSelect()
  438. }
  439. },
  440. handleChangeNewInventory(val){
  441. const inventory = this.editForm.inventory? Number(this.editForm.inventory):0
  442. this.editForm.differenceCount = val - inventory
  443. }
  444. },
  445. }
  446. </script>
  447. <style>
  448. .red-num{
  449. color: #f5222d;
  450. }
  451. </style>