create.vue 11 KB

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