purchase-invoice-add-or-update.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <div>
  3. <div class="my-title">{{ !id ? '新增': formDisable ? '详情' : '修改' }}</div>
  4. <div style="margin-top: 20px"></div>
  5. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" :disabled="formDisable" label-width="auto">
  6. <el-row class="my-row">
  7. <el-col :span="8">
  8. <el-form-item label="采购发票编码" prop="code">
  9. <el-input v-model="dataForm.code" :disabled="true" placeholder="系统自动生成"></el-input>
  10. </el-form-item>
  11. </el-col>
  12. <el-col :span="8" >
  13. <el-form-item label="发票类型" prop="type">
  14. <el-select v-model="dataForm.type" filterable placeholder="请选择">
  15. <el-option
  16. v-for="item in typeState"
  17. :key="item.code"
  18. :label="item.value"
  19. :value="item.code">
  20. </el-option>
  21. </el-select>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="8" >
  25. <el-form-item label="发票类别代码" prop="typeCode">
  26. <el-input v-model="dataForm.typeCode" placeholder=""></el-input>
  27. </el-form-item>
  28. </el-col>
  29. </el-row>
  30. <el-row class="my-row">
  31. <el-col :span="8">
  32. <el-form-item label="发票号" prop="invoiceNumber">
  33. <el-input v-model="dataForm.invoiceNumber" placeholder=""></el-input>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="8">
  37. <el-form-item label="开票电话" prop="phone">
  38. <el-input v-model="dataForm.phone" placeholder=""></el-input>
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="8" >
  42. <el-form-item label="发票金额" prop="invoiceAmount">
  43. <el-input v-model="dataForm.invoiceAmount" placeholder=""></el-input>
  44. </el-form-item>
  45. </el-col>
  46. </el-row>
  47. <el-row class="my-row">
  48. <el-col :span="8" >
  49. <el-form-item label="币种" prop="currency">
  50. <el-select v-model="dataForm.currency" filterable placeholder="请选择">
  51. <el-option
  52. v-for="item in currencyType"
  53. :key="item.code"
  54. :label="item.value"
  55. :value="item.code">
  56. </el-option>
  57. </el-select>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="8">
  61. <el-form-item label="供应商" prop="supplierId">
  62. <el-select
  63. v-model="dataForm.supplierId"
  64. remote
  65. @change="cusChange"
  66. clearable
  67. placeholder="请选择">
  68. <el-option
  69. v-for="item in optionsCus"
  70. :key="item.supplierId"
  71. :label="item.supplierName"
  72. :value="item.supplierId">
  73. </el-option>
  74. </el-select>
  75. </el-form-item>
  76. </el-col>
  77. </el-row>
  78. <el-row class="my-row">
  79. <el-col :span="15">
  80. <el-form-item label="备注说明" prop="notes">
  81. <el-input type="textarea"
  82. v-model="dataForm.notes"
  83. :rows="4"
  84. maxlength="300"
  85. show-word-limit
  86. placeholder="备注说明"></el-input>
  87. </el-form-item>
  88. </el-col>
  89. </el-row>
  90. <el-row class="my-row">
  91. <upload-component :title="'附件'" :accept="'*'" :file-obj-list="fileList" @uploadSuccess="uploadSuccess"/>
  92. </el-row>
  93. <div v-loading="supplierLoading">
  94. <h4>客户信息</h4>
  95. <el-row class="my-row">
  96. <el-col :span="8">
  97. <el-form-item label="发票抬头" prop="invoiceTitle">
  98. <el-input v-model="dataForm.invoiceTitle" :value="supplierInfo.invoiceTitle" disabled></el-input>
  99. </el-form-item>
  100. </el-col>
  101. <el-col :span="8">
  102. <el-form-item label="企业税号" prop="taxNumber">
  103. <el-input v-model="dataForm.taxNumber" :value="supplierInfo.taxNumber" disabled></el-input>
  104. </el-form-item>
  105. </el-col>
  106. <el-col :span="8">
  107. <el-form-item label="开户银行" prop="bank">
  108. <el-input v-model="dataForm.bank" :value="supplierInfo.bank" disabled></el-input>
  109. </el-form-item>
  110. </el-col>
  111. </el-row>
  112. <el-row class="my-row">
  113. <el-col :span="8">
  114. <el-form-item label="银行账号" prop="account">
  115. <el-input v-model="dataForm.account" :value="supplierInfo.account" disabled></el-input>
  116. </el-form-item>
  117. </el-col>
  118. <el-col :span="8">
  119. <el-form-item label="电话" prop="tel">
  120. <el-input v-model="dataForm.tel" :value="supplierInfo.tel" disabled></el-input>
  121. </el-form-item>
  122. </el-col>
  123. <el-col :span="8">
  124. <el-form-item label="传真" prop="fax">
  125. <el-input v-model="dataForm.fax" :value="supplierInfo.fax" disabled></el-input>
  126. </el-form-item>
  127. </el-col>
  128. </el-row>
  129. </div>
  130. </el-form>
  131. <span slot="footer" class="dialog-footer">
  132. <el-button @click="onChose">取消</el-button>
  133. <el-button v-if="!formDisable" type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  134. </span>
  135. </div>
  136. </template>
  137. <script>
  138. import { getSupplierNameList, getSupplierDetail } from '@/api/sale'
  139. import { getPurchaseInvoiceDetail } from '@/api/finance'
  140. import uploadComponent from '../common/upload-component'
  141. export default {
  142. name: 'purchase-invoice-add-or-update',
  143. components: {
  144. uploadComponent
  145. },
  146. data () {
  147. return {
  148. visible: false,
  149. formDisable: false,
  150. dataList: [],
  151. fileList: [],
  152. id: 0,
  153. dataForm: {},
  154. optionsType: [],
  155. optionsApplier: [],
  156. materialDetails: [],
  157. optionsCus: [], // 供应商下拉列表
  158. supplierInfo: {},
  159. supplierVisible: false,
  160. supplierLoading: false,
  161. totalAmount: 0,
  162. dataRule: {
  163. type: [{ required: true, message: '发票类型不能为空', trigger: 'blur' }],
  164. typeCode: [{ required: true, message: '发票类别代码不能为空', trigger: 'blur' }],
  165. invoiceNumber: [{ required: true, message: '发票号不能为空', trigger: 'blur' }],
  166. phone: [{ required: true, message: '开票电话不能为空', trigger: 'blur' }],
  167. currency: [{ required: true, message: '币种不能为空', trigger: 'blur' }],
  168. invoiceAmount: [{ required: true, message: '发票金额不能为空', trigger: 'blur' }],
  169. supplierId: [{ required: true, message: '供应商不能为空', trigger: 'blur' }]
  170. },
  171. typeState: [ // 发票类型映射关系
  172. {
  173. code: '1',
  174. value: '增值税专用发票'
  175. },
  176. {
  177. code: '2',
  178. value: '增值税普通发票'
  179. },
  180. {
  181. code: '3',
  182. value: '形式发票'
  183. }
  184. ],
  185. currencyType: [ // 币种映射关系
  186. {
  187. code: '1',
  188. value: '人民币'
  189. }
  190. ]
  191. }
  192. },
  193. watch: {
  194. 'dataForm.customerId' (value) {
  195. this.optionsCus.forEach(v => {
  196. if (v.supplierId === value) {
  197. this.dataForm.supplierName = v.supplierName
  198. }
  199. })
  200. }
  201. },
  202. methods: {
  203. onChose () {
  204. this.$emit('onChose')
  205. },
  206. async init (id, formDisable) {
  207. this.visible = true
  208. this.id = id || 0
  209. this.formDisable = formDisable
  210. await getSupplierNameList().then(({data}) => {
  211. if (data && data.code === '200') {
  212. this.optionsCus = data.data
  213. }
  214. })
  215. if (!id) return
  216. await getPurchaseInvoiceDetail(this.id).then(({data}) => {
  217. if (data && data.code === '200') {
  218. this.dataForm = data.data
  219. // 文件列表
  220. this.fileList = []
  221. if (data.data.attachList) {
  222. data.data.attachList.forEach((item) => {
  223. this.fileList.push({
  224. name: item.fileName,
  225. url: item.url,
  226. id: item.url
  227. })
  228. })
  229. }
  230. }
  231. })
  232. await this.cusChange()
  233. },
  234. validateField (type) {
  235. this.$refs.dataForm.validateField(type)
  236. },
  237. // 表单提交
  238. dataFormSubmit () {
  239. this.$refs['dataForm'].validate((valid) => {
  240. if (valid) {
  241. // 添加附件
  242. let fList = this.fileList
  243. if (fList.length > 0) {
  244. this.dataForm.attachList = []
  245. for (let i = 0; i < fList.length; i++) {
  246. this.dataForm.attachList.push({
  247. fileName: fList[i].name,
  248. url: fList[i].url
  249. })
  250. }
  251. } else {
  252. this.$message.error('请上传文件')
  253. return
  254. }
  255. // 添加客户信息
  256. if (this.dataForm.supplierId && this.supplierInfo) {
  257. Object.assign(this.dataForm, this.supplierInfo)
  258. }
  259. // let finSalesInvoice = {finSalesInvoice: this.dataForm}
  260. this.$http({
  261. url: !this.id ? this.$http.adornUrl(`/biz-service/purchase/invoice/save`) : this.$http.adornUrl(`/biz-service/purchase/invoice/update`),
  262. method: 'post',
  263. data: this.$http.adornData(this.dataForm)
  264. }).then(({data}) => {
  265. if (data && data.code === '200') {
  266. this.$message({
  267. message: '操作成功',
  268. type: 'success',
  269. duration: 1500,
  270. onClose: () => {
  271. this.onChose()
  272. this.$emit('refreshDataList')
  273. }
  274. })
  275. } else {
  276. this.$message.error(data.msg)
  277. }
  278. })
  279. }
  280. })
  281. },
  282. uploadSuccess (fileList) {
  283. this.fileList = fileList
  284. },
  285. // 客户选中切换
  286. cusChange () {
  287. if (!this.dataForm.supplierId) {
  288. this.supplierInfo = {}
  289. this.supplierVisible = false
  290. }
  291. this.customerloading = true
  292. getSupplierDetail(this.dataForm.supplierId).then(({data}) => {
  293. if (data && data.code === '200') {
  294. let supplierInfo = data.data
  295. this.supplierInfo = {
  296. invoiceTitle: supplierInfo.invoiceTitle,
  297. taxNumber: supplierInfo.taxNumber,
  298. bank: supplierInfo.bank,
  299. account: supplierInfo.account,
  300. tel: supplierInfo.tel,
  301. fax: supplierInfo.fax
  302. }
  303. }
  304. this.supplierloading = false
  305. })
  306. }
  307. }
  308. }
  309. </script>
  310. <style scoped>
  311. </style>