123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- const moment = require("moment");
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- var grouponIndex = new Vue({
- el: "#groupon-index",
- data() {
- return {
- grouponType: '',
- grouponName: '',
- grouponOptions: [],
- statusType: 'all',
- grouponData: [],
- searchKey: '',
- currentPage: 1,
- totalPage: 0,
- offset: 0,
- limit: 10,
- dialogTeamDetail: false,
- grouponGoodsData: [],
- grouponTeamList: [],
- is_define_grouponTeamListLeng: '',
- is_dialog_opt: false,
- temp: null
- }
- },
- mounted() {
- this.getgrouponOptions()
- },
- methods: {
- selectChange(val) {
- this.grouponType = val;
- this.grouponOptions.forEach(i => {
- if (i.id == val) {
- this.grouponName = i.label
- }
- })
- this.offset = 0;
- this.currentPage = 1;
- this.getgrouponData()
- },
- getgrouponOptions() {
- let that = this;
- Fast.api.ajax({
- url: 'shopro/activity/activity/all',
- loading: true,
- type: 'GET',
- data: {
- type: 'groupon'
- }
- }, function (ret, res) {
- if (res.data.length) {
- res.data.forEach(i => {
- that.grouponOptions.push({
- value: i.id,
- label: i.title
- })
- })
- that.grouponType = that.grouponOptions[0].value;
- that.grouponName = that.grouponOptions[0].label;
- that.getgrouponData();
- }
- return false;
- })
- },
- getgrouponData() {
- var that = this;
- window.clearInterval(that.temp)
- that.is_dialog_opt = false
- Fast.api.ajax({
- url: 'shopro/activity/groupon/index',
- loading: true,
- type: 'GET',
- data: {
- sort: 'id',
- order: 'desc',
- offset: that.offset,
- limit: that.limit,
- activity_id: that.grouponType,
- status: that.statusType,
- search: that.searchKey,
- }
- }, function (ret, res) {
- let arrMsg = []
- res.data.rows.forEach(i => {
- arrMsg.push({
- id: i.id,
- goods_title: i.goods.title,
- goods_image: i.goods.image,
- createtime: i.createtime,
- user_nickname: i.groupon_log[0].user_nickname,
- arr: i.groupon_log,
- expiretime: i.expiretime,
- // expiretime: 1590810077,
- countDown: '',
- status: i.status,
- status_text: i.status_text,
- num: i.num,
- current_num: i.current_num
- })
- })
- that.totalPage = res.data.total
- that.timer(arrMsg)
- return false;
- })
- },
- timer(arr) {
- let that = this;
- that.temp = setInterval(() => {
- arr.forEach((item, index) => {
- that.$set(arr[index], 'countDown', that.countDownFun(item.expiretime * 1000));
- });
- that.grouponData = arr
- }, 1000);
- },
- countDownFun(time) {
- time--;
- let nowTime = new Date().getTime();
- if (nowTime <= time) {
- let timediff = Math.round((time - nowTime) / 1000);
- let day = parseInt(timediff / 3600 / 24) > 9 ? parseInt(timediff / 3600 / 24) : '0' + parseInt(timediff / 3600 / 24);
- let hour = parseInt((timediff / 3600) % 24) > 9 ? parseInt((timediff / 3600) % 24) : '0' + parseInt((timediff / 3600) % 24);
- let minute = parseInt((timediff / 60) % 60) > 9 ? parseInt((timediff / 60) % 60) : '0' + parseInt((timediff / 60) % 60);
- let second = timediff % 60 > 9 ? timediff % 60 : '0' + timediff % 60;
- return day + "天" + hour + "时" + minute + "分" + second + "秒";
- } else {
- return "-";
- }
- },
- goDetail(id, row) {
- this.dialogTeamDetail = true
- this.grouponGoodsData = []
- this.grouponGoodsData.push(row)
- this.grouponTeamList = JSON.parse(JSON.stringify(this.grouponGoodsData[0].arr));
- },
- handleSizeChange(val) {
- this.offset = 0;
- this.currentPage = 1;
- this.limit = val
- this.getgrouponData()
- },
- handleCurrentChange(val) {
- this.currentPage = val;
- this.offset = (val - 1) * this.limit
- this.getgrouponData()
- },
- handleTeamDetailClose() {
- this.dialogTeamDetail = false
- if (this.is_dialog_opt) {
- this.getgrouponData()
- }
- },
- refreshTeamer(index) {
- let that = this;
- Fast.api.ajax({
- url: 'shopro/user_fake/random_user',
- loading: true,
- type: 'GET',
- data: {}
- }, function (ret, res) {
- if (index == null) {
- that.grouponTeamList.push({
- createtime: Date.parse(new Date()) / 1000,
- user_nickname: res.data.nickname,
- is_leader: false,
- user_avatar: res.data.avatar,
- is_fictitious: true,
- id: res.data.id,
- is_define: true
- })
- } else {
- let arr = {
- createtime: Date.parse(new Date()) / 1000,
- user_nickname: res.data.nickname,
- is_leader: false,
- user_avatar: res.data.avatar,
- is_fictitious: true,
- id: res.data.id,
- is_define: true
- }
- for (key in arr) {
- that.grouponTeamList[index][key] = arr[key]
- }
- }
- let leng = 0
- that.grouponTeamList.forEach(i => {
- if (!i.is_define) {
- leng++
- }
- })
- that.is_define_grouponTeamListLeng = leng
- })
- },
- defineTeamer(index, row) {
- let that = this;
- Fast.api.ajax({
- url: `shopro/activity/groupon/addFictitious/id/${that.grouponGoodsData[0].id}`,
- loading: true,
- type: 'POST',
- data: {
- avatar: row.user_avatar,
- nickname: row.user_nickname
- }
- }, function (ret, res) {
- that.is_dialog_opt = true
- that.grouponGoodsData = []
- res.data.goods_title = res.data.goods.title
- res.data.goods_image = res.data.goods.image
- that.grouponGoodsData.push(res.data)
- that.grouponTeamList = JSON.parse(JSON.stringify(that.grouponGoodsData[0].groupon_log));
- })
- },
- cancelTeamer(index) {
- this.grouponTeamList.splice(index, 1)
- },
- dismissTeam() {
- let that = this;
- that.dialogTeamDetail = false
- Fast.api.ajax({
- url: `shopro/activity/groupon/invalidGroupon/id/${that.grouponGoodsData[0].id}`,
- loading: true,
- type: 'POST',
- data: {}
- }, function (ret, res) {
- that.getgrouponData()
- })
- },
- callSearch(e) {
- var evt = window.event || e;
- if (evt.keyCode == 13) {
- this.offset = 0;
- this.currentPage = 1;
- this.getgrouponData();
- }
- }
- },
- beforeDestroy() {
- window.clearInterval(this.temp)
- },
- watch: {
- statusType(newVal, oldVal) {
- if (newVal, oldVal) {
- this.currentPage = 1;
- this.offset = 0;
- this.limit = 10;
- this.getgrouponData()
- }
- }
- },
- })
- },
- detail: function () {
- var vue = new Vue({
- el: "#groupon-detail",
- data() {
- return {
- grouponGoodsData: [],
- grouponTeamList: [],
- is_define_grouponTeamListLeng: '',
- // is_dialog_opt:false,
- temp: null
- }
- },
- mounted() {
- let id = Config.id
- let that = this;
- Fast.api.ajax({
- url: `shopro/activity/groupon/detail/id/${id}`,
- loading: true,
- type: 'GET',
- data: {}
- }, function (ret, res) {
- let arrMsg = []
- let datas = []
- datas.push(res.data)
- datas.forEach(i => {
- arrMsg.push({
- id: i.id,
- goods_title: i.goods?i.goods.title:"",
- goods_image: i.goods?i.goods.image:"",
- createtime: i.createtime,
- user_nickname: i.groupon_log[0].user_nickname,
- arr: i.groupon_log,
- expiretime: i.expiretime,
- status: i.status,
- status_text: i.status_text,
- num: i.num,
- current_num: i.current_num
- })
- })
- that.grouponGoodsData = arrMsg;
- that.grouponTeamList = JSON.parse(JSON.stringify(that.grouponGoodsData[0].arr));
- let leng = 0
- that.grouponTeamList.forEach(i => {
- if (!i.is_define) {
- leng++
- }
- })
- that.is_define_grouponTeamListLeng = leng
- return false;
- })
- },
- methods: {
- refreshTeamer(index) {
- let that = this;
- Fast.api.ajax({
- url: 'shopro/user_fake/random_user',
- loading: true,
- type: 'GET',
- data: {}
- }, function (ret, res) {
- if (index == null) {
- that.grouponTeamList.push({
- createtime: Date.parse(new Date()) / 1000,
- user_nickname: res.data.nickname,
- is_leader: false,
- user_avatar: res.data.avatar,
- is_fictitious: true,
- id: res.data.id,
- is_define: true
- })
- } else {
- let arr = {
- createtime: Date.parse(new Date()) / 1000,
- user_nickname: res.data.nickname,
- is_leader: false,
- user_avatar: res.data.avatar,
- is_fictitious: true,
- id: res.data.id,
- is_define: true
- }
- for (key in arr) {
- that.grouponTeamList[index][key] = arr[key]
- }
- }
- let leng = 0
- that.grouponTeamList.forEach(i => {
- if (!i.is_define) {
- leng++
- }
- })
- that.is_define_grouponTeamListLeng = leng
- })
- },
- defineTeamer(index, row) {
- let that = this;
- Fast.api.ajax({
- url: `shopro/activity/groupon/addFictitious/id/${that.grouponGoodsData[0].id}`,
- loading: true,
- type: 'POST',
- data: {
- avatar: row.user_avatar,
- nickname: row.user_nickname
- }
- }, function (ret, res) {
- // that.is_dialog_opt=true
- that.grouponGoodsData = []
- res.data.goods_title = res.data.goods.title
- res.data.goods_image = res.data.goods.image
- that.grouponGoodsData.push(res.data)
- that.grouponTeamList = JSON.parse(JSON.stringify(that.grouponGoodsData[0].groupon_log));
- })
- },
- cancelTeamer(index) {
- this.grouponTeamList.splice(index, 1)
- },
- dismissTeam() {
- let that = this;
- that.dialogTeamDetail = false
- Fast.api.ajax({
- url: `shopro/activity/groupon/invalidGroupon/id/${that.grouponGoodsData[0].id}`,
- loading: true,
- type: 'POST',
- data: {}
- }, function (ret, res) {
- Fast.api.close({
- data: 123
- })
- })
- },
- }
- })
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|