discountCodeList.vue 8.6 KB

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