stockModal.vue 9.3 KB

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