addCustomer.vue 9.4 KB

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