add-client.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. const { id } = options
  78. console.log(options)
  79. // if (customer_id && agency_user_id) {
  80. this.fetchCustomerDetail(id)
  81. // }
  82. },
  83. fetchCustomerDetail (id) {
  84. agentApi.fetchCustomerDetail({id}).then(res => {
  85. if (res.data) {
  86. const exg = /(\d*)-(\d*)/
  87. this.setData({
  88. is_edit: true,
  89. params: res.data,
  90. first_budget_p1: res.data.first_budget ? res.data.first_budget.match(exg)[1] : '',
  91. first_budget_p2: res.data.first_budget ? res.data.first_budget.match(exg)[2] : '',
  92. ideal_area_1: res.data.ideal_area ? res.data.ideal_area.match(exg)[1] : '',
  93. ideal_area_2: res.data.ideal_area ? res.data.ideal_area.match(exg)[2] : ''
  94. })
  95. }
  96. }).finally(data=>{
  97. wx.hideLoading()
  98. })
  99. },
  100. bindInput:function (event) {
  101. var obj = {},
  102. key = event.target.dataset['key'];
  103. obj[key] = event.detail.value;
  104. this.setData(obj);
  105. },
  106. onRateChange(event) {
  107. this.setData({
  108. 'params.user_wish':event.detail
  109. })
  110. },
  111. changeSwitch:function (e) {
  112. let isHideNum = e.detail.value
  113. this.setData({
  114. isHideNum
  115. })
  116. },
  117. showPopup(e) {
  118. let {type} = e.currentTarget.dataset
  119. this.setData({
  120. show: true,
  121. pp_type:type,
  122. popArray:KEYPOP[type]
  123. });
  124. },
  125. getUserList(){
  126. agentApi.fetchUserByPhone({
  127. phone_num: this.data.params.user_phone
  128. }).then(res => {
  129. if (res.code===0&&res.data) {
  130. this.setData({
  131. show: true,
  132. popArray:[{
  133. name: res.data.phone,
  134. item: res.data
  135. }]
  136. });
  137. }
  138. else{
  139. app.ShowModel('提示','获取该手机号码用户失败,无法新增客户');
  140. }
  141. }).finally(() => {
  142. wx.hideLoading()
  143. })
  144. },
  145. handleItem(e){
  146. let {val,item} = e.currentTarget.dataset
  147. let params = this.data.params
  148. if (item) {
  149. params['user_gender'] = item.gender
  150. params['user_phone_belong'] = item.phone_belong
  151. params['user_id'] = item.user_id
  152. }
  153. else{
  154. params[this.data.pp_type] = val
  155. }
  156. let obj = {
  157. show: false,
  158. params
  159. }
  160. console.log(obj);
  161. this.setData(obj)
  162. },
  163. onClose() {
  164. this.setData({ show: false });
  165. },
  166. handleSubmit () {
  167. if (this.data.is_edit) {
  168. return this.updateCustomer()
  169. }
  170. return this.addCustomer()
  171. },
  172. addCustomer(){
  173. this.setData({
  174. 'params.first_budget':`${this.data.first_budget_p1}-${this.data.first_budget_p2}万元`,
  175. 'params.ideal_area':`${this.data.ideal_area_1}-${this.data.ideal_area_1}平`
  176. })
  177. let params = this.data.params
  178. // if (!params['user_id']) {
  179. // return app.ShowModel('提示',`请输入电话号码后选择用户信息`);
  180. // }
  181. let NONULL = [{
  182. name:'手机号码',
  183. id: 'user_phone'
  184. },{
  185. name:'姓名',
  186. id: 'user_name'
  187. }]
  188. for (let i = 0; i < NONULL.length; i++) {
  189. const item = NONULL[i];
  190. if (!params[item.id]) {
  191. return app.ShowModel('提示',`${item.name}不能为空`);
  192. }
  193. }
  194. agentApi.addCustomer(params).then(res => {
  195. console.log(res)
  196. if (res.code == 0) {
  197. wx.showModal({
  198. title: '提示',
  199. content: '添加成功',
  200. showCancel: false,
  201. success (res) {
  202. wx.navigateBack()
  203. }
  204. })
  205. }
  206. else{
  207. app.ShowModel('提示','添加失败,请检查输入信息是否有误或重复添加');
  208. }
  209. }).catch(() => {
  210. app.ShowModel('提示','添加失败,请检查输入信息是否有误或重复添加');
  211. }).finally(() => {
  212. wx.hideLoading()
  213. })
  214. },
  215. updateCustomer () {
  216. this.setData({
  217. 'params.first_budget':`${this.data.first_budget_p1}-${this.data.first_budget_p2}万元`,
  218. 'params.ideal_area':`${this.data.ideal_area_1}-${this.data.ideal_area_2}平`
  219. })
  220. let params = this.data.params
  221. if (!params.user_name) {
  222. app.ShowModel('姓名不能为空')
  223. return
  224. }
  225. agentApi.updateCustomer(params).then(res => {
  226. if (res.code == 0) {
  227. wx.showModal({
  228. title: '提示',
  229. content: '修改成功',
  230. showCancel: false,
  231. success (res) {
  232. wx.navigateBack()
  233. }
  234. })
  235. } else {
  236. app.ShowModel('修改失败');
  237. }
  238. })
  239. },
  240. //item(index,pagePath,text)
  241. onTabItemTap:function(item) {
  242. },
  243. showGender () {
  244. this.setData({
  245. genterShow: true
  246. })
  247. },
  248. changeGenter (e) {
  249. console.log(e)
  250. let { value } = e.detail
  251. value = this.data.StrGenter[value]
  252. this.setData({
  253. genterShow: false,
  254. 'params.user_gender': value === '男性' ? 'M' : 'F'
  255. })
  256. },
  257. showText () {
  258. this.setData({
  259. textShow: true
  260. })
  261. },
  262. hideText () {
  263. this.setData({
  264. textShow: false
  265. })
  266. },
  267. });