groupon.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. activity_id: new URLSearchParams(location.search).get('activity_id'),
  9. data: [],
  10. order: '',
  11. sort: '',
  12. filter: {
  13. drawer: false,
  14. data: {
  15. status: 'all',
  16. user: { field: 'user_id', value: '' },
  17. 'goods.title': '',
  18. },
  19. tools: {
  20. user: {
  21. type: 'tinputprepend',
  22. label: '团长信息',
  23. placeholder: '请输入查询内容',
  24. value: {
  25. field: 'user_id',
  26. value: '',
  27. },
  28. options: {
  29. data: [
  30. {
  31. label: '团长ID',
  32. value: 'user_id',
  33. },
  34. {
  35. label: '团长昵称',
  36. value: 'user.nickname',
  37. },
  38. {
  39. label: '团长手机号',
  40. value: 'user.mobile',
  41. },
  42. ],
  43. }
  44. },
  45. 'goods.title': {
  46. type: 'tinput',
  47. label: '商品名称',
  48. value: '',
  49. },
  50. },
  51. condition: {},
  52. },
  53. statusList: [{
  54. name: '全部',
  55. type: 'all',
  56. },
  57. {
  58. name: '进行中',
  59. type: 'ing',
  60. },
  61. {
  62. name: '已成团',
  63. type: 'finish',
  64. },
  65. {
  66. name: '虚拟成团',
  67. type: 'finish_fictitious',
  68. },
  69. {
  70. name: '已过期',
  71. type: 'invalid ',
  72. }],
  73. statusClass: {
  74. ing: 'warning',
  75. finish: 'success',
  76. finish_fictitious: 'success',
  77. invalid: 'danger',
  78. },
  79. })
  80. function getData() {
  81. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  82. tempSearch.activity_id = state.activity_id
  83. let search = composeFilter(tempSearch, {
  84. 'user.nickname': 'like',
  85. 'goods.title': 'like',
  86. });
  87. Fast.api.ajax({
  88. url: 'shopro/activity/groupon',
  89. type: 'GET',
  90. data: {
  91. type: state.type,
  92. page: pagination.page,
  93. list_rows: pagination.list_rows,
  94. order: state.order,
  95. sort: state.sort,
  96. ...search,
  97. },
  98. }, function (ret, res) {
  99. state.data = res.data.data
  100. pagination.total = res.data.total
  101. return false
  102. }, function (ret, res) { })
  103. }
  104. function onChangeSort({ prop, order }) {
  105. state.order = order == 'ascending' ? 'asc' : 'desc';
  106. state.sort = prop;
  107. getData();
  108. }
  109. function onOpenFilter() {
  110. state.filter.drawer = true
  111. }
  112. function onChangeFilter() {
  113. pagination.page = 1
  114. getData()
  115. state.filter.drawer && (state.filter.drawer = false)
  116. }
  117. function onChangeTab() {
  118. pagination.page = 1
  119. getData()
  120. }
  121. const pagination = reactive({
  122. page: 1,
  123. list_rows: 10,
  124. total: 0,
  125. })
  126. function onDetail(id) {
  127. Fast.api.open(`shopro/activity/groupon/detail/id/${id}?id=${id}`, "详情", {
  128. callback() {
  129. getData()
  130. }
  131. })
  132. }
  133. onMounted(() => {
  134. getData()
  135. })
  136. return {
  137. state,
  138. getData,
  139. onChangeSort,
  140. onOpenFilter,
  141. onChangeFilter,
  142. onChangeTab,
  143. pagination,
  144. onDetail,
  145. }
  146. }
  147. }
  148. createApp('index', index);
  149. },
  150. detail: () => {
  151. const { reactive, onMounted, getCurrentInstance } = Vue
  152. const detail = {
  153. setup() {
  154. const { proxy } = getCurrentInstance();
  155. const state = reactive({
  156. id: new URLSearchParams(location.search).get('id'),
  157. data: {},
  158. statusClass: {
  159. ing: 'warning',
  160. finish: 'success',
  161. finish_fictitious: 'success',
  162. invalid: 'danger',
  163. },
  164. })
  165. function getDetail() {
  166. Fast.api.ajax({
  167. url: `shopro/activity/groupon/detail/id/${state.id}`,
  168. type: 'GET',
  169. }, function (ret, res) {
  170. state.data = res.data
  171. return false
  172. }, function (ret, res) { })
  173. }
  174. function onInvalid() {
  175. Fast.api.ajax({
  176. url: `shopro/activity/groupon/invalid/id/${state.id}`,
  177. type: 'GET',
  178. }, function (ret, res) {
  179. getDetail()
  180. }, function (ret, res) { })
  181. }
  182. function onAddUser() {
  183. Fast.api.ajax({
  184. url: 'shopro/data/fake_user/getRandom',
  185. type: 'GET',
  186. }, function (ret, res) {
  187. state.data.groupon_logs.push({
  188. avatar: res.data.avatar,
  189. nickname: res.data.nickname,
  190. is_fictitious: 1,
  191. is_temp: true,
  192. });
  193. return false
  194. }, function (ret, res) { })
  195. }
  196. function onConfirm(item) {
  197. Fast.api.ajax({
  198. url: `shopro/activity/groupon/addUser/id/${state.id}`,
  199. type: 'POST',
  200. data: {
  201. avatar: item.avatar,
  202. nickname: item.nickname,
  203. }
  204. }, function (ret, res) {
  205. getDetail()
  206. }, function (ret, res) { })
  207. }
  208. function onCancel(index) {
  209. state.data.groupon_logs.splice(index, 1);
  210. }
  211. onMounted(() => {
  212. getDetail()
  213. })
  214. return {
  215. state,
  216. onInvalid,
  217. onAddUser,
  218. onConfirm,
  219. onCancel,
  220. }
  221. }
  222. }
  223. createApp('detail', detail);
  224. },
  225. };
  226. return Controller;
  227. });