order.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. data: () => {
  4. return {
  5. statusStyle: {
  6. unpaid: 'warning',
  7. paid: 'success',
  8. completed: 'success',
  9. closed: 'danger',
  10. cancel: 'info',
  11. closed: 'danger',
  12. }
  13. }
  14. },
  15. index: () => {
  16. const { ref, reactive, onMounted } = Vue
  17. const index = {
  18. setup() {
  19. const state = reactive({
  20. data: [],
  21. filter: {
  22. drawer: false,
  23. data: {
  24. status: 'all',
  25. order: { field: 'id', value: '' },
  26. user: { field: 'user_id', value: '' },
  27. platform: '',
  28. 'pay.pay_type': '',
  29. createtime: [],
  30. },
  31. tools: {
  32. order: {
  33. type: 'tinputprepend',
  34. label: '查询内容',
  35. placeholder: '请输入查询内容',
  36. value: {
  37. field: 'id',
  38. value: '',
  39. },
  40. options: {
  41. data: [{
  42. label: '订单ID',
  43. value: 'id',
  44. },
  45. {
  46. label: '订单编号',
  47. value: 'order_sn',
  48. },
  49. {
  50. label: '支付单号',
  51. value: 'pay.pay_sn',
  52. }],
  53. }
  54. },
  55. user: {
  56. type: 'tinputprepend',
  57. label: '用户信息',
  58. placeholder: '请输入查询内容',
  59. value: {
  60. field: 'user_id',
  61. value: '',
  62. },
  63. options: {
  64. data: [{
  65. label: '用户ID',
  66. value: 'user_id',
  67. },
  68. {
  69. label: '用户昵称',
  70. value: 'user.nickname',
  71. },
  72. {
  73. label: '用户手机号',
  74. value: 'user.mobile',
  75. }],
  76. }
  77. },
  78. platform: {
  79. type: 'tselect',
  80. label: '订单来源',
  81. value: '',
  82. options: {
  83. data: [],
  84. props: {
  85. label: 'name',
  86. value: 'type',
  87. },
  88. },
  89. },
  90. 'pay.pay_type': {
  91. type: 'tselect',
  92. label: '支付方式',
  93. value: '',
  94. options: {
  95. data: [],
  96. props: {
  97. label: 'name',
  98. value: 'type',
  99. },
  100. },
  101. },
  102. createtime: {
  103. type: 'tdatetimerange',
  104. label: '下单时间',
  105. value: [],
  106. },
  107. },
  108. condition: {},
  109. },
  110. })
  111. const type = reactive({
  112. data: {}
  113. })
  114. function getType() {
  115. Fast.api.ajax({
  116. url: 'shopro/trade/order/getType',
  117. type: 'GET',
  118. }, function (ret, res) {
  119. type.data = res.data
  120. for (key in res.data) {
  121. if (key == 'pay_type') {
  122. state.filter.tools['pay.pay_type'].options.data = res.data[key]
  123. } else if (key == 'platform') {
  124. state.filter.tools[key].options.data = res.data[key]
  125. }
  126. }
  127. return false
  128. }, function (ret, res) { })
  129. }
  130. function getData() {
  131. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  132. let search = composeFilter(tempSearch, {
  133. order_sn: 'like',
  134. 'pay.pay_sn': 'like',
  135. 'user.nickname': 'like',
  136. 'user.mobile': 'like',
  137. createtime: 'range',
  138. });
  139. Fast.api.ajax({
  140. url: 'shopro/trade/order',
  141. type: 'GET',
  142. data: {
  143. page: pagination.page,
  144. list_rows: pagination.list_rows,
  145. ...search,
  146. },
  147. }, function (ret, res) {
  148. state.data = res.data.orders.data
  149. pagination.total = res.data.orders.total
  150. type.data?.status?.forEach(item => {
  151. item.num = res.data[item.type]
  152. })
  153. return false
  154. }, function (ret, res) { })
  155. }
  156. function onOpenFilter() {
  157. state.filter.drawer = true
  158. }
  159. function onChangeFilter() {
  160. pagination.page = 1
  161. getData()
  162. state.filter.drawer && (state.filter.drawer = false)
  163. }
  164. function onChangeTab() {
  165. pagination.page = 1
  166. getData()
  167. }
  168. const pagination = reactive({
  169. page: 1,
  170. list_rows: 10,
  171. total: 0,
  172. })
  173. const exportLoading = ref(false);
  174. function onExport() {
  175. exportLoading.value = true;
  176. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  177. let search = composeFilter(tempSearch, {
  178. order_sn: 'like',
  179. 'pay.pay_sn': 'like',
  180. 'user.nickname': 'like',
  181. 'user.mobile': 'like',
  182. createtime: 'range',
  183. });
  184. if (Config.save_type == 'download') {
  185. window.location.href = `${Config.moduleurl}/shopro/trade/order/export?page=${pagination.page}&list_rows=${pagination.list_rows}&search=${search.search}`;
  186. exportLoading.value = false;
  187. } else if (Config.save_type == 'save') {
  188. Fast.api.ajax({
  189. url: 'shopro/trade/order/export',
  190. type: 'GET',
  191. data: {
  192. page: pagination.page,
  193. list_rows: pagination.list_rows,
  194. ...search,
  195. },
  196. }, function (ret, res) {
  197. exportLoading.value = false;
  198. }, function (ret, res) { })
  199. }
  200. }
  201. function onDetail(id) {
  202. Fast.api.open(`shopro/trade/order/detail/id/${id}?id=${id}`, "详情", {
  203. callback() {
  204. getData()
  205. }
  206. })
  207. }
  208. onMounted(() => {
  209. getType()
  210. getData()
  211. })
  212. return {
  213. onClipboard,
  214. ...Controller.data(),
  215. state,
  216. type,
  217. getData,
  218. onOpenFilter,
  219. onChangeFilter,
  220. onChangeTab,
  221. pagination,
  222. exportLoading,
  223. onExport,
  224. onDetail,
  225. }
  226. }
  227. }
  228. createApp('index', index);
  229. },
  230. detail: () => {
  231. const { reactive, onMounted } = Vue
  232. const detail = {
  233. setup() {
  234. const state = reactive({
  235. id: new URLSearchParams(location.search).get('id'),
  236. detail: {},
  237. })
  238. function getDetail() {
  239. Fast.api.ajax({
  240. url: `shopro/trade/order/detail/id/${state.id}`,
  241. type: 'GET',
  242. }, function (ret, res) {
  243. state.detail = res.data;
  244. return false
  245. }, function (ret, res) { })
  246. }
  247. onMounted(() => {
  248. getDetail()
  249. })
  250. return {
  251. ...Controller.data(),
  252. state,
  253. }
  254. }
  255. }
  256. createApp('detail', detail);
  257. },
  258. };
  259. return Controller;
  260. });