BaseFormBackYY.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">
  3. <a-form :form="form">
  4. <a-form-item v-show="false" >
  5. <a-input v-decorator="['id']" type="hidden"/>
  6. <a-input v-decorator="['storeId']" type="hidden"/>
  7. <a-input v-decorator="['pickId']" type="hidden"/>
  8. <a-input v-decorator="['outFlag']" type="hidden"/>
  9. <a-input v-decorator="['outStoreFormId']" type="hidden"/>
  10. </a-form-item>
  11. <a-row :gutter="24">
  12. <a-col :lg="12" :md="24" :sm="24">
  13. <a-form-item
  14. label="出库单号"
  15. :labelCol="BaseTool.Constant.labelCol"
  16. :wrapperCol="BaseTool.Constant.wrapperCol"
  17. >
  18. <a-input
  19. disabled
  20. style="width: 70%"
  21. v-decorator="['outNo', {rules: [{required: false, message: '出库单号不能为空'}]}]" />
  22. <a-button type="primary" style="width: 30%" @click="handleSparePickFormSelect">选择</a-button>
  23. </a-form-item>
  24. </a-col>
  25. </a-row>
  26. </a-form>
  27. <title-divider title="备件明细" width="90px"></title-divider>
  28. <!-- <div class="table-operator" style="margin-bottom: 8px;">
  29. <a-button size="small" type="primary" @click="handleSpareStoreSelect">
  30. <a-icon type="plus"/>
  31. 添加
  32. </a-button>
  33. <a-button class="margin-left8" size="small" type="danger" @click="handleDel">
  34. <a-icon type="delete"/>
  35. 删除
  36. </a-button>
  37. </div> -->
  38. <a-table
  39. bordered
  40. :data-source="data"
  41. :columns="columns"
  42. tableLayout="auto"
  43. rowKey="autoId"
  44. :row-selection="rowSelection">
  45. <template slot="num" slot-scope="text, record">
  46. <div class="editable-cell-input-wrapper">
  47. <a-input :value="text" :id="record.autoId + ',num'" @change="$event => onQuantityChange($event, record.autoId, 'num')" />
  48. </div>
  49. </template>
  50. <template slot="remark" slot-scope="text, record">
  51. <div>
  52. <a-input v-model="record.remark" />
  53. </div>
  54. </template>
  55. <span slot="action" slot-scope="record">
  56. <template>
  57. <a @click="handleBaseFormForModifySelect(record)">修改</a>
  58. <a-divider type="vertical" />
  59. <a-popconfirm title="是否要删除该条数据?" @confirm="handleDelOne(record)">
  60. <a>删除</a>
  61. </a-popconfirm>
  62. </template>
  63. </span>
  64. </a-table>
  65. <a-row :gutter="48" >
  66. <a-col :md="48" :sm="48">
  67. <span class="table-page-search-submitButtons" style="float: right;margin-top: 10px">
  68. <a-button :loading="confirmLoading" type="primary" @click="save()">提交</a-button>
  69. <a-button style="margin-left: 8px" @click="handleCancel()">返回</a-button>
  70. </span>
  71. </a-col>
  72. </a-row>
  73. <spare-pick-form-select-modal ref="sparePickFormSelectModal" @selected="handleSparePickFormSelected"/>
  74. <spare-back-form-select-modal ref="spareBackFormSelectModal" @selected="handleSpareBackFormSelected"/>
  75. <spare-store-select-modal ref="spareStoreSelectModal" @selected="handleSpareStoreSelected"/>
  76. <detail-base-form ref="detailBaseForm" @selected="handleDetailSelected"/>
  77. <store-select-modal ref="storeSelectModal" @selected="handleStoreSelected"/>
  78. <base-form-for-modify ref="baseFormForModify" @selected="handleBaseFormForModifySelected"/>
  79. <OutStoreFormSelectModal ref="outStoreFormSelectModal" @selected="handleOutStoreSelected" />
  80. </a-card>
  81. </template>
  82. <script>
  83. import pick from 'lodash.pick'
  84. import { addOutStoreBackFormYY, updateOutStoreFormYY, fetchOutStoreForm } from '@/api/store/outstoreform'
  85. import SparePickFormSelectModal from '@/views/store/sparepickform/modules/SparePickFormSelectModal.vue'
  86. import SpareBackFormSelectModal from '@/views/store/sparebackform/modules/SpareBackFormSelectModal'
  87. import DetailBaseForm from './DetailBaseForm'
  88. import StoreSelectModal from '@/views/store/store/modules/StoreSelectModal'
  89. import SpareStoreSelectModal from '@/views/store/sparestore/modules/SpareStoreSelectModalYY'
  90. import BaseFormForModify from '@/views/store/outstoredetail/modules/BaseFormForModify'
  91. import BaseTool from '@/utils/tool'
  92. import OutStoreFormSelectModal from './OutStoreFormSelectModal'
  93. import { queryUsersByParentDeptNatureAll } from '@/api/upms/user'
  94. import { fetchStoreTree } from '@/api/store/store'
  95. import { getSbPositions } from '@/api/repair/application-form'
  96. import { fetchSbTypeTree } from '@/api/project/project'
  97. export default {
  98. name: 'BaseOutStoreFormYY',
  99. components: {
  100. DetailBaseForm,
  101. SparePickFormSelectModal,
  102. SpareBackFormSelectModal,
  103. SpareStoreSelectModal,
  104. StoreSelectModal,
  105. OutStoreFormSelectModal,
  106. BaseFormForModify
  107. },
  108. data () {
  109. return {
  110. confirmLoading: false,
  111. modalTitle: null,
  112. form: this.$form.createForm(this),
  113. visible: false,
  114. maskClosable: false,
  115. outFlag: 1,
  116. tokenType: 1,
  117. model: {},
  118. sbPositionList: [],
  119. feeFromMap: {},
  120. lyDeptMap: {},
  121. flagMap: {},
  122. sdDeptMap: {},
  123. storeId: null,
  124. treeData: [],
  125. // 下拉框map
  126. typeMap: {},
  127. deptYYMap: {},
  128. // 表头
  129. columns: [
  130. {
  131. title: '序号',
  132. dataIndex: 'index',
  133. customRender: (text, record, index) => {
  134. return index + 1
  135. }
  136. },
  137. {
  138. title: '名称',
  139. dataIndex: 'spareName'
  140. },
  141. {
  142. title: '编号',
  143. dataIndex: 'no'
  144. },
  145. {
  146. title: '规格',
  147. dataIndex: 'ggxh'
  148. },
  149. {
  150. title: '批次',
  151. dataIndex: 'cbatch'
  152. },
  153. {
  154. title: '数量',
  155. dataIndex: 'num',
  156. width: 150,
  157. scopedSlots: { customRender: 'num' }
  158. },
  159. {
  160. title: '单位',
  161. dataIndex: 'unit'
  162. },
  163. {
  164. title: '仓库',
  165. dataIndex: 'storeName'
  166. },
  167. {
  168. title: '货架号',
  169. dataIndex: 'storePosition'
  170. }
  171. ],
  172. data: [],
  173. storeTreeDate: [],
  174. userList: {},
  175. user: this.$store.getters.userInfo,
  176. selectedRowKeys: [],
  177. selectedRows: [],
  178. options: {
  179. rowSelection: {
  180. selectedRowKeys: this.selectedRowKeys
  181. }
  182. },
  183. rowSelection: {
  184. onChange: (selectedRowKeys, selectedRows) => {
  185. this.selectedRowKeys = selectedRowKeys
  186. this.selectedRows = selectedRows
  187. }
  188. }
  189. }
  190. },
  191. props: {
  192. },
  193. created () {
  194. this.setTree()
  195. // 下拉框map
  196. this.getSbPositions()
  197. this.feeFromMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.FEE_FORM_TYPE)
  198. this.lyDeptMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.DEPT_TYPE_LY)
  199. this.sdDeptMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.DEPT_TYPE_SD)
  200. this.flagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PROJECT_NEW_AND_OLD)
  201. console.log(this.lyDeptMap)
  202. console.log(this.sdDeptMap)
  203. this.deptYYMap = this.DictCache.getChildrenList(this.DictCache.TYPE.OUT_STORE_FORM_DEPT_CODE).map(item => {
  204. if (item.code === 'SBB') {
  205. item.children = this.DictCache.getChildrenList(this.DictCache.TYPE.SBB)
  206. }
  207. return item
  208. })
  209. console.log(1, this.deptYYMap, 1)
  210. // this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.OUT_STORE_FORM_TYPE)
  211. },
  212. methods: {
  213. base (record, model) {
  214. this.visible = true
  215. this.model = model
  216. this.outFlag = record.outFlag
  217. if (record.outFlag === 1) {
  218. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.OUT_STORE_FORM_TYPE)
  219. } else {
  220. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_BACK_FORM_TYPE)
  221. }
  222. const params = { deptId: this.user.companyId }
  223. params.nature = this.DictCache.VALUE.SYS_DEPT_NATURE.FEN_GONG_SI
  224. queryUsersByParentDeptNatureAll(params).then(res => {
  225. this.userList = res.data
  226. })
  227. fetchStoreTree().then(res => {
  228. this.storeTreeDate = res.data
  229. })
  230. // 如果是空标识添加
  231. if (this.BaseTool.Object.isBlank(record.id)) {
  232. this.modalTitle = '添加'
  233. this.data = []
  234. const { form: { setFieldsValue } } = this
  235. // 日期处理
  236. this.$nextTick(() => {
  237. setFieldsValue(Object.assign(pick(record, [
  238. 'outFlag'
  239. ]), pick(model, [
  240. 'sbCph'
  241. ]), {
  242. 'sbPosition': model.sbPosition.split('->')
  243. }))
  244. })
  245. return
  246. }
  247. this.modalTitle = '编辑'
  248. const { form: { setFieldsValue } } = this
  249. // 日期处理
  250. this.storeId = record.storeId
  251. this.$nextTick(() => {
  252. setFieldsValue(Object.assign(pick(record, [
  253. 'id',
  254. 'outNo',
  255. 'outStoreFormId',
  256. 'userId',
  257. 'applyDept',
  258. 'userTime',
  259. 'storeId',
  260. 'storeName',
  261. 'pickId',
  262. 'feeFrom',
  263. 'pickNo',
  264. 'type',
  265. 'remark'
  266. ])))
  267. })
  268. this.data = record.detailList
  269. },
  270. setTree () {
  271. fetchSbTypeTree({
  272. flag: this.tokenType
  273. }).then((res) => {
  274. this.treeData = res.data.map(item => {
  275. item.selectable = item.children == null
  276. return item
  277. })
  278. })
  279. },
  280. save () {
  281. const { form: { validateFieldsAndScroll } } = this
  282. this.confirmLoading = true
  283. validateFieldsAndScroll((errors, values) => {
  284. if (errors) {
  285. this.confirmLoading = false
  286. return
  287. }
  288. if (this.data.length === 0) {
  289. this.$message.error('请添加出库详情')
  290. this.confirmLoading = false
  291. return
  292. }
  293. values.detailList = this.data.filter(item => item.num > 0)
  294. values.userTime = BaseTool.Date.formatter(values.userTime, BaseTool.Date.PICKER_NORM_DATE_PATTERN)
  295. // 日期处理
  296. console.log(values)
  297. addOutStoreBackFormYY(values)
  298. .then(() => {
  299. this.handleCancel(values)
  300. }).catch(() => {
  301. this.confirmLoading = false
  302. })
  303. // if (this.BaseTool.String.isBlank(values.id)) {
  304. // addOutStoreFormYY(values)
  305. // .then(() => {
  306. // this.handleCancel(values)
  307. // }).catch(() => {
  308. // this.confirmLoading = false
  309. // })
  310. // } else {
  311. // updateOutStoreFormYY(values)
  312. // .then(() => {
  313. // this.handleCancel(values)
  314. // }).catch(() => {
  315. // this.confirmLoading = false
  316. // })
  317. // }
  318. })
  319. },
  320. loadData (selectedOptions) {
  321. console.log(selectedOptions)
  322. const targetOption = selectedOptions[selectedOptions.length - 1]
  323. targetOption.loading = true
  324. getSbPositions({ parentId: targetOption.id }).then(res => {
  325. targetOption.loading = false
  326. targetOption.children = res.data.map(item => {
  327. item = {
  328. label: item.name,
  329. value: item.name
  330. }
  331. return item
  332. })
  333. this.sbPositionList = [...this.sbPositionList]
  334. })
  335. },
  336. getSbPositions (parentId) {
  337. getSbPositions({ parentId }).then(res => {
  338. console.log(res)
  339. this.sbPositionList = res.data.map(item => {
  340. item = {
  341. label: item.name,
  342. value: item.name,
  343. id: item.id,
  344. isLeaf: false
  345. }
  346. return item
  347. })
  348. })
  349. },
  350. handleCancel (values) {
  351. this.visible = false
  352. this.confirmLoading = false
  353. this.form.resetFields()
  354. if (this.BaseTool.Object.isNotBlank(values)) {
  355. this.$emit('ok', values)
  356. } else {
  357. this.$emit('ok')
  358. }
  359. },
  360. typeChange (values) {
  361. this.type = values
  362. },
  363. handleStoreSelect () {
  364. this.$refs.storeSelectModal.base({}, { filter: -1 })
  365. },
  366. handleStoreSelected (record, keys, rows) {
  367. // 重新选择了仓库,则明细需要全部清空
  368. this.data = []
  369. const [ key ] = keys
  370. const [ row ] = rows
  371. const { form: { setFieldsValue } } = this
  372. this.storeId = key
  373. // 日期处理
  374. this.$nextTick(() => {
  375. setFieldsValue(Object.assign({
  376. 'storeId': key,
  377. 'storeName': row.name
  378. }))
  379. })
  380. },
  381. handleSparePickFormSelect () {
  382. this.$refs.outStoreFormSelectModal.base()
  383. },
  384. handleOutStoreSelected (record, keys, rows) {
  385. const [ key ] = keys
  386. const [ row ] = rows
  387. const { form: { setFieldsValue } } = this
  388. // 日期处理
  389. console.log(keys, rows)
  390. fetchOutStoreForm({ id: key }).then(res => {
  391. this.data = res.data.detailList.map(item => {
  392. item.num = 0
  393. return item
  394. })
  395. })
  396. setFieldsValue(Object.assign({
  397. 'outStoreFormId': key,
  398. 'outNo': row.outNo
  399. }))
  400. },
  401. handleSparePickFormSelected (record, keys, rows) {
  402. const [ key ] = keys
  403. const [ row ] = rows
  404. const { form: { setFieldsValue } } = this
  405. // 日期处理
  406. setFieldsValue(Object.assign({
  407. 'pickId': key,
  408. 'pickNo': row.pickNo
  409. }))
  410. },
  411. handleSpareBackFormSelected (record, keys, rows) {
  412. const [ key ] = keys
  413. const [ row ] = rows
  414. const { form: { setFieldsValue } } = this
  415. // 日期处理
  416. setFieldsValue(Object.assign({
  417. 'pickId': key,
  418. 'pickNo': row.pickNo
  419. }))
  420. },
  421. handleDetailSelect () {
  422. if (this.storeId == null) {
  423. this.$message.error('请先选择仓库')
  424. return
  425. }
  426. this.$refs.detailBaseForm.base({ storeId: this.storeId })
  427. },
  428. handleDetailSelected (record) {
  429. const { data } = this
  430. data.push(record)
  431. },
  432. handleDel (id) {
  433. const data = [...this.data]
  434. if (this.selectedRowKeys.length === 0) {
  435. this.$message.error('请至少选择一条数据')
  436. return
  437. }
  438. this.data = data.filter(item => !this.selectedRowKeys.includes(item.id))
  439. },
  440. handleDelOne (record) {
  441. const data = [...this.data]
  442. this.data = data.filter(item => record.autoId !== item.autoId)
  443. },
  444. handleSpareStoreSelect () {
  445. this.$refs.spareStoreSelectModal.base({ tokenType: this.tokenType })
  446. },
  447. handleSpareStoreSelected (record, keys, rows) {
  448. console.log(rows)
  449. const { data } = this
  450. for (let i = 0; i < rows.length; i++) {
  451. let find = false
  452. for (let j = 0; j < data.length; j++) {
  453. if (rows[i].autoId === data[j].autoId) {
  454. find = true
  455. break
  456. }
  457. }
  458. if (!find) {
  459. const selectData = rows[i]
  460. selectData.storeNum = selectData.num
  461. selectData.num = 1
  462. data.push(selectData)
  463. }
  464. }
  465. },
  466. handleStoreChange (value) {
  467. this.storeId = value
  468. },
  469. handleBaseFormForModifySelect (record) {
  470. this.$refs.baseFormForModify.base(record)
  471. },
  472. handleBaseFormForModifySelected (values) {
  473. console.log('values' + values.id)
  474. const { data } = this
  475. for (let j = 0; j < data.length; j++) {
  476. if (values.id === data[j].id) {
  477. data[j].num = values.num
  478. data[j].totalPrice = values.totalPrice
  479. break
  480. }
  481. }
  482. },
  483. onQuantityChange (e, autoId, attr) {
  484. const value = e.target.value
  485. console.log(value)
  486. if (value !== 0 && !value) {
  487. return
  488. }
  489. const data = [...this.data]
  490. const target = data.find(item => item.autoId === autoId)
  491. if (this.outFlag === 1 && value > target.storeNum) {
  492. this.$message.error('领用数量不能大于库存数量')
  493. target[attr] = 1
  494. return
  495. }
  496. console.log('target: ' + target)
  497. if (target) {
  498. target[attr] = value
  499. this.data = data
  500. }
  501. },
  502. onTotalPriceChange (e, id, attr) {
  503. const value = e.target.value
  504. console.log(value)
  505. if (value !== 0 && !value) {
  506. return
  507. }
  508. const data = [...this.data]
  509. const target = data.find(item => item.id === id)
  510. console.log('target: ' + target)
  511. if (target) {
  512. target[attr] = value
  513. this.data = data
  514. }
  515. }
  516. }
  517. }
  518. </script>