checkModal.vue 13 KB

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