leadslistsearch.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. const {
  2. api_leads_selects,
  3. api_get_country_city
  4. } = require('../../utils/api.js');
  5. const {
  6. net
  7. } = require('../../utils/net.js');
  8. const util = require('../../utils/util.js');
  9. Page({
  10. data: {
  11. businessRole: '',
  12. searchCode: "",
  13. sourceUserIds: [],
  14. searchTimeType: "",
  15. creatTimeArr: [{
  16. name: "周",
  17. typeArr: [{
  18. name: "本周",
  19. value: "2"
  20. }, {
  21. name: "上周",
  22. value: "1"
  23. }]
  24. }, {
  25. name: "月",
  26. typeArr: [{
  27. name: "本月",
  28. value: "4"
  29. }, {
  30. name: "上月",
  31. value: "3"
  32. }]
  33. }],
  34. // 国家城市
  35. loadingCountry: true,
  36. cityArr: [],
  37. cityId: "",
  38. countryArr: [],
  39. countryId: '',
  40. // 创建时间
  41. createTimeStart: "",
  42. createTimeEnd: "",
  43. currentFilter: 'searchScenarioSels',
  44. filterObj: {
  45. searchScenarioSels: {
  46. checked: 1,
  47. name: '筛选场景',
  48. value: "",
  49. typeArr: []
  50. },
  51. leadsStatusSels: {
  52. checked: '',
  53. name: '状态',
  54. value: "2",
  55. typeArr: []
  56. },
  57. sourceUser: {
  58. name: '来源人',
  59. value: "4"
  60. },
  61. countryAndCity: {
  62. name: '国家城市',
  63. value: "5"
  64. },
  65. createTime: {
  66. name: '创建时间',
  67. value: "6"
  68. }
  69. },
  70. },
  71. onLoad: function (options) {
  72. // 个人分销商和顾问没有场景筛选
  73. this.setData({
  74. businessRole: util.getStorageSync('userInfo').businessRole
  75. }, () => {
  76. const {
  77. businessRole
  78. } = this.data
  79. if (businessRole == 2) {
  80. let filterObj = this.data.filterObj
  81. delete filterObj.searchScenarioSels
  82. delete filterObj.sourceUser
  83. this.setData({
  84. filterObj: filterObj,
  85. currentFilter: 'leadsStatusSels'
  86. })
  87. }
  88. })
  89. // 筛选条件回显
  90. const resultData = options.resultData ? JSON.parse(options.resultData) : {}
  91. const {
  92. countryId,
  93. cityId,
  94. searchScenario,
  95. status,
  96. sourceUserIds,
  97. searchTimeType,
  98. createTimeStart,
  99. createTimeEnd
  100. } = resultData
  101. this.setData({
  102. sourceUserIds: sourceUserIds ? JSON.parse(sourceUserIds) : [],
  103. [`filterObj.sourceUser.checked`]: sourceUserIds ? true : '',
  104. [`filterObj.searchScenarioSels.checked`]: searchScenario || '',
  105. [`filterObj.leadsStatusSels.checked`]: status || '',
  106. cityId: cityId || '',
  107. countryId: countryId || '',
  108. [`filterObj.countryAndCity.checked`]: cityId || countryId ? true : ''
  109. })
  110. if (searchTimeType || createTimeStart || createTimeEnd) {
  111. this.setData({
  112. searchTimeType: searchTimeType,
  113. [`filterObj.createTime.checked`]: true
  114. })
  115. if (searchTimeType == 0) {
  116. this.setData({
  117. createTimeStart: createTimeStart ? util.formatTimeStr(createTimeStart) : '',
  118. createTimeEnd: createTimeEnd ? util.formatTimeStr(createTimeEnd - 23 * 3600 + 59 * 60 + 59) : ''
  119. })
  120. }
  121. }
  122. this.getCountryAndCity()
  123. this.getLeadsSelects()
  124. },
  125. onReady: function () {
  126. wx.setNavigationBarTitle({
  127. title: '客户搜索'
  128. })
  129. wx.setBackgroundColor({
  130. backgroundColorBottom: '#fafafa'
  131. });
  132. },
  133. onShow: function () {
  134. },
  135. onHide: function () {
  136. },
  137. getCountryAndCity() {
  138. let params = {
  139. url: api_get_country_city
  140. }
  141. net.req(params).then((res) => {
  142. let countryList = []
  143. if (res && res.data && Array.isArray(res.data) && res.data.length) {
  144. countryList = res.data.slice(1)
  145. } else {
  146. countryList = []
  147. }
  148. this.setData({
  149. countryArr: countryList,
  150. loadingCountry: false
  151. }, () => {
  152. if (this.data.countryId) {
  153. res.data.forEach(element => {
  154. if (element.id == this.data.countryId && element.son && element.son.length > 0) {
  155. let cityList = []
  156. element.son.forEach(item => {
  157. cityList = cityList.concat(item.citys)
  158. })
  159. this.setData({
  160. cityArr: cityList
  161. })
  162. }
  163. });
  164. }
  165. })
  166. })
  167. },
  168. filterTypeTap(e) {
  169. this.setData({
  170. currentFilter: e.currentTarget.dataset.index
  171. })
  172. },
  173. filterTypeClassifyTap(e) {
  174. const value = e.currentTarget.dataset.value
  175. const {
  176. currentFilter,
  177. filterObj
  178. } = this.data
  179. const setChecked = `filterObj.${currentFilter}.checked`
  180. this.setData({
  181. [setChecked]: value
  182. })
  183. },
  184. // 确定
  185. sureTap() {
  186. const {
  187. countryId,
  188. cityId,
  189. filterObj,
  190. createTimeStart,
  191. createTimeEnd,
  192. searchTimeType,
  193. sourceUserIds
  194. } = this.data
  195. const resultData = {}
  196. if (countryId) resultData.countryId = countryId
  197. if (cityId) resultData.cityId = cityId
  198. const {
  199. searchScenarioSels,
  200. leadsStatusSels
  201. } = filterObj
  202. if (searchScenarioSels && searchScenarioSels.checked) resultData.searchScenario = searchScenarioSels.checked
  203. if (leadsStatusSels && leadsStatusSels.checked) resultData.status = leadsStatusSels.checked
  204. if (searchTimeType || (searchTimeType === 0)) resultData.searchTimeType = searchTimeType
  205. if (createTimeStart) resultData.createTimeStart = new Date(createTimeStart.split('-').join("/")).getTime()
  206. if (createTimeEnd) resultData.createTimeEnd = new Date(createTimeEnd.split('-').join("/")).getTime() + (23 * 3600 + 59 * 60 + 59)
  207. if (sourceUserIds && sourceUserIds.length) resultData.sourceUserIds = JSON.stringify(sourceUserIds)
  208. let pages = getCurrentPages();
  209. let prevPage = pages[pages.length - 2];
  210. if (prevPage && prevPage.getResultDataCallack) {
  211. prevPage.getResultDataCallack(resultData);
  212. wx.navigateBack();
  213. }
  214. },
  215. // 重置
  216. resetTap() {
  217. const {
  218. businessRole
  219. } = this.data
  220. this.setData({
  221. createTimeStart: "",
  222. createTimeEnd: "",
  223. searchTimeType: "",
  224. currentFilter: (businessRole == 2) ? 'leadsStatusSels' : "searchScenarioSels",
  225. [`filterObj.searchScenarioSels.checked`]: '',
  226. [`filterObj.leadsStatusSels.checked`]: "",
  227. [`filterObj.countryAndCity.checked`]: "",
  228. [`filterObj.sourceUser.checked`]: "",
  229. [`filterObj.createTime.checked`]: "",
  230. cityId: "",
  231. countryId: "",
  232. cityArr: [],
  233. sourceUserIds: [],
  234. createTimeStart: "",
  235. createTimeEnd: ""
  236. })
  237. },
  238. creatTimeTap(e) {
  239. this.setData({
  240. searchTimeType: e.currentTarget.dataset.value,
  241. createTimeStart: "",
  242. createTimeEnd: "",
  243. [`filterObj.createTime.checked`]: true
  244. })
  245. },
  246. createTimeStartChange(event) {
  247. this.setData({
  248. createTimeStart: event.detail.value,
  249. searchTimeType: 0,
  250. [`filterObj.createTime.checked`]: true
  251. })
  252. },
  253. createTimeEndChange(event) {
  254. this.setData({
  255. createTimeEnd: event.detail.value,
  256. searchTimeType: 0,
  257. [`filterObj.createTime.checked`]: true
  258. })
  259. },
  260. selectCountryTap(e) {
  261. const {
  262. index,
  263. id
  264. } = e.currentTarget.dataset
  265. const cityData = this.data.countryArr[index] && this.data.countryArr[index].son
  266. let cityList = []
  267. if (cityData && Array.isArray(cityData) && cityData.length > 0) {
  268. cityData.forEach(item => {
  269. cityList = cityList.concat(item.citys)
  270. })
  271. }
  272. this.setData({
  273. searchCode: '',
  274. countryId: id,
  275. cityArr: cityList,
  276. cityId: "",
  277. [`filterObj.countryAndCity.checked`]: true
  278. })
  279. },
  280. touchSearch(event) {
  281. this.setData({
  282. searchCode: event.detail.value
  283. })
  284. let _this = this;
  285. clearTimeout(this.timer)
  286. this.timer = setTimeout(() => {
  287. _this.searchCityHandle(event);
  288. }, 500)
  289. },
  290. searchCityHandle(event) {
  291. const {
  292. value
  293. } = event.detail
  294. let cityData = this.data.countryArr.filter(item => item.id == this.data.countryId)[0].son
  295. let cityList = []
  296. if (cityData && Array.isArray(cityData) && cityData.length > 0) {
  297. cityData.forEach(item => {
  298. cityList = cityList.concat(item.citys)
  299. })
  300. }
  301. if (value) {
  302. // 获取筛选后的值
  303. let result = []
  304. cityList.forEach(element => {
  305. const {
  306. name,
  307. enName
  308. } = element
  309. if ((name.indexOf(value) !== -1) || (enName.toLowerCase().indexOf(value.toLowerCase()) !== -1)) {
  310. result.push(element)
  311. }
  312. })
  313. this.setData({
  314. cityArr: result
  315. })
  316. } else {
  317. this.setData({
  318. cityArr: cityList
  319. })
  320. }
  321. },
  322. selectCityTap(e) {
  323. const {
  324. id
  325. } = e.currentTarget.dataset
  326. this.setData({
  327. [`filterObj.countryAndCity.checked`]: true,
  328. cityId: id,
  329. })
  330. },
  331. getLeadsSelects() {
  332. let params = {
  333. url: api_leads_selects,
  334. }
  335. this.setData({
  336. loadingFlag: true
  337. })
  338. net.req(params).then((res) => {
  339. const {
  340. leadsStatusSels,
  341. searchScenarioSels
  342. } = res.data
  343. this.setData({
  344. [`filterObj.searchScenarioSels.typeArr`]: searchScenarioSels,
  345. [`filterObj.leadsStatusSels.typeArr`]: leadsStatusSels,
  346. loadingFlag: false
  347. })
  348. })
  349. },
  350. goSourceUserList() {
  351. wx.navigateTo({
  352. url: `/pages/sourcePersonList/sourcePersonList?sourceUserIds=${JSON.stringify(this.data.sourceUserIds)}&checkType=2`
  353. })
  354. },
  355. // 来源人
  356. getSourcePersonCallack(data) {
  357. this.setData({
  358. sourceUserIds: data,
  359. [`filterObj.sourceUser.checked`]: data.length ? true : ''
  360. })
  361. }
  362. })