BaseFormYY.vue 15 KB

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