discountCodeList.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="discountCodeList">
  3. <Header/>
  4. <div class="contentInner">
  5. <div class="search-form">
  6. <el-form
  7. :inline="true"
  8. ref="form"
  9. style="margin-left: 10px"
  10. >
  11. <el-form-item>
  12. <el-form-item class="label-input" label="激活码" style="margin-right:30px;">
  13. <el-input placeholder="输入生成激活码数量" v-model="discountNumber" type="number" :oninput="numberInput"></el-input>
  14. </el-form-item>
  15. <el-button @click="onSubmit" size="medium" type="primary" :loading="loading">生成</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-form :inline="true">
  19. <el-form-item class="label-input" label="导出选项:" style="margin-right:30px;">
  20. <el-radio v-model="exportRadio" :label="-1">全部</el-radio>
  21. <el-radio v-model="exportRadio" :label="1">已使用</el-radio>
  22. <el-radio v-model="exportRadio" :label="0">未使用</el-radio>
  23. </el-form-item>
  24. <el-button @click="onExport" size="medium" type="primary" :loading="exportLoading">导出 excel</el-button>
  25. </el-form>
  26. </div>
  27. <div class="table-box">
  28. <el-table :data="tableData" style="width: 100%" v-loading="tableloading">
  29. <el-table-column class="table-firstC" label="激活码" prop="discount_code" width="150"></el-table-column>
  30. <el-table-column label="状态" prop="is_used" width="150" :formatter="handleStatus"></el-table-column>
  31. <el-table-column label="使用者" prop="consumer_name" width="150"></el-table-column>
  32. <el-table-column label="使用时间" prop="use_time" width="200"></el-table-column>
  33. <el-table-column label="使用者所属机构" prop="consumer_org_name" width="250"></el-table-column>
  34. <el-table-column label="创建时间" prop="create_time" width="200"></el-table-column>
  35. <el-table-column fixed="right" label="操作" prop width="100">
  36. <template slot-scope="scope">
  37. <el-button @click="handleDel(scope.row)" type="text">删除</el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. </div>
  42. <el-pagination
  43. :current-page="currentPage"
  44. :page-size="10"
  45. :page-sizes="[1, 10, 20, 30, 40, 50]"
  46. :total="courseTotal"
  47. @current-change="handleCurrentChange"
  48. @size-change="handleSizeChange"
  49. layout="total, sizes, prev, pager, next, jumper"
  50. ></el-pagination>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import Header from "@/components/Header";
  56. import { LearnWebSI } from "@/api/ajax";
  57. import { getToken } from '@/utils/auth'
  58. export default {
  59. name: "courselist",
  60. components: {
  61. Header
  62. },
  63. data () {
  64. return {
  65. bookId: '',
  66. discountNumber:null, // 生成数量
  67. loading:false,
  68. tableData: [], // 数据内容
  69. currentPage: 1, // 当前页码
  70. page_capacity: 10, // 每页条数
  71. courseTotal: 0, // 数据总条数
  72. tableloading:true,
  73. usedStatus:{
  74. 'true':'已使用',
  75. 'false':'未使用'
  76. },
  77. exportRadio:-1,
  78. exportLoading:false,
  79. }
  80. },
  81. created() {
  82. const _this = this
  83. _this.bookId = this.$route.query.bookId
  84. this.getList();
  85. },
  86. methods:{
  87. numberInput() {
  88. this.discountNumber = this.discountNumber.replace(/[^0-9]/g, "");
  89. },
  90. // 切换每页条数
  91. handleSizeChange (val) {
  92. this.currentPage = 1;
  93. this.page_capacity = val;
  94. this.getList();
  95. },
  96. // 切换页码
  97. handleCurrentChange (val) {
  98. this.currentPage = val;
  99. this.getList();
  100. },
  101. // 生成数量
  102. onSubmit () {
  103. if(this.discountNumber){
  104. this.loading = true;
  105. let MethodName = 'order-discount_manager-BatchCreateDiscountCodeFoGoods'
  106. let data = {
  107. goods_id:this.bookId,
  108. goods_type:101,
  109. count:Number(this.discountNumber)
  110. }
  111. LearnWebSI(MethodName, data)
  112. .then((res) => {
  113. this.$message.success("操作成功");
  114. this.discountNumber = null
  115. this.loading = false;
  116. this.pageIndex = 1
  117. this.getList()
  118. })
  119. .catch(() => {
  120. this.loading = false;
  121. });
  122. }else{
  123. this.$message(
  124. {
  125. type: "warning",
  126. message: "请输入生成激活码数量!",
  127. },
  128. 2000
  129. );
  130. return false;
  131. }
  132. },
  133. // 查询数据列表
  134. getList () {
  135. let MethodName = "page_query-PageQueryGoodsDiscountCodeList";
  136. let data = {
  137. goods_id: this.bookId,
  138. goods_type: 101,
  139. page_capacity: this.page_capacity,
  140. cur_page: this.currentPage,
  141. use_status:-1
  142. };
  143. LearnWebSI(MethodName, data).then(
  144. (res) => {
  145. let _this = this;
  146. _this.tableData = res.discount_code_list;
  147. _this.courseTotal = res.total_count;
  148. _this.tableloading = false;
  149. }
  150. );
  151. },
  152. // 处理发布状态
  153. handleStatus (row) {
  154. if (row) {
  155. return this.usedStatus[row.is_used];
  156. }
  157. },
  158. // 删除书籍
  159. handleDel (row) {
  160. this.$confirm("确定要删除此激活码吗?", "提示", {
  161. confirmButtonText: "确定",
  162. cancelButtonText: "取消",
  163. type: "warning",
  164. })
  165. .then(() => {
  166. let MethodName = "order-discount_manager-DeleteGoodsDiscountCode";
  167. let data = {
  168. goods_id:this.bookId,
  169. goods_type:101,
  170. discount_code_id: row.id,
  171. };
  172. LearnWebSI(MethodName, data).then(
  173. (res) => {
  174. this.currentPage = 1;
  175. this.getList()
  176. this.$message({
  177. type: 'success',
  178. message: '删除成功!'
  179. })
  180. }
  181. ).catch(() => {
  182. })
  183. })
  184. .catch(() => { });
  185. },
  186. // 导出
  187. onExport(){
  188. this.exportLoading = true
  189. let userInfor = getToken();
  190. let UserCode = '',
  191. UserType = '',
  192. SessionID = ''
  193. if (userInfor) {
  194. let user = JSON.parse(getToken());
  195. UserCode = user.user_code;
  196. UserType = user.user_type;
  197. SessionID = user.session_id;
  198. }
  199. let MethodName = "data_export-ExportGoodsDiscountCodeList"
  200. let data = {
  201. goods_id: this.bookId,
  202. goods_type: 101,
  203. use_status:this.exportRadio
  204. }
  205. window.open(process.env.VUE_APP_BASE_API +
  206. `/GCLSLearnWebSI/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&Parameter=${encodeURIComponent(JSON.stringify(data))}`)
  207. this.exportLoading = false
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .discountCodeList{
  214. width: 100%;
  215. background: #f5f5f5;
  216. .contentInner{
  217. width: 100%;
  218. max-width: 1200px;
  219. margin: 0 auto;
  220. height: auto;
  221. padding:30px 0;
  222. }
  223. .search-form{
  224. display: flex;
  225. align-items: center;
  226. justify-content: space-between;
  227. }
  228. }
  229. </style>