groupon.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. const moment = require("moment");
  2. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  3. var Controller = {
  4. index: function () {
  5. var grouponIndex = new Vue({
  6. el: "#groupon-index",
  7. data() {
  8. return {
  9. grouponType: '',
  10. grouponName: '',
  11. grouponOptions: [],
  12. statusType: 'all',
  13. grouponData: [],
  14. searchKey: '',
  15. currentPage: 1,
  16. totalPage: 0,
  17. offset: 0,
  18. limit: 10,
  19. dialogTeamDetail: false,
  20. grouponGoodsData: [],
  21. grouponTeamList: [],
  22. is_define_grouponTeamListLeng: '',
  23. is_dialog_opt: false,
  24. temp: null
  25. }
  26. },
  27. mounted() {
  28. this.getgrouponOptions()
  29. },
  30. methods: {
  31. selectChange(val) {
  32. this.grouponType = val;
  33. this.grouponOptions.forEach(i => {
  34. if (i.id == val) {
  35. this.grouponName = i.label
  36. }
  37. })
  38. this.offset = 0;
  39. this.currentPage = 1;
  40. this.getgrouponData()
  41. },
  42. getgrouponOptions() {
  43. let that = this;
  44. Fast.api.ajax({
  45. url: 'shopro/activity/activity/all',
  46. loading: true,
  47. type: 'GET',
  48. data: {
  49. type: 'groupon'
  50. }
  51. }, function (ret, res) {
  52. if (res.data.length) {
  53. res.data.forEach(i => {
  54. that.grouponOptions.push({
  55. value: i.id,
  56. label: i.title
  57. })
  58. })
  59. that.grouponType = that.grouponOptions[0].value;
  60. that.grouponName = that.grouponOptions[0].label;
  61. that.getgrouponData();
  62. }
  63. return false;
  64. })
  65. },
  66. getgrouponData() {
  67. var that = this;
  68. window.clearInterval(that.temp)
  69. that.is_dialog_opt = false
  70. Fast.api.ajax({
  71. url: 'shopro/activity/groupon/index',
  72. loading: true,
  73. type: 'GET',
  74. data: {
  75. sort: 'id',
  76. order: 'desc',
  77. offset: that.offset,
  78. limit: that.limit,
  79. activity_id: that.grouponType,
  80. status: that.statusType,
  81. search: that.searchKey,
  82. }
  83. }, function (ret, res) {
  84. let arrMsg = []
  85. res.data.rows.forEach(i => {
  86. arrMsg.push({
  87. id: i.id,
  88. goods_title: i.goods.title,
  89. goods_image: i.goods.image,
  90. createtime: i.createtime,
  91. user_nickname: i.groupon_log[0].user_nickname,
  92. arr: i.groupon_log,
  93. expiretime: i.expiretime,
  94. // expiretime: 1590810077,
  95. countDown: '',
  96. status: i.status,
  97. status_text: i.status_text,
  98. num: i.num,
  99. current_num: i.current_num
  100. })
  101. })
  102. that.totalPage = res.data.total
  103. that.timer(arrMsg)
  104. return false;
  105. })
  106. },
  107. timer(arr) {
  108. let that = this;
  109. that.temp = setInterval(() => {
  110. arr.forEach((item, index) => {
  111. that.$set(arr[index], 'countDown', that.countDownFun(item.expiretime * 1000));
  112. });
  113. that.grouponData = arr
  114. }, 1000);
  115. },
  116. countDownFun(time) {
  117. time--;
  118. let nowTime = new Date().getTime();
  119. if (nowTime <= time) {
  120. let timediff = Math.round((time - nowTime) / 1000);
  121. let day = parseInt(timediff / 3600 / 24) > 9 ? parseInt(timediff / 3600 / 24) : '0' + parseInt(timediff / 3600 / 24);
  122. let hour = parseInt((timediff / 3600) % 24) > 9 ? parseInt((timediff / 3600) % 24) : '0' + parseInt((timediff / 3600) % 24);
  123. let minute = parseInt((timediff / 60) % 60) > 9 ? parseInt((timediff / 60) % 60) : '0' + parseInt((timediff / 60) % 60);
  124. let second = timediff % 60 > 9 ? timediff % 60 : '0' + timediff % 60;
  125. return day + "天" + hour + "时" + minute + "分" + second + "秒";
  126. } else {
  127. return "-";
  128. }
  129. },
  130. goDetail(id, row) {
  131. this.dialogTeamDetail = true
  132. this.grouponGoodsData = []
  133. this.grouponGoodsData.push(row)
  134. this.grouponTeamList = JSON.parse(JSON.stringify(this.grouponGoodsData[0].arr));
  135. },
  136. handleSizeChange(val) {
  137. this.offset = 0;
  138. this.currentPage = 1;
  139. this.limit = val
  140. this.getgrouponData()
  141. },
  142. handleCurrentChange(val) {
  143. this.currentPage = val;
  144. this.offset = (val - 1) * this.limit
  145. this.getgrouponData()
  146. },
  147. handleTeamDetailClose() {
  148. this.dialogTeamDetail = false
  149. if (this.is_dialog_opt) {
  150. this.getgrouponData()
  151. }
  152. },
  153. refreshTeamer(index) {
  154. let that = this;
  155. Fast.api.ajax({
  156. url: 'shopro/user_fake/random_user',
  157. loading: true,
  158. type: 'GET',
  159. data: {}
  160. }, function (ret, res) {
  161. if (index == null) {
  162. that.grouponTeamList.push({
  163. createtime: Date.parse(new Date()) / 1000,
  164. user_nickname: res.data.nickname,
  165. is_leader: false,
  166. user_avatar: res.data.avatar,
  167. is_fictitious: true,
  168. id: res.data.id,
  169. is_define: true
  170. })
  171. } else {
  172. let arr = {
  173. createtime: Date.parse(new Date()) / 1000,
  174. user_nickname: res.data.nickname,
  175. is_leader: false,
  176. user_avatar: res.data.avatar,
  177. is_fictitious: true,
  178. id: res.data.id,
  179. is_define: true
  180. }
  181. for (key in arr) {
  182. that.grouponTeamList[index][key] = arr[key]
  183. }
  184. }
  185. let leng = 0
  186. that.grouponTeamList.forEach(i => {
  187. if (!i.is_define) {
  188. leng++
  189. }
  190. })
  191. that.is_define_grouponTeamListLeng = leng
  192. })
  193. },
  194. defineTeamer(index, row) {
  195. let that = this;
  196. Fast.api.ajax({
  197. url: `shopro/activity/groupon/addFictitious/id/${that.grouponGoodsData[0].id}`,
  198. loading: true,
  199. type: 'POST',
  200. data: {
  201. avatar: row.user_avatar,
  202. nickname: row.user_nickname
  203. }
  204. }, function (ret, res) {
  205. that.is_dialog_opt = true
  206. that.grouponGoodsData = []
  207. res.data.goods_title = res.data.goods.title
  208. res.data.goods_image = res.data.goods.image
  209. that.grouponGoodsData.push(res.data)
  210. that.grouponTeamList = JSON.parse(JSON.stringify(that.grouponGoodsData[0].groupon_log));
  211. })
  212. },
  213. cancelTeamer(index) {
  214. this.grouponTeamList.splice(index, 1)
  215. },
  216. dismissTeam() {
  217. let that = this;
  218. that.dialogTeamDetail = false
  219. Fast.api.ajax({
  220. url: `shopro/activity/groupon/invalidGroupon/id/${that.grouponGoodsData[0].id}`,
  221. loading: true,
  222. type: 'POST',
  223. data: {}
  224. }, function (ret, res) {
  225. that.getgrouponData()
  226. })
  227. },
  228. callSearch(e) {
  229. var evt = window.event || e;
  230. if (evt.keyCode == 13) {
  231. this.offset = 0;
  232. this.currentPage = 1;
  233. this.getgrouponData();
  234. }
  235. }
  236. },
  237. beforeDestroy() {
  238. window.clearInterval(this.temp)
  239. },
  240. watch: {
  241. statusType(newVal, oldVal) {
  242. if (newVal, oldVal) {
  243. this.currentPage = 1;
  244. this.offset = 0;
  245. this.limit = 10;
  246. this.getgrouponData()
  247. }
  248. }
  249. },
  250. })
  251. },
  252. detail: function () {
  253. var vue = new Vue({
  254. el: "#groupon-detail",
  255. data() {
  256. return {
  257. grouponGoodsData: [],
  258. grouponTeamList: [],
  259. is_define_grouponTeamListLeng: '',
  260. // is_dialog_opt:false,
  261. temp: null
  262. }
  263. },
  264. mounted() {
  265. let id = Config.id
  266. let that = this;
  267. Fast.api.ajax({
  268. url: `shopro/activity/groupon/detail/id/${id}`,
  269. loading: true,
  270. type: 'GET',
  271. data: {}
  272. }, function (ret, res) {
  273. let arrMsg = []
  274. let datas = []
  275. datas.push(res.data)
  276. datas.forEach(i => {
  277. arrMsg.push({
  278. id: i.id,
  279. goods_title: i.goods?i.goods.title:"",
  280. goods_image: i.goods?i.goods.image:"",
  281. createtime: i.createtime,
  282. user_nickname: i.groupon_log[0].user_nickname,
  283. arr: i.groupon_log,
  284. expiretime: i.expiretime,
  285. status: i.status,
  286. status_text: i.status_text,
  287. num: i.num,
  288. current_num: i.current_num
  289. })
  290. })
  291. that.grouponGoodsData = arrMsg;
  292. that.grouponTeamList = JSON.parse(JSON.stringify(that.grouponGoodsData[0].arr));
  293. let leng = 0
  294. that.grouponTeamList.forEach(i => {
  295. if (!i.is_define) {
  296. leng++
  297. }
  298. })
  299. that.is_define_grouponTeamListLeng = leng
  300. return false;
  301. })
  302. },
  303. methods: {
  304. refreshTeamer(index) {
  305. let that = this;
  306. Fast.api.ajax({
  307. url: 'shopro/user_fake/random_user',
  308. loading: true,
  309. type: 'GET',
  310. data: {}
  311. }, function (ret, res) {
  312. if (index == null) {
  313. that.grouponTeamList.push({
  314. createtime: Date.parse(new Date()) / 1000,
  315. user_nickname: res.data.nickname,
  316. is_leader: false,
  317. user_avatar: res.data.avatar,
  318. is_fictitious: true,
  319. id: res.data.id,
  320. is_define: true
  321. })
  322. } else {
  323. let arr = {
  324. createtime: Date.parse(new Date()) / 1000,
  325. user_nickname: res.data.nickname,
  326. is_leader: false,
  327. user_avatar: res.data.avatar,
  328. is_fictitious: true,
  329. id: res.data.id,
  330. is_define: true
  331. }
  332. for (key in arr) {
  333. that.grouponTeamList[index][key] = arr[key]
  334. }
  335. }
  336. let leng = 0
  337. that.grouponTeamList.forEach(i => {
  338. if (!i.is_define) {
  339. leng++
  340. }
  341. })
  342. that.is_define_grouponTeamListLeng = leng
  343. })
  344. },
  345. defineTeamer(index, row) {
  346. let that = this;
  347. Fast.api.ajax({
  348. url: `shopro/activity/groupon/addFictitious/id/${that.grouponGoodsData[0].id}`,
  349. loading: true,
  350. type: 'POST',
  351. data: {
  352. avatar: row.user_avatar,
  353. nickname: row.user_nickname
  354. }
  355. }, function (ret, res) {
  356. // that.is_dialog_opt=true
  357. that.grouponGoodsData = []
  358. res.data.goods_title = res.data.goods.title
  359. res.data.goods_image = res.data.goods.image
  360. that.grouponGoodsData.push(res.data)
  361. that.grouponTeamList = JSON.parse(JSON.stringify(that.grouponGoodsData[0].groupon_log));
  362. })
  363. },
  364. cancelTeamer(index) {
  365. this.grouponTeamList.splice(index, 1)
  366. },
  367. dismissTeam() {
  368. let that = this;
  369. that.dialogTeamDetail = false
  370. Fast.api.ajax({
  371. url: `shopro/activity/groupon/invalidGroupon/id/${that.grouponGoodsData[0].id}`,
  372. loading: true,
  373. type: 'POST',
  374. data: {}
  375. }, function (ret, res) {
  376. Fast.api.close({
  377. data: 123
  378. })
  379. })
  380. },
  381. }
  382. })
  383. },
  384. add: function () {
  385. Controller.api.bindevent();
  386. },
  387. edit: function () {
  388. Controller.api.bindevent();
  389. },
  390. api: {
  391. bindevent: function () {
  392. Form.api.bindevent($("form[role=form]"));
  393. }
  394. }
  395. };
  396. return Controller;
  397. });