BaseForm.vue 15 KB

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