index.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'moment'], function ($, undefined, Backend, Table, Form, Moment) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted, ref, watch } = Vue
  5. const index = {
  6. setup() {
  7. const state = reactive({
  8. status: 0,
  9. data: [],
  10. filter: {
  11. drawer: false,
  12. data: {
  13. name: '',
  14. },
  15. tools: {
  16. name: {
  17. type: 'tinput',
  18. field: 'name',
  19. value: '',
  20. label: '商品名称',
  21. placeholder: '请输入商品名称',
  22. },
  23. },
  24. condition: {}
  25. }
  26. })
  27. const dispatchType = ref('live');
  28. // 直播间表格
  29. const live = reactive({
  30. data: [],
  31. order: '',
  32. sort: '',
  33. selected: [],
  34. });
  35. //商品库表格
  36. const goods = reactive({
  37. data: [],
  38. order: '',
  39. sort: '',
  40. });
  41. // 获取直播间数据
  42. function getLiveData() {
  43. Fast.api.ajax({
  44. url: 'shopro/app/mplive/room',
  45. type: 'GET',
  46. data: {
  47. sort: live.sort,
  48. order: live.order
  49. },
  50. }, function (ret, res) {
  51. live.data = res.data;
  52. return false
  53. }, function (ret, res) { })
  54. }
  55. function getData() {
  56. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  57. let search = composeFilter(tempSearch, {
  58. name: 'like',
  59. });
  60. Fast.api.ajax({
  61. url: 'shopro/app/mplive/goods',
  62. type: 'GET',
  63. data: {
  64. page: pagination.page,
  65. list_rows: pagination.list_rows,
  66. ...search,
  67. },
  68. }, function (ret, res) {
  69. goods.data = res.data.data
  70. pagination.total = res.data.total
  71. return false
  72. }, function (ret, res) { })
  73. }
  74. function formatPrice(price, type) {
  75. if (type === 1) {
  76. return '';
  77. } else if (type === 2) {
  78. return '~' + price + '元';
  79. } else {
  80. return price + '元';
  81. }
  82. }
  83. function onOpenFilter() {
  84. state.filter.drawer = true
  85. }
  86. function onChangeFilter() {
  87. pagination.page = 1
  88. getData()
  89. state.filter.drawer && (state.filter.drawer = false)
  90. }
  91. const pagination = reactive({
  92. page: 1,
  93. list_rows: 10,
  94. total: 0,
  95. })
  96. function addRow() {
  97. Fast.api.open(`shopro/app/mplive/room/add?type=add`, "添加直播间", {
  98. callback() {
  99. getLiveData()
  100. }
  101. })
  102. }
  103. function editRow(id) {
  104. Fast.api.open(`shopro/app/mplive/room/edit?type=edit&id=${id}`, "编辑直播间", {
  105. callback() {
  106. getLiveData()
  107. }
  108. })
  109. }
  110. function deleteApi(id) {
  111. Fast.api.ajax({
  112. url: `shopro/app/mplive/room/delete/id/${id}`,
  113. type: 'DELETE',
  114. }, function (ret, res) {
  115. getLiveData()
  116. }, function (ret, res) { })
  117. }
  118. //表格排序
  119. function onChangeSort({ prop, order }) {
  120. live.order = order == 'ascending' ? 'asc' : 'desc';
  121. live.sort = prop;
  122. getLiveData();
  123. }
  124. //推流地址
  125. async function pushUrl(id) {
  126. Fast.api.open(`shopro/app/mplive/room/pushUrl?id=${id}`, "推流地址", {
  127. callback() {
  128. getLiveData()
  129. }
  130. })
  131. }
  132. //分享二维码
  133. async function shareQrcode(id) {
  134. Fast.api.open(`shopro/app/mplive/room/qrcode?id=${id}`, "分享二维码", {
  135. callback() {
  136. getLiveData()
  137. }
  138. })
  139. }
  140. //同步直播间
  141. function sync() {
  142. Fast.api.ajax({
  143. url: `shopro/app/mplive/room/sync`,
  144. type: 'GET',
  145. }, function (ret, res) {
  146. live.data = res.data;
  147. }, function (ret, res) { })
  148. }
  149. //直播回放
  150. function playBack(id) {
  151. Fast.api.open(`shopro/app/mplive/room/playback?id=${id}`, "直播回放列表", {
  152. callback() {
  153. getLiveData()
  154. }
  155. })
  156. }
  157. //添加商品
  158. function addGoods() {
  159. Fast.api.open(`shopro/app/mplive/goods/add?type=add`, "添加商品", {
  160. callback() {
  161. getData()
  162. }
  163. })
  164. }
  165. //编辑商品
  166. function editGoods(id) {
  167. Fast.api.open(`shopro/app/mplive/goods/edit?type=edit&id=${id}`, "编辑商品", {
  168. callback() {
  169. getData()
  170. }
  171. })
  172. }
  173. // 删除商品
  174. function deleteGoods(id) {
  175. Fast.api.ajax({
  176. url: `shopro/app/mplive/goods/delete/id/${id}`,
  177. type: 'DELETE',
  178. }, function (ret, res) {
  179. getData()
  180. }, function (ret, res) { })
  181. }
  182. // 获取状态
  183. function getStatus(id) {
  184. Fast.api.ajax({
  185. url: `shopro/app/mplive/goods/status/id/${id}`,
  186. type: 'GET',
  187. }, function (ret, res) {
  188. getData()
  189. }, function (ret, res) { })
  190. }
  191. //审核
  192. function check(id, act) {
  193. Fast.api.ajax({
  194. url: `shopro/app/mplive/goods/audit/id/${id}`,
  195. type: 'POST',
  196. data: {
  197. act
  198. },
  199. }, function (ret, res) {
  200. getData()
  201. }, function (ret, res) { })
  202. }
  203. watch(() => dispatchType.value, () => {
  204. if (dispatchType.value === 'live') {
  205. getLiveData()
  206. } else {
  207. getData()
  208. }
  209. })
  210. onMounted(() => {
  211. getLiveData()
  212. })
  213. return {
  214. state,
  215. live,
  216. goods,
  217. dispatchType,
  218. getData,
  219. onOpenFilter,
  220. onChangeFilter,
  221. pagination,
  222. formatPrice,
  223. getLiveData,
  224. addRow,
  225. editRow,
  226. deleteApi,
  227. Moment,
  228. sync,
  229. playBack,
  230. shareQrcode,
  231. pushUrl,
  232. addGoods,
  233. editGoods,
  234. deleteGoods,
  235. check,
  236. getStatus,
  237. onChangeSort
  238. }
  239. }
  240. }
  241. createApp('index', index);
  242. },
  243. };
  244. return Controller;
  245. });