add-client.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //Page Object
  2. import agentApi from '../../apis/agent'
  3. let app = getApp();
  4. let KEYPOP = {
  5. user_phone_belong:[{
  6. id:'',
  7. name:'海外'
  8. },{
  9. id:'',
  10. name:'国内'
  11. }],
  12. buy_house_address:[{
  13. id:'',
  14. name:'香洲区'
  15. },{
  16. id:'',
  17. name:'斗门区'
  18. }],
  19. purpose:[{
  20. id:'',
  21. name:'改善'
  22. },{
  23. id:'',
  24. name:'刚需'
  25. }],
  26. rooms:[{
  27. id:'',
  28. name:'1室'
  29. },{
  30. id:'',
  31. name:'2室'
  32. },{
  33. id:'',
  34. name:'3室'
  35. }]
  36. }
  37. Page({
  38. data: {
  39. popArray:[],
  40. show: false,
  41. genterShow: false,
  42. pp_type:'',
  43. value: 0,
  44. isHideNum:false,
  45. StrGenter: ['男性', '女性'],
  46. genderMap: {
  47. M: '男性',
  48. F: '女性'
  49. },
  50. first_budget_p1:'',
  51. first_budget_p2:'',
  52. ideal_area_1:'',
  53. ideal_area_2:'',
  54. params:{
  55. user_name:"",
  56. user_id: "",
  57. user_phone: "",
  58. user_phone_belong: "",
  59. user_gender: "M",
  60. user_wish: 0,
  61. user_requires: "",
  62. first_budget: "",
  63. total_budget: "",
  64. buy_house_address: "",
  65. ideal_area: "",
  66. purpose: "",
  67. rooms: "",
  68. property_type: "",
  69. remarks: "",
  70. cur_step: "",
  71. is_valid: "",
  72. agency_user_id: getApp().globalData.userinfo.user_id
  73. }
  74. },
  75. onLoad: function(options) {
  76. const { customer_id, agency_user_id } = options
  77. console.log(options)
  78. if (customer_id && agency_user_id) {
  79. this.fetchCustomerDetail(agency_user_id, customer_id)
  80. }
  81. },
  82. fetchCustomerDetail (agency_user_id,user_id) {
  83. agentApi.fetchCustomerDetail({agency_user_id,user_id}).then(res => {
  84. if (res.data) {
  85. const exg = /(\d*)-(\d*)/
  86. this.setData({
  87. is_edit: true,
  88. params: res.data,
  89. first_budget_p1: res.data.first_budget ? res.data.first_budget.match(exg)[1] : '',
  90. first_budget_p2: res.data.first_budget ? res.data.first_budget.match(exg)[2] : '',
  91. ideal_area_1: res.data.ideal_area ? res.data.ideal_area.match(exg)[1] : '',
  92. ideal_area_2: res.data.ideal_area ? res.data.ideal_area.match(exg)[2] : ''
  93. })
  94. }
  95. }).finally(data=>{
  96. wx.hideLoading()
  97. })
  98. },
  99. bindInput:function (event) {
  100. var obj = {},
  101. key = event.target.dataset['key'];
  102. obj[key] = event.detail.value;
  103. this.setData(obj);
  104. },
  105. onRateChange(event) {
  106. this.setData({
  107. 'params.user_wish':event.detail
  108. })
  109. },
  110. changeSwitch:function (e) {
  111. let isHideNum = e.detail.value
  112. this.setData({
  113. isHideNum
  114. })
  115. },
  116. showPopup(e) {
  117. let {type} = e.currentTarget.dataset
  118. this.setData({
  119. show: true,
  120. pp_type:type,
  121. popArray:KEYPOP[type]
  122. });
  123. },
  124. getUserList(){
  125. agentApi.fetchUserByPhone({
  126. phone_num: this.data.params.user_phone
  127. }).then(res => {
  128. if (res.code===0&&res.data) {
  129. this.setData({
  130. show: true,
  131. popArray:[{
  132. name: res.data.phone,
  133. item: res.data
  134. }]
  135. });
  136. }
  137. else{
  138. app.ShowModel('提示','获取该手机号码用户失败,无法新增客户');
  139. }
  140. }).finally(() => {
  141. wx.hideLoading()
  142. })
  143. },
  144. handleItem(e){
  145. let {val,item} = e.currentTarget.dataset
  146. let params = this.data.params
  147. if (item) {
  148. params['user_gender'] = item.gender
  149. params['user_phone_belong'] = item.phone_belong
  150. params['user_id'] = item.user_id
  151. }
  152. else{
  153. params[this.data.pp_type] = val
  154. }
  155. let obj = {
  156. show: false,
  157. params
  158. }
  159. console.log(obj);
  160. this.setData(obj)
  161. },
  162. onClose() {
  163. this.setData({ show: false });
  164. },
  165. handleSubmit () {
  166. if (this.data.is_edit) {
  167. return this.updateCustomer()
  168. }
  169. return this.addCustomer()
  170. },
  171. addCustomer(){
  172. this.setData({
  173. 'params.first_budget':`${this.data.first_budget_p1}-${this.data.first_budget_p2}万元`,
  174. 'params.ideal_area':`${this.data.ideal_area_1}-${this.data.ideal_area_1}平`
  175. })
  176. let params = this.data.params
  177. if (!params['user_id']) {
  178. return app.ShowModel('提示',`请输入电话号码后选择用户信息`);
  179. }
  180. let NONULL = [{
  181. name:'手机号码',
  182. id: 'user_phone'
  183. },{
  184. name:'姓名',
  185. id: 'user_name'
  186. }]
  187. for (let i = 0; i < NONULL.length; i++) {
  188. const item = NONULL[i];
  189. if (!params[item.id]) {
  190. return app.ShowModel('提示',`${item.name}不能为空`);
  191. }
  192. }
  193. agentApi.addCustomer(params).then(res => {
  194. console.log(res)
  195. if (res.code == 0) {
  196. wx.showModal({
  197. title: '提示',
  198. content: '添加成功',
  199. showCancel: false,
  200. success (res) {
  201. wx.navigateBack()
  202. }
  203. })
  204. }
  205. else{
  206. app.ShowModel('提示','添加失败,请检查输入信息是否有误或重复添加');
  207. }
  208. }).catch(() => {
  209. app.ShowModel('提示','添加失败,请检查输入信息是否有误或重复添加');
  210. }).finally(() => {
  211. wx.hideLoading()
  212. })
  213. },
  214. updateCustomer () {
  215. this.setData({
  216. 'params.first_budget':`${this.data.first_budget_p1}-${this.data.first_budget_p2}万元`,
  217. 'params.ideal_area':`${this.data.ideal_area_1}-${this.data.ideal_area_2}平`
  218. })
  219. let params = this.data.params
  220. if (!params.user_name) {
  221. app.ShowModel('姓名不能为空')
  222. return
  223. }
  224. agentApi.updateCustomer(params).then(res => {
  225. if (res.code == 0) {
  226. wx.showModal({
  227. title: '提示',
  228. content: '修改成功',
  229. showCancel: false,
  230. success (res) {
  231. wx.navigateBack()
  232. }
  233. })
  234. } else {
  235. app.ShowModel('修改失败');
  236. }
  237. })
  238. },
  239. //item(index,pagePath,text)
  240. onTabItemTap:function(item) {
  241. },
  242. showGender () {
  243. this.setData({
  244. genterShow: true
  245. })
  246. },
  247. changeGenter (e) {
  248. console.log(e)
  249. let { value } = e.detail
  250. value = this.data.StrGenter[value]
  251. this.setData({
  252. genterShow: false,
  253. 'params.user_gender': value === '男性' ? 'M' : 'F'
  254. })
  255. },
  256. showText () {
  257. this.setData({
  258. textShow: true
  259. })
  260. },
  261. hideText () {
  262. this.setData({
  263. textShow: false
  264. })
  265. },
  266. });