agent.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. data: () => {
  4. return {
  5. statusStyle: {
  6. normal: { label: '正常', color: '#52c41a' },
  7. pending: { label: '审核中', color: '#faad14' },
  8. reject: { label: '拒绝', color: '#f56c6c' },
  9. freeze: { label: '冻结', color: '#409eff' },
  10. forbidden: { label: '禁用', color: '#999999' },
  11. }
  12. }
  13. },
  14. index: () => {
  15. const { reactive, onMounted } = Vue
  16. const index = {
  17. setup() {
  18. const state = reactive({
  19. data: [],
  20. filter: {
  21. drawer: false,
  22. data: {
  23. tabActive: 'all',
  24. user: { field: 'user_id', value: '' },
  25. level: '',
  26. status: '',
  27. createtime: [],
  28. },
  29. tools: {
  30. user: {
  31. type: 'tinputprepend',
  32. label: '会员信息',
  33. placeholder: '请输入查询内容',
  34. value: {
  35. field: 'user_id',
  36. value: '',
  37. },
  38. options: {
  39. data: [{
  40. label: '用户ID',
  41. value: 'user_id',
  42. },
  43. {
  44. label: '用户昵称',
  45. value: 'user.nickname',
  46. },
  47. {
  48. label: '用户手机号',
  49. value: 'user.mobile',
  50. }]
  51. }
  52. },
  53. level: {
  54. type: 'tselect',
  55. label: '分销商等级',
  56. value: '',
  57. options: {
  58. data: [],
  59. props: {
  60. label: 'name',
  61. value: 'level',
  62. },
  63. },
  64. },
  65. status: {
  66. type: 'tselect',
  67. label: '审核状态',
  68. value: '',
  69. options: {
  70. data: [{
  71. value: 'normal',
  72. label: '正常',
  73. },
  74. {
  75. value: 'forbidden',
  76. label: '禁用',
  77. },
  78. {
  79. value: 'pending',
  80. label: '审核中',
  81. },
  82. {
  83. value: 'freeze',
  84. label: '冻结',
  85. },
  86. {
  87. value: 'reject',
  88. label: '拒绝',
  89. }],
  90. },
  91. },
  92. createtime: {
  93. type: 'tdatetimerange',
  94. label: '更新时间',
  95. value: [],
  96. },
  97. },
  98. condition: {},
  99. }
  100. })
  101. const type = reactive({
  102. data: {
  103. status: [{
  104. type: 'all',
  105. name: '分销商',
  106. },
  107. {
  108. type: 'pending',
  109. name: '待审核',
  110. },
  111. {
  112. type: '0',
  113. name: '待升级',
  114. }],
  115. }
  116. })
  117. function getLevelSelect() {
  118. Fast.api.ajax({
  119. url: `shopro/commission/level/select`,
  120. type: 'GET',
  121. }, function (ret, res) {
  122. state.filter.tools.level.options.data = res.data;
  123. return false
  124. }, function (ret, res) { })
  125. }
  126. function getData() {
  127. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  128. let search = composeFilter(tempSearch, {
  129. 'user.nickname': 'like',
  130. 'user.mobile': 'like',
  131. createtime: 'range',
  132. });
  133. let temp = JSON.parse(search.search);
  134. if (temp && temp.tabActive) {
  135. if (temp.tabActive[0] == 'pending') {
  136. temp.status = ['pending', '='];
  137. delete temp.tabActive;
  138. } else if (temp.tabActive[0] == '0') {
  139. temp.level_status = ['0', '>'];
  140. delete temp.tabActive;
  141. }
  142. }
  143. search = { search: JSON.stringify(temp) };
  144. Fast.api.ajax({
  145. url: 'shopro/commission/agent',
  146. type: 'GET',
  147. data: {
  148. page: pagination.page,
  149. list_rows: pagination.list_rows,
  150. ...search,
  151. },
  152. }, function (ret, res) {
  153. state.data = res.data.data
  154. pagination.total = res.data.total
  155. return false
  156. }, function (ret, res) { })
  157. }
  158. function onOpenFilter() {
  159. state.filter.drawer = true
  160. }
  161. function onChangeFilter() {
  162. pagination.page = 1
  163. getData()
  164. state.filter.drawer && (state.filter.drawer = false)
  165. }
  166. function onChangeTab() {
  167. pagination.page = 1
  168. getData()
  169. }
  170. const pagination = reactive({
  171. page: 1,
  172. list_rows: 10,
  173. total: 0,
  174. })
  175. function onEdit(id, data) {
  176. Fast.api.ajax({
  177. url: `shopro/commission/agent/edit/id/${id}`,
  178. type: 'POST',
  179. data: data,
  180. }, function (ret, res) {
  181. getData();
  182. }, function (ret, res) { })
  183. }
  184. function onDetail(id) {
  185. Fast.api.open(`shopro/commission/agent/detail/id/${id}?id=${id}`, "详情", {
  186. callback() {
  187. getData()
  188. }
  189. })
  190. }
  191. onMounted(() => {
  192. getLevelSelect()
  193. getData()
  194. })
  195. return {
  196. ...Controller.data(),
  197. state,
  198. type,
  199. getData,
  200. onOpenFilter,
  201. onChangeFilter,
  202. onChangeTab,
  203. pagination,
  204. onEdit,
  205. onDetail,
  206. }
  207. }
  208. }
  209. createApp('index', index);
  210. },
  211. detail: () => {
  212. const { reactive, onMounted } = Vue
  213. const detail = {
  214. setup() {
  215. const state = reactive({
  216. id: new URLSearchParams(location.search).get('id'),
  217. data: {},
  218. })
  219. function getDetail() {
  220. Fast.api.ajax({
  221. url: `shopro/commission/agent/detail/id/${state.id}`,
  222. type: 'GET',
  223. }, function (ret, res) {
  224. state.data = res.data
  225. applyInfo.data = JSON.parse(JSON.stringify(state.data.apply_info))
  226. getLog()
  227. return false
  228. }, function (ret, res) { })
  229. }
  230. function onChangeStatus(status) {
  231. onEdit({ status });
  232. }
  233. function onChangeLevel() {
  234. Fast.api.open(`shopro/commission/level/select?level=${state.data.level}`, "更换分销等级", {
  235. callback(level) {
  236. onEdit({ level });
  237. }
  238. })
  239. }
  240. function onChangeParentUser() {
  241. Fast.api.open(`shopro/commission/agent/select?id=${state.data.user_id}`, "更换上级分销商", {
  242. callback() {
  243. getDetail()
  244. }
  245. })
  246. }
  247. const applyInfo = reactive({
  248. flag: false,
  249. data: []
  250. })
  251. function onCancelApplyInfo() {
  252. applyInfo.data = JSON.parse(JSON.stringify(state.data.apply_info));
  253. applyInfo.flag = false;
  254. }
  255. function onSaveApplyInfo() {
  256. onEdit({ apply_info: applyInfo.data });
  257. applyInfo.flag = false;
  258. }
  259. function onDeleteApplyInfo(index) {
  260. applyInfo.data.splice(index, 1);
  261. }
  262. function onEdit(data) {
  263. Fast.api.ajax({
  264. url: `shopro/commission/agent/edit/id/${state.id}`,
  265. type: 'POST',
  266. data,
  267. }, function (ret, res) {
  268. getDetail()
  269. }, function (ret, res) { })
  270. }
  271. function onTeam() {
  272. Fast.api.open(`shopro/commission/agent/team?id=${state.id}`, "查看团队")
  273. }
  274. const log = reactive({
  275. tabActive: 'log',
  276. data: [],
  277. status: {
  278. 0: 'info',
  279. 1: 'success',
  280. '-1': 'warning',
  281. '-2': 'danger',
  282. }
  283. })
  284. function getLog() {
  285. let search = composeFilter({ agent_id: state.id });
  286. Fast.api.ajax({
  287. url: `shopro/commission/${log.tabActive}`,
  288. type: 'GET',
  289. data: {
  290. page: pagination.page,
  291. list_rows: pagination.list_rows,
  292. ...search,
  293. },
  294. }, function (ret, res) {
  295. if (log.tabActive == 'order') {
  296. log.data = res.data.list.data;
  297. pagination.total = res.data.list.total;
  298. } else {
  299. log.data = res.data.data;
  300. pagination.total = res.data.total;
  301. }
  302. return false
  303. }, function (ret, res) { })
  304. }
  305. function onChangeTab() {
  306. pagination.page = 1
  307. log.data = []
  308. getLog()
  309. }
  310. const pagination = reactive({
  311. page: 1,
  312. list_rows: 10,
  313. total: 0,
  314. })
  315. function countCommission(item) {
  316. if (item) {
  317. let commission = 0;
  318. let commissioned = 0;
  319. item.forEach((r) => {
  320. if (r.status == 1) {
  321. commissioned += Number(r.commission);
  322. }
  323. commission += Number(r.commission);
  324. });
  325. return `${commission}元/${commissioned}元`;
  326. }
  327. }
  328. onMounted(() => {
  329. getDetail()
  330. })
  331. return {
  332. ...Controller.data(),
  333. state,
  334. getDetail,
  335. onChangeStatus,
  336. onChangeLevel,
  337. onChangeParentUser,
  338. applyInfo,
  339. onCancelApplyInfo,
  340. onSaveApplyInfo,
  341. onDeleteApplyInfo,
  342. onEdit,
  343. onTeam,
  344. log,
  345. getLog,
  346. onChangeTab,
  347. pagination,
  348. countCommission,
  349. }
  350. }
  351. }
  352. createApp('detail', detail);
  353. },
  354. select: () => {
  355. const { reactive, onMounted } = Vue
  356. const { ElMessage } = ElementPlus
  357. const select = {
  358. setup() {
  359. const state = reactive({
  360. id: new URLSearchParams(location.search).get('id'),
  361. data: [],
  362. filter: {
  363. data: {
  364. user: { field: 'user_id', value: '' },
  365. },
  366. },
  367. userDetail: {},
  368. parent_user_id: ''
  369. })
  370. async function getUserDetail() {
  371. Fast.api.ajax({
  372. url: `shopro/user/user/detail/id/${state.id}`,
  373. type: 'GET',
  374. }, function (ret, res) {
  375. state.userDetail = res.data;
  376. state.parent_user_id = state.userDetail?.parent_user_id;
  377. return false
  378. }, function (ret, res) { })
  379. }
  380. function getData() {
  381. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  382. let search = composeFilter(tempSearch, {
  383. 'user.nickname': 'like',
  384. 'user.mobile': 'like',
  385. });
  386. Fast.api.ajax({
  387. url: 'shopro/commission/agent/select',
  388. type: 'GET',
  389. data: {
  390. page: pagination.page,
  391. list_rows: pagination.list_rows,
  392. ...search,
  393. },
  394. }, function (ret, res) {
  395. state.data = res.data.data
  396. pagination.total = res.data.total
  397. return false
  398. }, function (ret, res) { })
  399. }
  400. const pagination = reactive({
  401. page: 1,
  402. list_rows: 10,
  403. total: 0,
  404. })
  405. function onSelect(row) {
  406. state.parent_user_id = row.user_id;
  407. }
  408. async function onConfirm() {
  409. if (state.parent_user_id == -1) {
  410. ElMessage.info('请选择上级');
  411. return;
  412. }
  413. Fast.api.ajax({
  414. url: `shopro/commission/agent/changeParentUser/id/${state.id}`,
  415. type: 'POST',
  416. data: {
  417. parent_user_id: state.parent_user_id,
  418. },
  419. }, function (ret, res) {
  420. Fast.api.close()
  421. }, function (ret, res) { })
  422. }
  423. onMounted(() => {
  424. getUserDetail()
  425. getData()
  426. })
  427. return {
  428. ...Controller.data(),
  429. state,
  430. getData,
  431. pagination,
  432. onSelect,
  433. onConfirm,
  434. }
  435. }
  436. }
  437. createApp('select', select);
  438. },
  439. team: () => {
  440. const { reactive, onMounted } = Vue
  441. const team = {
  442. setup() {
  443. const state = reactive({
  444. id: new URLSearchParams(location.search).get('id'),
  445. data: {},
  446. })
  447. async function getTeam() {
  448. Fast.api.ajax({
  449. url: `shopro/commission/agent/team/id/${state.id}`,
  450. type: 'GET',
  451. }, function (ret, res) {
  452. state.data = res.data;
  453. return false
  454. }, function (ret, res) { })
  455. }
  456. onMounted(() => {
  457. getTeam()
  458. })
  459. return {
  460. ...Controller.data(),
  461. state,
  462. }
  463. }
  464. }
  465. createApp('team', team);
  466. },
  467. };
  468. return Controller;
  469. });