create.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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="realname">
  18. <u-input placeholder="请输入真实姓名" v-model="form.realname" type="text"></u-input>
  19. </u-form-item>
  20. <u-form-item label-width="150" label="备注信息" prop="remark" label-position="top">
  21. <u-input placeholder="客户描述说明,如客户意向户型或面积等信息" v-model="form.remark" type="textarea"></u-input>
  22. </u-form-item>
  23. </u-form>
  24. <u-gap height="60"></u-gap>
  25. <u-button type="primary" :diabled="submitButtonDisabled" @click="submitHandle">提交</u-button>
  26. </view>
  27. <!-- 列表选择 -->
  28. <u-select mode="single-column" :list="propertySelectList" v-model="propertySelectShow" @confirm="propertySelectConfirm"></u-select>
  29. <u-select mode="single-column" :list="salerSelectList" v-model="salerSelectShow" @confirm="salerSelectConfirm"></u-select>
  30. <!-- modal -->
  31. <u-modal v-model="submitModalShow" content="请务必仔细确认各项信息是否正确" :show-cancel-button="true" @confirm="submit()"></u-modal>
  32. <u-modal v-model="modalShow" :content="modalContent" :show-cancel-button="true" @cancel="modalCancel()" @confirm="modalConfirm()"></u-modal>
  33. <!-- utoast -->
  34. <u-toast ref="uToast" />
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. isEdit: false,
  42. form: {
  43. name: null,
  44. realname: null,
  45. phone: null,
  46. sex: 'male',
  47. remark: null,
  48. estate_id: null,
  49. estate_name: null,
  50. saler_id: null,
  51. saler_name: null
  52. },
  53. customer_id: null,
  54. submitButtonDisabled: true,
  55. rules: {
  56. name: [
  57. {
  58. required: true,
  59. message: '姓名不得为空',
  60. trigger: ['change', 'blur']
  61. },
  62. ],
  63. phone: [
  64. {
  65. required: true,
  66. message: '手机号不得为空',
  67. trigger: ['change', 'blur']
  68. },
  69. // 11个字符判断
  70. {
  71. len: 11,
  72. message: '手机号格式不正确',
  73. trigger: ['change', 'blur']
  74. },
  75. ],
  76. estate_name: [
  77. {
  78. required: true,
  79. message: '意向项目不能为空',
  80. trigger: ['change']
  81. },
  82. ]
  83. },
  84. propertySelectShow: false,
  85. propertySelectList: [],
  86. salerSelectShow: false,
  87. salerSelectList: [],
  88. submitModalShow: false,
  89. modalShow: false,
  90. modalContent: ''
  91. };
  92. },
  93. onLoad(data) {
  94. const that = this
  95. const eventChannel = that.getOpenerEventChannel(); // that 需指向 this
  96. // 监听data事件,获取上一页面通过eventChannel.emit传送到当前页面的数据
  97. if (eventChannel.on) {
  98. eventChannel.on('data', data => {
  99. if (data) {
  100. that.form.name = data.info.name;
  101. that.form.realname = data.info.realname;
  102. that.form.phone = data.info.phone;
  103. that.form.sex = data.info.sex;
  104. that.form.remark = data.info.demand;
  105. that.form.id = data.info.id;
  106. that.isEdit = true
  107. wx.setNavigationBarTitle({
  108. title: '编辑客户-' + data.info.name
  109. })
  110. }
  111. })
  112. }
  113. },
  114. created () {
  115. },
  116. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  117. onReady() {
  118. this.$refs.uForm.setRules(this.rules);
  119. },
  120. methods: {
  121. // 选择所属项目回调
  122. propertySelectConfirm(e) {
  123. e.map((val, index) => {
  124. this.form.estate_id = val.value;
  125. this.form.estate_name = val.label;
  126. });
  127. },
  128. submitHandle() {
  129. const that = this
  130. this.$refs.uForm.validate(valid => {
  131. if (valid) {
  132. // 验证成功
  133. let apiStr = 'apicustomeradd'
  134. let params = {
  135. phone_type: 1,
  136. name: that.form.name,
  137. realname: that.form.realname,
  138. phone: that.form.phone.replace(/\s+/g, ''),
  139. sex: that.form.sex,
  140. demand: that.form.remark,
  141. }
  142. if(that.isEdit) {
  143. apiStr = 'apicustomeredit'
  144. params.id = that.form.id
  145. }
  146. uni.api.cust[apiStr](params).then(res => {
  147. if (that.isEdit) {
  148. uni.$msgConfirm('编辑成功', () => {
  149. uni.reLaunch({
  150. url: '/pages/cust/list'
  151. })
  152. }, () => {
  153. uni.reLaunch({
  154. url: '/pages/cust/list'
  155. })
  156. })
  157. } else {
  158. uni.$msgConfirm('添加成功,是否前往客户列表?', () => {
  159. uni.reLaunch({
  160. url: '/pages/cust/list'
  161. })
  162. }, () => {
  163. this.form = {
  164. name: null,
  165. realname: null,
  166. phone: null,
  167. sex: 'male',
  168. remark: null,
  169. estate_id: null,
  170. estate_name: null,
  171. }
  172. })
  173. }
  174. })
  175. } else {
  176. console.log('验证失败');
  177. }
  178. });
  179. },
  180. // 获取手机号
  181. getPhoneNumber: function(e) {
  182. // 点击获取手机号码按钮
  183. let _that = this;
  184. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  185. _that.$refs.uToast.show({
  186. title: '您可以在个人设置中再次绑定',
  187. type: 'warning'
  188. });
  189. setTimeout(() => {
  190. _that.reLunchUser();
  191. }, 1500);
  192. return; // 即用户拒绝授权
  193. }
  194. console.log(e.detail.errMsg);
  195. console.log(e.detail.iv);
  196. console.log(e.detail.encryptedData);
  197. let iv = e.detail.iv;
  198. let encryptedData = e.detail.encryptedData;
  199. // 不是登陆完第一时间授权
  200. wx.login({
  201. success(res) {
  202. if (res.code) {
  203. // 设置用户手机号
  204. _that.setUserPhoneNumber(encryptedData, iv, res.code);
  205. } else {
  206. this.$refs.uToast.show({
  207. title: res.errMsg,
  208. type: 'warning'
  209. });
  210. console.log('登录失败!' + res.errMsg);
  211. }
  212. }
  213. });
  214. },
  215. // 以下是工具函数
  216. // 关闭键盘
  217. hideKeyboard() {
  218. uni.hideKeyboard();
  219. },
  220. // 格式化日期的月份或天数的显示(小于10,在前面增加0)
  221. getFormatDate(value) {
  222. if (value == undefined || value == '') {
  223. return '';
  224. }
  225. var str = value;
  226. if (parseInt(value) < 10) {
  227. str = '0' + value;
  228. }
  229. return str;
  230. }
  231. }
  232. };
  233. </script>
  234. <style lang="scss">
  235. .page {
  236. padding: 20rpx;
  237. background-color: #ffffff;
  238. }
  239. .form {
  240. border-radius: 10rpx;
  241. padding: 0 40rpx;
  242. }
  243. .popup-body {
  244. .tips-title {
  245. font-size: $u-p;
  246. margin-bottom: 20rpx;
  247. }
  248. .tips-content {
  249. font-size: $u-p2;
  250. color: $u-tips-color;
  251. margin-bottom: 60rpx;
  252. }
  253. }
  254. .id_card {
  255. color: #606266;
  256. width: 100%;
  257. height: 350rpx;
  258. display: flex;
  259. flex-direction: column;
  260. align-items: center;
  261. justify-content: center;
  262. background-color: #f4f5f6;
  263. font-size: $u-p2;
  264. }
  265. .footer {
  266. position: absolute;
  267. text-align: center;
  268. bottom: 40rpx;
  269. font-size: $u-p2;
  270. .agreement {
  271. color: $u-type-error;
  272. }
  273. }
  274. .slot-content {
  275. font-size: 28rpx;
  276. color: $u-content-color;
  277. padding: 20rpx;
  278. }
  279. </style>