stockModal.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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="ipagination.total"
  13. :openType="openType"
  14. :stockType="stockType"
  15. @changeForm="handleChangeForm"
  16. ></edit-form>
  17. <div>
  18. <a-button v-if="form.taskType === 2&&openType!='detail'" style="margin-bottom: 6px" type="primary" @click="onChangeGoods"
  19. >选择商品</a-button
  20. >
  21. <a-table
  22. v-if="dataSource.length"
  23. ref="table"
  24. size="middle"
  25. bordered
  26. rowKey="id"
  27. :scroll="{ x: 'max-content'}"
  28. :columns="columns"
  29. :dataSource="dataSource"
  30. :loading="loading"
  31. :pagination="ipagination"
  32. @change="handleTableChange"
  33. >
  34. <span v-if="isShowBtn" slot="action" slot-scope="text, record">
  35. <!-- <a-divider type="vertical" /> -->
  36. <a-popconfirm @confirm="handleDelete(record)" title="确定删除吗?">
  37. <a v-if="form.taskType!=1">删除</a>
  38. </a-popconfirm>
  39. </span>
  40. <template slot="inventory" slot-scope="value, record">
  41. {{ parseInt(value) }}
  42. </template>
  43. <!-- <template slot="customName" slot-scope="text, record">
  44. {{ record.name }}
  45. <a-tag v-if="record.enableSerialNumber == 1" color="orange">序</a-tag>
  46. <a-tag v-if="record.enableBatchNumber == 1" color="orange">批</a-tag>
  47. </template> -->
  48. </a-table>
  49. </div>
  50. </a-spin>
  51. <template slot="footer">
  52. <a-button @click="handleCancel">取消</a-button>
  53. <a-button v-if="isShowBtn" @click="handleOk" type="primary">确认发布盘点任务</a-button>
  54. </template>
  55. </a-modal>
  56. <j-select-material-modal
  57. @ok="getGoods"
  58. @all="findAllSelect"
  59. ref="selectModal"
  60. :multi="true"
  61. :isStock="true"
  62. ></j-select-material-modal>
  63. </div>
  64. </template>
  65. <script>
  66. import editForm from './editForm.vue'
  67. import table from '../utils/table'
  68. import JSelectMaterialModal from '../../../components/jeecgbiz/modal/JSelectMaterialModal2.vue'
  69. import { getAction, postAction } from '@/api/manage'
  70. import { getMaterialByBatchNumber } from '@/api/api'
  71. import { newTableMixin } from '@/mixins/newTableMixin'
  72. // import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  73. // import { Form } from 'ant-design-vue'
  74. // const useForm = Form.useForm
  75. export default {
  76. components: { editForm, JSelectMaterialModal },
  77. mixins: [newTableMixin],
  78. props: {
  79. rules: {
  80. type: Object,
  81. default: () => {
  82. return {}
  83. },
  84. },
  85. stockVisible: {
  86. type: Boolean,
  87. default: false,
  88. },
  89. title: {
  90. type: String,
  91. default: '新增',
  92. },
  93. spinnerList: {
  94. type: Array,
  95. default: () => [],
  96. },
  97. deoptData: {
  98. type: Array,
  99. default: () => [],
  100. },
  101. taskId: {
  102. type: String,
  103. default: '',
  104. },
  105. openType: {
  106. type: String,
  107. default: 'add',
  108. },
  109. },
  110. data() {
  111. return {
  112. width: '1600px',
  113. visible: false,
  114. confirmLoading: false,
  115. prefixNo: '',
  116. loading: false,
  117. dataSource: [],
  118. columns: table.goodsColums,
  119. url: {
  120. add: '/stocktaking/add',
  121. update: '/stocktaking/detailUpdate',
  122. },
  123. form: {},
  124. isShow: false,
  125. stockType: 'task',
  126. batchNumberStr: ''
  127. }
  128. },
  129. watch: {
  130. stockVisible(val) {
  131. if (val) {
  132. if (this.taskId) {
  133. this.$nextTick(() => {
  134. this.getList(this.taskId)
  135. })
  136. return
  137. }
  138. } else {
  139. this.dataSource = []
  140. this.ipagination.current = 1
  141. this.loading = false
  142. }
  143. },
  144. },
  145. computed: {
  146. isShowBtn() {
  147. if (this.openType === 'add') return true
  148. if (this.openType === 'detail') return false
  149. if (this.form.taskStatus !== 1) return false
  150. return true
  151. },
  152. },
  153. methods: {
  154. handleCancel() {
  155. this.$emit('update:stockVisible', false)
  156. },
  157. handleOk() {
  158. this.$refs.editForm.form.validateFields((err, values) => {
  159. if (!err) {
  160. const params = { ...values }
  161. if (params.taskType === 2) {
  162. params.materialExtendIdList = this.dataSource.map((item) => item.batchNumber)
  163. }
  164. const url = this.openType === 'add' ? this.url.add : this.url.update
  165. postAction(url, params).then((res) => {
  166. if (res.code === 200) {
  167. this.$message.success('操作成功')
  168. this.handleCancel()
  169. } else {
  170. this.$message.error(res.msg)
  171. }
  172. })
  173. }
  174. })
  175. },
  176. onChangeGoods() {
  177. if(!this.form.depotId){
  178. this.$message.warning('请选择仓库!')
  179. return
  180. }
  181. // this.$refs.selectModal.queryParam.depotId = this.form.depotId
  182. this.$refs.selectModal.showModal()
  183. },
  184. getList(id) {
  185. const url = '/stocktaking/detail/' + id
  186. const url2 = `/stocktaking/detailByItemList?currentPage=${this.ipagination.current}&pageSize=${this.ipagination.pageSize}`
  187. const form = this.$refs['editForm'].form
  188. getAction(url).then((res) => {
  189. const {
  190. depotId,
  191. taskName,
  192. taskStatus,
  193. taskType,
  194. createTime,
  195. createByName,
  196. materialCount,
  197. positionRange,
  198. creator,
  199. id,
  200. number
  201. } = res.data
  202. form.setFieldsValue({
  203. depotId,
  204. taskName,
  205. taskStatus,
  206. taskType,
  207. createTime,
  208. createByName,
  209. materialCount,
  210. positionRange,
  211. creator,
  212. id,
  213. number
  214. })
  215. postAction(url2, { taskStocktakingId: id }).then((res) => {
  216. this.dataSource = res.data
  217. this.ipagination.total = this.dataSource.length
  218. const materialExtendIdList = this.dataSource.map((item) => item.batchNumber)
  219. form.setFieldsValue({
  220. materialExtendIdList,
  221. })
  222. this.getForm(form.getFieldsValue())
  223. console.log('this.dataSource',this.dataSource)
  224. console.log('this.columns',this.columns)
  225. })
  226. })
  227. },
  228. getGoods(rows, ids) {
  229. const str = ids
  230. .split(',')
  231. .filter((item) => item)
  232. .join(',')
  233. if(!this.form.depotId){
  234. this.$message.warning('请选择仓库!')
  235. return
  236. }
  237. getAction('/materialBatch/findBatchNumbersByBarCode',{
  238. barCodes: str,
  239. depotId:this.form.depotId
  240. }).then((res) => {
  241. const batchStr = res.data.split(',')
  242. .filter((item) => item)
  243. .join(',')
  244. this.batchNumberStr = batchStr
  245. this.getBatchData()
  246. })
  247. },
  248. findAllSelect() {
  249. if(!this.form.depotId){
  250. this.$message.warning('请选择仓库!')
  251. return
  252. }
  253. getAction('/materialBatch/findBatchNumbersByBarCode',{
  254. depotId:this.form.depotId
  255. }).then((res) => {
  256. this.$refs.selectModal.close()
  257. const batchStr = res.data.split(',')
  258. .filter((item) => item)
  259. .join(',')
  260. this.batchNumberStr = batchStr
  261. this.getBatchData()
  262. })
  263. },
  264. getBatchData() {
  265. const params = {
  266. batchNumber: this.batchNumberStr,
  267. // organId: '',
  268. // mpList: '',
  269. // prefixNo: '',
  270. }
  271. getAction(`/material/getMaterialByBatchNumber?currentPage=${this.ipagination.current}&pageSize=${this.ipagination.pageSize}`, params).then((res) => {
  272. this.dataSource = res.data.rows
  273. if(this.dataSource.length===0){
  274. this.$message.warning('暂无数据!')
  275. }
  276. this.ipagination.total = Number(res.data.total)
  277. this.dataSource = this.dataSource.reduce((acc, cur) => {
  278. const hasDuplicate = acc.some((item) => item.batchNumber === cur.batchNumber)
  279. if (!hasDuplicate) {
  280. acc.push(cur)
  281. }
  282. return acc
  283. }, [])
  284. })
  285. },
  286. getForm(val) {
  287. this.form = val
  288. this.$refs['editForm'].model = val
  289. },
  290. //删除
  291. handleDelete(record) {
  292. this.dataSource = this.dataSource.filter((item) => item.batchNumber !== record.batchNumber)
  293. this.ipagination.total -=1
  294. },
  295. handleChangeForm(val) {
  296. this.dataSource = []
  297. this.ipagination.current = 1
  298. this.ipagination.total = 0
  299. this.getForm(val)
  300. if (val.taskType === 1) {
  301. this.findAllSelect()
  302. }
  303. },
  304. handleDrag() {},
  305. // ipagination() {},
  306. handleTableChange(pagination) {
  307. if (pagination && pagination.current) {
  308. this.ipagination = pagination
  309. }
  310. if(this.openType=='add'){
  311. this.getBatchData()
  312. }else{
  313. this.getList(this.taskId)
  314. }
  315. },
  316. },
  317. }
  318. </script>
  319. <style></style>