create.vue 6.8 KB

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