contract-record-add-or-update.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <div>
  3. <div class="my-title">{{ !id?'新增':'修改' }}</div>
  4. <!-- 表单 -->
  5. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  6. <el-row class="my-row">
  7. <el-col :span="8">
  8. <el-form-item label="合同编码" prop="contractCode">
  9. <el-input v-model="dataForm.contractCode" disabled placeholder="合同编码由系统生成"></el-input>
  10. </el-form-item>
  11. </el-col>
  12. <el-col :span="8">
  13. <el-form-item label="合同评审编码" prop="reCode">
  14. <el-select
  15. v-model="dataForm.reCode"
  16. remote
  17. placeholder="请选择">
  18. <el-option
  19. v-for="item in optionsReCode"
  20. :key="item.reCode"
  21. :label="item.customerName + ' (' + item.reCode + ' )'"
  22. :value="item.reCode">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="8">
  28. <el-form-item label="合同号" prop="contractNumber">
  29. <el-input v-model="dataForm.contractNumber" placeholder="合同号"></el-input>
  30. </el-form-item>
  31. </el-col>
  32. </el-row>
  33. <el-row class="my-row">
  34. <el-col :span="8">
  35. <el-form-item label="项目名称" prop="projectName">
  36. <el-input v-model="dataForm.projectName"></el-input>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8">
  40. <el-form-item label="合同交期" prop="deliveryTime">
  41. <el-date-picker
  42. v-model="dataForm.deliveryTime"
  43. value-format="yyyy-MM-dd"
  44. type="date">
  45. </el-date-picker>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="8">
  49. <el-form-item label="实际交付日期" prop="actualDeliveryTime">
  50. <el-input v-model="dataForm.actualDeliveryTime" disabled></el-input>
  51. </el-form-item>
  52. </el-col>
  53. </el-row>
  54. <el-row class="my-row" style="margin-top: 20px">
  55. <el-form-item label="备注" prop="notes">
  56. <el-input type="textarea" v-model="dataForm.notes"></el-input>
  57. </el-form-item>
  58. </el-row>
  59. <el-row v-if="isProductListVisible">
  60. <div class="title"><span style="color: red">*</span> 物料列表</div>
  61. <el-table
  62. :data="productList"
  63. border
  64. style="width: 100%;">
  65. <el-table-column
  66. label="序号"
  67. type="index"
  68. width="50"
  69. align="center">
  70. </el-table-column>
  71. <el-table-column
  72. prop="mapNumber"
  73. header-align="center"
  74. align="center"
  75. min-width="120"
  76. :show-tooltip-when-overflow="true"
  77. label="图号">
  78. </el-table-column>
  79. <el-table-column
  80. prop="productName"
  81. header-align="center"
  82. align="center"
  83. min-width="120"
  84. :show-tooltip-when-overflow="true"
  85. label="物料名称">
  86. </el-table-column>
  87. <el-table-column
  88. prop="productSpecifications"
  89. header-align="center"
  90. align="center"
  91. min-width="120"
  92. :show-tooltip-when-overflow="true"
  93. label="规格">
  94. </el-table-column>
  95. <el-table-column
  96. prop="cnt"
  97. header-align="center"
  98. align="center"
  99. min-width="160"
  100. label="数量">
  101. </el-table-column>
  102. <el-table-column
  103. prop="unitName"
  104. header-align="center"
  105. align="center"
  106. min-width="160"
  107. label="单位">
  108. </el-table-column>
  109. <el-table-column
  110. prop="price"
  111. header-align="center"
  112. align="center"
  113. min-width="100"
  114. label="含税单价">
  115. <template slot-scope="scope">
  116. <span>{{ scope.row.price == null ? '0' : scope.row.price }}</span>
  117. </template>
  118. </el-table-column>
  119. <el-table-column
  120. prop="amount"
  121. header-align="center"
  122. align="center"
  123. min-width="100"
  124. label="含税总价">
  125. <template slot-scope="scope">
  126. <span>{{ (scope.row.cnt*scope.row.price).toFixed(1) }}</span>
  127. </template>
  128. </el-table-column>
  129. <el-table-column
  130. prop="rate"
  131. header-align="center"
  132. align="center"
  133. min-width="120"
  134. label="税率">
  135. <template slot-scope="scope">
  136. <span>{{scope.row.rate}}</span>&nbsp;%
  137. </template>
  138. </el-table-column>
  139. <el-table-column
  140. prop="notes"
  141. header-align="center"
  142. align="center"
  143. min-width="140"
  144. :show-tooltip-when-overflow="true"
  145. label="备注">
  146. </el-table-column>
  147. <el-table-column
  148. fixed="right"
  149. header-align="center"
  150. align="center"
  151. width="150"
  152. label="操作">
  153. <template slot-scope="scope">
  154. <el-button type="text" size="small" @click="updateProductHandle(scope.row)">编辑</el-button>
  155. <el-button style="color: red" type="text" size="small" @click="deleteProductHandle(scope.row.recordId)">删除</el-button>
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <el-row style="text-align: center; margin-top: 10px;">
  160. <el-button type="primary" icon="el-icon-plus" @click="addProductHandle()"></el-button>
  161. </el-row>
  162. </el-row>
  163. <el-row class="my-row">
  164. <upload-component :display-star="false" :title="'附件'" :accept="'*'" :file-obj-list="fileList" @uploadSuccess="uploadSuccess"/>
  165. </el-row>
  166. </el-form>
  167. <span slot="footer" class="dialog-footer">
  168. <el-button @click="onChose">取消</el-button>
  169. <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  170. </span>
  171. <add-or-update v-if="productUpdateVisible" ref="productDialog" @addItem="addItem" />
  172. <!-- <add-or-update-product v-if="productUpdateVisible" ref="productDialog" @changeItem="changeItem"/>-->
  173. <!-- <template-chose v-if="inboundVisible" ref="inbound" @addItems="addItems" />-->
  174. </div>
  175. </template>
  176. <script>
  177. import UploadComponent from '../common/upload-component'
  178. import TemplateChose from '../product/template-chose'
  179. import AddOrUpdate from '../product/template-add-or-update'
  180. import { getReviewCodeList, geContractBookDetail, getCommunicationList } from '@/api/cus'
  181. export default {
  182. name: 'contract-record-add-or-update',
  183. components: {
  184. UploadComponent,
  185. TemplateChose,
  186. AddOrUpdate
  187. },
  188. computed: {
  189. orgId: {
  190. get () { return this.$store.state.user.orgId }
  191. }
  192. },
  193. watch: {
  194. 'dataForm.reCode' (value) {
  195. let d = this.optionsReCode.find(item => item.reCode === value)
  196. if (!d) return
  197. getCommunicationList(d.coId).then(({data}) => {
  198. if (data && data.code === '200') {
  199. this.isProductListVisible = true
  200. this.productList = data.data
  201. }
  202. })
  203. }
  204. },
  205. data () {
  206. return {
  207. visible: false,
  208. optionsReCode: [],
  209. fileList: [],
  210. dataList: [],
  211. isProductListVisible: false, // 物料列表是否显示
  212. productUpdateVisible: false, // 物料修改对话框是否显示
  213. inboundVisible: false, // 物料新增对话框是否显示
  214. productList: [],
  215. id: 0,
  216. dataForm: {},
  217. dataRule: {
  218. reCode: [{ required: true, message: '请选择合同评审编码', trigger: 'change' }],
  219. contractNumber: [{ required: true, message: '合同号不能为空', trigger: 'blur' }],
  220. deliveryTime: [{ required: true, message: '合同交期不能为空', trigger: 'change' }],
  221. projectName: [{ required: true, message: '项目名称不能为空', trigger: 'blur' }]
  222. }
  223. }
  224. },
  225. methods: {
  226. onChose () {
  227. this.$emit('onChose')
  228. },
  229. async init (id) {
  230. this.fileList = []
  231. this.dataForm = {}
  232. // this.optionsReCode = []
  233. this.visible = true
  234. this.id = id || 0
  235. // 获取合同评审编码列表
  236. await getReviewCodeList().then(({data}) => {
  237. if (data) {
  238. this.optionsReCode = data.data
  239. }
  240. })
  241. // 详情
  242. if (!id) return
  243. this.isProductListVisible = true
  244. await geContractBookDetail(this.id).then(({data}) => {
  245. if (data && data.code === '200') {
  246. this.dataForm = data.data
  247. // 附件
  248. if (data.data.attachList) {
  249. data.data.attachList.forEach((item) => {
  250. this.fileList.push({
  251. name: item.fileName,
  252. url: item.url,
  253. id: item.url
  254. })
  255. })
  256. }
  257. if (data.data.cusCBookProducts) {
  258. data.data.cusCBookProducts.forEach((item) => {
  259. this.addItem(item)
  260. })
  261. }
  262. }
  263. })
  264. },
  265. uploadSuccess (fileList) {
  266. this.fileList = fileList
  267. },
  268. validateField (type) {
  269. this.$refs.dataForm.validateField(type)
  270. },
  271. // 表单提交
  272. dataFormSubmit () {
  273. this.$refs['dataForm'].validate((valid) => {
  274. if (valid) {
  275. // 附件
  276. let fList = this.fileList
  277. if (fList.length > 0) {
  278. this.dataForm.attachList = []
  279. for (let i = 0; i < fList.length; i++) {
  280. this.dataForm.attachList.push({
  281. fileName: fList[i].name,
  282. url: fList[i].url
  283. })
  284. }
  285. }
  286. if (this.productList.length === 0) {
  287. this.$message.error('请选择任务单物料明细')
  288. return
  289. }
  290. this.dataForm.cusCBookProducts = this.productList
  291. // 物料明细
  292. this.$http({
  293. url: this.$http.adornUrl(`/biz-service/cusContractBook/${!this.id ? 'save' : 'update'}`),
  294. method: 'post',
  295. data: this.$http.adornData({...this.dataForm, orgId: this.orgId})
  296. }).then(({data}) => {
  297. if (data && data.code === '200') {
  298. this.$message({
  299. message: '操作成功',
  300. type: 'success',
  301. duration: 1500,
  302. onClose: () => {
  303. this.onChose()
  304. this.$emit('refreshDataList')
  305. }
  306. })
  307. } else {
  308. this.$message.error(data.msg)
  309. }
  310. })
  311. }
  312. })
  313. },
  314. // 删除物料项
  315. deleteProductHandle (recordId) {
  316. this.productList.splice(this.productList.findIndex((item) => item.recordId === recordId), 1)
  317. },
  318. // 编辑物料
  319. updateProductHandle (row) {
  320. this.productUpdateVisible = true
  321. this.$nextTick(() => {
  322. this.$refs.productDialog.init(1, row)
  323. })
  324. },
  325. // 添加物料
  326. addProductHandle () {
  327. this.productUpdateVisible = true
  328. this.$nextTick(() => {
  329. this.$refs.productDialog.init(1)
  330. })
  331. },
  332. addItem (item) {
  333. if (!item) return
  334. if (!item.recordId) {
  335. item.recordId = Math.round(Math.random() * 1000000)
  336. }
  337. if (this.productList.findIndex(item1 => item1.recordId === item.recordId) === -1) {
  338. this.productList.push({
  339. ...item
  340. })
  341. }
  342. }
  343. }
  344. }
  345. </script>
  346. <style scoped>
  347. </style>