mycreate.vue 7.8 KB

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