stockModal.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. :components="handleDrag(columns)"
  31. :pagination="ipagination"
  32. :loading="loading"
  33. @change="handleTableChange"
  34. >
  35. <span v-if="form.taskType === 2" 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="customName" slot-scope="text, record">
  42. {{ record.name }}
  43. <a-tag v-if="record.enableSerialNumber == 1" color="orange">序</a-tag>
  44. <a-tag v-if="record.enableBatchNumber == 1" color="orange">批</a-tag>
  45. </template> -->
  46. </a-table>
  47. </div>
  48. </a-spin>
  49. <template slot="footer">
  50. <a-button @click="handleCancel">取消</a-button>
  51. <a-button v-if="isShowBtn" @click="handleOk" type="primary">确认发布盘点任务</a-button>
  52. </template>
  53. </a-modal>
  54. <j-select-material-modal
  55. @ok="getGoods"
  56. @all="findAllSelect"
  57. ref="selectModal"
  58. :multi="true"
  59. ></j-select-material-modal>
  60. </div>
  61. </template>
  62. <script>
  63. import editForm from './editForm.vue'
  64. import table from '../utils/table'
  65. import JSelectMaterialModal from '../../../components/jeecgbiz/modal/JSelectMaterialModal.vue'
  66. import { getAction, postAction } from '@/api/manage'
  67. import { getMaterialByBatchNumber } from '@/api/api'
  68. import { newTableMixin } from '@/mixins/newTableMixin'
  69. // import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  70. // import { Form } from 'ant-design-vue'
  71. // const useForm = Form.useForm
  72. export default {
  73. components: { editForm, JSelectMaterialModal },
  74. mixins: [newTableMixin],
  75. props: {
  76. rules: {
  77. type: Object,
  78. default: () => {
  79. return {}
  80. },
  81. },
  82. stockVisible: {
  83. type: Boolean,
  84. default: false,
  85. },
  86. title: {
  87. type: String,
  88. default: '新增',
  89. },
  90. spinnerList: {
  91. type: Array,
  92. default: () => [],
  93. },
  94. deoptData: {
  95. type: Array,
  96. default: () => [],
  97. },
  98. taskId: {
  99. type: String,
  100. default: '',
  101. },
  102. openType: {
  103. type: String,
  104. default: 'add',
  105. },
  106. },
  107. data() {
  108. return {
  109. width: '1600px',
  110. visible: false,
  111. confirmLoading: false,
  112. prefixNo: '',
  113. loading: false,
  114. dataSource: [],
  115. columns: table.goodsColums,
  116. url: {
  117. add: '/stocktaking/add',
  118. update: '/stocktaking/detailUpdate',
  119. },
  120. form: {},
  121. isShow: false,
  122. stockType: 'task',
  123. }
  124. },
  125. watch: {
  126. stockVisible(val) {
  127. if (val) {
  128. if (this.taskId) {
  129. this.$nextTick(() => {
  130. this.getDetailList(this.taskId)
  131. })
  132. return
  133. }
  134. } else {
  135. this.dataSource = []
  136. this.ipagination.current = 1
  137. this.loading = false
  138. }
  139. },
  140. },
  141. computed: {
  142. isShowBtn() {
  143. return this.openType !== 'detail' || this.form.taskStatus !== 1
  144. },
  145. },
  146. methods: {
  147. handleCancel() {
  148. this.$emit('update:stockVisible', false)
  149. },
  150. handleOk() {
  151. this.$refs.editForm.form.validateFields((err, values) => {
  152. if (!err) {
  153. const params = { ...values }
  154. if (params.taskType === 2) {
  155. params.materialExtendIdList = this.dataSource.map((item) => item.batchNumber)
  156. }
  157. const url = this.openType === 'add' ? this.url.add : this.url.update
  158. postAction(url, params).then((res) => {
  159. this.$message.success('操作成功')
  160. this.handleCancel()
  161. })
  162. }
  163. })
  164. },
  165. onChangeGoods() {
  166. this.$refs.selectModal.queryParam.depotId = this.form.depotId
  167. this.$refs.selectModal.showModal()
  168. },
  169. getDetailList(id) {
  170. const url = '/stocktaking/detail/' + id
  171. const url2 = '/stocktaking/detailByItemList'
  172. const form = this.$refs['editForm'].form
  173. getAction(url).then((res) => {
  174. const {
  175. depotId,
  176. taskName,
  177. taskStatus,
  178. taskType,
  179. createTime,
  180. createByName,
  181. materialCount,
  182. positionRange,
  183. creator,
  184. id,
  185. } = res.data
  186. form.setFieldsValue({
  187. depotId,
  188. taskName,
  189. taskStatus,
  190. taskType,
  191. createTime,
  192. createByName,
  193. materialCount,
  194. positionRange,
  195. creator,
  196. id,
  197. })
  198. postAction(url2, { taskStocktakingId: id }).then((res) => {
  199. this.dataSource = res.data
  200. this.ipagination.total = this.dataSource.length
  201. const materialExtendIdList = this.dataSource.map((item) => item.batchNumber)
  202. form.setFieldsValue({
  203. materialExtendIdList,
  204. })
  205. this.getForm(form.getFieldsValue())
  206. })
  207. })
  208. },
  209. getGoods(rows, ids) {
  210. const str = ids
  211. .split(',')
  212. .filter((item) => item)
  213. .join(',')
  214. this.getBatchData(str)
  215. },
  216. findAllSelect() {
  217. const params = { ...this.$refs.selectModal.queryParam }
  218. getAction('/material/findBatchNumbersBySelect', params).then((res) => {
  219. this.$refs.selectModal.close()
  220. this.getBatchData(res.data)
  221. })
  222. },
  223. getBatchData(val) {
  224. const batchStr = val
  225. .split(',')
  226. .filter((item) => item)
  227. .join(',')
  228. const params = {
  229. batchNumber: batchStr,
  230. organId: '',
  231. mpList: '',
  232. prefixNo: '',
  233. }
  234. getMaterialByBatchNumber(params).then((res) => {
  235. this.dataSource.push(...res.data)
  236. this.dataSource = this.dataSource.reduce((acc, cur) => {
  237. const hasDuplicate = acc.some((item) => item.batchNumber === cur.batchNumber)
  238. if (!hasDuplicate) {
  239. acc.push(cur)
  240. }
  241. return acc
  242. }, [])
  243. })
  244. },
  245. getForm(val) {
  246. this.form = val
  247. this.$refs['editForm'].model = val
  248. },
  249. //删除
  250. handleDelete(record) {
  251. this.dataSource = this.dataSource.filter((item) => item.batchNumber !== record.batchNumber)
  252. },
  253. onClearList(val) {
  254. this.dataSource = []
  255. this.getForm(val)
  256. if (val.taskType === 1) {
  257. this.findAllSelect()
  258. }
  259. },
  260. handleDrag() {},
  261. // ipagination() {},
  262. handleTableChange() {},
  263. },
  264. }
  265. </script>
  266. <style></style>