MergeModal.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="1200"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-form :form="form">
  10. <row-list :col="1" v-show="false">
  11. <row-item>
  12. <a-form-item>
  13. <a-input v-decorator="['id']" type="hidden"/>
  14. </a-form-item>
  15. </row-item>
  16. </row-list>
  17. <row-list :col="1">
  18. <row-item>
  19. <a-form-item
  20. label="合并采购单名称"
  21. :labelCol="BaseTool.Constant.labelCol2"
  22. :wrapperCol="BaseTool.Constant.wrapperCol2">
  23. <a-input v-decorator="['title',{rules: [{required: true, message: '合并采购单名称不能为空'}]}]" />
  24. </a-form-item>
  25. </row-item>
  26. </row-list>
  27. </a-form>
  28. <a-table
  29. bordered
  30. :data-source="data"
  31. :columns="columns"
  32. tableLayout="auto"
  33. rowKey="id"
  34. :scroll="{ x: 1500 }"
  35. >
  36. <template #status="text">
  37. <badge :text="BaseTool.Object.getField(statusMap,text)" :status="DictCache.COLOR.LONG_YAN_PURCHASE_ORDER_STATUS[text]"/>
  38. </template>
  39. <span slot="action" slot-scope="record">
  40. <template>
  41. <a-popconfirm title="是否要删除该条数据?" @confirm="handleDelOne(record)">
  42. <a>删除</a>
  43. </a-popconfirm>
  44. </template>
  45. </span>
  46. </a-table>
  47. <template slot="footer">
  48. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  49. </template>
  50. </a-modal>
  51. </template>
  52. <script>
  53. import pick from 'lodash.pick'
  54. import { mergePurchase, updatamergePurchase } from '@/api/purchase/purchase-order'
  55. export default {
  56. data () {
  57. return {
  58. visible: false,
  59. title: '',
  60. form: this.$form.createForm(this),
  61. confirmLoading: false,
  62. data: [],
  63. cptcodeMap: {},
  64. cbustypeMap: {},
  65. typeMap: {},
  66. columns: [
  67. {
  68. title: '序号',
  69. dataIndex: 'index',
  70. checked: true,
  71. width: 70,
  72. customRender: (text, record, index) => {
  73. return index + 1
  74. }
  75. },
  76. {
  77. title: '计划类型',
  78. dataIndex: 'type',
  79. checked: true,
  80. width: 100,
  81. customRender: (text, record, index) => {
  82. return this.BaseTool.Table.getMapText(this.typeMap, text)
  83. }
  84. },
  85. {
  86. title: '采购类型',
  87. dataIndex: 'cptcode',
  88. checked: true,
  89. width: 130,
  90. customRender: (text, record, index) => {
  91. return this.BaseTool.Table.getMapText(this.cptcodeMap, text)
  92. }
  93. },
  94. {
  95. title: '业务类型',
  96. dataIndex: 'cbustype',
  97. checked: true,
  98. width: 150,
  99. customRender: (text, record, index) => {
  100. return this.BaseTool.Table.getMapText(this.cbustypeMap, text)
  101. }
  102. },
  103. {
  104. title: '关联设备',
  105. dataIndex: 'positionNo',
  106. checked: true,
  107. width: 150
  108. },
  109. {
  110. title: '采购数量',
  111. dataIndex: 'totalNum',
  112. checked: true,
  113. width: 150
  114. },
  115. {
  116. title: '请购人员',
  117. dataIndex: 'createdUserName',
  118. checked: true,
  119. width: 150
  120. },
  121. {
  122. title: '用友单号',
  123. checked: true,
  124. width: 100,
  125. dataIndex: 'yongYouId'
  126. },
  127. {
  128. title: '需求日期',
  129. dataIndex: 'needDate',
  130. checked: true,
  131. width: 150
  132. },
  133. {
  134. title: '计划到货日期',
  135. dataIndex: 'planGetDate',
  136. checked: true,
  137. width: 150
  138. },
  139. {
  140. title: '申请时间',
  141. dataIndex: 'updateTime',
  142. checked: true,
  143. width: 150
  144. },
  145. {
  146. title: '请购原因',
  147. checked: true,
  148. width: 100,
  149. dataIndex: 'cmemo'
  150. },
  151. {
  152. title: '错误消息',
  153. checked: true,
  154. width: 100,
  155. dataIndex: 'errorMessage'
  156. },
  157. {
  158. title: '操作',
  159. key: 'action',
  160. width: '200px',
  161. fixed: 'right',
  162. checked: true,
  163. align: 'center',
  164. scopedSlots: { customRender: 'action' }
  165. }
  166. ]
  167. }
  168. },
  169. created () {
  170. // 下拉框map
  171. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.LONG_YAN_PURCHASE_TYPE)
  172. this.cptcodeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.LONG_YAN_PURCHASE_ORDER_PLAN_TYPE)
  173. this.cbustypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.LONG_YAN_PURCHASE_BUSINESS_TYPE)
  174. },
  175. methods: {
  176. base (record, list = []) {
  177. this.visible = true
  178. this.data = list
  179. if (this.BaseTool.Object.isBlank(record)) {
  180. this.title = '新增合并采购单'
  181. return
  182. }
  183. this.title = '编辑合并采购单'
  184. // this.data = record.detailVOS
  185. const { form: { setFieldsValue } } = this
  186. this.$nextTick(() => {
  187. setFieldsValue(Object.assign(pick(record, [
  188. 'id'
  189. ])))
  190. })
  191. },
  192. save () {
  193. const { form: { validateFieldsAndScroll } } = this
  194. this.confirmLoading = true
  195. validateFieldsAndScroll((errors, values) => {
  196. if (errors) {
  197. Object.values(errors).map(item => {
  198. this.$message.error(item.errors[0].message)
  199. })
  200. this.confirmLoading = false
  201. return
  202. }
  203. values.purchaseOrderStr = this.data.map(item => {
  204. return pick(item, [
  205. 'id',
  206. 'sbId',
  207. 'type',
  208. 'oldOrNew',
  209. 'projectId',
  210. 'positionNo',
  211. 'cptcode',
  212. 'remark',
  213. 'cdepcode',
  214. 'cbustype',
  215. 'planGetDate',
  216. 'needDate'
  217. ])
  218. })
  219. if (values.id) {
  220. updatamergePurchase(values).then(res => {
  221. this.$message.success('修改成功!')
  222. this.handleCancel()
  223. }).catch(() => {
  224. this.confirmLoading = false
  225. })
  226. } else {
  227. mergePurchase(values.title, { purchaseOrderStr: values.purchaseOrderStr }).then(res => {
  228. this.$message.success('创建成功!')
  229. this.handleCancel()
  230. }).catch(() => {
  231. this.confirmLoading = false
  232. })
  233. }
  234. })
  235. },
  236. handleDelOne (record) {
  237. const data = [...this.data]
  238. this.data = data.filter(item => record.id !== item.id)
  239. },
  240. handleCancel (values) {
  241. this.visible = false
  242. this.confirmLoading = false
  243. this.data = []
  244. this.form.resetFields()
  245. this.$emit('ok', values)
  246. }
  247. }
  248. }
  249. </script>
  250. <style>
  251. </style>