index.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. <?php defined('YII_ENV') or exit('Access Denied'); ?>
  2. <style>
  3. .set-el-button {
  4. padding: 0 !important;
  5. border: 0;
  6. margin: 0 5px;
  7. }
  8. .sort-input {
  9. width: 100%;
  10. background-color: #F3F5F6;
  11. height: 32px;
  12. }
  13. .sort-input span {
  14. height: 32px;
  15. width: 100%;
  16. line-height: 32px;
  17. display: inline-block;
  18. padding: 0 10px;
  19. font-size: 13px;
  20. }
  21. .sort-input .el-input__inner {
  22. height: 32px;
  23. line-height: 32px;
  24. background-color: #F3F5F6;
  25. float: left;
  26. padding: 0 10px;
  27. border: 0;
  28. }
  29. .table-body {
  30. padding: 20px;
  31. background-color: #fff;
  32. }
  33. .table-info .el-button {
  34. padding: 0 !important;
  35. border: 0;
  36. margin: 0 5px;
  37. }
  38. .input-item {
  39. margin: 0 0 20px;
  40. }
  41. .input-item-name {
  42. margin-right: 5px;
  43. }
  44. .input-search {
  45. margin-right: 30px;
  46. }
  47. .input-item .el-input-group__append {
  48. background-color: #fff;
  49. border-left: 0;
  50. width: 10%;
  51. padding: 0;
  52. }
  53. .input-item .el-input-group__append .el-button {
  54. padding: 0;
  55. }
  56. .input-item .el-input-group__append .el-button {
  57. margin: 0;
  58. }
  59. .data-pop-info {
  60. /* padding: 18px 15px 30px; */
  61. color: #333;
  62. }
  63. .data-pop-mode {
  64. background: #F8F8F8;
  65. border-radius: 4px;
  66. margin-bottom: 10px;
  67. }
  68. .data-pop-top {
  69. height: 90px;
  70. }
  71. .data-price {
  72. width: 200px;
  73. flex-direction: column;
  74. border-right: 1px solid #E5E5E5;
  75. }
  76. .data-info {
  77. flex: 1;
  78. padding: 22px 15px;
  79. font-size: 16px;
  80. }
  81. .data-info-name {
  82. display: inline-block;
  83. text-align: end;
  84. }
  85. .data-pop-detail {
  86. padding: 15px 18px;
  87. }
  88. .data-detail-mode {
  89. min-width: 33%;
  90. flex-shrink: 0;
  91. text-align: center;
  92. margin-top: 16px;
  93. line-height: 26px;
  94. font-size: 16px;
  95. }
  96. .share-pop-model {
  97. margin-top: 20px;
  98. }
  99. .share-name {
  100. width: 90px;
  101. display: inline-block;
  102. margin-right: 18px;
  103. text-align: end;
  104. }
  105. .flex-y-center {
  106. display: -webkit-box;
  107. display: -webkit-flex;
  108. display: flex;
  109. -webkit-box-align: center;
  110. -webkit-align-items: center;
  111. -ms-flex-align: center;
  112. -ms-grid-row-align: center;
  113. align-items: center;
  114. }
  115. </style>
  116. <div id="app" v-cloak>
  117. <el-card shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  118. <div slot="header">
  119. <span>优惠券管理</span>
  120. <el-button style="float: right; margin-top: -8px;" type="primary" size="small" @click="$navigate({r:'store/client/coupon/edit'})">新建优惠券
  121. </el-button>
  122. </div>
  123. <div class="table-body">
  124. <div id="qrcode-info" style="position: fixed;top: 10000000000px;">
  125. <!-- 背景图 -->
  126. <el-image id="couponBak" style="width: 144px; height: 144px;" src="/resources/img/plugins/coupon/coupon_bak.png"></el-image>
  127. <!-- 头像 -->
  128. <el-image id="topImg" style="width: 144px; height: 144px;" v-if="mall_info" :src="mall_info.mall_logo"></el-image>
  129. <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
  130. <!-- 生成的海报图片 -->
  131. <el-image id="posterImg" style="width: 375px; height: 603px;" :src="this.shareData.poster"></el-image>
  132. <!-- 生成海报 -->
  133. <canvas id="myCanvas" width="375" height="603" style="border:1px solid #d3d3d3;"></canvas>
  134. </div>
  135. <div class="input-item">
  136. <div flex>
  137. <div flex="cross:center" class="input-search">
  138. <div class="input-item-name">优惠券名称:</div>
  139. <div class="input-item-text">
  140. <el-input @keyup.enter.native="search" size="small" placeholder="请输入优惠券名称搜索" v-model="searchData.name" clearable @clear="search"></el-input>
  141. </div>
  142. </div>
  143. <div flex="cross:center" class="input-search">
  144. <div class="input-item-name">类型:</div>
  145. <div>
  146. <el-select v-model="searchData.type" placeholder="请选择" size="small">
  147. <el-option label="全部" :value="0"></el-option>
  148. <el-option v-for="(item,index) in type_text" :key="index" :label="item" :value="index">{{item}}
  149. </el-option>
  150. </el-select>
  151. </div>
  152. </div>
  153. <div flex="cross:center" class="input-search">
  154. <div class="input-item-name">状态:</div>
  155. <div>
  156. <el-select v-model="searchData.status" placeholder="请选择" size="small">
  157. <el-option label="全部" :value="0"></el-option>
  158. <el-option v-for="(item,index) in status_text" :key="index" :label="item" :value="index">{{item}}
  159. </el-option>
  160. </el-select>
  161. </div>
  162. </div>
  163. <div style="margin-left: 90px;margin-top: 0px;">
  164. <el-button type="primary" size="small" @click="search">搜索</el-button>
  165. <el-button type="warning" @click="clereSearch" v-if="searchData.name || searchData.type || searchData.status" style="padding: 9px 15px !important;">清除搜索条件</el-button>
  166. <el-button type="primary" size="small" @click="batchDel">批量删除</el-button>
  167. </div>
  168. </div>
  169. </div>
  170. <el-table v-loading="loading" stripe :data="list" @selection-change="scFormTab" style="width: 100%;margin-bottom: 15px">
  171. <el-table-column type="selection" width="50"></el-table-column>
  172. <el-table-column width='100' prop="id" label="优惠券id" align="center"></el-table-column>
  173. <el-table-column width='250' prop="name" label="优惠券名称" align="center"></el-table-column>
  174. <el-table-column width='150' prop="type" label="优惠券类型" align="center">
  175. <template slot-scope="scope">
  176. <div>
  177. {{scope.row.type == 1?'折扣券':'满减券'}}
  178. </div>
  179. </template>
  180. </el-table-column>
  181. <el-table-column width='250' prop="discount" label="优惠内容" align="center">
  182. <template slot-scope="scope">
  183. <div>{{scope.row.content}}</div>
  184. </template>
  185. </el-table-column>
  186. <el-table-column width='150' prop="received_number" label="已领取" align="center">
  187. <template slot-scope="scope">
  188. <div v-if="scope.row.received_number">
  189. <el-button type="text" @click="couponDetail(1, scope.row.id)">{{scope.row.received_number}}</el-button>
  190. </div>
  191. <div v-else>{{scope.row.received_number}}</div>
  192. </template>
  193. </el-table-column>
  194. <el-table-column width='150' prop="used_number" label="已使用" align="center">
  195. <template slot-scope="scope">
  196. <div v-if="scope.row.used_number">
  197. <el-button @click="couponDetail(2, scope.row.id)" type="text">{{scope.row.used_number}}</el-button>
  198. </div>
  199. <div v-else>{{scope.row.used_number}}</div>
  200. </template>
  201. </el-table-column>
  202. <el-table-column prop="total_count" label="剩余数量" align="center"></el-table-column>
  203. <el-table-column width='150' prop="is_failure" label="状态" align="center">
  204. <template slot-scope="scope">
  205. <span> {{status_text[scope.row.coupon_status]}} </span>
  206. </template>
  207. </el-table-column>
  208. <el-table-column label="操作" width="290" align="center">
  209. <template slot-scope="scope">
  210. <el-button v-if="scope.row.coupon_status != 1" type="text" @click="openPop(scope.$index,1)">数据</el-button>
  211. <el-button v-if="scope.row.coupon_status==1 || scope.row.coupon_status==2" type="text" @click="openPop(scope.$index,2)">推广码</el-button>
  212. <el-button v-if="scope.row.coupon_status==1 || scope.row.coupon_status==2" type="text" @click="openPop(scope.$index,3)">编辑</el-button>
  213. <el-button v-if="scope.row.coupon_status==3 || scope.row.coupon_status==4" type="text" @click="openPop(scope.$index,7)">查看</el-button>
  214. <el-button type="text" @click="openPop(scope.$index,6)">复制</el-button>
  215. </template>
  216. </el-table-column>
  217. </el-table>
  218. <div flex="box:last cross:center">
  219. <div style="visibility: hidden">
  220. <el-button plain type="primary" size="small">批量操作1</el-button>
  221. <el-button plain type="primary" size="small">批量操作2</el-button>
  222. </div>
  223. <el-col :span="24" class="toolbar">
  224. <el-pagination v-if="pagination" style="float: right;" background @current-change="pageChange" layout="prev, pager, next" :page-count="pageCount">
  225. </el-pagination>
  226. </el-col>
  227. </div>
  228. </div>
  229. <el-dialog title="效果数据" :visible.sync="dataPop" width="40%">
  230. <div class="data-pop-info" v-loading="dataPopLoading">
  231. <div class="data-pop-top data-pop-mode" flex>
  232. <div class="data-price" flex="cross:center main:center">
  233. <div v-if="coupon_info.type==2">
  234. <span style="font-size: 14px;">¥</span>
  235. <span style="font-size: 20px;">{{coupon_info.sub_price}}</span>
  236. </div>
  237. <div v-if="coupon_info.type==1">
  238. <span style="font-size: 14px;"></span>
  239. <span style="font-size: 20px;">{{coupon_info.discount}}折</span>
  240. </div>
  241. <div style="margin-top: 5px;font-size: 16px;color: #636363;">{{coupon_info.content}}</div>
  242. </div>
  243. <div class="data-info">
  244. <div flex>
  245. <div class="data-info-name">券名称:</div>
  246. <div style="color: #4098F4;">{{coupon_info.name}}</div>
  247. </div>
  248. <div style="color: #636363;margin-top: 10px;">
  249. <span class="data-info-name">使用时间:</span>
  250. <span v-if="coupon_info.expire_type==2">{{coupon_info.use_time}}</span>
  251. <span v-else-if="coupon_info.expire_type==1">领取后{{coupon_info.expire_day}}天过期</span>
  252. <span v-else-if="coupon_info.expire_type==3">领取后{{coupon_info.effect_days}}天生效,有效期{{coupon_info.expire_day}}天</span>
  253. </div>
  254. </div>
  255. </div>
  256. <div class="data-pop-mode data-pop-detail" flex="wrap:wrap">
  257. <div class="data-detail-mode">
  258. <div class="data-detail-name">用券金额</div>
  259. <div class="data-detail-num">{{user_coupons.total_payed_amount}}</div>
  260. </div>
  261. <div class="data-detail-mode">
  262. <div class="data-detail-name">优惠总金额</div>
  263. <div class="data-detail-num">{{user_coupons.total_discount_amount}}</div>
  264. </div>
  265. <div class="data-detail-mode">
  266. <div class="data-detail-name">使用率</div>
  267. <div class="data-detail-num">{{user_coupons.use_probability}}</div>
  268. </div>
  269. <div class="data-detail-mode">
  270. <div class="data-detail-name">用券会员数</div>
  271. <div class="data-detail-num">{{user_coupons.use_user_number}}</div>
  272. </div>
  273. <div class="data-detail-mode">
  274. <div class="data-detail-name">支付订单数</div>
  275. <div class="data-detail-num">{{user_coupons.use_order_number}}</div>
  276. </div>
  277. <div class="data-detail-mode">
  278. <div class="data-detail-name">支付金额</div>
  279. <div class="data-detail-num">{{user_coupons.total_use_coupon_payed_amount}}</div>
  280. </div>
  281. </div>
  282. <div>
  283. <div style="margin-bottom: 16px;">使用优惠券购买商品</div>
  284. <el-table :data="good_statistics" style="width: 100%" stripe>
  285. <el-table-column prop="good" label="商品" align="center">
  286. <template slot-scope="scope">
  287. <div size="small" class="flex-y-center">
  288. <com-image width='50px' height='50px' :src=scope.row.cover_pic style="border-radius: 50%"></com-image>
  289. <span style="padding-left: 10px;">{{scope.row.goods_name}}</span>
  290. </div>
  291. </template>
  292. </el-table-column>
  293. <el-table-column prop="payed_number" label="付款件数" align="center"></el-table-column>
  294. <el-table-column prop="buyed_user_number" label="付款人数" align="center"></el-table-column>
  295. </el-table>
  296. </div>
  297. <div style="padding: 14px 0;">
  298. <el-pagination v-if="dataPopPagination" :page-size="dataPopPagination.pageSize" style="float: right;" background @current-change="pageChangeDataPop" layout="prev, pager, next" :total="dataPopPagination.totalCount">
  299. </el-pagination>
  300. </div>
  301. </div>
  302. </el-dialog>
  303. <el-dialog v-loading="posterLoading" element-loading-text="生成海报中" title="分享" :visible.sync="sharePop" width="30%">
  304. <div class="share-pop-model">
  305. <div class="share-name">分享链接</div>
  306. <el-input style="width: 50%;" v-model="shareData.url" placeholder="暂无链接" disabled>
  307. <template slot="append">
  308. <el-button circle size="mini" type="text" @click="copyLink(shareData.url)" class="copy_btn">复制</el-button>
  309. </template>
  310. </el-input>
  311. </div>
  312. <div class="share-pop-model" flex>
  313. <div class="share-name">二维码</div>
  314. <div style="width: 180px; height: 180px;background: #F2F2F2;margin-right: 12px;" flex="main:center cross:center">
  315. <el-image style="width: 144px; height: 144px;" :src="shareData.img"></el-image>
  316. </div>
  317. <el-button flex type="text" @click="getPoster">下载海报</el-button>
  318. <el-button flex type="text" @click="downloadShareImg('qrcode')">下载二维码</el-button>
  319. </div>
  320. </el-dialog>
  321. </el-card>
  322. </div>
  323. <script src="/resources/unpkg/clipboard@1.5.12/dist/clipboard.min.js"></script>
  324. <script>
  325. const app = new Vue({
  326. el: '#app',
  327. data() {
  328. return {
  329. loading: false,
  330. list: [],
  331. searchData: {
  332. name: '',
  333. type: 0,
  334. status: 0,
  335. },
  336. pagination: null,
  337. dataPopPagination: null,
  338. page: 1,
  339. status_text: {
  340. 1: '未开始',
  341. 2: '领取中',
  342. 3: '已过期',
  343. 4: '已失效'
  344. },
  345. type_text: {
  346. 1: '折扣券',
  347. 2: '满减券'
  348. },
  349. dataPop: false, //数据弹窗
  350. dataPopLoading: false,
  351. user_coupons: {
  352. total_payed_amount: 0,
  353. total_discount_amount: 0,
  354. use_probability: 0,
  355. receive_user_number: 0,
  356. use_order_number: 0,
  357. total_use_coupon_payed_amount: 0,
  358. use_user_number: 0,
  359. },
  360. coupon_info: {
  361. name: '优惠券',
  362. content: '满100减10元',
  363. use_time: '--',
  364. },
  365. sharePop: false, //分享弹窗
  366. shareData: {
  367. url: "", //链接
  368. img: "", //二维码
  369. poster: '', // 海报图片
  370. poster_filename: '', // 海报图片文件名
  371. qrcode_filename: '', // 二维码文件名
  372. },
  373. good_statistics: [],
  374. list_index: 0, // 当前选中的列表索引,用于弹窗
  375. posterLoading: false,
  376. posterArr: {}, //生成的海报列表
  377. posterSrc: "",
  378. mall_info: {},
  379. pageSize: 10,
  380. pageCount: 1,
  381. delIds:[],
  382. };
  383. },
  384. created() {
  385. this.loadData();
  386. },
  387. methods: {
  388. //搜索
  389. search() {
  390. this.page = 1;
  391. this.loadData();
  392. },
  393. clereSearch() {
  394. this.searchData.name = '';
  395. this.searchData.type = 0;
  396. this.searchData.status = 0;
  397. this.search();
  398. },
  399. handleCenter: function(row, column) {
  400. let para = Object.assign({
  401. id: column.id
  402. }, {
  403. is_join: column.is_join
  404. });
  405. request({
  406. params: {
  407. r: 'mall/coupon/edit-center'
  408. },
  409. data: para,
  410. method: 'post'
  411. }).then(e => {
  412. if (e.data.code === 0) {
  413. this.$message({
  414. message: e.data.msg,
  415. type: 'success'
  416. });
  417. } else {
  418. this.$alert(e.data.msg, '提示', {
  419. confirmButtonText: '确定'
  420. })
  421. }
  422. }).catch(e => {});
  423. },
  424. //带着ID前往编辑页面
  425. handleEdit: function(row, column) {
  426. navigateTo({
  427. r: 'mall/coupon/edit',
  428. id: column.id
  429. });
  430. },
  431. // 优惠券发放页面
  432. handleSend: function(row, column) {
  433. navigateTo({
  434. r: 'mall/coupon/send',
  435. id: column.id
  436. });
  437. },
  438. //分页
  439. pageChange(page) {
  440. this.page = page;
  441. this.loadData();
  442. },
  443. pageChangeDataPop(page) {
  444. this.dataPopPage = page;
  445. this.openPop(this.list_index, 1);
  446. },
  447. //删除
  448. batchDel(){
  449. if(this.delIds.length<=0){
  450. this.$message.error('请选中要删除的数据');
  451. return false;
  452. }
  453. var ids = this.delIds
  454. this.$confirm('确认删除所选中的记录吗?', '提示', {
  455. type: 'warning'
  456. }).then(() => {
  457. this.loading = true;
  458. let para = {
  459. id: ids
  460. };
  461. request({
  462. params: {
  463. r: 'store/client/coupon/del'
  464. },
  465. data: para,
  466. method: 'post'
  467. }).then(e => {
  468. this.loading = false;
  469. if (e.data.code === 0) {
  470. const h = this.$createElement;
  471. this.$message({
  472. message: '删除成功',
  473. type: 'success'
  474. });
  475. setTimeout(() => {
  476. navigateTo({ r: 'store/client/coupon/index'});
  477. }, 300);
  478. } else {
  479. this.$alert(e.data.msg, '提示', {
  480. confirmButtonText: '确定'
  481. })
  482. }
  483. }).catch(e => {
  484. this.$alert(e.data.msg, '提示', {
  485. confirmButtonText: '确定'
  486. })
  487. });
  488. })
  489. },
  490. // 根据参数获取请求信息
  491. loadData() {
  492. this.loading = true;
  493. request({
  494. params: {
  495. r: 'store/client/coupon/index',
  496. page: this.page,
  497. page_size: this.pageSize,
  498. name: this.searchData.name,
  499. type: this.searchData.type,
  500. status: this.searchData.status,
  501. },
  502. }).then(e => {
  503. this.loading = false;
  504. if (e.data.code === 0) {
  505. this.list = e.data.data.list;
  506. this.mall_info = e.data.data.mall_info;
  507. this.pagination = e.data.data.pagination;
  508. this.pageSize = e.data.data.pageSize;
  509. this.pageCount = e.data.data.page_count;
  510. // console.log(this.pagination.totalCount);
  511. } else {
  512. this.listLoading = false;
  513. this.$message({
  514. message: e.data.msg,
  515. type: 'error'
  516. });
  517. }
  518. }).catch(e => {
  519. this.listLoading = false;
  520. });
  521. },
  522. // 打开数据弹窗
  523. async openPop(index, type) {
  524. this.list_index = index;
  525. if (type == 1) { //查看数据
  526. let self = this
  527. self.dataPop = true;
  528. self.dataPopLoading = true;
  529. request({
  530. params: {
  531. r: 'store/client/coupon/coupon-statistics',
  532. coupon_id: this.list[index].id,
  533. page: this.dataPopPage
  534. },
  535. method: 'get'
  536. }).then(e => {
  537. this.dataPopLoading = false;
  538. if (e.data.code == 0) {
  539. if (e.data.data.user_coupons) {
  540. self.user_coupons = e.data.data.user_coupons;
  541. }
  542. if (e.data.data.good_statistics.length) {
  543. self.good_statistics = e.data.data.good_statistics;
  544. }
  545. if (e.data.data.coupon_info) {
  546. self.coupon_info = e.data.data.coupon_info;
  547. }
  548. self.dataPopPagination = e.data.data.good_statistics.pagination;
  549. } else {
  550. self.$message.error(e.data.msg);
  551. }
  552. }).catch(e => {
  553. this.dataPopLoading = false;
  554. console.log(e);
  555. this.$message.error('网络错误');
  556. });
  557. } else if (type == 2) { //推广
  558. let codeImgSrc = await this.getQrCode(this.list[index].page_link);
  559. this.shareData.img = codeImgSrc;
  560. this.shareData.url = this.list[index].page_link;
  561. // this.shareData.poster = this.list[index].poster_url;
  562. this.shareData.poster_filename = this.list[index].poster_filename;
  563. this.shareData.qrcode_filename = this.list[index].qrcode_filename;
  564. this.sharePop = true;
  565. } else if (type == 3) { //编辑
  566. navigateTo({
  567. r: 'store/client/coupon/edit',
  568. coupon_id: this.list[index].id
  569. });
  570. } else if (type == 4) { //失效
  571. // this.$confirm('活动失效后,无法继续编辑优惠券内容;买家无法再领取该优惠券,但之前已领取的优惠券,在有效期内仍可继续使用。', '失效', {
  572. // confirmButtonText: '确定',
  573. // cancelButtonText: '取消',
  574. // }).then(() => {
  575. // this.listLoading = true;
  576. // request({
  577. // params: {
  578. // r: 'coupon/coupon/failure',
  579. // coupon_id: this.list[index].id,
  580. // },
  581. // method: 'get'
  582. // }).then(e => {
  583. // this.listLoading = false;
  584. // if (e.data.code == 0) {
  585. // this.$message.success(e.data.msg);
  586. // this.list[index].coupon_status = 4;
  587. // } else {
  588. // this.$message.error(e.data.msg);
  589. // }
  590. // }).catch(e => {
  591. // this.listLoading = false;
  592. // console.log(e);
  593. // this.$message.error('网络错误');
  594. // });
  595. // }).catch(() => { //点击取消
  596. //
  597. // });
  598. } else if (type == 5) { //删除
  599. // this.$confirm('删除后将不可恢复,确定删除?', '删除', {
  600. // confirmButtonText: '确定',
  601. // cancelButtonText: '取消',
  602. // }).then(() => {
  603. // let self = this;
  604. // self.loading = true;
  605. // request({
  606. // params: {
  607. // r: 'coupon/coupon/delete',
  608. // },
  609. // data: {
  610. // coupon_id: self.list[index].id
  611. // },
  612. // method: 'post'
  613. // }).then(e => {
  614. // this.loading = false;
  615. // if (e.data.code == 0) {
  616. // self.$message.success(e.data.msg);
  617. // self.list.splice(index, 1);
  618. // } else {
  619. // self.$message.error(e.data.msg)
  620. // }
  621. // }).catch(e => {
  622. // this.loading = false;
  623. // console.log(e);
  624. // this.$message.error('网络错误');
  625. // });
  626. // }).catch(() => { //点击取消
  627. //
  628. // });
  629. } else if (type == 6) { // 复制
  630. navigateTo({
  631. r: 'store/client/coupon/edit',
  632. coupon_id: this.list[index].id,
  633. is_copy: true,
  634. });
  635. } else if (type == 7) { // 查看
  636. navigateTo({
  637. r: 'store/client/coupon/edit',
  638. coupon_id: this.list[index].id,
  639. status: this.list[index].status_int
  640. });
  641. }
  642. },
  643. // 图片下载
  644. downloadShareImg(type) {
  645. if ('qrcode' == type) {
  646. if (!this.shareData.img) {
  647. this.$message.error('暂无图片');
  648. return;
  649. }
  650. var img_url = this.shareData.img;
  651. var filename = this.shareData.qrcode_filename;
  652. } else {
  653. if (!this.shareData.poster) {
  654. this.$message.error('暂无图片');
  655. return;
  656. }
  657. var img_url = this.shareData.poster;
  658. var filename = this.shareData.poster_filename;
  659. }
  660. fetch(img_url).then(res => res.blob().then(blob => {
  661. var a = document.createElement('a');
  662. var url = window.URL.createObjectURL(blob);
  663. a.href = url;
  664. a.download = filename;
  665. a.click();
  666. window.URL.revokeObjectURL(url);
  667. }))
  668. },
  669. copyLink(str) {
  670. var clipboard = new Clipboard('.copy_btn', {
  671. text: function() {
  672. return str;
  673. }
  674. });
  675. var self = this;
  676. clipboard.on('success', function(e) {
  677. // console.log("success")
  678. self.$message.success('复制成功');
  679. e.clearSelection();
  680. clipboard.destroy()
  681. });
  682. clipboard.on('error', function(e) {
  683. // console.log("error")
  684. self.$message.error('复制失败,请手动复制');
  685. });
  686. },
  687. // 跳转 已使用/已领取页面
  688. couponDetail(status, coupon_id) {
  689. let url = 'store/client/coupon/user-coupon-detail';
  690. navigateTo({
  691. r: url,
  692. status: status,
  693. coupon_id: coupon_id,
  694. });
  695. },
  696. // 生成二维码
  697. getQrCode(url) {
  698. let qrcodeInfo = document.getElementById("qrcode-info");
  699. document.getElementById("qrcode").remove(); //删除生成的二维码
  700. let addCodeDom = document.createElement("div")
  701. addCodeDom.setAttribute("id", "qrcode");
  702. addCodeDom.setAttribute("style", "width:300px; height:300px;");
  703. qrcodeInfo.appendChild(addCodeDom) //添加标签
  704. let qrCodeDom = document.getElementById("qrcode")
  705. var qrcode = new QRCode(qrCodeDom, {
  706. width: 300,
  707. height: 300
  708. });
  709. qrcode.makeCode(url);
  710. // 获取二维码生成的图片信息
  711. let src = "";
  712. return new Promise((req, rej) => {
  713. setTimeout(() => {
  714. src = qrCodeDom.getElementsByTagName("img")[0].src;
  715. req(src)
  716. }, 200);
  717. })
  718. },
  719. // 生成海报
  720. getPoster() {
  721. try {
  722. // 存在海报则不重新生成
  723. if (this.posterArr[this.list_index]) {
  724. this.shareData.poster = this.posterArr[this.list_index];
  725. return;
  726. }
  727. this.posterLoading = true;
  728. let qrcodeInfo = document.getElementById("qrcode-info");
  729. var c = document.getElementById("myCanvas");
  730. // 清空上一个生成的海报
  731. c.remove();
  732. // 创建标签
  733. let addPosterDom = document.createElement("canvas")
  734. addPosterDom.setAttribute("id", "myCanvas");
  735. addPosterDom.setAttribute("width", "375");
  736. addPosterDom.setAttribute("height", "603");
  737. qrcodeInfo.appendChild(addPosterDom);
  738. c = document.getElementById("myCanvas");
  739. var ctx = c.getContext("2d");
  740. // 背景图
  741. let bak = document.getElementById("couponBak");
  742. ctx.drawImage(bak, 0, 0, 375, 603);
  743. // 圆
  744. ctx.beginPath();
  745. ctx.arc(187.5, 105, 40, 0, 2 * Math.PI);
  746. ctx.closePath();
  747. ctx.fillStyle = "#FFF";
  748. ctx.fill(); //填充颜色
  749. let mall_header_data = JSON.parse(localStorage.getItem("mall_header_data"));
  750. // 店名
  751. ctx.font = "bold 17px Arial";
  752. ctx.fillStyle = "#000";
  753. ctx.textAlign = 'center';
  754. ctx.fillText(this.mall_info.mall_name, 187.5, 175);
  755. // 优惠券类型
  756. ctx.font = "bold 14px Arial";
  757. ctx.fillStyle = "#000";
  758. ctx.textAlign = 'center';
  759. ctx.fillText("送你一张优惠券", 187.5, 205);
  760. // 额度
  761. ctx.font = "bold 22px Arial";
  762. ctx.fillStyle = "#DB0505";
  763. ctx.textAlign = 'center';
  764. // ctx.fillText(this.list[this.list_index].content,187.5,265);
  765. ctx.fillText(this.list[this.list_index].name, 187.5, 265);
  766. let type = this.list[this.list_index].appoint_type;
  767. let typeStr = "全场可用";
  768. if (type == 1) {
  769. typeStr = "指定商品分类可用";
  770. } else if (type == 2) {
  771. typeStr = "指定商品可用";
  772. }
  773. // 可使用的类型
  774. ctx.font = "14px Arial";
  775. ctx.fillStyle = "#DB0505";
  776. ctx.textAlign = 'center';
  777. // ctx.fillText("全部商品任意金额可用",187.5,295);
  778. ctx.fillText(typeStr, 187.5, 295);
  779. // 二维码
  780. let code = document.getElementById("qrcode").getElementsByTagName("img")[0];
  781. ctx.drawImage(code, 140, 380.5, 95, 95);
  782. // 商城头像
  783. ctx.beginPath();
  784. ctx.arc(187.25, 104.75, 36.25, 0, 2 * Math.PI);
  785. ctx.clip();
  786. let topImg = document.getElementById("topImg");
  787. ctx.drawImage(topImg, 147.5, 65, 80, 80);
  788. this.shareData.poster = c.toDataURL('image/png');
  789. this.posterArr[this.list_index] = this.shareData.poster;
  790. console.info(this.shareData.poster);
  791. this.posterLoading = false;
  792. this.downloadShareImg('poster');
  793. } catch (error) {
  794. console.info(error);
  795. this.posterLoading = false;
  796. this.$message.error('生成失败');
  797. }
  798. },
  799. scFormTab(sel){
  800. var ids =[];
  801. sel.forEach(function (item,index,sel){
  802. ids.push(item.id);
  803. });
  804. this.delIds = ids;
  805. },
  806. }
  807. })
  808. </script>