purchase-add-or-update.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <!-- 采购新增/修改 -->
  2. <template>
  3. <div>
  4. <div class="my-title">{{ !id ? '新增': display ? '详情' : '修改' }}</div>
  5. <!-- 工作流 -->
  6. <div v-show="display && 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" :disabled="display">
  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. v-if="!display"
  119. fixed="right"
  120. header-align="center"
  121. align="center"
  122. width="150"
  123. label="操作">
  124. <template slot-scope="scope">
  125. <el-button type="text" size="small" @click="addMaterialHandle(scope.row, false)">编辑</el-button>
  126. <el-button style="color: red" type="text" size="small" @click="deleteMaterialHandle(scope.row.detailId)">删除</el-button>
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. </el-row>
  131. <el-row v-if="!display" style="text-align: center; margin-top: 10px;">
  132. <el-button type="primary" icon="el-icon-plus" @click="addMaterial"></el-button>
  133. </el-row>
  134. </el-form>
  135. <span slot="footer" class="dialog-footer">
  136. <el-button @click="onChose">取消</el-button>
  137. <el-button v-if="!display" type="primary" @click="dataFormSubmit()">确定</el-button>
  138. </span>
  139. <!-- 新增物品 -->
  140. <Add v-show="addMaterialVisible" ref="comAddMaterial" @addItem="addMaterialCallback"/>
  141. </div>
  142. </template>
  143. <script>
  144. import Add from './add-material'
  145. import { getDictList } from '@/api/dict'
  146. import { getPurchaseDetail } from '@/api/sale'
  147. import { dealStepData, dealStepLogs } from '@/api/util'
  148. import UserComponent from '../common/user-component'
  149. export default {
  150. name: 'purchase-add-or-update',
  151. components: {
  152. UserComponent,
  153. Add
  154. },
  155. data () {
  156. return {
  157. visible: false,
  158. display: false,
  159. dataList: [],
  160. id: 0,
  161. dataForm: {},
  162. optionsType: [],
  163. materialDetails: [],
  164. addMaterialVisible: false,
  165. dataRule: {
  166. purchaseType: [{ required: true, message: '请选择采购类别', trigger: 'change' }],
  167. applierId: [{ required: true, message: '请选择申请人', trigger: 'change' }]
  168. },
  169. stepList: [],
  170. logList: []
  171. }
  172. },
  173. methods: {
  174. onChose () {
  175. this.$emit('onChose')
  176. },
  177. // 获取采购类别字典
  178. getTypeList () {
  179. getDictList({type: 'purchase_type'}).then(({data}) => {
  180. if (data) {
  181. this.optionsType = data
  182. }
  183. })
  184. },
  185. async init (id, display) {
  186. this.materialDetails = []
  187. this.dataForm = {
  188. payType: '0'
  189. }
  190. this.visible = true
  191. this.id = id || 0
  192. this.display = display
  193. // 获取采购类别字典
  194. if (!id || !display) {
  195. this.getTypeList()
  196. }
  197. if (!id) return
  198. await getPurchaseDetail(this.id).then(({data}) => {
  199. if (data && data.code === '200') {
  200. this.dataForm = data.data
  201. // 流程图展示
  202. if (data.data.workFlowBusinessExt) {
  203. dealStepData(data.data.workFlowBusinessExt.workFlowProcessStepList, this.stepList)
  204. dealStepLogs(data.data.workFlowBusinessExt.processLogList, this.logList)
  205. }
  206. // 获取采购物品明细
  207. if (data.data.purchaseDetails) {
  208. this.materialDetails = data.data.purchaseDetails
  209. if (this.materialDetails && this.materialDetails.length > 0) {
  210. this.materialDetails.forEach((item) => {
  211. item.detailId = Math.round(Math.random() * 1000000)
  212. })
  213. }
  214. }
  215. }
  216. })
  217. },
  218. validateField (type) {
  219. this.$refs.dataForm.validateField(type)
  220. },
  221. // 表单提交
  222. dataFormSubmit () {
  223. this.$refs['dataForm'].validate((valid) => {
  224. if (valid) {
  225. // 添加采购物品明细
  226. this.dataForm.purchaseDetails = this.materialDetails
  227. this.$http({
  228. url: this.$http.adornUrl(`/biz-service/purchaseDetail/${!this.id ? 'save' : 'update'}`),
  229. method: 'post',
  230. data: this.$http.adornData({...this.dataForm, applierId: this.$store.state.user.id, orgId: this.$store.state.user.orgId})
  231. }).then(({data}) => {
  232. if (data && data.code === '200') {
  233. this.$message({
  234. message: '操作成功',
  235. type: 'success',
  236. duration: 1500,
  237. onClose: () => {
  238. this.onChose()
  239. this.$emit('refreshDataList')
  240. }
  241. })
  242. } else {
  243. this.$message.error(data.msg)
  244. }
  245. })
  246. }
  247. })
  248. },
  249. addMaterial () {
  250. this.addMaterialVisible = true
  251. this.$nextTick(() => {
  252. this.$refs.comAddMaterial.init(null, null, null, this.optionsType)
  253. })
  254. },
  255. addMaterialHandle (row, disable) {
  256. this.addMaterialVisible = true
  257. this.$nextTick(() => {
  258. this.$refs.comAddMaterial.init(row.detailId, disable, row, this.optionsType)
  259. })
  260. },
  261. deleteMaterialHandle (detailId) {
  262. this.materialDetails.splice(this.materialDetails.findIndex((item) => item.detailId === detailId))
  263. this.calTotal()
  264. },
  265. addMaterialCallback (data) {
  266. if (!data) return
  267. this.addMaterialVisible = false
  268. let i = this.materialDetails.findIndex((item) => item.detailId === data.detailId)
  269. if (i > -1) {
  270. this.materialDetails.splice(i)
  271. }
  272. this.materialDetails.push(data)
  273. this.calTotal()
  274. },
  275. // 百分比
  276. formatPercent (row) {
  277. if (!row.taxRate) return ''
  278. let str = (Number(row.taxRate * 100)).toFixed(0)
  279. str += '%'
  280. return str
  281. },
  282. // 采购类型
  283. formatType (row) {
  284. if (!row.purchaseType || !this.optionsType) return ''
  285. const item1 = this.optionsType.find((item) => item.code === row.purchaseType.toString())
  286. return item1 ? item1.value : ''
  287. }
  288. }
  289. }
  290. </script>
  291. <style scoped>
  292. </style>