discountCodeList.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 ="value=value.replace(/[^0-9]/g,'')"></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. // 切换每页条数
  88. handleSizeChange (val) {
  89. this.currentPage = 1;
  90. this.page_capacity = val;
  91. this.getList();
  92. },
  93. // 切换页码
  94. handleCurrentChange (val) {
  95. this.currentPage = val;
  96. this.getList();
  97. },
  98. // 生成数量
  99. onSubmit () {
  100. if(this.discountNumber){
  101. this.loading = true;
  102. let MethodName = 'order-discount_manager-BatchCreateDiscountCodeFoGoods'
  103. let data = {
  104. goods_id:this.bookId,
  105. goods_type:101,
  106. count:Number(this.discountNumber)
  107. }
  108. LearnWebSI(MethodName, data)
  109. .then((res) => {
  110. this.$message.success("操作成功");
  111. this.discountNumber = null
  112. this.loading = false;
  113. this.pageIndex = 1
  114. this.getList()
  115. })
  116. .catch(() => {
  117. this.loading = false;
  118. });
  119. }else{
  120. this.$message(
  121. {
  122. type: "warning",
  123. message: "请输入生成激活码数量!",
  124. },
  125. 2000
  126. );
  127. return false;
  128. }
  129. },
  130. // 查询数据列表
  131. getList () {
  132. let MethodName = "page_query-PageQueryGoodsDiscountCodeList";
  133. let data = {
  134. goods_id: this.bookId,
  135. goods_type: 101,
  136. page_capacity: this.page_capacity,
  137. cur_page: this.currentPage,
  138. use_status:-1
  139. };
  140. LearnWebSI(MethodName, data).then(
  141. (res) => {
  142. let _this = this;
  143. _this.tableData = res.discount_code_list;
  144. _this.courseTotal = res.total_count;
  145. _this.tableloading = false;
  146. }
  147. );
  148. },
  149. // 处理发布状态
  150. handleStatus (row) {
  151. if (row) {
  152. return this.usedStatus[row.is_used];
  153. }
  154. },
  155. // 删除书籍
  156. handleDel (row) {
  157. this.$confirm("确定要删除此优惠码吗?", "提示", {
  158. confirmButtonText: "确定",
  159. cancelButtonText: "取消",
  160. type: "warning",
  161. })
  162. .then(() => {
  163. let MethodName = "order-discount_manager-DeleteGoodsDiscountCode";
  164. let data = {
  165. goods_id:this.bookId,
  166. goods_type:101,
  167. discount_code_id: row.id,
  168. };
  169. LearnWebSI(MethodName, data).then(
  170. (res) => {
  171. this.currentPage = 1;
  172. this.getList()
  173. this.$message({
  174. type: 'success',
  175. message: '删除成功!'
  176. })
  177. }
  178. ).catch(() => {
  179. })
  180. })
  181. .catch(() => { });
  182. },
  183. // 导出
  184. onExport(){
  185. this.exportLoading = true
  186. let userInfor = getToken();
  187. let UserCode = '',
  188. UserType = '',
  189. SessionID = ''
  190. if (userInfor) {
  191. let user = JSON.parse(getToken());
  192. UserCode = user.user_code;
  193. UserType = user.user_type;
  194. SessionID = user.session_id;
  195. }
  196. let MethodName = "data_export-ExportGoodsDiscountCodeList"
  197. let data = {
  198. goods_id: this.bookId,
  199. goods_type: 101,
  200. use_status:this.exportRadio
  201. }
  202. window.open(process.env.VUE_APP_BASE_API +
  203. `/GCLSLearnWebSI/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&Parameter=${encodeURIComponent(JSON.stringify(data))}`)
  204. this.exportLoading = false
  205. }
  206. }
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. .discountCodeList{
  211. width: 100%;
  212. background: #f5f5f5;
  213. .contentInner{
  214. width: 100%;
  215. max-width: 1200px;
  216. margin: 0 auto;
  217. height: auto;
  218. padding:30px 0;
  219. }
  220. .search-form{
  221. display: flex;
  222. align-items: center;
  223. justify-content: space-between;
  224. }
  225. }
  226. </style>