人民医院前端

AddOrEditCustomer.vue 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div v-loading="loading">
  3. <el-row :gutter="5">
  4. <el-col :span="20">
  5. <el-form
  6. ref="ruleForm"
  7. :model="ruleForm"
  8. label-width="100px"
  9. style="font-size: 14px"
  10. class="order_form">
  11. <el-row>
  12. <el-col :span="6">
  13. <el-form-item label="客户名称" prop="name">
  14. <el-input v-model="ruleForm.name" placeholder="请输入客户名称" />
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="6">
  18. <el-form-item label="电话" prop="telphone">
  19. <el-input v-model="ruleForm.telphone" placeholder="请输入客户电话" />
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="6">
  23. <el-form-item label="性别" prop="sex">
  24. <el-radio-group v-model="ruleForm.sex">
  25. <el-radio label="男">男</el-radio>
  26. <el-radio label="女">女</el-radio>
  27. </el-radio-group>
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="6">
  31. <el-form-item label="身份证号" prop="idcard">
  32. <el-input v-model="ruleForm.idcard" placeholder="请输入身份证号" />
  33. </el-form-item>
  34. </el-col>
  35. </el-row>
  36. <el-row>
  37. <el-col :span="6">
  38. <el-form-item label="客户住址" prop="adddress">
  39. <el-input v-model="ruleForm.adddress" type="textarea" placeholder="请输入客户住址" />
  40. </el-form-item>
  41. </el-col>
  42. </el-row>
  43. <el-form-item>
  44. <el-button type="primary" @click="submitForm">保存</el-button>
  45. </el-form-item>
  46. </el-form>
  47. </el-col>
  48. </el-row>
  49. </div>
  50. </template>
  51. <script>
  52. import { addOrEditCustomerList, getCustomerList } from '@/api/customerManagement/customerList'
  53. import { validateTel } from '@/utils/validate'
  54. import { mapGetters } from 'vuex'
  55. export default {
  56. name: 'AddOrEditCustomer',
  57. props: {
  58. callinNum: {
  59. type: String,
  60. default: ''
  61. }
  62. },
  63. data() {
  64. var phoneNumbersinput = (rule, value, callback) => {
  65. if (value !== '') { // 不为空的时候进行验证
  66. validateTel(value) ? callback() : callback(new Error('联系电话格式错误'))
  67. } else { // 为空的时候就直接放过去(这里一定要写,不然既不报错也不会往下走【应该和router的next()相同】)
  68. callback()
  69. }
  70. }
  71. return {
  72. rowid: 0,
  73. ruleForm: {
  74. id: 0, // 客户id
  75. name: '', // 客户名称
  76. telphone: '', // 客户电话
  77. sex: '', // 性别
  78. idcard: '', // 身份证号
  79. adddress: '' // 客户住址
  80. },
  81. loading: false,
  82. isButton: true
  83. }
  84. },
  85. computed: {
  86. ...mapGetters(['screenState'])
  87. },
  88. watch: {
  89. screenState: function() {
  90. if (this.screenState && this.callinNum) {
  91. this.getList()
  92. }
  93. }
  94. },
  95. created() {
  96. if (this.callinNum) {
  97. this.getList()
  98. this.ruleForm.telphone = this.callinNum
  99. }
  100. },
  101. methods: {
  102. submitForm() {
  103. this.$emit('fromChild', this.ruleForm.cusName)
  104. console.log(this.ruleForm)
  105. this.$refs.ruleForm.validate((valid) => {
  106. if (valid) {
  107. this.loading = true
  108. const data = {
  109. id: this.rowid,
  110. name: this.ruleForm.name, // 客户名称 string
  111. telphone: this.ruleForm.telphone, // 客户电话 string
  112. sex: this.ruleForm.sex, // 客户性别 string
  113. idcard: this.ruleForm.idcard, // 身份证号 string
  114. adddress: this.ruleForm.adddress // 客户住址 string
  115. }
  116. // 添加
  117. if (!this.rowid) {
  118. addOrEditCustomerList(data)
  119. .then((response) => {
  120. this.loading = false
  121. if (response.state.toLowerCase() === 'success') {
  122. this.$message({
  123. message: '恭喜你,添加成功!',
  124. type: 'success',
  125. duration: 1000
  126. })
  127. this.$bus.$emit('eventName', this.ruleForm)
  128. } else {
  129. this.$message({
  130. message: '添加失败,该客户已存在!',
  131. type: 'success',
  132. duration: 1000
  133. })
  134. }
  135. })
  136. .catch((response) => {
  137. this.loading = false
  138. })
  139. return
  140. }
  141. // 编辑
  142. addOrEditCustomerList(data)
  143. .then((response) => {
  144. this.loading = false
  145. if (response.state.toLowerCase() === 'success') {
  146. this.$message({
  147. message: '恭喜你,客户信息编辑成功!',
  148. type: 'success',
  149. duration: 1000
  150. })
  151. this.$bus.$emit('eventName', this.ruleForm)
  152. }
  153. })
  154. .catch(() => {
  155. this.loading = false
  156. })
  157. } else {
  158. this.$message({
  159. type: 'error',
  160. message: '请输入有效的必填项信息!',
  161. offset: 50,
  162. duration: 1000
  163. })
  164. return false
  165. }
  166. })
  167. },
  168. // 获取详情
  169. getList() {
  170. return new Promise((resolve) => {
  171. const params = {
  172. pageindex: 1, // int 第几页
  173. pagesize: 99, // int 每页几条信息
  174. telephone: this.callinNum.toString() // 联系电话
  175. }
  176. getCustomerList(params).then((response) => {
  177. this.loading = false
  178. if (response.state.toLowerCase() === 'success') {
  179. const res = response.rows[0]
  180. console.log(res)
  181. if (res) {
  182. this.rowid = res.F_CustomerId
  183. this.ruleForm.name = res.F_CustomerName // 客户名称
  184. this.ruleForm.telphone = res.F_Telephone // 客户电话
  185. this.ruleForm.sex = res.F_Sex // 性别
  186. this.ruleForm.idcard = res.F_IdCard // 身份证号
  187. this.ruleForm.adddress = res.F_Address // 客户住址
  188. this.$emit('cus-info-list', res)
  189. this.$bus.$emit('eventName', this.ruleForm)
  190. }
  191. }
  192. })
  193. resolve()
  194. })
  195. }
  196. }
  197. }
  198. </script>
  199. <style rel="stylesheet/scss" lang="scss">
  200. .order_form {
  201. .form_select {
  202. width: 100%;
  203. }
  204. .form_date {
  205. width: 100%;
  206. }
  207. }
  208. </style>