addCustomer.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div>
  3. <el-form ref="form" v-loading="addLoading" :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 :span="3" class="col-txt"><span>小区-分期</span></el-col>
  10. <el-col :span="9" class="col-input">
  11. <el-form-item>
  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. @change="handleChange"
  20. />
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="3" class="col-txt"><span>选房日</span></el-col>
  24. <el-col :span="9" class="col-input">
  25. <el-form-item prop="">
  26. <el-date-picker
  27. v-model="form.roomSelectionDate"
  28. popper-class="statistic_base"
  29. type="date"
  30. placeholder="年月日"
  31. value-format="yyyy-MM-dd"
  32. />
  33. </el-form-item>
  34. </el-col>
  35. </el-row>
  36. <el-row>
  37. <el-col :span="3" class="col-txt"><span>批次号</span></el-col>
  38. <el-col :span="9" class="col-input">
  39. <el-form-item prop="companyId">
  40. <el-input v-model="form.batchNumber" />
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="3" class="col-txt"><span>选房号</span></el-col>
  44. <el-col :span="9" class="col-input">
  45. <el-form-item prop="companyId">
  46. <el-input v-model="form.roomSelectionNumber" />
  47. </el-form-item>
  48. </el-col>
  49. </el-row>
  50. <el-row>
  51. <!-- 特殊表单 -->
  52. <div v-for="(item, index) in form.dynamicItem" :key="index">
  53. <el-row style="margin-top: 10px">
  54. <el-col :span="2" class="col-txt"><span>购房人{{ index + 1 }}</span></el-col>
  55. <el-col :span="4" class="col-input">
  56. <el-form-item :prop="'dynamicItem.' + index + '.name'">
  57. <el-input
  58. v-model="item.name"
  59. placeholder="请填写姓名"
  60. />
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="4" class="col-input">
  64. <el-form-item :prop="'dynamicItem.' + index + '.identityCard'">
  65. <el-input
  66. v-model="item.identityCard"
  67. placeholder="请填写身份证号"
  68. />
  69. </el-form-item>
  70. </el-col>
  71. <el-col :span="4" class="col-input">
  72. <el-form-item :prop="'dynamicItem.' + index + '.phone'">
  73. <el-input
  74. v-model="item.phone"
  75. placeholder="请填写手机号"
  76. />
  77. </el-form-item>
  78. </el-col>
  79. <el-col v-if="index !== 0" :span="6" class="col-input">
  80. <el-form-item :prop="'dynamicItem.' + index + '.relationship'">
  81. <el-select
  82. v-model="item.relationship"
  83. placeholder="与1的关系"
  84. filterable
  85. clearable
  86. :popper-append-to-body="false"
  87. popper-class="statistic_base"
  88. >
  89. <el-option
  90. v-for="relationship in dc_data.RELATIONSHIP"
  91. :key="relationship.value"
  92. :label="relationship.label"
  93. :value="relationship.value"
  94. :popper-append-to-body="false"
  95. popper-class="statistic_base"
  96. />
  97. </el-select>
  98. </el-form-item>
  99. </el-col>
  100. <el-col :span="2" class="col-input">
  101. <el-button v-if="index !== 0" type="danger" size="mini" @click="deleteItem(item, index)">-</el-button>
  102. </el-col>
  103. </el-row>
  104. </div>
  105. </el-row>
  106. <el-row>
  107. <el-col :span="2" class="col-txt">
  108. <el-button size="small" type="text" @click="addItem">+继续添加</el-button>
  109. </el-col>
  110. </el-row>
  111. </el-card>
  112. </el-col>
  113. </el-row>
  114. </el-form>
  115. <div style="text-align: right">
  116. <el-button @click="cancel">取 消</el-button>
  117. <el-button v-if="!isView" type="primary" @click="confirmSubmit()">提 交</el-button>
  118. </div>
  119. </div>
  120. </template>
  121. <script>
  122. import Base from '@/views/base/base'
  123. import BaseData from '@/views/base/baseData'
  124. export default {
  125. name: 'AddCustomer',
  126. components: { },
  127. mixins: [Base, BaseData],
  128. data() {
  129. return {
  130. dc_key: ['RELATIONSHIP'],
  131. form: {
  132. dynamicItem: [
  133. {
  134. id: '',
  135. customerManagementId: '',
  136. name: '',
  137. identityCard: '',
  138. phone: '',
  139. relationship: ''
  140. }
  141. ]
  142. },
  143. rules: {
  144. },
  145. addLoading: false,
  146. options: [],
  147. isView: false
  148. }
  149. },
  150. mounted() {
  151. this.getTreeSelectData()
  152. },
  153. methods: {
  154. initData(data) {
  155. if (data.isView) {
  156. this.isView = true
  157. } else {
  158. this.isView = false
  159. }
  160. this.initDict(this.dc_key).then(res => {
  161. this.getById(data.id)
  162. })
  163. },
  164. handleChange(value) {
  165. },
  166. getById(val) {
  167. this.baseRequest('getById', { id: val }).then(res => {
  168. this.form = res.data
  169. this.form.findids = [res.data.groupId, res.data.discId]
  170. this.$set(this.form, 'dynamicItem', [])
  171. if (res.data.buyerJson) {
  172. const json = JSON.parse(res.data.buyerJson)
  173. json.forEach(item => {
  174. const data = {
  175. name: item.name,
  176. identityCard: item.identityCard,
  177. phone: item.phone,
  178. relationship: item.relationship
  179. }
  180. this.form.dynamicItem.push(data)
  181. })
  182. } else {
  183. this.addItem()
  184. }
  185. })
  186. },
  187. confirmSubmit: function() {
  188. const _this = this
  189. this.$refs.form.validate(valid => {
  190. if (valid) {
  191. let soaUrl = 'add'
  192. if (_this.form.id) {
  193. soaUrl = 'edit'
  194. }
  195. const extraData = {
  196. groupId: _this.form.findids[0],
  197. discId: _this.form.findids[1],
  198. buyerJson: JSON.stringify(_this.form.dynamicItem)
  199. }
  200. const postData = Object.assign({}, _this.form, extraData)
  201. console.log('postData', postData)
  202. this.baseRequest(soaUrl, postData).then(res => {
  203. if (res.data.code == '200') {
  204. _this.$message({
  205. message: '新增成功',
  206. type: 'success'
  207. })
  208. _this.cancel()
  209. } else {
  210. _this.$message({
  211. message: res.msg,
  212. type: 'warning'
  213. })
  214. }
  215. }).catch(err => {
  216. _this.$message({
  217. message: err,
  218. type: 'warning'
  219. })
  220. })
  221. } else {
  222. console.log('error submit!!')
  223. return false
  224. }
  225. })
  226. },
  227. cancel() {
  228. this.$emit('cancel')
  229. },
  230. getTreeSelectData: function() {
  231. this.baseInfoRequest('getTreeData3', {}).then((res) => {
  232. this.options = res.data.data
  233. }).catch(() => {
  234. })
  235. },
  236. addItem(length) {
  237. this.form.dynamicItem.push({
  238. id: '',
  239. customerManagementId: '',
  240. name: '',
  241. identityCard: '',
  242. phone: '',
  243. relationship: ''
  244. })
  245. },
  246. // 删除方法
  247. deleteItem(item, index) {
  248. this.form.dynamicItem.splice(index, 1)
  249. },
  250. baseRequest(opUrl, postData) {
  251. return this.$channel.globeRequest('CustomerManagementController', opUrl, postData, 'project')
  252. },
  253. baseInfoRequest: function(opUrl, postData) {
  254. return this.$channel.baseRequest('ParkInfoController', opUrl, postData, 'User')
  255. }
  256. }
  257. }
  258. </script>
  259. <style scoped>
  260. </style>