create.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. if (data.info && data.info.name) {
  157. that.form.name = data.info.name
  158. that.form.phone = data.info.phone
  159. that.form.sex = data.info.sex
  160. that.form.remark = data.info.demand
  161. }
  162. })
  163. }
  164. },
  165. created () {
  166. this.userInfo2 = uni.getStorageSync('MD_userInfo2')
  167. const dictObj = uni.getStorageSync('MD_dict')
  168. this.areaTypeObj = arrToObj(dictObj.area_type)
  169. uni.api.estate.apiestatelist({page_size: 100, report_open: 1, is_pub: 1}).then(res => {
  170. let list = res.list || []
  171. this.estateList = [...list]
  172. })
  173. },
  174. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  175. onReady() {
  176. this.$refs.uForm.setRules(this.rules);
  177. },
  178. methods: {
  179. phoneHandle () {
  180. let p = this.form.phone
  181. p = p.replace(/ /g, '')
  182. this.form.phone = p
  183. this.form = {...this.form}
  184. },
  185. getEstateList () {
  186. uni.api.estate.apiestatelist({page_size: 100, report_open: 1, is_pub: 1, estate_name: this.curEstateName}).then(res => {
  187. let list = res.list || []
  188. this.estateList = [...list]
  189. })
  190. },
  191. listItemHandle (val) {
  192. let eIds = [...this.eIds]
  193. let eArr = [...this.eArr]
  194. let cIndex = eIds.indexOf(val.estate_id)
  195. if (cIndex > -1 ) {
  196. eIds.splice(cIndex,1)
  197. eArr.splice(cIndex,1)
  198. } else {
  199. eIds.push(val.estate_id)
  200. eArr.push(val)
  201. }
  202. this.eIds = [...eIds]
  203. this.eArr = [...eArr]
  204. },
  205. clearListHandle () {
  206. this.propertySelectShow = false
  207. this.eIds = []
  208. this.eArr = []
  209. this.form.estate_name = ''
  210. },
  211. saveListHandle () {
  212. let errMsg = ''
  213. let eNames = this.eArr.map(item => {
  214. if (item.phone_type == '2') {
  215. errMsg = item.estate_name
  216. }
  217. return item.estate_name
  218. })
  219. this.form.estate_name = eNames.join(',')
  220. if (this.eArr.length === 1 && this.eArr[0].phone_type == '2') {
  221. this.form.phone_type = '2'
  222. } else {
  223. this.form.phone_type = '1'
  224. }
  225. if (errMsg && this.eArr.length > 1) {
  226. uni.$msg(`${errMsg}是前三后四报备项目,请单独报备`)
  227. } else {
  228. this.propertySelectShow = false
  229. }
  230. },
  231. // // 选择所属项目回调
  232. // propertySelectConfirm(e) {
  233. // e.map((val, index) => {
  234. // this.form.estate_id = val.value;
  235. // this.form.estate_name = val.label;
  236. // });
  237. // },
  238. // openEstateList () {
  239. // uni.navigateTo({
  240. // url: `/pages/estate/list?eid=${this.form.estate_id}&ename=${this.form.estate_name}`
  241. // })
  242. // },
  243. submitHandle() {
  244. const that = this
  245. this.$refs.uForm.validate(valid => {
  246. if (valid) {
  247. // 验证成功
  248. let params = {
  249. phone_type: that.form.phone_type || '1',
  250. name: that.form.name,
  251. phone: that.form.phone.replace(/\s+/g, ''),
  252. sex: that.form.sex,
  253. remark: that.form.remark,
  254. // estate_id: that.form.estate_id,
  255. // estate_name: that.form.estate_name,
  256. }
  257. if (params.phone_type == '2') {
  258. if (that.phoneBefore3 && that.phoneAfter4) {
  259. params.phone = `${that.phoneBefore3}****${that.phoneAfter4}`
  260. } else {
  261. that.$refs.uToast.show({
  262. title: '请输入报备手机号的前三后四',
  263. type: 'warning'
  264. });
  265. return
  266. }
  267. }
  268. this.eArr.forEach((eObj, i) => {
  269. let newParams = {...params}
  270. newParams.estate_id = eObj.estate_id
  271. newParams.estate_name = eObj.estate_name
  272. uni.api.estate.apireportadd(newParams).then(res => {
  273. if (i === this.eArr.length - 1) {
  274. uni.$msgConfirm('报备成功,是否前往报备列表?', () => {
  275. uni.navigateTo({
  276. url: '/pages/agent/recommend/list'
  277. })
  278. }, () => {
  279. this.form = {
  280. name: null,
  281. phone: null,
  282. sex: 'male',
  283. remark: null,
  284. }
  285. })
  286. }
  287. })
  288. })
  289. } else {
  290. console.log('验证失败');
  291. }
  292. });
  293. },
  294. // 获取手机号
  295. getPhoneNumber: function(e) {
  296. // 点击获取手机号码按钮
  297. let _that = this;
  298. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  299. _that.$refs.uToast.show({
  300. title: '您可以在个人设置中再次绑定',
  301. type: 'warning'
  302. });
  303. setTimeout(() => {
  304. _that.reLunchUser();
  305. }, 1500);
  306. return; // 即用户拒绝授权
  307. }
  308. console.log(e.detail.errMsg);
  309. console.log(e.detail.iv);
  310. console.log(e.detail.encryptedData);
  311. let iv = e.detail.iv;
  312. let encryptedData = e.detail.encryptedData;
  313. // 不是登陆完第一时间授权
  314. wx.login({
  315. success(res) {
  316. if (res.code) {
  317. // 设置用户手机号
  318. _that.setUserPhoneNumber(encryptedData, iv, res.code);
  319. } else {
  320. this.$refs.uToast.show({
  321. title: res.errMsg,
  322. type: 'warning'
  323. });
  324. console.log('登录失败!' + res.errMsg);
  325. }
  326. }
  327. });
  328. },
  329. // 以下是工具函数
  330. // 关闭键盘
  331. hideKeyboard() {
  332. uni.hideKeyboard();
  333. },
  334. // 格式化日期的月份或天数的显示(小于10,在前面增加0)
  335. getFormatDate(value) {
  336. if (value == undefined || value == '') {
  337. return '';
  338. }
  339. var str = value;
  340. if (parseInt(value) < 10) {
  341. str = '0' + value;
  342. }
  343. return str;
  344. }
  345. }
  346. };
  347. </script>
  348. <style lang="scss">
  349. .page {
  350. padding: 20rpx;
  351. background-color: #ffffff;
  352. }
  353. .form {
  354. border-radius: 10rpx;
  355. padding: 0 40rpx;
  356. }
  357. .popup-body {
  358. .tips-title {
  359. font-size: $u-p;
  360. margin-bottom: 20rpx;
  361. }
  362. .tips-content {
  363. font-size: $u-p2;
  364. color: $u-tips-color;
  365. margin-bottom: 60rpx;
  366. }
  367. }
  368. .id_card {
  369. color: #606266;
  370. width: 100%;
  371. height: 350rpx;
  372. display: flex;
  373. flex-direction: column;
  374. align-items: center;
  375. justify-content: center;
  376. background-color: #f4f5f6;
  377. font-size: $u-p2;
  378. }
  379. .footer {
  380. position: absolute;
  381. text-align: center;
  382. bottom: 40rpx;
  383. font-size: $u-p2;
  384. .agreement {
  385. color: $u-type-error;
  386. }
  387. }
  388. .slot-content {
  389. font-size: 28rpx;
  390. color: $u-content-color;
  391. padding: 20rpx;
  392. }
  393. .scoped-estate-list {
  394. .sel-item {
  395. display: flex;
  396. border-bottom: 1PX solid #dcdcdc;
  397. padding: 20rpx;
  398. &.cur {
  399. background: #369af7;
  400. border-radius: 10rpx;
  401. overflow: hidden;
  402. .img {
  403. opacity: .6;
  404. }
  405. .p1 {
  406. color: #fff;
  407. }
  408. .p3 {
  409. color: #fff;
  410. }
  411. }
  412. }
  413. .sel-left {
  414. width: 180rpx;
  415. border-radius: 10rpx;
  416. .img {
  417. width: 180rpx;
  418. height: 120rpx;
  419. border-radius: 10rpx;
  420. }
  421. }
  422. .sel-right {
  423. // width: 450rpx;
  424. margin-left: 20rpx;
  425. .p1 {
  426. font-size: 30rpx;
  427. font-weight: bold;
  428. margin-bottom: 10rpx;
  429. }
  430. .p2 {
  431. margin-bottom: 10rpx;
  432. }
  433. .p3 {
  434. color: #369af7;
  435. font-size: 24rpx;
  436. font-weight: bold;
  437. }
  438. }
  439. }
  440. .scoped-estate-popup {
  441. height: 100%;
  442. padding-bottom: 100rpx;
  443. .popup-body {
  444. box-sizing: border-box;
  445. border-bottom: 1PX solid #dcdcdc;
  446. }
  447. }
  448. .scoped-popup-header-input {
  449. position: fixed;
  450. width: 90%;
  451. display: flex;
  452. border-bottom: 1PX solid #dcdcdc;
  453. .input {
  454. flex: 1;
  455. padding-left: 20rpx;
  456. height: 80rpx;
  457. .u-input__input {
  458. height: 80rpx;
  459. }
  460. }
  461. .b {
  462. width: 200rpx;
  463. height: 80rpx;
  464. line-height: 80rpx;
  465. background: #2d8cf0;
  466. color: #fff;
  467. text-align: center;
  468. margin-left: 20rpx;
  469. }
  470. }
  471. </style>