communicate-add-or-update.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="!id ? '新增': display ? '详情' : '修改'"
  5. width="70%"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible">
  8. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  9. <el-row class="my-row">
  10. <el-col :span="8">
  11. <el-form-item label="客户名称" prop="cusId">
  12. <el-select
  13. v-model="dataForm.cusId"
  14. :disabled="display"
  15. remote
  16. placeholder="请选择">
  17. <el-option
  18. v-for="item in optionsCus"
  19. :key="item.value"
  20. :label="item.customerName"
  21. :value="item.customerId">
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="8" style="padding-left: 20px">
  27. <el-form-item label="联系人" prop="name">
  28. <el-input v-model="dataForm.name" disabled placeholder="联系人"></el-input>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="8" style="padding-left: 20px">
  32. <el-form-item label="沟通类别" prop="coType">
  33. <el-select
  34. v-model="dataForm.coType"
  35. :disabled="display"
  36. remote
  37. placeholder="请选择">
  38. <el-option
  39. v-for="item in options"
  40. :key="item.code"
  41. :label="item.value"
  42. :value="item.code">
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. </el-col>
  47. </el-row>
  48. <el-row class="my-row">
  49. <el-form-item label="备注说明">
  50. <el-input v-model="dataForm.code" :disabled="display"></el-input>
  51. </el-form-item>
  52. </el-row>
  53. <el-row class="my-row">
  54. <div class="title"><span style="color: red">*</span> 沟通扫描件</div>
  55. <el-upload
  56. class="upload-demo"
  57. ref="upload"
  58. :multiple="true"
  59. action="#"
  60. accept="image/jpeg,image/gif,image/png"
  61. :on-preview="handlePreview"
  62. :on-remove="handleRemove"
  63. :on-change="handleChange"
  64. :file-list="fileList"
  65. :limit="5"
  66. :on-exceed="handleExceed"
  67. :auto-upload="false">
  68. <el-button v-show="!display" slot="trigger" size="small" type="primary">选取文件</el-button>
  69. <el-button v-show="!display" style="margin-left: 10px;" size="small" type="success" @click="submitUpload">开始上传</el-button>
  70. <div v-show="!display" slot="tip" class="el-upload__tip">只能上传jpg/png文件,最多5张图片,且每张图片不超过10M</div>
  71. </el-upload>
  72. </el-row>
  73. <div class="title"><span style="color: red">*</span> 订单产品明细</div>
  74. <el-row>
  75. <el-table
  76. :data="cusRCommProductVOS"
  77. border
  78. style="width: 100%;">
  79. <el-table-column
  80. label="序号"
  81. type="index"
  82. width="50"
  83. align="center">
  84. </el-table-column>
  85. <el-table-column
  86. prop="productName"
  87. header-align="center"
  88. align="center"
  89. label="产品名称">
  90. </el-table-column>
  91. <el-table-column
  92. prop="cnt"
  93. header-align="center"
  94. align="center"
  95. label="数量"
  96. width="170">
  97. <template slot-scope="scope">
  98. <el-input-number v-model="scope.row.cnt" :disabled="display" :min="1" style="width: 140px;"/>
  99. </template>
  100. </el-table-column>
  101. <el-table-column
  102. prop="price"
  103. header-align="center"
  104. align="center"
  105. label="含税单价">
  106. <template slot-scope="scope">
  107. <el-input-number v-model="scope.row.price" :disabled="display" :precision="2" :step="0.1" :min="0" style="width: 140px;"/>
  108. </template>
  109. </el-table-column>
  110. <el-table-column
  111. prop="amount"
  112. header-align="center"
  113. align="center"
  114. label="含税总价">
  115. <template slot-scope="scope">
  116. <span>{{ (scope.row.cnt*scope.row.price).toFixed(2) }}</span>
  117. </template>
  118. </el-table-column>
  119. <el-table-column
  120. prop="rate"
  121. header-align="center"
  122. align="center"
  123. label="税率">
  124. <template slot-scope="scope">
  125. <el-input type="number" v-model="scope.row.rate" :disabled="display">
  126. <template slot="append">%</template>
  127. </el-input>
  128. </template>
  129. </el-table-column>
  130. <el-table-column
  131. prop="notes"
  132. header-align="center"
  133. align="center"
  134. label="备注">
  135. </el-table-column>
  136. </el-table>
  137. </el-row>
  138. <el-row v-if="!display" style="text-align: center; margin-top: 10px;">
  139. <el-button type="primary" icon="el-icon-plus" @click="inBound"></el-button>
  140. </el-row>
  141. </el-form>
  142. <span slot="footer" class="dialog-footer">
  143. <el-button @click="visible = false">取消</el-button>
  144. <el-button v-if="!display" type="primary" @click="dataFormSubmit()">确定</el-button>
  145. </span>
  146. </el-dialog>
  147. <!-- 图片预览 -->
  148. <el-dialog title="图片预览" :visible.sync="previewVisible" width="50%">
  149. <img :src="previewPath" :alt="previewName" style="width:100%;height:100%" />
  150. </el-dialog>
  151. <template-chose v-if="inboundVisible" ref="inbound" @addItem="addItem" />
  152. </div>
  153. </template>
  154. <script>
  155. import templateChose from '../product/template-chose'
  156. import { getCustomer, getCoDetail } from '@/api/cus'
  157. import { uploadUrl, downloadUrl, uploadFiles } from '@/api/file'
  158. import { getDictList } from '@/api/dict'
  159. export default {
  160. name: 'communicate-add-or-update',
  161. components: {templateChose},
  162. computed: {
  163. orgId: {
  164. get () { return this.$store.state.user.orgId }
  165. }
  166. },
  167. data () {
  168. return {
  169. inboundVisible: false,
  170. visible: false,
  171. display: false,
  172. dictType: 'material_type',
  173. options: [],
  174. optionsCus: [],
  175. dataList: [],
  176. fileList: [],
  177. id: 0,
  178. cusRCommProductVOS: [],
  179. dataForm: {},
  180. dataRule: {
  181. cusId: [{ required: true, message: '客户名称不能为空', trigger: 'blur' }],
  182. coType: [{ required: true, message: '沟通类别不能为空', trigger: 'change' }],
  183. name: [{ required: true, message: '联系人不能为空', trigger: 'blur' }]
  184. },
  185. uploadUrl: uploadUrl,
  186. previewPath: '',
  187. previewName: '',
  188. previewVisible: false
  189. }
  190. },
  191. watch: {
  192. 'dataForm.cusId' (value) {
  193. this.optionsCus.forEach(v => {
  194. if (v.customerId === value) {
  195. this.dataForm.name = v.contact
  196. }
  197. })
  198. }
  199. },
  200. methods: {
  201. async init (id, display) {
  202. this.dataForm = {}
  203. this.cusRCommProductVOS = []
  204. this.visible = true
  205. this.id = id || 0
  206. this.display = display
  207. // 获取沟通类别
  208. await getDictList({type: 'communication_type'}).then(({data}) => {
  209. if (data) {
  210. this.options = data
  211. }
  212. })
  213. await getCustomer().then(({data}) => {
  214. if (data && data.code === '200') {
  215. this.optionsCus = data.data
  216. }
  217. })
  218. if (!id) return
  219. await getCoDetail(this.id).then(({data}) => {
  220. if (data && data.code === '200') {
  221. this.dataForm = data.data
  222. // 附件显示
  223. this.fileList = []
  224. data.data.attachList.forEach((item) => {
  225. this.fileList.push({
  226. name: item.fileName,
  227. url: item.url,
  228. id: item.url
  229. })
  230. })
  231. if (data.data.cusRCommProductVOS) {
  232. data.data.cusRCommProductVOS.forEach((item) => {
  233. this.cusRCommProductVOS.push({
  234. cnt: item.cnt,
  235. price: item.price,
  236. productId: item.productId,
  237. rate: item.rate,
  238. productName: item.productName,
  239. notes: item.notes
  240. })
  241. })
  242. }
  243. }
  244. })
  245. },
  246. submitUpload () {
  247. // this.$refs.upload.submit()
  248. if (this.fileList.length === 0) {
  249. return this.$message.warning('请选取文件后再上传')
  250. }
  251. const formData = new FormData()
  252. this.fileList.forEach((file) => {
  253. formData.append('file', file.raw)
  254. })
  255. uploadFiles(formData).then(({data}) => {
  256. if (data && data.code === '200') {
  257. data.data.forEach((item) => {
  258. let fileData = this.fileList.find((file) => file.name === item.originFileName)
  259. fileData.url = item.fileUrl
  260. })
  261. this.$message.success('上传成功')
  262. } else {
  263. this.$message.error('上传失败')
  264. }
  265. })
  266. },
  267. handleRemove (file, fileList) {
  268. this.fileList = fileList
  269. },
  270. handlePreview (file) {
  271. if (file && file.url) {
  272. // 获取文件路径
  273. this.previewPath = downloadUrl + file.url
  274. this.previewName = file.name
  275. this.previewVisible = true
  276. }
  277. },
  278. handleChange (file, fileList) {
  279. this.fileList = fileList
  280. },
  281. handleExceed (files, fileList) {
  282. this.$message.warning(`当前限制选择 5 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
  283. },
  284. // 表单提交
  285. dataFormSubmit () {
  286. this.$refs['dataForm'].validate((valid) => {
  287. if (valid) {
  288. // 添加附件
  289. let fList = this.fileList
  290. // console.log('fileList = ' + fList)
  291. if (fList.length > 0) {
  292. this.dataForm.attachList = []
  293. for (let i = 0; i < fList.length; i++) {
  294. this.dataForm.attachList.push({
  295. fileName: fList[i].name,
  296. url: fList[i].url
  297. })
  298. }
  299. }
  300. this.dataForm.cusRCommProductVOS = this.cusRCommProductVOS
  301. this.$http({
  302. url: this.$http.adornUrl(`/biz-service/cusCommunication/save`),
  303. method: 'post',
  304. data: this.$http.adornData({...this.dataForm, orgId: this.orgId})
  305. }).then(({data}) => {
  306. if (data && data.code === '200') {
  307. this.$message({
  308. message: '操作成功',
  309. type: 'success',
  310. duration: 1500,
  311. onClose: () => {
  312. this.visible = false
  313. this.$emit('refreshDataList')
  314. }
  315. })
  316. } else {
  317. this.$message.error(data.msg)
  318. }
  319. })
  320. }
  321. })
  322. },
  323. validateField (type) {
  324. this.$refs.dataForm.validateField(type)
  325. },
  326. inBound () {
  327. this.inboundVisible = true
  328. this.$nextTick(() => {
  329. this.$refs.inbound.init()
  330. })
  331. },
  332. addItem (item) {
  333. this.cusRCommProductVOS.push({
  334. cnt: 1,
  335. price: 0,
  336. productId: item.productId,
  337. rate: 0,
  338. productName: item.productName,
  339. notes: item.notes
  340. })
  341. }
  342. }
  343. }
  344. </script>
  345. <style scoped>
  346. .my-line{
  347. border-bottom: 1px solid #c0c4cc;
  348. margin-bottom: 10px;
  349. }
  350. .title{
  351. padding: 10px 0 ;
  352. }
  353. </style>