purchase-add-or-update.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <!-- 采购新增/修改 -->
  2. <template>
  3. <div>
  4. <div class="my-title">{{ !id ? '新增': '修改' }}</div>
  5. <!-- 工作流 -->
  6. <div v-show="dataForm.workFlowBusinessExt">
  7. <el-steps :active="dataForm.workFlowBusinessExt&&dataForm.workFlowBusinessExt.workFlowProcessStepList?dataForm.workFlowBusinessExt.workFlowProcessStepList.length + 2:0" align-center style="margin-bottom: 20px">
  8. <template v-for="(item, i) in stepList">
  9. <el-step :icon="item.icon" :title="item.title" :description="item.description"></el-step>
  10. </template>
  11. </el-steps>
  12. <el-collapse style="margin-bottom: 20px">
  13. <el-collapse-item>
  14. <template slot="title">
  15. <span style="color: red">审批日志(展开查看更多):</span>
  16. </template>
  17. <template v-for="(item, i) in logList">
  18. <div>{{++i}}:{{item.approverName}} {{item.createTime}} {{item.approvalValue}}</div>
  19. </template>
  20. </el-collapse-item>
  21. </el-collapse>
  22. </div>
  23. <!-- 表单 -->
  24. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  25. <el-row class="my-row">
  26. <el-col :span="8">
  27. <el-form-item label="采购编码" prop="procurementCode">
  28. <el-input v-model="dataForm.procurementCode" :disabled="true" placeholder="系统自动生成,无需填写"></el-input>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="16" style="padding-left: 20px">
  32. <el-form-item label="付款方式" prop="payType">
  33. <el-radio-group v-model="dataForm.payType">
  34. <el-radio :label='"0"'>对公转账</el-radio>
  35. <el-radio :label='"1"'>先行垫付</el-radio>
  36. <el-radio :label='"2"'>财务预支</el-radio>
  37. </el-radio-group>
  38. </el-form-item>
  39. </el-col>
  40. </el-row>
  41. <div class="title"><span style="color: red">*</span> 采购物品明细</div>
  42. <el-row>
  43. <el-table
  44. :data="materialDetails"
  45. border
  46. style="width: 100%;">
  47. <el-table-column
  48. label="序号"
  49. type="index"
  50. width="50"
  51. align="center">
  52. </el-table-column>
  53. <el-table-column
  54. prop="detailId"
  55. label="ID"
  56. v-if="false">
  57. </el-table-column>
  58. <el-table-column
  59. prop="materialName"
  60. header-align="center"
  61. align="center"
  62. min-width="120"
  63. :show-tooltip-when-overflow="true"
  64. label="物品名称">
  65. </el-table-column>
  66. <el-table-column
  67. prop="specification"
  68. header-align="center"
  69. align="center"
  70. min-width="120"
  71. :show-tooltip-when-overflow="true"
  72. label="型号及规格">
  73. </el-table-column>
  74. <el-table-column
  75. prop="purchaseType"
  76. header-align="center"
  77. align="center"
  78. :formatter="formatType"
  79. label="采购类别">
  80. </el-table-column>
  81. <el-table-column
  82. prop="cnt"
  83. header-align="center"
  84. align="center"
  85. label="数量">
  86. </el-table-column>
  87. <el-table-column
  88. prop="unitName"
  89. header-align="center"
  90. align="center"
  91. label="单位">
  92. </el-table-column>
  93. <el-table-column
  94. prop="deadline"
  95. header-align="center"
  96. align="center"
  97. min-width="160"
  98. :show-tooltip-when-overflow="true"
  99. label="采购期限">
  100. </el-table-column>
  101. <el-table-column
  102. prop="batchNumber"
  103. header-align="center"
  104. align="center"
  105. min-width="140"
  106. :show-tooltip-when-overflow="true"
  107. label="批次号/用途">
  108. </el-table-column>
  109. <el-table-column
  110. prop="notes"
  111. header-align="center"
  112. align="center"
  113. min-width="160"
  114. :show-tooltip-when-overflow="true"
  115. label="备注">
  116. </el-table-column>
  117. <el-table-column
  118. fixed="right"
  119. header-align="center"
  120. align="center"
  121. width="150"
  122. label="操作">
  123. <template slot-scope="scope">
  124. <el-button type="text" size="small" @click="addMaterialHandle(scope.row, false)">编辑</el-button>
  125. <el-button style="color: red" type="text" size="small" @click="deleteMaterialHandle(scope.row.detailId)">删除</el-button>
  126. </template>
  127. </el-table-column>
  128. </el-table>
  129. </el-row>
  130. <el-row style="text-align: center; margin-top: 10px;">
  131. <el-button type="primary" icon="el-icon-plus" @click="addMaterial"></el-button>
  132. </el-row>
  133. </el-form>
  134. <span slot="footer" class="dialog-footer">
  135. <el-button @click="onChose">取消</el-button>
  136. <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  137. </span>
  138. <!-- 新增物品 -->
  139. <Add v-show="addMaterialVisible" ref="comAddMaterial" :options-type="optionsType" @addItem="addMaterialCallback"/>
  140. </div>
  141. </template>
  142. <script>
  143. import Add from './add-material'
  144. import {getOutsourceDetailByScheduleId, getPurchaseDetail} from '@/api/sale'
  145. import { dealStepData, dealStepLogs } from '@/api/util'
  146. import UserComponent from '../common/user-component'
  147. import {getDictList} from '@/api/dict'
  148. export default {
  149. name: 'purchase-add-or-update',
  150. props: {
  151. optionsType: {
  152. type: Array,
  153. default: () => []
  154. }
  155. },
  156. components: {
  157. UserComponent,
  158. Add
  159. },
  160. data () {
  161. return {
  162. visible: false,
  163. dataList: [],
  164. thisOptionsType: this.optionsType,
  165. id: 0,
  166. dataForm: {},
  167. materialDetails: [],
  168. addMaterialVisible: false,
  169. dataRule: {
  170. purchaseType: [{ required: true, message: '请选择采购类别', trigger: 'change' }],
  171. applierId: [{ required: true, message: '请选择申请人', trigger: 'change' }]
  172. },
  173. stepList: [],
  174. logList: [],
  175. totalAmount: 0,
  176. prodProductionIds: [] // 排产ID的集合
  177. }
  178. },
  179. methods: {
  180. onChose () {
  181. this.$emit('onChose')
  182. },
  183. async init (id, scheduleIds, tableId) {
  184. if (scheduleIds) {
  185. this.prodProductionIds = scheduleIds
  186. }
  187. this.materialDetails = []
  188. this.dataForm = {
  189. payType: '0'
  190. }
  191. this.visible = true
  192. this.id = id || 0
  193. if (tableId) {
  194. this.dataForm.tableId = tableId
  195. this.dataForm.type = 1
  196. } else {
  197. // 来源:0:自己/1:排产
  198. this.dataForm.type = 0
  199. }
  200. // 获取采购类别字典
  201. if (!id) {
  202. this.getTypeList()
  203. }
  204. if (!id && !tableId) return
  205. if (this.prodProductionIds.length > 0) {
  206. await getOutsourceDetailByScheduleId({'prodProductionIds': this.prodProductionIds}).then(({data}) => {
  207. if (data && data.code === '200' && data.data) {
  208. this.materialDetails = data.data
  209. if (this.materialDetails && this.materialDetails.length > 0) {
  210. this.materialDetails.forEach((item) => {
  211. item.detailId = Math.round(Math.random() * 1000000)
  212. })
  213. this.calTotal()
  214. }
  215. }
  216. })
  217. } else {
  218. await getPurchaseDetail(this.id).then(({data}) => {
  219. if (data && data.code === '200') {
  220. this.dataForm = data.data
  221. // 流程图展示
  222. if (data.data.workFlowBusinessExt) {
  223. dealStepData(data.data.workFlowBusinessExt.workFlowProcessStepList, this.stepList)
  224. dealStepLogs(data.data.workFlowBusinessExt.processLogList, this.logList)
  225. }
  226. // 获取采购物品明细
  227. if (data.data.purchaseDetails) {
  228. this.materialDetails = data.data.purchaseDetails
  229. if (this.materialDetails && this.materialDetails.length > 0) {
  230. this.materialDetails.forEach((item) => {
  231. item.detailId = Math.round(Math.random() * 1000000)
  232. })
  233. }
  234. }
  235. }
  236. })
  237. }
  238. },
  239. validateField (type) {
  240. this.$refs.dataForm.validateField(type)
  241. },
  242. // 表单提交
  243. dataFormSubmit () {
  244. this.$refs['dataForm'].validate((valid) => {
  245. if (valid) {
  246. // 添加采购物品明细
  247. this.dataForm.purchaseDetails = this.materialDetails
  248. this.dataForm.type = 0 // 来源:0:自己/1:排产
  249. this.$http({
  250. url: this.$http.adornUrl(`/biz-service/purchaseDetail/${!this.id ? 'save' : 'update'}`),
  251. method: 'post',
  252. data: this.$http.adornData({...this.dataForm, applierId: this.$store.state.user.id, orgId: this.$store.state.user.orgId})
  253. }).then(({data}) => {
  254. if (data && data.code === '200') {
  255. this.$message({
  256. message: '操作成功',
  257. type: 'success',
  258. duration: 1500,
  259. onClose: () => {
  260. this.onChose()
  261. this.$emit('refreshDataList')
  262. }
  263. })
  264. } else {
  265. this.$message.error(data.msg)
  266. }
  267. })
  268. }
  269. })
  270. },
  271. addMaterial () {
  272. this.addMaterialVisible = true
  273. this.$nextTick(() => {
  274. this.$refs.comAddMaterial.init(null, null, null)
  275. })
  276. },
  277. addMaterialHandle (row, disable) {
  278. this.addMaterialVisible = true
  279. this.$nextTick(() => {
  280. this.$refs.comAddMaterial.init(row.detailId, disable, row)
  281. })
  282. },
  283. deleteMaterialHandle (detailId) {
  284. this.materialDetails.splice(this.materialDetails.findIndex((item) => item.detailId === detailId), 1)
  285. // this.calTotal()
  286. },
  287. addMaterialCallback (data) {
  288. if (!data) return
  289. this.addMaterialVisible = false
  290. let i = this.materialDetails.findIndex((item) => item.detailId === data.detailId)
  291. if (i > -1) {
  292. this.materialDetails.splice(i, 1)
  293. }
  294. this.materialDetails.push(data)
  295. // this.calTotal()
  296. },
  297. // 百分比
  298. formatPercent (row) {
  299. if (!row.taxRate) return ''
  300. let str = (Number(row.taxRate * 100)).toFixed(0)
  301. str += '%'
  302. return str
  303. },
  304. // 采购类型
  305. formatType (row) {
  306. if (!row.purchaseType || !this.thisOptionsType) return ''
  307. const item1 = this.thisOptionsType.find((item) => item.code === row.purchaseType.toString())
  308. return item1 ? item1.value : ''
  309. },
  310. // 获取采购类别字典
  311. getTypeList () {
  312. getDictList({type: 'purchase_type'}).then(({data}) => {
  313. if (data) {
  314. this.thisOptionsType = data
  315. }
  316. })
  317. },
  318. calTotal () {
  319. let total = 0
  320. if (this.materialDetails) {
  321. this.materialDetails.forEach((item) => {
  322. total += item.taxAmount ? Number(item.taxAmount) : 0
  323. })
  324. }
  325. this.totalAmount = total
  326. }
  327. }
  328. }
  329. </script>
  330. <style scoped>
  331. </style>