order.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted, ref } = Vue
  5. const index = {
  6. setup() {
  7. const state = reactive({
  8. data: [],
  9. filter: {
  10. drawer: false,
  11. data: {
  12. buyer: { field: 'buyer_id', value: '' },
  13. agent: { field: 'agent_id', value: '' },
  14. reward: { field: 'reward.agent_id', value: '' },
  15. 'order.order_sn': '',
  16. 'order_item.goods_title': '',
  17. 'order.createtime': [],
  18. commission_time: [],
  19. commission_order_status: '',
  20. commission_reward_status: '',
  21. },
  22. tools: {
  23. buyer: {
  24. type: 'tinputprepend',
  25. label: '下单用户',
  26. placeholder: '请输入查询内容',
  27. value: {
  28. field: 'buyer_id',
  29. value: '',
  30. },
  31. options: {
  32. data: [{
  33. label: '用户ID',
  34. value: 'buyer_id',
  35. },
  36. {
  37. label: '用户昵称',
  38. value: 'buyer.nickname',
  39. },
  40. {
  41. label: '用户手机号',
  42. value: 'buyer.mobile',
  43. }],
  44. }
  45. },
  46. agent: {
  47. type: 'tinputprepend',
  48. label: '推广分销商',
  49. placeholder: '请输入查询内容',
  50. value: {
  51. field: 'agent_id',
  52. value: '',
  53. },
  54. options: {
  55. data: [{
  56. label: '推广ID',
  57. value: 'agent_id',
  58. },
  59. {
  60. label: '推广昵称',
  61. value: 'agent.nickname',
  62. },
  63. {
  64. label: '推广手机号',
  65. value: 'agent.mobile',
  66. }],
  67. }
  68. },
  69. reward: {
  70. type: 'tinputprepend',
  71. label: '结算分销商',
  72. placeholder: '请输入查询内容',
  73. value: {
  74. field: 'reward.agent_id',
  75. value: '',
  76. },
  77. options: {
  78. data: [{
  79. label: '结算ID',
  80. value: 'reward.agent_id',
  81. },
  82. {
  83. label: '结算昵称',
  84. value: 'reward.agent_nickname',
  85. },
  86. {
  87. label: '结算手机号',
  88. value: 'reward.agent_mobile',
  89. }],
  90. }
  91. },
  92. 'order.order_sn': {
  93. type: 'tinput',
  94. label: '订单号',
  95. placeholder: '请输入查询内容',
  96. value: '',
  97. },
  98. 'order_item.goods_title': {
  99. type: 'tinput',
  100. label: '商品名称',
  101. placeholder: '请输入查询内容',
  102. value: '',
  103. },
  104. 'order.createtime': {
  105. type: 'tdatetimerange',
  106. label: '下单时间',
  107. value: [],
  108. },
  109. commission_time: {
  110. type: 'tdatetimerange',
  111. label: '分佣时间',
  112. value: [],
  113. },
  114. commission_order_status: {
  115. type: 'tselect',
  116. label: '订单结算状态',
  117. value: '',
  118. options: {
  119. data: [{
  120. label: '已扣除',
  121. value: '-2',
  122. },
  123. {
  124. label: '已取消',
  125. value: '-1',
  126. },
  127. {
  128. label: '不计入',
  129. value: '0',
  130. },
  131. {
  132. label: '已计入',
  133. value: '1',
  134. }],
  135. },
  136. },
  137. commission_reward_status: {
  138. type: 'tselect',
  139. label: '佣金结算状态',
  140. value: '',
  141. options: {
  142. data: [{
  143. label: '已退回',
  144. value: '-2',
  145. },
  146. {
  147. label: '已取消',
  148. value: '-1',
  149. },
  150. {
  151. label: '未结算',
  152. value: '0',
  153. },
  154. {
  155. label: '已结算',
  156. value: '1',
  157. }],
  158. },
  159. },
  160. },
  161. condition: {},
  162. },
  163. count: {},
  164. statusStyle: {
  165. '-2': 'danger',
  166. '-1': 'warning',
  167. 0: 'info',
  168. 1: 'success',
  169. }
  170. })
  171. function getData() {
  172. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  173. let search = composeFilter(tempSearch, {
  174. 'buyer.nickname': 'like',
  175. 'buyer.mobile': 'like',
  176. 'agent.nickname': 'like',
  177. 'agent.mobile': 'like',
  178. 'reward.agent_nickname': 'like',
  179. 'reward.agent_mobile': 'like',
  180. 'order.order_sn': 'like',
  181. 'order_item.goods_title': 'like',
  182. 'order.createtime': 'range',
  183. commission_time: 'range',
  184. });
  185. Fast.api.ajax({
  186. url: 'shopro/commission/order',
  187. type: 'GET',
  188. data: {
  189. page: pagination.page,
  190. list_rows: pagination.list_rows,
  191. ...search,
  192. },
  193. }, function (ret, res) {
  194. state.count = res.data.count;
  195. state.data = res.data.list.data
  196. pagination.total = res.data.list.total
  197. return false
  198. }, function (ret, res) { })
  199. }
  200. function onOpenFilter() {
  201. state.filter.drawer = true
  202. }
  203. function onChangeFilter() {
  204. pagination.page = 1
  205. getData()
  206. state.filter.drawer && (state.filter.drawer = false)
  207. }
  208. const pagination = reactive({
  209. page: 1,
  210. list_rows: 10,
  211. total: 0,
  212. })
  213. const arraySpanMethod = ({ row, column, rowIndex, columnIndex }) => {
  214. if (columnIndex == 1) {
  215. return [1, 6];
  216. } else if (
  217. columnIndex == 3 ||
  218. columnIndex == 4 ||
  219. columnIndex == 5 ||
  220. columnIndex == 6 ||
  221. columnIndex == 7
  222. ) {
  223. return [0, 0];
  224. }
  225. };
  226. function countRewards(row) {
  227. let commission = 0;
  228. let commissioned = 0;
  229. row.forEach((r) => {
  230. if (r.status == 1) {
  231. commissioned += Number(r.commission);
  232. }
  233. commission += Number(r.commission);
  234. });
  235. return `${commission.toFixed(2)}元/${commissioned.toFixed(2)}元`;
  236. }
  237. const rewardsPopover = reactive({
  238. flag: {},
  239. commission: '',
  240. });
  241. function onConfirmRewardsPopover(index, id) {
  242. Fast.api.ajax({
  243. url: 'shopro/commission/order/edit',
  244. type: 'POST',
  245. data: {
  246. commission_reward_id: id,
  247. commission: rewardsPopover.commission,
  248. },
  249. }, function (ret, res) {
  250. onCancelRewardsPopover(index)
  251. getData()
  252. }, function (ret, res) { })
  253. }
  254. function onCancelRewardsPopover(index) {
  255. rewardsPopover.flag[index] = false;
  256. rewardsPopover.commission = '';
  257. }
  258. const commissionPopover = reactive({
  259. flag: {},
  260. type: null,
  261. isDelete: '1',
  262. });
  263. function onConfirmCommissionPopover(index, id) {
  264. let params = { commission_order_id: id };
  265. if (commissionPopover.type == 'confirm') {
  266. onConfirm(params);
  267. }
  268. if (commissionPopover.type == 'cancel') {
  269. params = { ...params, deduct_order_money: commissionPopover.isDelete };
  270. onCancel(params);
  271. }
  272. if (commissionPopover.type == 'back') {
  273. params = { ...params, deduct_order_money: commissionPopover.isDelete };
  274. onBack(params);
  275. }
  276. onCancelCommissionPopover(index);
  277. }
  278. function onCancelCommissionPopover(index) {
  279. commissionPopover.flag[index] = false;
  280. commissionPopover.isDelete = '1';
  281. }
  282. function onConfirm(data) {
  283. Fast.api.ajax({
  284. url: 'shopro/commission/order/confirm',
  285. type: 'POST',
  286. data: data,
  287. }, function (ret, res) {
  288. getData();
  289. }, function (ret, res) { })
  290. }
  291. function onCancel(data) {
  292. Fast.api.ajax({
  293. url: 'shopro/commission/order/cancel',
  294. type: 'POST',
  295. data: data,
  296. }, function (ret, res) {
  297. getData();
  298. }, function (ret, res) { })
  299. }
  300. function onBack(data) {
  301. Fast.api.ajax({
  302. url: 'shopro/commission/order/back',
  303. type: 'POST',
  304. data: data,
  305. }, function (ret, res) {
  306. getData();
  307. }, function (ret, res) { })
  308. }
  309. function onOpenGoodsDetail(id) {
  310. Fast.api.open(`shopro/goods/goods/add?type=edit&id=${id}`, "商品详情", {
  311. callback() {
  312. getData()
  313. }
  314. })
  315. }
  316. function onOpenOrderDetail(id) {
  317. Fast.api.open(`shopro/order/order/detail?id=${id}`, "订单详情", {
  318. callback() {
  319. getData()
  320. }
  321. })
  322. }
  323. const exportLoading = ref(false);
  324. function onExport(type) {
  325. exportLoading.value = true;
  326. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  327. let search = composeFilter(tempSearch, {
  328. 'buyer.nickname': 'like',
  329. 'buyer.mobile': 'like',
  330. 'agent.nickname': 'like',
  331. 'agent.mobile': 'like',
  332. 'reward.agent_nickname': 'like',
  333. 'reward.agent_mobile': 'like',
  334. 'order.order_sn': 'like',
  335. 'order_item.goods_title': 'like',
  336. 'order.createtime': 'range',
  337. commission_time: 'range',
  338. });
  339. if (Config.save_type == 'download') {
  340. window.location.href = `${Config.moduleurl}/shopro/commission/order/${type}?page=${pagination.page}&list_rows=${pagination.list_rows}&search=${search.search}`;
  341. exportLoading.value = false;
  342. } else if (Config.save_type == 'save') {
  343. Fast.api.ajax({
  344. url: `shopro/commission/order/${type}`,
  345. type: 'GET',
  346. data: {
  347. page: pagination.page,
  348. list_rows: pagination.list_rows,
  349. ...search,
  350. },
  351. }, function (ret, res) {
  352. exportLoading.value = false;
  353. }, function (ret, res) { })
  354. }
  355. }
  356. onMounted(() => {
  357. getData()
  358. })
  359. return {
  360. onClipboard,
  361. state,
  362. getData,
  363. onOpenFilter,
  364. onChangeFilter,
  365. pagination,
  366. arraySpanMethod,
  367. countRewards,
  368. rewardsPopover,
  369. onConfirmRewardsPopover,
  370. onCancelRewardsPopover,
  371. commissionPopover,
  372. onConfirmCommissionPopover,
  373. onCancelCommissionPopover,
  374. onConfirm,
  375. onCancel,
  376. onBack,
  377. onOpenGoodsDetail,
  378. onOpenOrderDetail,
  379. exportLoading,
  380. onExport,
  381. }
  382. }
  383. }
  384. createApp('index', index);
  385. },
  386. };
  387. return Controller;
  388. });