create.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. <u-input placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  16. </u-form-item>
  17. <u-form-item label-width="150" label="备注信息" prop="remark" label-position="top">
  18. <u-input placeholder="客户描述说明,如客户意向户型或面积等信息" v-model="form.remark" type="textarea"></u-input>
  19. </u-form-item>
  20. <u-form-item label-width="150" label="意向项目" prop="estate_name" required>
  21. <u-input type="select" :select-open="propertySelectShow" v-model="form.estate_name" placeholder="请选择推荐项目" @click="propertySelectShow = true"></u-input>
  22. <!-- <u-input type="select" :select-open="propertySelectShow" v-model="form.estate_name" placeholder="请选择推荐项目" @click="openEstateList"></u-input> -->
  23. </u-form-item>
  24. <!-- <u-form-item v-show="form.estate_id !== null" label-width="180" label="指定置业顾问" prop="saler_id">
  25. <u-input type="select" :select-open="salerSelectShow" v-model="form.saler_name" placeholder="非必选" @click="salerSelectShow = true"></u-input>
  26. </u-form-item> -->
  27. </u-form>
  28. <u-gap height="60"></u-gap>
  29. <u-button type="primary" :diabled="submitButtonDisabled" @click="submitHandle">提交</u-button>
  30. </view>
  31. <!-- 列表选择 -->
  32. <!-- <u-select mode="single-column" :list="propertySelectList" v-model="propertySelectShow" @confirm="propertySelectConfirm"></u-select> -->
  33. <u-select mode="single-column" :list="salerSelectList" v-model="salerSelectShow" @confirm="salerSelectConfirm"></u-select>
  34. <!-- modal -->
  35. <u-modal v-model="submitModalShow" content="请务必仔细确认各项信息是否正确" :show-cancel-button="true" @confirm="submit()"></u-modal>
  36. <u-modal v-model="modalShow" :content="modalContent" :show-cancel-button="true" @cancel="modalCancel()" @confirm="modalConfirm()"></u-modal>
  37. <!-- utoast -->
  38. <u-toast ref="uToast" />
  39. <u-popup v-model="propertySelectShow" mode="center" width="90%" height="100%">
  40. <view class="bwin-popup scoped-estate-popup">
  41. <view class="scoped-popup-header-input">
  42. <u-input class="input" v-model="curEstateName" placeholder="请输入关键字搜索楼盘"></u-input>
  43. <view class="b" @click="getEstateList">搜索</view>
  44. </view>
  45. <view class="popup-body">
  46. <view class="scoped-estate-list">
  47. <view v-for="(item, index) in estateList" :class="form.estate_id == item.id ? 'sel-item cur' : 'sel-item'" @click="listItemHandle(item)" :key="index">
  48. <view class="sel-left">
  49. <image class="img" :src="item.pri_image" mode="aspectFill"></image>
  50. </view>
  51. <view class="sel-right">
  52. <view class="p1">{{item.estate_name}}</view>
  53. <view class="p2">
  54. <u-tag
  55. :text="areaTypeObj[item.area_type]"
  56. :type="'success'"
  57. size="mini"
  58. ></u-tag>
  59. </view>
  60. <view class="p3" v-if="userInfo2.auth_state == 1">带看需收集:{{ item.report_visit }}</view>
  61. <view class="p3" v-if="userInfo2.auth_state == 1">报备/带看保护期:{{ item.report_lock }}天/{{ item.lead_lock }}</view>
  62. <!-- <view class="p3" v-if="userInfo2.auth_state == 1">预计奖励:{{ item.brokerage }}</view> -->
  63. </view>
  64. </view>
  65. </view>
  66. <view class="popup-footer" style="position: fixed;bottom: 10rpx;">
  67. <u-button size="medium" @click="propertySelectShow = false">关闭</u-button>
  68. <u-button size="medium" type="primary" @click="propertySelectShow = false">确定</u-button>
  69. </view>
  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}).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. getEstateList () {
  172. uni.api.estate.apiestatelist({page_size: 100, report_open: 1, estate_name: this.curEstateName}).then(res => {
  173. let list = res.list || []
  174. this.estateList = [...list]
  175. })
  176. },
  177. listItemHandle (val) {
  178. this.form.estate_id = val.estate_id;
  179. this.form.estate_name = val.estate_name;
  180. },
  181. // 选择所属项目回调
  182. propertySelectConfirm(e) {
  183. e.map((val, index) => {
  184. this.form.estate_id = val.value;
  185. this.form.estate_name = val.label;
  186. });
  187. },
  188. // openEstateList () {
  189. // uni.navigateTo({
  190. // url: `/pages/estate/list?eid=${this.form.estate_id}&ename=${this.form.estate_name}`
  191. // })
  192. // },
  193. submitHandle() {
  194. const that = this
  195. this.$refs.uForm.validate(valid => {
  196. if (valid) {
  197. // 验证成功
  198. uni.api.estate.apireportadd({
  199. phone_type: 1,
  200. name: that.form.name,
  201. phone: that.form.phone,
  202. sex: that.form.sex,
  203. remark: that.form.remark,
  204. estate_id: that.form.estate_id,
  205. estate_name: that.form.estate_name,
  206. }).then(res => {
  207. uni.$msgConfirm('报备成功,是否前往报备列表?', () => {
  208. uni.navigateTo({
  209. url: '/pages/agent/recommend/list'
  210. })
  211. }, () => {
  212. this.form = {
  213. name: null,
  214. phone: null,
  215. sex: 'male',
  216. remark: null,
  217. estate_id: null,
  218. estate_name: null,
  219. }
  220. })
  221. })
  222. } else {
  223. console.log('验证失败');
  224. }
  225. });
  226. },
  227. // 获取手机号
  228. getPhoneNumber: function(e) {
  229. // 点击获取手机号码按钮
  230. let _that = this;
  231. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  232. _that.$refs.uToast.show({
  233. title: '您可以在个人设置中再次绑定',
  234. type: 'warning'
  235. });
  236. setTimeout(() => {
  237. _that.reLunchUser();
  238. }, 1500);
  239. return; // 即用户拒绝授权
  240. }
  241. console.log(e.detail.errMsg);
  242. console.log(e.detail.iv);
  243. console.log(e.detail.encryptedData);
  244. let iv = e.detail.iv;
  245. let encryptedData = e.detail.encryptedData;
  246. // 不是登陆完第一时间授权
  247. wx.login({
  248. success(res) {
  249. if (res.code) {
  250. // 设置用户手机号
  251. _that.setUserPhoneNumber(encryptedData, iv, res.code);
  252. } else {
  253. this.$refs.uToast.show({
  254. title: res.errMsg,
  255. type: 'warning'
  256. });
  257. console.log('登录失败!' + res.errMsg);
  258. }
  259. }
  260. });
  261. },
  262. // 以下是工具函数
  263. // 关闭键盘
  264. hideKeyboard() {
  265. uni.hideKeyboard();
  266. },
  267. // 格式化日期的月份或天数的显示(小于10,在前面增加0)
  268. getFormatDate(value) {
  269. if (value == undefined || value == '') {
  270. return '';
  271. }
  272. var str = value;
  273. if (parseInt(value) < 10) {
  274. str = '0' + value;
  275. }
  276. return str;
  277. }
  278. }
  279. };
  280. </script>
  281. <style lang="scss">
  282. .page {
  283. padding: 20rpx;
  284. background-color: #ffffff;
  285. }
  286. .form {
  287. border-radius: 10rpx;
  288. padding: 0 40rpx;
  289. }
  290. .popup-body {
  291. .tips-title {
  292. font-size: $u-p;
  293. margin-bottom: 20rpx;
  294. }
  295. .tips-content {
  296. font-size: $u-p2;
  297. color: $u-tips-color;
  298. margin-bottom: 60rpx;
  299. }
  300. }
  301. .id_card {
  302. color: #606266;
  303. width: 100%;
  304. height: 350rpx;
  305. display: flex;
  306. flex-direction: column;
  307. align-items: center;
  308. justify-content: center;
  309. background-color: #f4f5f6;
  310. font-size: $u-p2;
  311. }
  312. .footer {
  313. position: absolute;
  314. text-align: center;
  315. bottom: 40rpx;
  316. font-size: $u-p2;
  317. .agreement {
  318. color: $u-type-error;
  319. }
  320. }
  321. .slot-content {
  322. font-size: 28rpx;
  323. color: $u-content-color;
  324. padding: 20rpx;
  325. }
  326. .scoped-estate-list {
  327. .sel-item {
  328. display: flex;
  329. border-bottom: 1PX solid #dcdcdc;
  330. padding: 20rpx;
  331. &.cur {
  332. background: #369af7;
  333. border-radius: 10rpx;
  334. overflow: hidden;
  335. .img {
  336. opacity: .6;
  337. }
  338. .p1 {
  339. color: #fff;
  340. }
  341. .p3 {
  342. color: #fff;
  343. }
  344. }
  345. }
  346. .sel-left {
  347. width: 180rpx;
  348. border-radius: 10rpx;
  349. .img {
  350. width: 180rpx;
  351. height: 120rpx;
  352. border-radius: 10rpx;
  353. }
  354. }
  355. .sel-right {
  356. // width: 450rpx;
  357. margin-left: 20rpx;
  358. .p1 {
  359. font-size: 30rpx;
  360. font-weight: bold;
  361. margin-bottom: 10rpx;
  362. }
  363. .p2 {
  364. margin-bottom: 10rpx;
  365. }
  366. .p3 {
  367. color: #369af7;
  368. font-size: 24rpx;
  369. font-weight: bold;
  370. }
  371. }
  372. }
  373. .scoped-estate-popup {
  374. height: 100%;
  375. padding-bottom: 100rpx;
  376. .popup-body {
  377. }
  378. }
  379. .scoped-popup-header-input {
  380. position: fixed;
  381. width: 90%;
  382. display: flex;
  383. .input {
  384. flex: 1;
  385. padding-left: 20rpx;
  386. height: 80rpx;
  387. }
  388. .b {
  389. width: 200rpx;
  390. height: 80rpx;
  391. line-height: 80rpx;
  392. background: #2d8cf0;
  393. color: #fff;
  394. text-align: center;
  395. margin-left: 20rpx;
  396. }
  397. }
  398. </style>