outsource-add-or-update.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <!-- 委外新增、修改 -->
  2. <template>
  3. <div>
  4. <div class="my-title">委外</div>
  5. <!-- 表单 -->
  6. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  7. <el-row class="my-row">
  8. <el-col :span="8">
  9. <el-form-item label="委外编码" prop="purchaseCode">
  10. <el-input v-model="dataForm.purchaseCode" disabled placeholder="委外编码由系统生成"></el-input>
  11. </el-form-item>
  12. </el-col>
  13. <el-col :span="16">
  14. <el-form-item label="付款方式" prop="payType">
  15. <el-radio-group v-model="dataForm.payType">
  16. <el-radio :label='"1"'>对公转账</el-radio>
  17. <el-radio :label='"2"'>先行垫付</el-radio>
  18. <el-radio :label='"3"'>财务预支</el-radio>
  19. </el-radio-group>
  20. </el-form-item>
  21. </el-col>
  22. </el-row>
  23. <el-row class="my-row">
  24. <el-col :span="8">
  25. <el-form-item label="委外类别" prop="commissionType">
  26. <el-select
  27. v-model="dataForm.commissionType"
  28. remote
  29. placeholder="请选择">
  30. <el-option
  31. v-for="item in optionsType"
  32. :key="item.code"
  33. :label="item.value"
  34. :value="item.code">
  35. </el-option>
  36. </el-select>
  37. </el-form-item>
  38. </el-col>
  39. </el-row>
  40. <div class="title"><span style="color: red">*</span> 委外产品明细</div>
  41. <el-row class="my-row">
  42. <el-table
  43. :data="productDetails"
  44. border
  45. style="width: 100%;">
  46. <el-table-column
  47. label="序号"
  48. type="index"
  49. width="50"
  50. align="center">
  51. </el-table-column>
  52. <el-table-column
  53. prop="detailId"
  54. label="ID"
  55. v-if="false">
  56. </el-table-column>
  57. <el-table-column
  58. prop="productName"
  59. header-align="center"
  60. align="center"
  61. min-width="120"
  62. label="产品名称">
  63. </el-table-column>
  64. <el-table-column
  65. prop="prodCode"
  66. header-align="center"
  67. align="center"
  68. min-width="120"
  69. label="产品编号">
  70. </el-table-column>
  71. <el-table-column
  72. prop="productSpec"
  73. header-align="center"
  74. align="center"
  75. min-width="120"
  76. label="型号及规格">
  77. </el-table-column>
  78. <el-table-column
  79. prop="cnt"
  80. header-align="center"
  81. align="center"
  82. label="数量">
  83. </el-table-column>
  84. <el-table-column
  85. prop="unitName"
  86. header-align="center"
  87. align="center"
  88. label="单位">
  89. </el-table-column>
  90. <el-table-column
  91. prop="deadline"
  92. header-align="center"
  93. align="center"
  94. min-width="140"
  95. :show-tooltip-when-overflow="true"
  96. label="委外期限">
  97. </el-table-column>
  98. <el-table-column
  99. prop="batchNumber"
  100. header-align="center"
  101. align="center"
  102. min-width="120"
  103. :show-tooltip-when-overflow="true"
  104. label="批次号">
  105. </el-table-column>
  106. <el-table-column
  107. prop="specificationExplian"
  108. header-align="center"
  109. align="center"
  110. min-width="120"
  111. :show-tooltip-when-overflow="true"
  112. label="要求说明">
  113. </el-table-column>
  114. <el-table-column
  115. prop="arrivedTime"
  116. header-align="center"
  117. align="center"
  118. min-width="140"
  119. :show-tooltip-when-overflow="true"
  120. label="到料时间">
  121. </el-table-column>
  122. <el-table-column
  123. prop="qualifiedCnt"
  124. header-align="center"
  125. align="center"
  126. label="合格数量">
  127. </el-table-column>
  128. <el-table-column
  129. prop="technologyFile"
  130. header-align="center"
  131. align="center"
  132. min-width="160"
  133. :show-tooltip-when-overflow="true"
  134. label="工艺文件">
  135. </el-table-column>
  136. <el-table-column
  137. prop="attachList"
  138. header-align="center"
  139. align="center"
  140. label="附件">
  141. <template slot-scope="scope">
  142. <div v-for="(item, index) in scope.row.attachList" style="display: inline">
  143. <span v-if="index > 0">,</span>
  144. <a :key="item.fileName + index" type="primary" href="#" @click="previewFile(item.fileName, item.url)">{{ item.fileName }}</a>
  145. </div>
  146. </template>
  147. </el-table-column>
  148. <el-table-column
  149. prop="price"
  150. header-align="center"
  151. align="center"
  152. min-width="100"
  153. label="不含税单价">
  154. </el-table-column>
  155. <el-table-column
  156. prop="taxPrice"
  157. header-align="center"
  158. align="center"
  159. label="含税单价">
  160. </el-table-column>
  161. <el-table-column
  162. prop="taxAmount"
  163. header-align="center"
  164. align="center"
  165. label="含税总价">
  166. </el-table-column>
  167. <el-table-column
  168. prop="taxRate"
  169. header-align="center"
  170. align="center"
  171. :formatter="formatPercent"
  172. label="税率">
  173. </el-table-column>
  174. <el-table-column
  175. prop="notes"
  176. header-align="center"
  177. align="center"
  178. label="备注">
  179. </el-table-column>
  180. <el-table-column
  181. fixed="right"
  182. header-align="center"
  183. align="center"
  184. width="80"
  185. label="操作">
  186. <template slot-scope="scope">
  187. <el-button type="text" size="small" @click="addProductHandle(scope.row, false)">编辑</el-button>
  188. <!-- <el-button style="color: red" type="text" size="small" @click="deleteProductHandle(scope.row.detailId)">删除</el-button>-->
  189. </template>
  190. </el-table-column>
  191. </el-table>
  192. </el-row>
  193. <el-row style="margin-top: 20px">
  194. <span>合计(含税): {{totalAmount}}</span>
  195. </el-row>
  196. <!-- <el-row style="text-align: center; margin-top: 10px;">-->
  197. <!-- <el-button type="primary" icon="el-icon-plus" @click="addMaterial"></el-button>-->
  198. <!-- </el-row>-->
  199. </el-form>
  200. <span slot="footer" class="dialog-footer">
  201. <el-button @click="onChose">取消</el-button>
  202. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  203. </span>
  204. <!-- 新增物品 -->
  205. <Add v-show="addProductVisible" ref="comAddProduct" @addItem="addProductCallback"/>
  206. <!-- 文件预览 -->
  207. <preview-component v-if="previewVisible" ref="preview"/>
  208. </div>
  209. </template>
  210. <script>
  211. import { getOutsourceDetail, getOutsourceDetailByScheduleId } from '@/api/sale'
  212. import { getDictList } from '@/api/dict'
  213. import Add from './add-product'
  214. import ApproveComponent from '../common/approve-component'
  215. import PreviewComponent from '../common/preview-component'
  216. export default {
  217. name: 'outsource-add-or-update',
  218. components: {
  219. PreviewComponent,
  220. ApproveComponent,
  221. Add
  222. },
  223. data () {
  224. return {
  225. id: 0,
  226. dataForm: {},
  227. dataRule: {
  228. payType: [{ required: true, message: '请选择付款方式', trigger: 'change' }],
  229. commissionType: [{ required: true, message: '请选择委外类别', trigger: 'change' }]
  230. },
  231. optionsType: [],
  232. totalAmount: 0,
  233. addProductVisible: false,
  234. productDetails: [],
  235. prodProductionIds: [], // 排产ID的集合
  236. previewVisible: false
  237. }
  238. },
  239. methods: {
  240. onChose () {
  241. this.$emit('onChose')
  242. },
  243. async init (id, prodProductionIds) {
  244. if (prodProductionIds) {
  245. this.prodProductionIds = prodProductionIds
  246. }
  247. this.productDetails = []
  248. this.dataForm = {
  249. payType: '1'
  250. }
  251. this.id = id || 0
  252. // 获取委外类别列表
  253. this.getType()
  254. // 详情
  255. if (!id) return
  256. if (this.prodProductionIds.length > 0) {
  257. await getOutsourceDetailByScheduleId({'prodProductionIds': this.prodProductionIds}).then(({data}) => {
  258. if (data && data.code === '200' && data.data) {
  259. this.productDetails = data.data
  260. if (this.productDetails && this.productDetails.length > 0) {
  261. this.productDetails.forEach((item) => {
  262. item.detailId = Math.round(Math.random() * 1000000)
  263. })
  264. this.calTotal()
  265. }
  266. }
  267. })
  268. } else {
  269. await getOutsourceDetail(this.id).then(({data}) => {
  270. if (data && data.code === '200' && data.data) {
  271. this.dataForm = data.data
  272. this.productDetails = data.data.purCommissionDetails
  273. if (this.productDetails && this.productDetails.length > 0) {
  274. this.productDetails.forEach((item) => {
  275. item.detailId = Math.round(Math.random() * 1000000)
  276. })
  277. this.calTotal()
  278. }
  279. }
  280. })
  281. }
  282. },
  283. // 获取类别
  284. getType () {
  285. getDictList({type: 'commission_type'}).then(({data}) => {
  286. if (data) {
  287. this.optionsType = data
  288. }
  289. })
  290. },
  291. validateField (type) {
  292. this.$refs.dataForm.validateField(type)
  293. },
  294. // 表单提交
  295. dataFormSubmit () {
  296. this.$refs['dataForm'].validate((valid) => {
  297. if (valid) {
  298. let action = ''
  299. if (this.prodProductionIds.length > 0) {
  300. action = `/biz-service/purCommDetail/save`
  301. } else {
  302. action = `/biz-service/purCommDetail/${!this.id ? 'save' : 'update'}`
  303. }
  304. // 产品明细
  305. this.$http({
  306. url: this.$http.adornUrl(action),
  307. method: 'post',
  308. data: this.$http.adornData({
  309. ...this.dataForm,
  310. purCommissionDetails: this.productDetails,
  311. applierId: this.$store.state.user.id,
  312. orgId: this.$store.state.user.orgId
  313. })
  314. }).then(({data}) => {
  315. if (data && data.code === '200') {
  316. this.$message({
  317. message: '操作成功',
  318. type: 'success',
  319. duration: 1500,
  320. onClose: () => {
  321. this.onChose()
  322. this.$emit('refreshDataList')
  323. }
  324. })
  325. } else {
  326. this.$message.error(data.msg)
  327. }
  328. })
  329. }
  330. })
  331. },
  332. addMaterial () {
  333. this.addProductVisible = true
  334. this.$nextTick(() => {
  335. this.$refs.comAddProduct.init()
  336. })
  337. },
  338. addProductHandle (row, disable) {
  339. this.addProductVisible = true
  340. this.$nextTick(() => {
  341. this.$refs.comAddProduct.init(row.detailId, disable, row)
  342. })
  343. },
  344. deleteProductHandle (detailId) {
  345. if (!detailId) return
  346. this.productDetails.splice(this.productDetails.findIndex((item) => item.detailId === detailId))
  347. this.calTotal()
  348. },
  349. addProductCallback (data) {
  350. if (!data) return
  351. this.addProductVisible = false
  352. let i = this.productDetails.findIndex((item) => item.detailId === data.detailId)
  353. if (i > -1) {
  354. this.productDetails.splice(i)
  355. }
  356. this.productDetails.push(data)
  357. this.calTotal()
  358. },
  359. calTotal () {
  360. let total = 0
  361. if (this.productDetails) {
  362. this.productDetails.forEach((item) => {
  363. total += item.taxAmount ? Number(item.taxAmount) : 0
  364. })
  365. }
  366. this.totalAmount = total
  367. },
  368. // 百分比
  369. formatPercent (row) {
  370. if (!row.taxRate) return ''
  371. let str = (Number(row.taxRate * 100)).toFixed(0)
  372. str += '%'
  373. return str
  374. },
  375. // 预览
  376. previewFile (fileName, url) {
  377. this.previewVisible = true
  378. this.$nextTick(() => {
  379. this.$refs.preview.init(fileName, url)
  380. })
  381. }
  382. }
  383. }
  384. </script>
  385. <style scoped>
  386. </style>