stockModal.vue 7.3 KB

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