index.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <style>
  2. .el-table th>.cell {
  3. color: #333;
  4. font-weight: bold;
  5. font-size: 14px;
  6. }
  7. .table1 .el-table__footer-wrapper,
  8. .table1 .el-table__header-wrapper {
  9. border-bottom: 1.4px solid #D6D6D6;
  10. }
  11. .share-pop-model {
  12. margin-bottom: 20px;
  13. }
  14. .share-name {
  15. width: 90px;
  16. display: inline-block;
  17. margin-right: 18px;
  18. text-align: end;
  19. }
  20. </style>
  21. <div id="app">
  22. <div class="table-body" style="min-width: 1000px;">
  23. <div slot="header" class="clearfix" style="height: 20px;">
  24. <span>活动列表</span>
  25. <el-button style="float: right; padding: 3px 12px;margin-left: 20px;height: 32px;" type="primary" @click="toPageAdd">添加活动</el-button>
  26. </div>
  27. <div slot="header" class="clearfix" style="margin-top: 20px;">
  28. <div id="qrcode-info" style="position: fixed;top: 10000000000px;">
  29. <!-- 背景图 -->
  30. <el-image id="couponBak" style="width: 144px; height: 144px;" src="/resources/img/plugins/coupon/coupon_bak.png"></el-image>
  31. <!-- 头像 -->
  32. <el-image id="topImg" style="width: 144px; height: 144px;" v-if="mall_info" :src="mall_info.mall_logo"></el-image>
  33. <!-- 二维码 -->
  34. <!-- <el-image id="codeImg" style="width: 95px; height: 95px;" src="/resources/img/plugins/coupon/code.png"></el-image> -->
  35. <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
  36. <!-- 生成的海报图片 -->
  37. <!-- <el-image id="posterImg" style="width: 375px; height: 603px;" :src="this.shareData.poster"></el-image>-->
  38. <!-- 生成海报 -->
  39. <!-- <canvas id="myCanvas" width="375" height="603" style="border:1px solid #d3d3d3;"></canvas>-->
  40. </div>
  41. <el-button :type="LoadDataType==-1?'primary':''" size="small" @click="getLoadData(-1)">全部</el-button>
  42. <el-button :type="LoadDataType==0?'primary':''" size="small" @click="getLoadData(0)">未开始</el-button>
  43. <el-button :type="LoadDataType==1?'primary':''" size="small" @click="getLoadData(1)">活动中</el-button>
  44. <el-button :type="LoadDataType==2?'primary':''" size="small" @click="getLoadData(2)">已结束</el-button>
  45. <div class="demo-input-suffix" style="margin-top: 20px;margin-bottom: 10px;">
  46. <el-input @keyup.enter.native="toSearchActivity" size="small" style="width:300px;margin-right: 20px;" placeholder="搜索商品名称" v-model="search.goods_name" clearable>
  47. </el-input>
  48. <el-button type="primary" size="small" @click="toSearchActivity">搜索</el-button>
  49. </div>
  50. </div>
  51. <template>
  52. <el-table :data="list" stripe style="width: 100%" v-loading="listLoading" class="table1">
  53. <el-table-column prop="id" label="编号" width="100" align="center"></el-table-column>
  54. <el-table-column prop="goods.name,goods.cover_pic" label="商品名称" width="210">
  55. <template slot-scope="scope">
  56. <div flex="box:first cross:top cross:center" v-if="scope.row.goods">
  57. <div style="padding-right: 5px;">
  58. <com-image mode="aspectFill" :src="scope.row.goods.cover_pic"></com-image>
  59. </div>
  60. <div>
  61. {{scope.row.goods.goods_name}}
  62. </div>
  63. </div>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="title" label="活动名称" align="center"></el-table-column>
  67. <el-table-column prop="group_size" label="成团人数" align="center"></el-table-column>
  68. <el-table-column prop="total_orders" label="成团订单数" align="center"></el-table-column>
  69. <el-table-column prop="total_orders_price" label="成团金额" align="center"></el-table-column>
  70. <el-table-column prop="goods_stock" label="拼团库存" align="center"></el-table-column>
  71. <el-table-column prop="give_balance" label="赠送余额" align="center"></el-table-column>
  72. <el-table-column prop="give_score" label="赠送积分" align="center"></el-table-column>
  73. <el-table-column prop="start_at,end_at" label="活动时间" width="300" align="center">
  74. <template slot-scope="scope">
  75. <div>{{scope.row.start_at|dateTimeFormat('Y-m-d H:i:s')}} ~ {{scope.row.end_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  76. </template>
  77. </el-table-column>
  78. <el-table-column prop="group_status" label="状态" align="center">
  79. <template slot-scope="scope">
  80. <el-tag effect="dark" size="small" type="info" v-if="scope.row.group_status == 0">未开始</el-tag>
  81. <el-tag effect="dark" size="small" type="success" v-if="scope.row.group_status == 1">活动中</el-tag>
  82. <el-tag effect="dark" size="small" type="warning" v-if="scope.row.group_status == 2">已结束</el-tag>
  83. </template>
  84. </el-table-column>
  85. <el-table-column prop="start_at,end_at" label="添加时间" width="150" align="center">
  86. <template slot-scope="scope">
  87. <div>{{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="操作" width="200" align="center">
  91. <template slot-scope="scope">
  92. <el-button @click="toGroupList(scope.row.id)" type="text" size="mini">开团列表</el-button>
  93. <el-button @click="groupGoodsDetail(scope.row.id)" type="text" size="mini">查看</el-button>
  94. <el-button @click="del(scope.row.id)" type="text" size="mini">删除</el-button>
  95. <el-button @click="openPop(scope.$index,2)" type="text" size="mini">推广码</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <div flex="main:right cross:center" style="margin-top: 20px;">
  100. <el-pagination v-if="pagination" :page-size="pagination.defaultPageSize" style="display: inline-block;float: right;" background @current-change="pageChange" layout="prev, pager, next" :total="pagination.totalCount">
  101. </el-pagination>
  102. </div>
  103. </template>
  104. </div>
  105. <!-- 这个是查看商品详情弹窗 -->
  106. <el-dialog title="查看明细" :visible.sync="dialogFormVisible" center width="60%">
  107. <el-table :data="group_buy_attr_list" :border='true' v-loading="dialogLoading">
  108. <el-table-column property="goods" label="商品名称" min-width="150" header-align="center" align="center">
  109. <template slot-scope="scope">
  110. <div style="display: flex;align-items: center;">
  111. <el-image v-if="scope.row.goods.cover_pic" :src="scope.row.goods.cover_pic" style="width: 55px;height: 55px;display: block;margin-right: 5px;flex-shrink: 0;"></el-image>
  112. <div>{{scope.row.goods.goods_name}}</div>
  113. </div>
  114. </template>
  115. </el-table-column>
  116. <el-table-column property="goodsAttr" label="商品SKU" min-width="150" align="center">
  117. <template slot-scope="scope">
  118. <span v-if="scope.row.goodsAttr.name">{{scope.row.goodsAttr.name}} </span>
  119. <span v-if="scope.row.goodsAttr.name==''">默认</span>
  120. </template>
  121. </el-table-column>
  122. <el-table-column label="单价" min-width="100" align="center">
  123. <template slot-scope="scope">
  124. <span>{{scope.row.goodsAttr.price}} </span>
  125. </template>
  126. </el-table-column>
  127. <el-table-column property="group_buy_price" label="拼团价" min-width="100" align="center"></el-table-column>
  128. <el-table-column property="stock" label="当前库存" min-width="100" align="center"></el-table-column>
  129. <el-table-column label="成团人数" align="center">
  130. <template slot-scope="scope">
  131. <span>{{scope.row.groupBuyActive.group_size}} </span>
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="虚拟拼团人数" align="center">
  135. <template slot-scope="scope">
  136. <span v-if="scope.row.groupBuyActive.virtual_group_type==1">0</span>
  137. <span v-if="scope.row.groupBuyActive.virtual_group_type==2">{{scope.row.groupBuyActive.group_size-scope.row.groupBuyActive.gt_group_size}} </span>
  138. </template>
  139. </el-table-column>
  140. <el-table-column label="是否虚拟成团" align="center">
  141. <template slot-scope="scope">
  142. <span v-if="scope.row.groupBuyActive.is_virtual==1">是</span>
  143. <span v-if="scope.row.groupBuyActive.is_virtual==0">否</span>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="赠送积分" align="center">
  147. <template slot-scope="scope">
  148. <span>{{scope.row.groupBuyActive.give_score}} </span>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="赠送余额" align="center">
  152. <template slot-scope="scope">
  153. <span>{{scope.row.groupBuyActive.give_balance}} </span>
  154. </template>
  155. </el-table-column>
  156. <el-table-column label="有效时间" align="center">
  157. <template slot-scope="scope">
  158. <span>{{formatEffectiveTime(scope.row.groupBuyActive.effective_time)}} </span>
  159. </template>
  160. </el-table-column>
  161. <el-table-column label="限购数量" align="center">
  162. <template slot-scope="scope">
  163. <span>{{scope.row.groupBuyActive.limit_buy_num}} </span>
  164. </template>
  165. </el-table-column>
  166. <el-table-column label="指定团长会员等级" align="center">
  167. <template slot-scope="scope">
  168. <span>{{commander_level_limit_text}}</span>
  169. </template>
  170. </el-table-column>
  171. <el-table-column label="指定团员会员等级" align="center">
  172. <template slot-scope="scope">
  173. <span>{{user_level_limit_text}}</span>
  174. </template>
  175. </el-table-column>
  176. </el-table>
  177. </el-dialog>
  178. <el-dialog v-loading="posterLoading" element-loading-text="生成海报中" title="分享" :visible.sync="sharePop" width="30%">
  179. <div class="share-pop-model">
  180. <div class="share-name">分享链接</div>
  181. <el-input style="width: 50%;" v-model="shareData.url" placeholder="暂无链接" disabled>
  182. <template slot="append">
  183. <el-button circle size="mini" type="text" @click="copyLink(shareData.url)" class="copy_btn">复制</el-button>
  184. </template>
  185. </el-input>
  186. </div>
  187. <div class="share-pop-model" flex>
  188. <div class="share-name">二维码</div>
  189. <div style="width: 180px; height: 180px;background: #F2F2F2;margin-right: 12px;" flex="main:center cross:center">
  190. <el-image style="width: 144px; height: 144px;" :src="shareData.img"></el-image>
  191. </div>
  192. <!-- <el-button flex type="text" @click="getPoster">下载海报</el-button>-->
  193. <el-button flex type="text" @click="downloadShareImg('qrcode')">下载二维码</el-button>
  194. </div>
  195. </el-dialog>
  196. </div>
  197. <script src="/resources/unpkg/clipboard@1.5.12/dist/clipboard.min.js"></script>
  198. <script>
  199. const app = new Vue({
  200. el: '#app',
  201. data() {
  202. return {
  203. listLoading: false,
  204. list: [],
  205. pagination: {
  206. total: 0
  207. },
  208. loading: false,
  209. LoadDataType: -1, //默认显示全部数据
  210. dialogFormVisible: false, //默认不显示弹窗
  211. group_buy_attr_list: [],
  212. goodsDetail: {},
  213. dialogLoading: false,
  214. search: {
  215. goods_name: '',
  216. group_status: -1,
  217. page: 1,
  218. },
  219. commander_level_limit_text: '',
  220. user_level_limit_text: '',
  221. shareData: {
  222. url: "", //链接
  223. img: "", //二维码
  224. poster: '', // 海报图片
  225. poster_filename: '', // 海报图片文件名
  226. qrcode_filename: '', // 二维码文件名
  227. },
  228. sharePop: false, //分享弹窗
  229. posterLoading: false,
  230. mall_info: {},
  231. }
  232. },
  233. methods: {
  234. // 页面跳转
  235. toPageAdd() {
  236. navigateTo({
  237. r: 'group-buy/default/add',
  238. })
  239. },
  240. // 跳转到当前商品活动的开团列表
  241. toGroupList(id) {
  242. navigateTo({
  243. r: 'group-buy/default/open-list',
  244. group_buy_active_id: id
  245. })
  246. },
  247. //状态按钮的点击事件
  248. getLoadData(e) {
  249. this.search.group_status = e;
  250. this.loadData()
  251. },
  252. toSearchActivity() {
  253. this.loadData()
  254. },
  255. // 查看商品详情
  256. groupGoodsDetail(id) {
  257. this.dialogFormVisible = true;
  258. this.dialogLoading = true;
  259. request({
  260. params: {
  261. r: 'group-buy/default/detail',
  262. id: id,
  263. },
  264. method: 'GET',
  265. }).then(e => {
  266. let res = e.data;
  267. this.dialogLoading = false;
  268. if (res.code === 0) {
  269. this.group_buy_attr_list = res.data.list;
  270. this.commander_level_limit_text = res.data.commander_level_limit_text;
  271. this.user_level_limit_text = res.data.user_level_limit_text;
  272. } else {
  273. this.$message.error(res.msg);
  274. }
  275. }).catch(e => {});
  276. },
  277. async openPop(index, type) {
  278. let codeImgSrc = await this.getQrCode(this.list[index].page_link);
  279. this.shareData.img = codeImgSrc;
  280. this.shareData.url = this.list[index].page_link;
  281. this.shareData.poster_filename = this.list[index].poster_filename;
  282. this.shareData.qrcode_filename = this.list[index].qrcode_filename;
  283. this.sharePop = true;
  284. },
  285. copyLink(str) {
  286. var clipboard = new Clipboard('.copy_btn', {
  287. text: function() {
  288. return str;
  289. }
  290. });
  291. var self = this;
  292. clipboard.on('success', function(e) {
  293. // console.log("success")
  294. self.$message.success('复制成功');
  295. e.clearSelection();
  296. clipboard.destroy()
  297. });
  298. clipboard.on('error', function(e) {
  299. // console.log("error")
  300. self.$message.error('复制失败,请手动复制');
  301. });
  302. },
  303. getQrCode(url) {
  304. let qrcodeInfo = document.getElementById("qrcode-info");
  305. document.getElementById("qrcode").remove(); //删除生成的二维码
  306. let addCodeDom = document.createElement("div")
  307. addCodeDom.setAttribute("id", "qrcode");
  308. addCodeDom.setAttribute("style", "width:300px; height:300px;");
  309. qrcodeInfo.appendChild(addCodeDom) //添加标签
  310. let qrCodeDom = document.getElementById("qrcode")
  311. var qrcode = new QRCode(qrCodeDom, {
  312. width: 300,
  313. height: 300
  314. });
  315. qrcode.makeCode(url);
  316. // 获取二维码生成的图片信息
  317. let src = "";
  318. return new Promise((req, rej) => {
  319. setTimeout(() => {
  320. src = qrCodeDom.getElementsByTagName("img")[0].src;
  321. req(src)
  322. }, 200);
  323. })
  324. },
  325. getPoster() {
  326. try {
  327. // 存在海报则不重新生成
  328. if (this.posterArr[this.list_index]) {
  329. this.shareData.poster = this.posterArr[this.list_index];
  330. return;
  331. }
  332. this.posterLoading = true;
  333. let qrcodeInfo = document.getElementById("qrcode-info");
  334. var c = document.getElementById("myCanvas");
  335. // 清空上一个生成的海报
  336. c.remove();
  337. // 创建标签
  338. let addPosterDom = document.createElement("canvas")
  339. addPosterDom.setAttribute("id", "myCanvas");
  340. addPosterDom.setAttribute("width", "375");
  341. addPosterDom.setAttribute("height", "603");
  342. qrcodeInfo.appendChild(addPosterDom);
  343. c = document.getElementById("myCanvas");
  344. var ctx = c.getContext("2d");
  345. // 背景图
  346. let bak = document.getElementById("couponBak");
  347. ctx.drawImage(bak, 0, 0, 375, 603);
  348. // 圆
  349. ctx.beginPath();
  350. ctx.arc(187.5, 105, 40, 0, 2 * Math.PI);
  351. ctx.closePath();
  352. ctx.fillStyle = "#FFF";
  353. ctx.fill(); //填充颜色
  354. let mall_header_data = JSON.parse(localStorage.getItem("mall_header_data"));
  355. // 店名
  356. ctx.font = "bold 17px Arial";
  357. ctx.fillStyle = "#000";
  358. ctx.textAlign = 'center';
  359. ctx.fillText(this.mall_info.mall_name, 187.5, 175);
  360. // 优惠券类型
  361. ctx.font = "bold 14px Arial";
  362. ctx.fillStyle = "#000";
  363. ctx.textAlign = 'center';
  364. ctx.fillText("送你一张优惠券", 187.5, 205);
  365. // 额度
  366. ctx.font = "bold 22px Arial";
  367. ctx.fillStyle = "#DB0505";
  368. ctx.textAlign = 'center';
  369. // ctx.fillText(this.list[this.list_index].content,187.5,265);
  370. ctx.fillText(this.list[this.list_index].name, 187.5, 265);
  371. let type = this.list[this.list_index].appoint_type;
  372. let typeStr = "全场可用";
  373. if (type == 1) {
  374. typeStr = "指定商品分类可用";
  375. } else if (type == 2) {
  376. typeStr = "指定商品可用";
  377. }
  378. // 可使用的类型
  379. ctx.font = "14px Arial";
  380. ctx.fillStyle = "#DB0505";
  381. ctx.textAlign = 'center';
  382. // ctx.fillText("全部商品任意金额可用",187.5,295);
  383. ctx.fillText(typeStr, 187.5, 295);
  384. // 二维码
  385. let code = document.getElementById("qrcode").getElementsByTagName("img")[0];
  386. ctx.drawImage(code, 140, 380.5, 95, 95);
  387. // 商城头像
  388. ctx.beginPath();
  389. ctx.arc(187.25, 104.75, 36.25, 0, 2 * Math.PI);
  390. ctx.clip();
  391. let topImg = document.getElementById("topImg");
  392. ctx.drawImage(topImg, 147.5, 65, 80, 80);
  393. this.shareData.poster = c.toDataURL('image/png');
  394. this.posterArr[this.list_index] = this.shareData.poster;
  395. console.info(this.shareData.poster);
  396. this.posterLoading = false;
  397. this.downloadShareImg('poster');
  398. } catch (error) {
  399. console.info(error);
  400. this.posterLoading = false;
  401. this.$message.error('生成失败');
  402. }
  403. },
  404. downloadShareImg(type) {
  405. // console.log(this.shareData);return null;
  406. if ('qrcode' == type) {
  407. if (!this.shareData.img) {
  408. this.$message.error('暂无图片');
  409. return;
  410. }
  411. var img_url = this.shareData.img;
  412. var filename = this.shareData.qrcode_filename;
  413. } else {
  414. if (!this.shareData.poster) {
  415. this.$message.error('暂无图片');
  416. return;
  417. }
  418. var img_url = this.shareData.poster;
  419. var filename = this.shareData.poster_filename;
  420. }
  421. fetch(img_url).then(res => res.blob().then(blob => {
  422. var a = document.createElement('a');
  423. var url = window.URL.createObjectURL(blob);
  424. a.href = url;
  425. a.download = filename;
  426. a.click();
  427. window.URL.revokeObjectURL(url);
  428. }))
  429. },
  430. // 删除拼团商品
  431. del(id) {
  432. this.$confirm('此操作将删除该拼团商品, 是否继续?', '提示', {
  433. confirmButtonText: '确定',
  434. cancelButtonText: '取消',
  435. type: 'warning'
  436. }).then(() => {
  437. this.delGroupGoods(id);
  438. }).catch(() => {
  439. this.$message({
  440. type: 'info',
  441. message: '已取消删除'
  442. });
  443. });
  444. },
  445. pageChange(page) {
  446. this.search.page = page;
  447. this.loadData();
  448. },
  449. delGroupGoods(id) {
  450. this.loading = true;
  451. request({
  452. params: {
  453. r: 'group-buy/default/del',
  454. id: id
  455. },
  456. method: 'get',
  457. }).then(e => {
  458. let res = e.data;
  459. this.listLoading = false;
  460. if (res.code === 0) {
  461. this.$message.success(res.msg);
  462. this.loadData();
  463. } else {
  464. this.$message.error(res.msg);
  465. }
  466. }).catch(e => {});
  467. },
  468. // 请求获取数据--获取拼团商品列表
  469. loadData() {
  470. this.listLoading = true;
  471. let params = {
  472. r: 'group-buy/default/index'
  473. };
  474. params = Object.assign(params, this.search);
  475. request({
  476. params: params,
  477. method: 'get',
  478. }).then(e => {
  479. let res = e.data;
  480. this.listLoading = false;
  481. if (res.code === 0) {
  482. this.list = res.data.list;
  483. this.mall_info = e.data.data.mall_info;
  484. this.pagination = res.data.pagination; //拿到关于页码页容量的数据
  485. } else {
  486. this.$message.error(res.msg);
  487. }
  488. }).catch(e => {});
  489. },
  490. formatEffectiveTime(value) {
  491. var h = parseInt(value / 60);
  492. var m = value % 60;
  493. return h + '小时' + m + '分';
  494. }
  495. },
  496. // 加载的时候获取到列表页
  497. mounted() {
  498. // 数据初始化
  499. this.LoadDataType = -1;
  500. this.loadData();
  501. }
  502. })
  503. </script>