stockModal.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. this.$message.success('操作成功')
  167. this.handleCancel()
  168. })
  169. }
  170. })
  171. },
  172. onChangeGoods() {
  173. this.$refs.selectModal.queryParam.depotId = this.form.depotId
  174. this.$refs.selectModal.showModal()
  175. },
  176. getList(id) {
  177. const url = '/stocktaking/detail/' + id
  178. const url2 = '/stocktaking/detailByItemList'
  179. const form = this.$refs['editForm'].form
  180. getAction(url).then((res) => {
  181. const {
  182. depotId,
  183. taskName,
  184. taskStatus,
  185. taskType,
  186. createTime,
  187. createByName,
  188. materialCount,
  189. positionRange,
  190. creator,
  191. id,
  192. } = res.data
  193. form.setFieldsValue({
  194. depotId,
  195. taskName,
  196. taskStatus,
  197. taskType,
  198. createTime,
  199. createByName,
  200. materialCount,
  201. positionRange,
  202. creator,
  203. id,
  204. })
  205. postAction(url2, { taskStocktakingId: id }).then((res) => {
  206. this.dataSource = res.data
  207. this.ipagination.total = this.dataSource.length
  208. const materialExtendIdList = this.dataSource.map((item) => item.batchNumber)
  209. form.setFieldsValue({
  210. materialExtendIdList,
  211. })
  212. this.getForm(form.getFieldsValue())
  213. })
  214. })
  215. },
  216. getGoods(rows, ids) {
  217. const str = ids
  218. .split(',')
  219. .filter((item) => item)
  220. .join(',')
  221. this.getBatchData(str)
  222. },
  223. findAllSelect() {
  224. const params = { ...this.$refs.selectModal.queryParam }
  225. getAction('/material/findBatchNumbersBySelect', params).then((res) => {
  226. this.$refs.selectModal.close()
  227. this.getBatchData(res.data)
  228. })
  229. },
  230. getBatchData(val) {
  231. const batchStr = val
  232. .split(',')
  233. .filter((item) => item)
  234. .join(',')
  235. const params = {
  236. batchNumber: batchStr,
  237. organId: '',
  238. mpList: '',
  239. prefixNo: '',
  240. }
  241. getMaterialByBatchNumber(params).then((res) => {
  242. this.dataSource.push(...res.data)
  243. this.dataSource = this.dataSource.reduce((acc, cur) => {
  244. const hasDuplicate = acc.some((item) => item.batchNumber === cur.batchNumber)
  245. if (!hasDuplicate) {
  246. acc.push(cur)
  247. }
  248. return acc
  249. }, [])
  250. })
  251. },
  252. getForm(val) {
  253. this.form = val
  254. this.$refs['editForm'].model = val
  255. },
  256. //删除
  257. handleDelete(record) {
  258. this.dataSource = this.dataSource.filter((item) => item.batchNumber !== record.batchNumber)
  259. },
  260. onClearList(val) {
  261. this.dataSource = []
  262. this.getForm(val)
  263. if (val.taskType === 1) {
  264. this.findAllSelect()
  265. }
  266. },
  267. handleDrag() {},
  268. // ipagination() {},
  269. handleTableChange() {},
  270. },
  271. }
  272. </script>
  273. <style></style>