user.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted } = Vue
  5. const index = {
  6. setup() {
  7. const state = reactive({
  8. data: [],
  9. order: '',
  10. sort: '',
  11. filter: {
  12. drawer: false,
  13. data: {
  14. user: { field: 'id', value: '' },
  15. createtime: [],
  16. logintime: [],
  17. },
  18. tools: {
  19. user: {
  20. type: 'tinputprepend',
  21. label: '用户信息',
  22. placeholder: '请输入查询内容',
  23. value: {
  24. field: 'id',
  25. value: '',
  26. },
  27. options: {
  28. data: [{
  29. label: '用户ID',
  30. value: 'id',
  31. },
  32. {
  33. label: '用户名',
  34. value: 'username',
  35. },
  36. {
  37. label: '昵称',
  38. value: 'nickname',
  39. },
  40. {
  41. label: '手机号',
  42. value: 'mobile',
  43. },
  44. {
  45. label: '邮箱',
  46. value: 'email',
  47. }],
  48. }
  49. },
  50. createtime: {
  51. type: 'tdatetimerange',
  52. label: '注册时间',
  53. value: [],
  54. },
  55. logintime: {
  56. type: 'tdatetimerange',
  57. label: '上次登录',
  58. value: [],
  59. },
  60. },
  61. condition: {},
  62. }
  63. })
  64. function getData() {
  65. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  66. let search = composeFilter(tempSearch, {
  67. username: 'like',
  68. nickname: 'like',
  69. mobile: 'like',
  70. email: 'like',
  71. createtime: 'range',
  72. logintime: 'range',
  73. });
  74. Fast.api.ajax({
  75. url: 'shopro/user/user',
  76. type: 'GET',
  77. data: {
  78. page: pagination.page,
  79. list_rows: pagination.list_rows,
  80. order: state.order,
  81. sort: state.sort,
  82. ...search,
  83. },
  84. }, function (ret, res) {
  85. state.data = res.data.data
  86. pagination.total = res.data.total
  87. return false
  88. }, function (ret, res) { })
  89. }
  90. function onChangeSort({ prop, order }) {
  91. state.order = order == 'ascending' ? 'asc' : 'desc';
  92. state.sort = prop;
  93. getData();
  94. }
  95. function onOpenFilter() {
  96. state.filter.drawer = true
  97. }
  98. function onChangeFilter() {
  99. pagination.page = 1
  100. getData()
  101. state.filter.drawer && (state.filter.drawer = false)
  102. }
  103. const pagination = reactive({
  104. page: 1,
  105. list_rows: 10,
  106. total: 0,
  107. })
  108. function onDetail(id) {
  109. Fast.api.open(`shopro/user/user/detail?id=${id}`, "详情", {
  110. callback() {
  111. getData()
  112. }
  113. })
  114. }
  115. function onDelete(id) {
  116. Fast.api.ajax({
  117. url: `shopro/user/user/delete/id/${id}`,
  118. type: 'DELETE',
  119. }, function (ret, res) {
  120. getData()
  121. }, function (ret, res) { })
  122. }
  123. onMounted(() => {
  124. getData()
  125. })
  126. return {
  127. state,
  128. getData,
  129. onChangeSort,
  130. onOpenFilter,
  131. onChangeFilter,
  132. pagination,
  133. onDetail,
  134. onDelete
  135. }
  136. }
  137. }
  138. createApp('index', index);
  139. },
  140. detail: () => {
  141. const { reactive, onMounted } = Vue
  142. const detail = {
  143. setup() {
  144. const state = reactive({
  145. type: new URLSearchParams(location.search).get('type'),
  146. id: new URLSearchParams(location.search).get('id'),
  147. detail: {}
  148. })
  149. function getDetail() {
  150. Fast.api.ajax({
  151. url: `shopro/user/user/detail/id/${state.id}`,
  152. type: 'GET',
  153. }, function (ret, res) {
  154. state.detail = res.data;
  155. return false
  156. }, function (ret, res) { })
  157. }
  158. const platform = {
  159. wechat: {
  160. openPlatform: '微信开放平台',
  161. miniProgram: '微信小程序',
  162. officialAccount: '微信公众平台',
  163. },
  164. };
  165. function statusStyle(key) {
  166. let flag = state.detail.verification?.[key];
  167. return `<span style="color:${flag ? 'var(--el-color-success)' : 'var(--el-color-warning)'}">
  168. ${flag ? '已' : '未'}${key == 'username' || key == 'password' ? '设置' : '认证'}
  169. </span>`;
  170. }
  171. function onSelectAvatar() {
  172. Fast.api.open(`general/attachment/select`, "选择", {
  173. callback: function (data) {
  174. state.detail.avatar = data.url;
  175. }
  176. });
  177. }
  178. async function onSave() {
  179. Fast.api.ajax({
  180. url: `shopro/user/user/edit/id/${state.id}`,
  181. type: 'POST',
  182. data: state.detail,
  183. }, function (ret, res) {
  184. getDetail()
  185. }, function (ret, res) { })
  186. }
  187. function onChangeParentUser() {
  188. Fast.api.open(`shopro/commission/agent/select?id=${state.id}`, "更换上级分销商", {
  189. callback() {
  190. getDetail()
  191. }
  192. })
  193. }
  194. function onRecharge(type) {
  195. Fast.api.open(`shopro/user/user/recharge?type=${type}&id=${state.detail.id}`, "充值", {
  196. callback: function () {
  197. getDetail();
  198. getLog()
  199. }
  200. });
  201. }
  202. const log = reactive({
  203. tabActive: 'money',
  204. data: [],
  205. })
  206. function getLog() {
  207. let url
  208. let search = {}
  209. if (log.tabActive == 'money' || log.tabActive == 'score' || log.tabActive == 'commission') {
  210. url = `shopro/user/wallet_log/${log.tabActive}/id/${state.id}`
  211. }
  212. if (log.tabActive == 'order') {
  213. url = `shopro/order/order`
  214. search = {
  215. search: JSON.stringify({
  216. user_id: state.id
  217. })
  218. }
  219. }
  220. if (log.tabActive == 'share') {
  221. url = `shopro/share`
  222. search = {
  223. id: state.id
  224. }
  225. }
  226. if (log.tabActive == 'coupon') {
  227. url = `shopro/user/user/coupon/id/${state.id}`
  228. }
  229. Fast.api.ajax({
  230. url: url,
  231. type: 'GET',
  232. data: {
  233. page: pagination.page,
  234. list_rows: pagination.list_rows,
  235. ...search,
  236. },
  237. }, function (ret, res) {
  238. if (log.tabActive == 'order') {
  239. log.data = res.data.orders.data
  240. pagination.total = res.data.orders.total
  241. } else {
  242. log.data = res.data.data
  243. pagination.total = res.data.total
  244. }
  245. return false
  246. }, function (ret, res) { })
  247. }
  248. const pagination = reactive({
  249. page: 1,
  250. list_rows: 10,
  251. total: 0,
  252. })
  253. function onChangeTab() {
  254. log.data = []
  255. pagination.page = 1
  256. pagination.total = 0
  257. getLog()
  258. }
  259. onMounted(() => {
  260. getDetail()
  261. getLog()
  262. })
  263. return {
  264. state,
  265. getDetail,
  266. platform,
  267. statusStyle,
  268. onSelectAvatar,
  269. onSave,
  270. onChangeParentUser,
  271. onRecharge,
  272. log,
  273. getLog,
  274. pagination,
  275. onChangeTab,
  276. }
  277. }
  278. }
  279. createApp('detail', detail);
  280. },
  281. recharge: () => {
  282. const { reactive, getCurrentInstance } = Vue
  283. const recharge = {
  284. setup() {
  285. const { proxy } = getCurrentInstance();
  286. const state = reactive({
  287. type: new URLSearchParams(location.search).get('type'),
  288. id: new URLSearchParams(location.search).get('id')
  289. })
  290. const form = reactive({
  291. model: {
  292. id: state.id,
  293. type: state.type,
  294. amount: '',
  295. memo: '',
  296. },
  297. rules: {
  298. amount: [{ required: true, message: '请输入', trigger: 'blur' }],
  299. },
  300. })
  301. function onConfirm() {
  302. proxy.$refs['formRef'].validate((valid) => {
  303. if (valid) {
  304. Fast.api.ajax({
  305. url: `shopro/user/user/recharge`,
  306. type: 'POST',
  307. data: form.model,
  308. }, function (ret, res) {
  309. Fast.api.close()
  310. }, function (ret, res) { })
  311. }
  312. });
  313. }
  314. return {
  315. state,
  316. form,
  317. onConfirm
  318. }
  319. }
  320. }
  321. createApp('recharge', recharge);
  322. },
  323. select: function () {
  324. const { reactive, onMounted } = Vue
  325. const select = {
  326. setup() {
  327. const state = reactive({
  328. id: new URLSearchParams(location.search).get('id') || false,
  329. filter: {
  330. drawer: false,
  331. data: {
  332. keyword: '',
  333. },
  334. tools: {},
  335. condition: {},
  336. },
  337. data: [],
  338. ids: [],
  339. isSelectAll: false,
  340. isIndeterminate: false,
  341. })
  342. function getData() {
  343. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  344. let search = composeFilter(tempSearch, {
  345. keyword: 'like',
  346. });
  347. Fast.api.ajax({
  348. url: 'shopro/user/user/select',
  349. type: 'GET',
  350. data: {
  351. page: pagination.page,
  352. list_rows: pagination.list_rows,
  353. ...search,
  354. },
  355. }, function (ret, res) {
  356. state.data = res.data.data
  357. pagination.total = res.data.total
  358. calculateSelect();
  359. return false
  360. }, function (ret, res) { })
  361. }
  362. const pagination = reactive({
  363. page: 1,
  364. list_rows: 10,
  365. total: 0,
  366. })
  367. function onChangeFilter() {
  368. pagination.page = 1
  369. getData()
  370. }
  371. function onSelect(type, row) {
  372. if (type) {
  373. state.ids.push(row.id);
  374. } else {
  375. let findIndex = state.ids.findIndex((id) => id == row.id);
  376. state.ids.splice(findIndex, 1);
  377. }
  378. calculateSelect();
  379. };
  380. function onSelectAll(type) {
  381. if (type) {
  382. state.data.forEach((item) => {
  383. state.ids.push(item.id);
  384. });
  385. state.ids = Array.from(new Set(state.ids));
  386. } else {
  387. state.data.forEach((item) => {
  388. if (state.ids.findIndex((id) => id == item.id) !== -1) {
  389. state.ids.splice(
  390. state.ids.findIndex((id) => id == item.id),
  391. 1,
  392. );
  393. }
  394. });
  395. }
  396. calculateSelect();
  397. }
  398. function calculateSelect() {
  399. state.isSelectAll = false;
  400. state.isIndeterminate = false;
  401. if (state.data.every((item) => state.ids.includes(item.id))) {
  402. state.isSelectAll = true;
  403. state.isIndeterminate = false;
  404. } else if (state.data.some((item) => state.ids.includes(item.id))) {
  405. state.isSelectAll = false;
  406. state.isIndeterminate = true;
  407. }
  408. if (state.data.length === 0) {
  409. state.isSelectAll = false;
  410. state.isIndeterminate = false;
  411. }
  412. }
  413. function onConfirm() {
  414. Fast.api.ajax({
  415. url: `shopro/coupon/send/id/${state.id}`,
  416. type: 'POST',
  417. data: {
  418. user_ids: state.ids
  419. },
  420. }, function (ret, res) {
  421. Fast.api.close()
  422. }, function (ret, res) { })
  423. }
  424. onMounted(() => {
  425. getData()
  426. })
  427. return {
  428. state,
  429. getData,
  430. pagination,
  431. onChangeFilter,
  432. onSelect,
  433. onSelectAll,
  434. onConfirm
  435. }
  436. }
  437. }
  438. createApp('select', select);
  439. },
  440. };
  441. return Controller;
  442. });