addCustomer.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" style="width: 100%;padding: 5px" :rules="rules">
  4. <el-row>
  5. <el-col style="padding-bottom: 10px">
  6. <span class="card_title">基本信息</span>
  7. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  8. <el-row>
  9. <el-col v-if="isView" :span="3" class="col-txt"><span><span class="red-asterisk" />小区-分期</span></el-col>
  10. <el-col v-if="isView" :span="9" class="col-input">
  11. <el-form-item prop="findids">
  12. <el-cascader
  13. ref="findids"
  14. v-model="form.findids"
  15. class="full"
  16. :append-to-body="false"
  17. :options="options"
  18. clearable
  19. disabled
  20. @change="handleChange"
  21. />
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="3" class="col-txt"><span>选房日</span></el-col>
  25. <el-col :span="9" class="col-input">
  26. <el-form-item>
  27. <el-date-picker
  28. v-model="form.roomSelectionDate"
  29. popper-class="statistic_base"
  30. type="datetime"
  31. placeholder="年月日"
  32. value-format="yyyy-MM-dd HH:mm:ss"
  33. />
  34. </el-form-item>
  35. </el-col>
  36. </el-row>
  37. <el-row>
  38. <el-col :span="3" class="col-txt"><span><span class="red-asterisk">*</span>批次号</span></el-col>
  39. <el-col :span="9" class="col-input">
  40. <el-form-item prop="batchNumber">
  41. <el-input v-model="form.batchNumber" />
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="3" class="col-txt"><span><span class="red-asterisk">*</span>选房号</span></el-col>
  45. <el-col :span="9" class="col-input">
  46. <el-form-item prop="roomSelectionNumber">
  47. <el-input v-model="form.roomSelectionNumber" />
  48. </el-form-item>
  49. </el-col>
  50. </el-row>
  51. <el-row>
  52. <!-- 特殊表单 -->
  53. <div v-for="(item, index) in form.dynamicItem" :key="index">
  54. <el-row style="margin-top: 10px">
  55. <el-col :span="2" class="col-txt"><span><span class="red-asterisk">*</span>购房人{{ index + 1 }}</span></el-col>
  56. <el-col :span="4" class="col-input">
  57. <el-form-item :prop="'dynamicItem.' + index + '.name'">
  58. <el-input
  59. v-model="item.name"
  60. placeholder="请填写姓名"
  61. />
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="4" class="col-input">
  65. <el-form-item
  66. :prop="'dynamicItem.' + index + '.identityCard'"
  67. :rules="rules.identityCard"
  68. >
  69. <el-input
  70. v-model="item.identityCard"
  71. placeholder="请填写身份证号"
  72. />
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="4" class="col-input">
  76. <el-form-item
  77. :prop="'dynamicItem.' + index + '.phone'"
  78. :rules="rules.phone"
  79. >
  80. <el-input
  81. v-model="item.phone"
  82. placeholder="请填写手机号"
  83. />
  84. </el-form-item>
  85. </el-col>
  86. <el-col v-if="index !== 0" :span="6" class="col-input">
  87. <el-form-item :prop="'dynamicItem.' + index + '.relationship'">
  88. <el-select
  89. v-model="item.relationship"
  90. placeholder="与1的关系"
  91. filterable
  92. clearable
  93. :popper-append-to-body="false"
  94. popper-class="statistic_base"
  95. >
  96. <el-option
  97. v-for="relationship in dc_data.RELATIONSHIP"
  98. :key="relationship.value"
  99. :label="relationship.label"
  100. :value="relationship.value"
  101. :popper-append-to-body="false"
  102. popper-class="statistic_base"
  103. />
  104. </el-select>
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="2" class="col-input">
  108. <el-button v-if="index !== 0" type="danger" size="mini" @click="deleteItem(item, index)">-</el-button>
  109. </el-col>
  110. </el-row>
  111. </div>
  112. </el-row>
  113. <el-row>
  114. <el-col :span="2" class="col-txt">
  115. <el-button size="small" type="text" @click="addItem">+继续添加</el-button>
  116. </el-col>
  117. </el-row>
  118. </el-card>
  119. </el-col>
  120. </el-row>
  121. </el-form>
  122. <div style="text-align: right">
  123. <el-button @click="cancel">取 消</el-button>
  124. <el-button v-if="!isView" :loading="addLoading" type="primary" @click="confirmSubmit()">提 交</el-button>
  125. </div>
  126. </div>
  127. </template>
  128. <script>
  129. import Base from '@/views/base/base'
  130. import BaseData from '@/views/base/baseData'
  131. export default {
  132. name: 'AddCustomer',
  133. components: { },
  134. mixins: [Base, BaseData],
  135. data() {
  136. var checkPhone = (rule, value, callback) => { // 手机号验证
  137. console.log(rule)
  138. if (rule.field === 'dynamicItem.0.phone') {
  139. if (!value) {
  140. return callback(new Error('手机号不能为空'))
  141. } else {
  142. const reg = /^1[3456789]\d{9}$/
  143. if (reg.test(value)) {
  144. callback()
  145. } else {
  146. return callback(new Error('请输入正确的手机号'))
  147. }
  148. }
  149. }
  150. callback()
  151. }
  152. return {
  153. dc_key: ['RELATIONSHIP'],
  154. form: {
  155. dynamicItem: [
  156. {
  157. id: '',
  158. customerManagementId: '',
  159. name: '',
  160. identityCard: '',
  161. phone: '',
  162. relationship: ''
  163. }
  164. ]
  165. },
  166. rules: {
  167. // findids: [{ required: true, message: '请选择小区-分期', trigger: 'change' }],
  168. roomSelectionDate: [{ required: true, message: '请输入选房日', trigger: 'change' }],
  169. batchNumber: [{ required: true, message: '请输入批次号', trigger: 'blur' }],
  170. roomSelectionNumber: [{ required: true, message: '请输入选房号', trigger: 'blur' }],
  171. phone: [
  172. {
  173. validator: checkPhone, trigger: 'blur'
  174. }],
  175. identityCard: [
  176. { required: true, message: '请输入身份证ID', trigger: 'blur' },
  177. { pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: '身份证格式不正确' }
  178. ]
  179. },
  180. addLoading: false,
  181. options: [],
  182. isView: false
  183. }
  184. },
  185. mounted() {
  186. this.getTreeSelectData()
  187. },
  188. methods: {
  189. initData(data) {
  190. this.isView = data.isView
  191. this.initDict(this.dc_key).then(res => {
  192. if (data.id) {
  193. this.getById(data.id)
  194. }
  195. })
  196. },
  197. handleChange(value) {
  198. },
  199. getById(val) {
  200. this.baseRequest('getById', { id: val }).then(res => {
  201. this.form = res.data
  202. this.form.findids = [res.data.groupId, res.data.discId]
  203. this.$set(this.form, 'dynamicItem', [])
  204. if (res.data.buyerJson) {
  205. const json = JSON.parse(res.data.buyerJson)
  206. json.forEach(item => {
  207. const data = {
  208. name: item.name,
  209. identityCard: item.identityCard,
  210. phone: item.phone,
  211. relationship: item.relationship,
  212. orderNum: item.orderNum
  213. }
  214. this.form.dynamicItem.push(data)
  215. })
  216. } else {
  217. this.addItem()
  218. }
  219. })
  220. },
  221. confirmSubmit: function() {
  222. const _this = this
  223. // if (!_this.form.findids[0]) {
  224. // this.$message({
  225. // message: '请选择小区',
  226. // type: 'warning'
  227. // })
  228. // return
  229. // }
  230. // if (!_this.form.findids[1]) {
  231. // this.$message({
  232. // message: '请选择分期',
  233. // type: 'warning'
  234. // })
  235. // return
  236. // }
  237. this.$refs.form.validate(valid => {
  238. if (valid) {
  239. _this.addLoading = true
  240. let soaUrl = 'add'
  241. if (_this.form.id) {
  242. soaUrl = 'edit'
  243. }
  244. const extraData = {
  245. // groupId: _this.form.findids[0],
  246. // discId: _this.form.findids[1],
  247. buyerJson: JSON.stringify(_this.form.dynamicItem)
  248. }
  249. const postData = Object.assign({}, _this.form, extraData)
  250. this.baseRequest(soaUrl, postData).then(res => {
  251. if (res.data.code == '200') {
  252. _this.$message({
  253. message: '新增成功',
  254. type: 'success'
  255. })
  256. _this.cancel()
  257. } else {
  258. _this.$message({
  259. message: res.data.msg,
  260. type: 'warning'
  261. })
  262. }
  263. _this.addLoading = false
  264. }).catch(err => {
  265. _this.$message({
  266. message: err,
  267. type: 'warning'
  268. })
  269. _this.addLoading = false
  270. })
  271. } else {
  272. console.log('error submit!!')
  273. return false
  274. }
  275. })
  276. },
  277. cancel() {
  278. this.$emit('cancel')
  279. },
  280. getTreeSelectData: function() {
  281. this.baseInfoRequest('getTreeData3', {}).then((res) => {
  282. this.options = res.data.data
  283. }).catch(() => {
  284. })
  285. },
  286. addItem(length) {
  287. this.form.dynamicItem.push({
  288. id: '',
  289. customerManagementId: '',
  290. name: '',
  291. identityCard: '',
  292. phone: '',
  293. relationship: ''
  294. })
  295. },
  296. // 删除方法
  297. deleteItem(item, index) {
  298. this.form.dynamicItem.splice(index, 1)
  299. },
  300. baseRequest(opUrl, postData) {
  301. return this.$channel.globeRequest('CustomerManagementController', opUrl, postData, 'project')
  302. },
  303. baseInfoRequest: function(opUrl, postData) {
  304. return this.$channel.baseRequest('ParkInfoController', opUrl, postData, 'User')
  305. }
  306. }
  307. }
  308. </script>
  309. <style scoped>
  310. .red-asterisk {
  311. color: red;
  312. }
  313. </style>