addCustomer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <app-layout :haveBackground="false">
  3. <view class="tbg">
  4. <view class="ti">
  5. 请完善客户信息
  6. </view>
  7. <image class="bg" src="https://t17.9026.com/web/statics/image/index/addcustomerbg.png" mode=""></image>
  8. <view class="customerInfo">
  9. <view class="top">基本信息</view>
  10. <view class="head" @click="uploadHead">
  11. <image class="bg"
  12. :src="form.avatar===''?'https://t17.9026.com/web/statics/image/index/headbg.png':form.avatar" mode="">
  13. </image>
  14. <image class="camera" src="https://t17.9026.com/web/statics/image/index/camera.png" mode=""></image>
  15. </view>
  16. <view class="main-left cross-center linp border_bottom">
  17. <view class="field">姓名</view>
  18. <input type="text" v-model="form.name" placeholder="请输入姓名" placeholder-style="font-size:28rpx" />
  19. </view>
  20. <view class="main-left cross-center linp border_bottom">
  21. <view class="field">手机号</view>
  22. <input type="text" v-model="form.mobile" placeholder="请输入手机号" placeholder-style="font-size:28rpx" />
  23. </view>
  24. </view>
  25. </view>
  26. <view class="oinfo" v-for="(item,index) in form.estates" :key="index">
  27. <view class="main-between cross-center linp border_bottom" >
  28. <view class="field" style="font-weight: bold;" >{{index===0?'楼盘信息':''}}</view>
  29. <view class="main-right" style="width: 210rpx;height: 100%;">
  30. <view class="cross-center curd-btn" @click="addOrDel()" v-if="index==form.estates.length-1">
  31. <image src="https://t17.9026.com/web/statics/image/sale/tianjia.png" mode=""></image>添加
  32. </view>
  33. <view class="cross-center curd-btn" @click="addOrDel(index)" style="margin-left: 30rpx;" v-if="form.estates.length>1">
  34. <image src="https://t17.9026.com/web/statics/image/sale/shanchu.png" mode=""></image>删除
  35. </view>
  36. </view>
  37. </view>
  38. <AppAreaPicker @customevent="areaEvent($event,index)" :ids="item.multiIndex" @cancel="areaCancel">
  39. <view class="main-left cross-center linp border_bottom">
  40. <view class="field">区域信息</view>
  41. <input type="text" :value="item.region" disabled placeholder="请选择区域" placeholder-style="font-size:28rpx" />
  42. </view>
  43. </AppAreaPicker>
  44. <view class="main-left cross-center linp border_bottom" @click="selectEstate(index)">
  45. <view class="field">楼盘名称</view>
  46. <input type="text" :value="item.estate_name" disabled placeholder="请选择楼盘" placeholder-style="font-size:28rpx" />
  47. </view>
  48. <!-- <view class="main-left cross-center linp border_bottom">
  49. <view class="field">楼盘性质</view>
  50. <input type="text" value="" placeholder="请选择楼盘性质" placeholder-style="font-size:28rpx"/>
  51. </view> -->
  52. <view class="main-left cross-center linp border_bottom">
  53. <view class="field">楼盘户号</view>
  54. <view class="main-left cross-center in_in">
  55. <input type="text" :value="item.estate_no" @input="estate_noInput($event,index)" placeholder="几栋" style="max-width: 120rpx;" placeholder-style="font-size:28rpx" />
  56. <view class="line_c"></view>
  57. <input type="text" :value="item.room_no" @input="room_noInput($event,index)" placeholder="几单元几楼几号" style="width: 250rpx;" placeholder-style="font-size:28rpx" />
  58. </view>
  59. </view>
  60. </view>
  61. <button type="default" class="complete" @click="submit">完成</button>
  62. <view style="height: 200rpx;"></view>
  63. </app-layout>
  64. </template>
  65. <script>
  66. import AppAreaPicker from "@/components/page-component/app-area-picker/app-area-picker.vue"
  67. import uploadFile from '@/core/upload.js';
  68. export default {
  69. components: {
  70. AppAreaPicker
  71. },
  72. data() {
  73. return {
  74. formIndex:'',
  75. form: {
  76. sale_customer_id: '',
  77. avatar: '',
  78. mobile: '',
  79. name: '',
  80. estates: []
  81. }
  82. };
  83. },
  84. onLoad(option) {
  85. this.form.sale_customer_id=option.id
  86. if(option.id!=undefined){
  87. uni.setNavigationBarTitle({
  88. title: '编辑客户'
  89. });
  90. this.$showLoading()
  91. this.$request({
  92. url:this.$api.sale.customer_detail,
  93. data:{
  94. sale_customer_id:option.id
  95. },
  96. method:'post'
  97. }).then(res=>{
  98. if(res.code===0){
  99. this.form.avatar=res.data.avatar
  100. this.form.mobile=res.data.mobile
  101. this.form.name=res.data.name
  102. for (let i = 0; i < res.data.userEstate.length; i++) {
  103. let item=res.data.userEstate[i]
  104. let estateItem={
  105. estate_id: item.estate_id,
  106. estate_no: item.estate_no,
  107. room_no: item.room_no,
  108. regionId:{},
  109. region:'',
  110. multiIndex:[item.estate.province_id,item.estate.city_id,item.estate.district_id],
  111. estate_name: item.estate.name,
  112. }
  113. this.form.estates.push(estateItem)
  114. }
  115. this.$hideLoading()
  116. }
  117. })
  118. }else{
  119. uni.setNavigationBarTitle({
  120. title: '添加客户'
  121. });
  122. this.form.estates.push({
  123. estate_id: '',
  124. estate_no: '',
  125. room_no: '',
  126. regionId:{},
  127. region:'',
  128. multiIndex:[],
  129. estate_name: '',
  130. })
  131. }
  132. // wx.enableAlertBeforeUnload({
  133. // message:'还未保存',
  134. // success:()=>{
  135. // console.log('qqqqqqqqqqqqqq')
  136. // }
  137. // })
  138. },
  139. onShow() {
  140. var pages = getCurrentPages();
  141. var currPage = pages[pages.length - 1]; //当前页面
  142. 'estateInfo' in currPage.$vm ? this.form.estates[this.formIndex].estate_name = currPage.$vm.estateInfo.name : ''
  143. 'estateInfo' in currPage.$vm ? this.form.estates[this.formIndex].estate_id = currPage.$vm.estateInfo.id : ''
  144. 'estateInfo' in currPage.$vm ? this.form.estates[this.formIndex].multiIndex = currPage.$vm.estateInfo.multiIndex : ''
  145. },
  146. methods: {
  147. addOrDel(i){
  148. if(i===undefined){
  149. this.form.estates.push({estate_id: '',estate_no: '',room_no: ''})
  150. }else{
  151. if(this.form.estates.length===1)return;
  152. uni.showModal({
  153. title: '提示',
  154. content: '确定要删除吗',
  155. success: (res)=> {
  156. if (res.confirm) {
  157. this.form.estates.splice(i,1)
  158. }
  159. }
  160. });
  161. }
  162. },
  163. areaEvent(data,index=this.formIndex) {
  164. if (data) {
  165. this.form.estates[index].regionId.province_id = data.province.id;
  166. this.form.estates[index].regionId.city_id = data.city.id;
  167. this.form.estates[index].regionId.district_id = data.district.id;
  168. this.form.estates[index].region = [data.province.name, data.city.name, data.district.name].join('')
  169. }
  170. },
  171. areaCancel(){
  172. this.region=''
  173. this.regionId={}
  174. },
  175. estate_noInput(e,index){
  176. this.form.estates[index].estate_no=e.target.value
  177. },
  178. room_noInput(e,index){
  179. this.form.estates[index].room_no=e.target.value
  180. },
  181. uploadHead() {
  182. uni.chooseImage({
  183. count: 1,
  184. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  185. sourceType: ['album', 'camera'], //从相册选择
  186. success: (res) => {
  187. console.log(res);
  188. console.log(JSON.stringify(res.tempFilePaths));
  189. uploadFile({
  190. url: this.$api.upload.file,
  191. filePath: res.tempFilePaths[0],
  192. fileType: 'image',
  193. fileName: ''
  194. }).then(res1 => {
  195. console.log(JSON.parse(res1.data))
  196. if (JSON.parse(res1.data).code === 0) {
  197. this.form.avatar = JSON.parse(res1.data).data.url
  198. }
  199. })
  200. }
  201. });
  202. },
  203. selectEstate(index) {
  204. this.formIndex=index
  205. uni.navigateTo({
  206. url: '/pages/sale/properties/addProperties'
  207. })
  208. },
  209. submit(){
  210. if(this.form.avatar===''){
  211. uni.showToast({
  212. title:'请上传头像',
  213. icon:'none'
  214. })
  215. return
  216. }
  217. if(this.form.name===''){
  218. uni.showToast({
  219. title:'请输入客户姓名',
  220. icon:'none'
  221. })
  222. return
  223. }
  224. if(this.form.mobile===''){
  225. uni.showToast({
  226. title:'请输入手机号',
  227. icon:'none'
  228. })
  229. return
  230. }
  231. if(!(/0?(1)[0-9]{10}/.test(this.form.mobile))){
  232. uni.showToast({
  233. title:'请输入正确的手机号',
  234. icon:'none'
  235. })
  236. return
  237. }
  238. for (let index = 0; index < this.form.estates.length; index++) {
  239. let item=this.form.estates[index]
  240. if(!item.estate_id || !item.estate_no || !item.room_no){
  241. uni.showToast({
  242. title:'请填写完整的楼盘信息',
  243. icon:'none'
  244. })
  245. return
  246. }
  247. }
  248. let data={
  249. avatar:this.form.avatar,
  250. mobile:this.form.mobile,
  251. name:this.form.name,
  252. }
  253. this.form.sale_customer_id?data.sale_customer_id=this.form.sale_customer_id:''
  254. for(let i in this.form.estates){
  255. for (let j in this.form.estates[i]) {
  256. if(j==='estate_id' || j==='estate_no' || j==='room_no'){
  257. let key=`estates[${i}][${j}]`
  258. data[key]=this.form.estates[i][j]
  259. }
  260. }
  261. }
  262. this.$request({
  263. url:this.$api.sale.customer_save,
  264. data:data,
  265. method:'post'
  266. }).then(res=>{
  267. if(res.code===0){
  268. uni.showToast({
  269. title:this.form.sale_customer_id?'编辑成功':'添加成功',
  270. })
  271. }else{
  272. uni.showToast({
  273. title:res.msg,
  274. icon:'none'
  275. })
  276. }
  277. }).catch(rej=>{
  278. uni.showToast({
  279. title:rej,
  280. icon:'none'
  281. })
  282. })
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. .addlp {
  289. width: 606rpx;
  290. height: 90rpx;
  291. border: 1rpx solid #A18353;
  292. border-radius: 10rpx;
  293. font-size: 32rpx;
  294. font-weight: bold;
  295. color: #A18353;
  296. margin-top: 39rpx;
  297. }
  298. .complete {
  299. width: 606rpx;
  300. height: 90rpx;
  301. background: #A18353;
  302. border-radius: 10rpx;
  303. font-size: 32rpx;
  304. font-weight: bold;
  305. color: #FFFFFF;
  306. margin-top: 36rpx;
  307. }
  308. .oinfo {
  309. width: 678rpx;
  310. height: auto;
  311. background: #FEFEFE;
  312. border-radius: 10rpx;
  313. margin: 20rpx auto 0;
  314. padding-bottom: 20rpx;
  315. .curd-btn {
  316. image {
  317. width: 26rpx;
  318. height: 26rpx;
  319. margin-right: 6rpx;
  320. }
  321. font-size: 26rpx;
  322. font-weight: 500;
  323. color: #A18353;
  324. }
  325. }
  326. .linp {
  327. height: 104rpx;
  328. padding: 0 35rpx;
  329. .field {
  330. width: 120rpx;
  331. font-size: 28rpx;
  332. font-weight: 500;
  333. color: #222222;
  334. margin-right: 30rpx;
  335. }
  336. input{
  337. font-size: 28rpx;
  338. }
  339. .val {}
  340. .in_in{
  341. .line_c{
  342. width: 21rpx;
  343. height: 3rpx;
  344. font-weight: bold;
  345. background-color: #494848;
  346. margin-right: 10rpx;
  347. }
  348. }
  349. }
  350. .border_bottom {
  351. border-bottom: 1px solid #EAEAEA;
  352. }
  353. .tbg {
  354. width: 100%;
  355. height: 660rpx;
  356. position: relative;
  357. padding-top: 176rpx;
  358. .ti {
  359. font-size: 36rpx;
  360. font-weight: bold;
  361. color: #FFFFFF;
  362. position: absolute;
  363. top: 75rpx;
  364. left: 36rpx;
  365. }
  366. .bg {
  367. width: 100%;
  368. height: 400rpx;
  369. position: absolute;
  370. top: 0;
  371. left: 0;
  372. z-index: -1;
  373. }
  374. .customerInfo {
  375. width: 678rpx;
  376. height: auto;
  377. background: #fff;
  378. border-radius: 10rpx;
  379. overflow: hidden;
  380. margin: 0 auto 20rpx;
  381. .top {
  382. height: 98rpx;
  383. background: #FCF7EA;
  384. font-size: 28rpx;
  385. font-weight: bold;
  386. color: #D0C9C1;
  387. padding: 36rpx 30rpx;
  388. }
  389. .head {
  390. width: 127rpx;
  391. height: 127rpx;
  392. position: relative;
  393. margin: 32rpx auto;
  394. background-color: #fefefe;
  395. z-index: 2;
  396. .bg {
  397. width: 127rpx;
  398. height: 127rpx;
  399. border-radius: 50%;
  400. }
  401. .camera {
  402. width: 41rpx;
  403. height: 32rpx;
  404. position: absolute;
  405. bottom: 5rpx;
  406. right: -6rpx;
  407. }
  408. }
  409. }
  410. }
  411. </style>