create.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <view class="page">
  3. <view class="form">
  4. <u-form :model="form" ref="uForm">
  5. <u-form-item label-width="150" label="姓名" prop="name" required>
  6. <u-input placeholder="请输入客户姓名" v-model="form.name" type="text"></u-input>
  7. </u-form-item>
  8. <u-form-item label-width="150" label="性别" prop="sex" required>
  9. <u-radio-group v-model="form.sex" active-color="#2979ff">
  10. <u-radio name="male">先生</u-radio>
  11. <u-radio name="female">女士</u-radio>
  12. </u-radio-group>
  13. </u-form-item>
  14. <u-form-item label-width="150" label="意向项目" prop="estate_name" required>
  15. <u-input type="select" :select-open="propertySelectShow" v-model="form.estate_name" placeholder="请选择推荐项目" @click="propertySelectShow = true"></u-input>
  16. <!-- <u-input type="select" :select-open="propertySelectShow" v-model="form.estate_name" placeholder="请选择推荐项目" @click="openEstateList"></u-input> -->
  17. </u-form-item>
  18. <u-form-item v-if="form.phone_type == '2'" label-width="150" label="手机号">
  19. <view @click.native="phoneHandle" style="position: absolute;left: 0;top: 0;width: 40px;height: 40px;"></view>
  20. <u-input placeholder="输前三" v-model="phoneBefore3" type="number" style="display: inline-block;width: 70px;" input-align="right"></u-input>
  21. <view style="display: inline-block;">****</view>
  22. <u-input placeholder="输后四" v-model="phoneAfter4" type="number" style="display: inline-block;width: 70px;"></u-input>
  23. </u-form-item>
  24. <u-form-item v-else label-width="150" label="手机号" prop="phone" required>
  25. <view @click.native="phoneHandle" style="position: absolute;left: 0;top: 0;width: 40px;height: 40px;"></view>
  26. <u-input placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  27. </u-form-item>
  28. <u-form-item label-width="150" label="备注信息" prop="remark" label-position="top">
  29. <u-input placeholder="客户描述说明,如客户意向户型或面积等信息" v-model="form.remark" type="textarea"></u-input>
  30. </u-form-item>
  31. </u-form>
  32. <u-gap height="60"></u-gap>
  33. <u-button type="primary" :diabled="submitButtonDisabled" @click="submitHandle">提交</u-button>
  34. </view>
  35. <!-- 列表选择 -->
  36. <!-- <u-select mode="single-column" :list="propertySelectList" v-model="propertySelectShow" @confirm="propertySelectConfirm"></u-select> -->
  37. <u-select mode="single-column" :list="salerSelectList" v-model="salerSelectShow" @confirm="salerSelectConfirm"></u-select>
  38. <!-- modal -->
  39. <u-modal v-model="submitModalShow" content="请务必仔细确认各项信息是否正确" :show-cancel-button="true" @confirm="submit()"></u-modal>
  40. <u-modal v-model="modalShow" :content="modalContent" :show-cancel-button="true" @cancel="modalCancel()" @confirm="modalConfirm()"></u-modal>
  41. <!-- utoast -->
  42. <u-toast ref="uToast" />
  43. <u-popup v-model="propertySelectShow" mode="center" width="90%" height="100%">
  44. <view class="bwin-popup scoped-estate-popup">
  45. <view class="scoped-popup-header-input">
  46. <u-input class="input" v-model="curEstateName" placeholder="没找到楼盘??点这输入关键字搜索"></u-input>
  47. <view class="b" @click="getEstateList">搜索</view>
  48. </view>
  49. <scroll-view :scroll-y="true" class="popup-body">
  50. <view class="scoped-estate-list">
  51. <view v-for="(item, index) in estateList" :class="eIds.indexOf(item.id) > -1 ? 'sel-item cur' : 'sel-item'" @click="listItemHandle(item)" :key="index">
  52. <view class="sel-left">
  53. <image class="img" :src="item.pri_image" mode="aspectFill"></image>
  54. </view>
  55. <view class="sel-right">
  56. <view class="p1">{{item.estate_name}}</view>
  57. <view class="p2">
  58. <u-tag
  59. :text="areaTypeObj[item.area_type]"
  60. :type="'success'"
  61. size="mini"
  62. ></u-tag>
  63. </view>
  64. <view class="p3" v-if="userInfo2.auth_state == 1">带看需收集:{{ item.report_visit }}</view>
  65. <view class="p3" v-if="userInfo2.auth_state == 1">报备/带看保护期:{{ item.report_lock }}天/{{ item.lead_lock }}天</view>
  66. </view>
  67. </view>
  68. </view>
  69. </scroll-view>
  70. <view class="popup-footer" style="position: fixed;bottom: 12rpx;">
  71. <u-button size="medium" @click="clearListHandle">清空</u-button>
  72. <u-button size="medium" type="primary" @click="saveListHandle">确定</u-button>
  73. </view>
  74. </view>
  75. </u-popup>
  76. </view>
  77. </template>
  78. <script>
  79. import { arrToObj } from '@/utils'
  80. export default {
  81. data() {
  82. return {
  83. form: {
  84. name: null,
  85. phone: null,
  86. sex: 'male',
  87. remark: null,
  88. phone_type: '1',
  89. saler_id: null,
  90. saler_name: null
  91. },
  92. eIds: [],
  93. eArr: [],
  94. phoneBefore3: '',
  95. phoneAfter4: '',
  96. customer_id: null,
  97. submitButtonDisabled: true,
  98. rules: {
  99. name: [
  100. {
  101. required: true,
  102. message: '姓名不得为空',
  103. trigger: ['change', 'blur']
  104. },
  105. ],
  106. phone: [
  107. {
  108. required: true,
  109. message: '手机号不得为空',
  110. trigger: ['change', 'blur']
  111. },
  112. // 11个字符判断
  113. {
  114. len: 11,
  115. message: '手机号格式不正确',
  116. trigger: ['change', 'blur']
  117. },
  118. ],
  119. estate_name: [
  120. {
  121. required: true,
  122. message: '意向项目不能为空',
  123. trigger: ['change']
  124. },
  125. ]
  126. },
  127. propertySelectShow: false,
  128. propertySelectList: [],
  129. estateList: [],
  130. areaTypeObj: {},
  131. userInfo2: {},
  132. curEstateName: '',
  133. salerSelectShow: false,
  134. salerSelectList: [],
  135. submitModalShow: false,
  136. modalShow: false,
  137. modalContent: ''
  138. };
  139. },
  140. onLoad(data) {
  141. const that = this
  142. const eventChannel = that.getOpenerEventChannel(); // that 需指向 this
  143. // 监听data事件,获取上一页面通过eventChannel.emit传送到当前页面的数据
  144. if (eventChannel.on) {
  145. eventChannel.on('data', data => {
  146. if (data.info && data.info.estate_id && data.info.estate_name) {
  147. that.form.estate_name = data.info.estate_name
  148. that.eIds = [data.info.estate_id]
  149. that.eArr = [
  150. {
  151. estate_id: data.info.estate_id,
  152. estate_name: data.info.estate_name,
  153. }
  154. ]
  155. }
  156. })
  157. }
  158. },
  159. created () {
  160. this.userInfo2 = uni.getStorageSync('MD_userInfo2')
  161. const dictObj = uni.getStorageSync('MD_dict')
  162. this.areaTypeObj = arrToObj(dictObj.area_type)
  163. uni.api.estate.apiestatelist({page_size: 100, report_open: 1, is_inner: 2}).then(res => {
  164. let list = res.list || []
  165. this.estateList = [...list]
  166. })
  167. },
  168. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  169. onReady() {
  170. this.$refs.uForm.setRules(this.rules);
  171. },
  172. methods: {
  173. phoneHandle () {
  174. let p = this.form.phone
  175. p = p.replace(/ /g, '')
  176. this.form.phone = p
  177. this.form = {...this.form}
  178. },
  179. getEstateList () {
  180. uni.api.estate.apiestatelist({page_size: 100, report_open: 1, is_inner: 2, estate_name: this.curEstateName}).then(res => {
  181. let list = res.list || []
  182. this.estateList = [...list]
  183. })
  184. },
  185. listItemHandle (val) {
  186. let eIds = [...this.eIds]
  187. let eArr = [...this.eArr]
  188. let cIndex = eIds.indexOf(val.estate_id)
  189. if (cIndex > -1 ) {
  190. eIds.splice(cIndex,1)
  191. eArr.splice(cIndex,1)
  192. } else {
  193. eIds.push(val.estate_id)
  194. eArr.push(val)
  195. }
  196. this.eIds = [...eIds]
  197. this.eArr = [...eArr]
  198. },
  199. clearListHandle () {
  200. this.propertySelectShow = false
  201. this.eIds = []
  202. this.eArr = []
  203. this.form.estate_name = ''
  204. },
  205. saveListHandle () {
  206. let errMsg = ''
  207. let eNames = this.eArr.map(item => {
  208. if (item.phone_type == '2') {
  209. errMsg = item.estate_name
  210. }
  211. return item.estate_name
  212. })
  213. this.form.estate_name = eNames.join(',')
  214. if (this.eArr.length === 1 && this.eArr[0].phone_type == '2') {
  215. this.form.phone_type = '2'
  216. } else {
  217. this.form.phone_type = '1'
  218. }
  219. if (errMsg && this.eArr.length > 1) {
  220. uni.$msg(`${errMsg}是前三后四报备项目,请单独报备`)
  221. } else {
  222. this.propertySelectShow = false
  223. }
  224. },
  225. // // 选择所属项目回调
  226. // propertySelectConfirm(e) {
  227. // e.map((val, index) => {
  228. // this.form.estate_id = val.value;
  229. // this.form.estate_name = val.label;
  230. // });
  231. // },
  232. // openEstateList () {
  233. // uni.navigateTo({
  234. // url: `/pages/estate/list?eid=${this.form.estate_id}&ename=${this.form.estate_name}`
  235. // })
  236. // },
  237. submitHandle() {
  238. const that = this
  239. this.$refs.uForm.validate(valid => {
  240. if (valid) {
  241. // 验证成功
  242. let params = {
  243. phone_type: that.form.phone_type || '1',
  244. name: that.form.name,
  245. phone: that.form.phone,
  246. sex: that.form.sex,
  247. remark: that.form.remark,
  248. // estate_id: that.form.estate_id,
  249. // estate_name: that.form.estate_name,
  250. }
  251. if (params.phone_type == '2') {
  252. if (that.phoneBefore3 && that.phoneAfter4) {
  253. params.phone = `${that.phoneBefore3}****${that.phoneAfter4}`
  254. } else {
  255. that.$refs.uToast.show({
  256. title: '请输入报备手机号的前三后四',
  257. type: 'warning'
  258. });
  259. return
  260. }
  261. }
  262. this.eArr.forEach((eObj, i) => {
  263. let newParams = {...params}
  264. newParams.estate_id = eObj.estate_id
  265. newParams.estate_name = eObj.estate_name
  266. uni.api.estate.apireportadd(newParams).then(res => {
  267. if (i === this.eArr.length - 1) {
  268. uni.$msgConfirm('报备成功,是否前往报备列表?', () => {
  269. uni.navigateTo({
  270. url: '/pages/agent/recommend/list'
  271. })
  272. }, () => {
  273. this.form = {
  274. name: null,
  275. phone: null,
  276. sex: 'male',
  277. remark: null,
  278. }
  279. })
  280. }
  281. })
  282. })
  283. } else {
  284. console.log('验证失败');
  285. }
  286. });
  287. },
  288. // 获取手机号
  289. getPhoneNumber: function(e) {
  290. // 点击获取手机号码按钮
  291. let _that = this;
  292. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  293. _that.$refs.uToast.show({
  294. title: '您可以在个人设置中再次绑定',
  295. type: 'warning'
  296. });
  297. setTimeout(() => {
  298. _that.reLunchUser();
  299. }, 1500);
  300. return; // 即用户拒绝授权
  301. }
  302. console.log(e.detail.errMsg);
  303. console.log(e.detail.iv);
  304. console.log(e.detail.encryptedData);
  305. let iv = e.detail.iv;
  306. let encryptedData = e.detail.encryptedData;
  307. // 不是登陆完第一时间授权
  308. wx.login({
  309. success(res) {
  310. if (res.code) {
  311. // 设置用户手机号
  312. _that.setUserPhoneNumber(encryptedData, iv, res.code);
  313. } else {
  314. this.$refs.uToast.show({
  315. title: res.errMsg,
  316. type: 'warning'
  317. });
  318. console.log('登录失败!' + res.errMsg);
  319. }
  320. }
  321. });
  322. },
  323. // 以下是工具函数
  324. // 关闭键盘
  325. hideKeyboard() {
  326. uni.hideKeyboard();
  327. },
  328. // 格式化日期的月份或天数的显示(小于10,在前面增加0)
  329. getFormatDate(value) {
  330. if (value == undefined || value == '') {
  331. return '';
  332. }
  333. var str = value;
  334. if (parseInt(value) < 10) {
  335. str = '0' + value;
  336. }
  337. return str;
  338. }
  339. }
  340. };
  341. </script>
  342. <style lang="scss">
  343. .page {
  344. padding: 20rpx;
  345. background-color: #ffffff;
  346. }
  347. .form {
  348. border-radius: 10rpx;
  349. padding: 0 40rpx;
  350. }
  351. .popup-body {
  352. .tips-title {
  353. font-size: $u-p;
  354. margin-bottom: 20rpx;
  355. }
  356. .tips-content {
  357. font-size: $u-p2;
  358. color: $u-tips-color;
  359. margin-bottom: 60rpx;
  360. }
  361. }
  362. .id_card {
  363. color: #606266;
  364. width: 100%;
  365. height: 350rpx;
  366. display: flex;
  367. flex-direction: column;
  368. align-items: center;
  369. justify-content: center;
  370. background-color: #f4f5f6;
  371. font-size: $u-p2;
  372. }
  373. .footer {
  374. position: absolute;
  375. text-align: center;
  376. bottom: 40rpx;
  377. font-size: $u-p2;
  378. .agreement {
  379. color: $u-type-error;
  380. }
  381. }
  382. .slot-content {
  383. font-size: 28rpx;
  384. color: $u-content-color;
  385. padding: 20rpx;
  386. }
  387. .scoped-estate-list {
  388. .sel-item {
  389. display: flex;
  390. border-bottom: 1PX solid #dcdcdc;
  391. padding: 20rpx;
  392. &.cur {
  393. background: #369af7;
  394. border-radius: 10rpx;
  395. overflow: hidden;
  396. .img {
  397. opacity: .6;
  398. }
  399. .p1 {
  400. color: #fff;
  401. }
  402. .p3 {
  403. color: #fff;
  404. }
  405. }
  406. }
  407. .sel-left {
  408. width: 180rpx;
  409. border-radius: 10rpx;
  410. .img {
  411. width: 180rpx;
  412. height: 120rpx;
  413. border-radius: 10rpx;
  414. }
  415. }
  416. .sel-right {
  417. // width: 450rpx;
  418. margin-left: 20rpx;
  419. .p1 {
  420. font-size: 30rpx;
  421. font-weight: bold;
  422. margin-bottom: 10rpx;
  423. }
  424. .p2 {
  425. margin-bottom: 10rpx;
  426. }
  427. .p3 {
  428. color: #369af7;
  429. font-size: 24rpx;
  430. font-weight: bold;
  431. }
  432. }
  433. }
  434. .scoped-estate-popup {
  435. height: 100%;
  436. padding-bottom: 100rpx;
  437. .popup-body {
  438. box-sizing: border-box;
  439. border-bottom: 1PX solid #dcdcdc;
  440. }
  441. }
  442. .scoped-popup-header-input {
  443. position: fixed;
  444. width: 90%;
  445. display: flex;
  446. border-bottom: 1PX solid #dcdcdc;
  447. .input {
  448. flex: 1;
  449. padding-left: 20rpx;
  450. height: 80rpx;
  451. .u-input__input {
  452. height: 80rpx;
  453. }
  454. }
  455. .b {
  456. width: 200rpx;
  457. height: 80rpx;
  458. line-height: 80rpx;
  459. background: #2d8cf0;
  460. color: #fff;
  461. text-align: center;
  462. margin-left: 20rpx;
  463. }
  464. }
  465. </style>