stockModal.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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="openType"
  14. :stockType="stockType"
  15. @getForm="getForm"
  16. @clear="onClearList"
  17. ></edit-form>
  18. <div>
  19. <a-button v-if="form.taskType === 2" style="margin-bottom: 6px" type="primary" @click="onChangeGoods"
  20. >选择商品</a-button
  21. >
  22. <a-table
  23. v-if="dataSource.length"
  24. ref="table"
  25. size="middle"
  26. bordered
  27. rowKey="id"
  28. :columns="columns"
  29. :dataSource="dataSource"
  30. :loading="loading"
  31. :scroll="{ y: 500 }"
  32. :pagination="false"
  33. @change="handleTableChange"
  34. >
  35. <span v-if="isShowBtn" slot="action" slot-scope="text, record">
  36. <!-- <a-divider type="vertical" /> -->
  37. <a-popconfirm @confirm="handleDelete(record)" title="确定删除吗?">
  38. <a>删除</a>
  39. </a-popconfirm>
  40. </span>
  41. <template slot="inventory" slot-scope="value, record">
  42. {{ parseInt(value) }}
  43. </template>
  44. <!-- <template slot="customName" slot-scope="text, record">
  45. {{ record.name }}
  46. <a-tag v-if="record.enableSerialNumber == 1" color="orange">序</a-tag>
  47. <a-tag v-if="record.enableBatchNumber == 1" color="orange">批</a-tag>
  48. </template> -->
  49. </a-table>
  50. </div>
  51. </a-spin>
  52. <template slot="footer">
  53. <a-button @click="handleCancel">取消</a-button>
  54. <a-button v-if="isShowBtn" @click="handleOk" type="primary">确认发布盘点任务</a-button>
  55. </template>
  56. </a-modal>
  57. <j-select-material-modal
  58. @ok="getGoods"
  59. @all="findAllSelect"
  60. ref="selectModal"
  61. :multi="true"
  62. :isStock="true"
  63. ></j-select-material-modal>
  64. </div>
  65. </template>
  66. <script>
  67. import editForm from './editForm.vue'
  68. import table from '../utils/table'
  69. import JSelectMaterialModal from '../../../components/jeecgbiz/modal/JSelectMaterialModal.vue'
  70. import { getAction, postAction } from '@/api/manage'
  71. import { getMaterialByBatchNumber } from '@/api/api'
  72. import { newTableMixin } from '@/mixins/newTableMixin'
  73. // import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  74. // import { Form } from 'ant-design-vue'
  75. // const useForm = Form.useForm
  76. export default {
  77. components: { editForm, JSelectMaterialModal },
  78. mixins: [newTableMixin],
  79. props: {
  80. rules: {
  81. type: Object,
  82. default: () => {
  83. return {}
  84. },
  85. },
  86. stockVisible: {
  87. type: Boolean,
  88. default: false,
  89. },
  90. title: {
  91. type: String,
  92. default: '新增',
  93. },
  94. spinnerList: {
  95. type: Array,
  96. default: () => [],
  97. },
  98. deoptData: {
  99. type: Array,
  100. default: () => [],
  101. },
  102. taskId: {
  103. type: String,
  104. default: '',
  105. },
  106. openType: {
  107. type: String,
  108. default: 'add',
  109. },
  110. },
  111. data() {
  112. return {
  113. width: '1600px',
  114. visible: false,
  115. confirmLoading: false,
  116. prefixNo: '',
  117. loading: false,
  118. dataSource: [],
  119. columns: table.goodsColums,
  120. url: {
  121. add: '/stocktaking/add',
  122. update: '/stocktaking/detailUpdate',
  123. },
  124. form: {},
  125. isShow: false,
  126. stockType: 'task',
  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. this.$refs.selectModal.queryParam.depotId = this.form.depotId
  178. this.$refs.selectModal.showModal()
  179. },
  180. getList(id) {
  181. const url = '/stocktaking/detail/' + id
  182. const url2 = '/stocktaking/detailByItemList'
  183. const form = this.$refs['editForm'].form
  184. getAction(url).then((res) => {
  185. const {
  186. depotId,
  187. taskName,
  188. taskStatus,
  189. taskType,
  190. createTime,
  191. createByName,
  192. materialCount,
  193. positionRange,
  194. creator,
  195. id,
  196. } = res.data
  197. form.setFieldsValue({
  198. depotId,
  199. taskName,
  200. taskStatus,
  201. taskType,
  202. createTime,
  203. createByName,
  204. materialCount,
  205. positionRange,
  206. creator,
  207. id,
  208. })
  209. postAction(url2, { taskStocktakingId: id }).then((res) => {
  210. this.dataSource = res.data
  211. this.ipagination.total = this.dataSource.length
  212. const materialExtendIdList = this.dataSource.map((item) => item.batchNumber)
  213. form.setFieldsValue({
  214. materialExtendIdList,
  215. })
  216. this.getForm(form.getFieldsValue())
  217. })
  218. })
  219. },
  220. getGoods(rows, ids) {
  221. const str = ids
  222. .split(',')
  223. .filter((item) => item)
  224. .join(',')
  225. this.getBatchData(str)
  226. },
  227. findAllSelect() {
  228. const params = { ...this.$refs.selectModal.queryParam }
  229. getAction('/material/findBatchNumbersBySelect', params).then((res) => {
  230. this.$refs.selectModal.close()
  231. this.getBatchData(res.data)
  232. })
  233. },
  234. getBatchData(val) {
  235. const batchStr = val
  236. .split(',')
  237. .filter((item) => item)
  238. .join(',')
  239. const params = {
  240. batchNumber: batchStr,
  241. organId: '',
  242. mpList: '',
  243. prefixNo: '',
  244. }
  245. getMaterialByBatchNumber(params).then((res) => {
  246. this.dataSource.push(...res.data)
  247. this.dataSource = this.dataSource.reduce((acc, cur) => {
  248. const hasDuplicate = acc.some((item) => item.batchNumber === cur.batchNumber)
  249. if (!hasDuplicate) {
  250. acc.push(cur)
  251. }
  252. return acc
  253. }, [])
  254. })
  255. },
  256. getForm(val) {
  257. this.form = val
  258. this.$refs['editForm'].model = val
  259. },
  260. //删除
  261. handleDelete(record) {
  262. this.dataSource = this.dataSource.filter((item) => item.batchNumber !== record.batchNumber)
  263. },
  264. onClearList(val) {
  265. this.dataSource = []
  266. this.getForm(val)
  267. if (val.taskType === 1) {
  268. this.findAllSelect()
  269. }
  270. },
  271. handleDrag() {},
  272. // ipagination() {},
  273. handleTableChange() {},
  274. },
  275. }
  276. </script>
  277. <style></style>