communicate-add-or-update.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. <upload-component :display="display" :title="'沟通扫描件'" :accept="'image/*'" :file-list="fileList"/>
  55. </el-row>
  56. <div class="title"><span style="color: red">*</span> 订单产品明细</div>
  57. <el-row>
  58. <el-table
  59. :data="cusRCommProductVOS"
  60. border
  61. style="width: 100%;">
  62. <el-table-column
  63. label="序号"
  64. type="index"
  65. width="50"
  66. align="center">
  67. </el-table-column>
  68. <el-table-column
  69. prop="productName"
  70. header-align="center"
  71. align="center"
  72. label="产品名称">
  73. </el-table-column>
  74. <el-table-column
  75. prop="cnt"
  76. header-align="center"
  77. align="center"
  78. label="数量"
  79. width="170">
  80. <template slot-scope="scope">
  81. <el-input-number v-model="scope.row.cnt" :disabled="display" :min="1" style="width: 140px;"/>
  82. </template>
  83. </el-table-column>
  84. <el-table-column
  85. prop="price"
  86. header-align="center"
  87. align="center"
  88. label="含税单价">
  89. <template slot-scope="scope">
  90. <el-input-number v-model="scope.row.price" :disabled="display" :precision="2" :step="0.1" :min="0" style="width: 140px;"/>
  91. </template>
  92. </el-table-column>
  93. <el-table-column
  94. prop="amount"
  95. header-align="center"
  96. align="center"
  97. label="含税总价">
  98. <template slot-scope="scope">
  99. <span>{{ (scope.row.cnt*scope.row.price).toFixed(2) }}</span>
  100. </template>
  101. </el-table-column>
  102. <el-table-column
  103. prop="rate"
  104. header-align="center"
  105. align="center"
  106. label="税率">
  107. <template slot-scope="scope">
  108. <el-input type="number" v-model="scope.row.rate" :disabled="display">
  109. <template slot="append">%</template>
  110. </el-input>
  111. </template>
  112. </el-table-column>
  113. <el-table-column
  114. prop="notes"
  115. header-align="center"
  116. align="center"
  117. label="备注">
  118. </el-table-column>
  119. </el-table>
  120. </el-row>
  121. <el-row v-if="!display" style="text-align: center; margin-top: 10px;">
  122. <el-button type="primary" icon="el-icon-plus" @click="inBound"></el-button>
  123. </el-row>
  124. </el-form>
  125. <span slot="footer" class="dialog-footer">
  126. <el-button @click="visible = false">取消</el-button>
  127. <el-button v-if="!display" type="primary" @click="dataFormSubmit()">确定</el-button>
  128. </span>
  129. </el-dialog>
  130. <template-chose v-if="inboundVisible" ref="inbound" @addItem="addItem" />
  131. </div>
  132. </template>
  133. <script>
  134. import templateChose from '../product/template-chose'
  135. import { getCustomer, getCoDetail } from '@/api/cus'
  136. import uploadComponent from '../common/upload-component'
  137. import { getDictList } from '@/api/dict'
  138. export default {
  139. name: 'communicate-add-or-update',
  140. components: {templateChose, uploadComponent},
  141. computed: {
  142. orgId: {
  143. get () { return this.$store.state.user.orgId }
  144. }
  145. },
  146. data () {
  147. return {
  148. inboundVisible: false,
  149. visible: false,
  150. display: false,
  151. dictType: 'material_type',
  152. options: [],
  153. optionsCus: [],
  154. dataList: [],
  155. fileList: [],
  156. id: 0,
  157. cusRCommProductVOS: [],
  158. dataForm: {},
  159. dataRule: {
  160. cusId: [{ required: true, message: '客户名称不能为空', trigger: 'blur' }],
  161. coType: [{ required: true, message: '沟通类别不能为空', trigger: 'change' }],
  162. name: [{ required: true, message: '联系人不能为空', trigger: 'blur' }]
  163. }
  164. }
  165. },
  166. watch: {
  167. 'dataForm.cusId' (value) {
  168. this.optionsCus.forEach(v => {
  169. if (v.customerId === value) {
  170. this.dataForm.name = v.contact
  171. }
  172. })
  173. }
  174. },
  175. methods: {
  176. async init (id, display) {
  177. this.dataForm = {}
  178. this.cusRCommProductVOS = []
  179. this.visible = true
  180. this.id = id || 0
  181. this.display = display
  182. // 获取沟通类别
  183. await getDictList({type: 'communication_type'}).then(({data}) => {
  184. if (data) {
  185. this.options = data
  186. }
  187. })
  188. await getCustomer().then(({data}) => {
  189. if (data && data.code === '200') {
  190. this.optionsCus = data.data
  191. }
  192. })
  193. if (!id) return
  194. await getCoDetail(this.id).then(({data}) => {
  195. if (data && data.code === '200') {
  196. this.dataForm = data.data
  197. // 附件显示
  198. this.fileList = []
  199. data.data.attachList.forEach((item) => {
  200. this.fileList.push({
  201. name: item.fileName,
  202. url: item.url,
  203. id: item.url
  204. })
  205. })
  206. if (data.data.cusRCommProductVOS) {
  207. data.data.cusRCommProductVOS.forEach((item) => {
  208. this.cusRCommProductVOS.push({
  209. cnt: item.cnt,
  210. price: item.price,
  211. productId: item.productId,
  212. rate: item.rate,
  213. productName: item.productName,
  214. notes: item.notes
  215. })
  216. })
  217. }
  218. }
  219. })
  220. },
  221. // 表单提交
  222. dataFormSubmit () {
  223. this.$refs['dataForm'].validate((valid) => {
  224. if (valid) {
  225. // 添加附件
  226. let fList = this.fileList
  227. // console.log('fileList = ' + fList)
  228. if (fList.length > 0) {
  229. this.dataForm.attachList = []
  230. for (let i = 0; i < fList.length; i++) {
  231. this.dataForm.attachList.push({
  232. fileName: fList[i].name,
  233. url: fList[i].url
  234. })
  235. }
  236. }
  237. this.dataForm.cusRCommProductVOS = this.cusRCommProductVOS
  238. this.$http({
  239. url: this.$http.adornUrl(`/biz-service/cusCommunication/save`),
  240. method: 'post',
  241. data: this.$http.adornData({...this.dataForm, orgId: this.orgId})
  242. }).then(({data}) => {
  243. if (data && data.code === '200') {
  244. this.$message({
  245. message: '操作成功',
  246. type: 'success',
  247. duration: 1500,
  248. onClose: () => {
  249. this.visible = false
  250. this.$emit('refreshDataList')
  251. }
  252. })
  253. } else {
  254. this.$message.error(data.msg)
  255. }
  256. })
  257. }
  258. })
  259. },
  260. validateField (type) {
  261. this.$refs.dataForm.validateField(type)
  262. },
  263. inBound () {
  264. this.inboundVisible = true
  265. this.$nextTick(() => {
  266. this.$refs.inbound.init()
  267. })
  268. },
  269. addItem (item) {
  270. this.cusRCommProductVOS.push({
  271. cnt: 1,
  272. price: 0,
  273. productId: item.productId,
  274. rate: 0,
  275. productName: item.productName,
  276. notes: item.notes
  277. })
  278. }
  279. }
  280. }
  281. </script>
  282. <style scoped>
  283. .my-line{
  284. border-bottom: 1px solid #c0c4cc;
  285. margin-bottom: 10px;
  286. }
  287. .title{
  288. padding: 10px 0 ;
  289. }
  290. </style>