index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="标题" prop="title">
  5. <el-input
  6. v-model="queryParams.title"
  7. placeholder="请输入标题"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="有效期" prop="limitTime">
  14. <el-date-picker v-model="limitTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
  15. </el-form-item>
  16. <el-form-item label="券类型" prop="couponType">
  17. <el-select v-model="queryParams.couponType" placeholder="请选择券类型" clearable size="small">
  18. <el-option
  19. v-for="dict in couponTypeOptions"
  20. :key="dict.dictValue"
  21. :label="dict.dictLabel"
  22. :value="dict.dictValue"
  23. />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="面额" prop="price">
  27. <el-input
  28. v-model="queryParams.price"
  29. placeholder="请输入面额"
  30. clearable
  31. size="small"
  32. @keyup.enter.native="handleQuery"
  33. />
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  37. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  38. </el-form-item>
  39. </el-form>
  40. <el-row :gutter="10" class="mb8">
  41. <el-col :span="1.5">
  42. <el-button
  43. type="primary"
  44. plain
  45. icon="el-icon-plus"
  46. size="mini"
  47. @click="handleAdd"
  48. v-hasPermi="['his:coupon:add']"
  49. >新增</el-button>
  50. </el-col>
  51. <el-col :span="1.5">
  52. <el-button
  53. type="success"
  54. plain
  55. icon="el-icon-edit"
  56. size="mini"
  57. :disabled="single"
  58. @click="handleUpdate"
  59. v-hasPermi="['his:coupon:edit']"
  60. >修改</el-button>
  61. </el-col>
  62. <el-col :span="1.5">
  63. <el-button
  64. type="danger"
  65. plain
  66. icon="el-icon-delete"
  67. size="mini"
  68. :disabled="multiple"
  69. @click="handleDelete"
  70. v-hasPermi="['his:coupon:remove']"
  71. >删除</el-button>
  72. </el-col>
  73. <el-col :span="1.5">
  74. <el-button
  75. type="warning"
  76. plain
  77. icon="el-icon-download"
  78. size="mini"
  79. :loading="exportLoading"
  80. @click="handleExport"
  81. v-hasPermi="['his:coupon:export']"
  82. >导出</el-button>
  83. </el-col>
  84. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  85. </el-row>
  86. <el-table v-loading="loading" border :data="couponList" @selection-change="handleSelectionChange">
  87. <el-table-column type="selection" width="55" align="center" />
  88. <el-table-column label="优惠券名称" align="center" prop="title" width="120px"/>
  89. <el-table-column label="面额" align="center" prop="price" />
  90. <el-table-column label="折扣" align="center" prop="rate" />
  91. <el-table-column label="数量" align="center" prop="number" />
  92. <el-table-column label="卷类型 " align="center" prop="couponType" width="120px">
  93. <template slot-scope="scope">
  94. <dict-tag :options="couponTypeOptions" :value="scope.row.couponType"/>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="状态" align="center" prop="status">
  98. <template slot-scope="scope">
  99. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="最低消费金额可用" align="center" prop="minPrice" />
  103. <el-table-column label="剩余数量" align="center" prop="remainNumber" />
  104. <el-table-column label="有效期" align="center" prop="limitTime" width="180"/>
  105. <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
  106. <el-table-column label="更改时间" align="center" prop="updateTime" width="180"/>
  107. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
  108. <template slot-scope="scope">
  109. <el-button
  110. size="mini"
  111. type="text"
  112. icon="el-icon-edit"
  113. @click="handleUpdate(scope.row)"
  114. v-hasPermi="['his:coupon:edit']"
  115. >修改</el-button>
  116. <el-button
  117. size="mini"
  118. type="text"
  119. @click="handledetails(scope.row)"
  120. >详情
  121. </el-button>
  122. <el-button
  123. size="mini"
  124. type="text"
  125. icon="el-icon-delete"
  126. @click="handleDelete(scope.row)"
  127. v-hasPermi="['his:coupon:remove']"
  128. >删除</el-button>
  129. <el-button
  130. size="mini"
  131. type="text"
  132. @click="send(scope.row)"
  133. v-hasPermi="['his:userCoupon:send']"
  134. >发送优惠劵
  135. </el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <pagination
  140. v-show="total>0"
  141. :total="total"
  142. :page.sync="queryParams.pageNum"
  143. :limit.sync="queryParams.pageSize"
  144. @pagination="getList"
  145. />
  146. <el-dialog title="发送优惠劵" :visible.sync="openSend" width="500px" append-to-body>
  147. <el-form ref="formSend" label-width="100px">
  148. <el-form-item label="优惠券名称" prop="title">
  149. <div style="margin-left: 20px;font-weight: bold;"> {{sendForm.title}}</div>
  150. </el-form-item>
  151. <el-form-item label="面额" prop="price" v-if="form.couponType==1">
  152. <div style="margin-left: 20px;font-weight: bold;"> {{sendForm.price}}</div>
  153. </el-form-item>
  154. <el-form-item label="搜索用户" >
  155. <el-input placeholder="输入电话号码查询用户" v-model="phone" class="input-with-select">
  156. <el-button slot="append" icon="el-icon-search" @click="selectPhone"></el-button>
  157. </el-input>
  158. </el-form-item>
  159. <el-form-item label="用户" >
  160. <el-select v-model="sendForm.userId">
  161. <el-option
  162. v-for="item in userList"
  163. :key="item.name"
  164. :label="item.name"
  165. :value="item.id">
  166. </el-option>
  167. </el-select>
  168. </el-form-item>
  169. </el-form>
  170. <div slot="footer" class="dialog-footer">
  171. <el-button type="primary" @click="submitSendForm">发 送</el-button>
  172. <el-button @click="cancelSend">取 消</el-button>
  173. </div>
  174. </el-dialog>
  175. <!-- 添加或修改优惠券对话框 -->
  176. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  177. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  178. <el-form-item label="优惠券名称" prop="title">
  179. <el-input v-model="form.title" placeholder="请输入优惠券名称" />
  180. </el-form-item>
  181. <el-form-item label="过期时间" prop="limitTime">
  182. <el-date-picker clearable size="small"
  183. v-model="form.limitTime"
  184. type="date"
  185. value-format="yyyy-MM-dd"
  186. placeholder="选择过期时间">
  187. </el-date-picker>
  188. </el-form-item>
  189. <el-form-item label="用户可领取数量" prop="limitCount" >
  190. <el-input-number v-model="form.limitCount" :min="1" label="请输入用户可领取数量"></el-input-number>
  191. </el-form-item>
  192. <el-form-item label="卷类型" prop="couponType">
  193. <el-select v-model="form.couponType" placeholder="请选择卷类型" @change="isShowChange">
  194. <el-option
  195. v-for="dict in couponTypeOptions"
  196. :key="dict.dictValue"
  197. :label="dict.dictLabel"
  198. :value="parseInt(dict.dictValue)"
  199. ></el-option>
  200. </el-select>
  201. </el-form-item>
  202. <el-form-item label="可用分类" prop="cateIds" v-show="form.couponType==5||form.couponType==6">
  203. <el-select v-model="form.cateIds" multiple placeholder="请选择可用分类">
  204. <el-option
  205. v-for="dict in cateIdsOptions"
  206. :key="dict.dictValue"
  207. :label="dict.dictLabel"
  208. :value="parseInt(dict.dictValue)"
  209. ></el-option>
  210. </el-select>
  211. </el-form-item>
  212. <el-form-item label="面额" prop="price" v-if="form.couponType==1||form.couponType==5||form.couponType==6">
  213. <el-input-number v-model="form.price" :min="0" label="请输入面额"></el-input-number>
  214. </el-form-item>
  215. <el-form-item label="最低消费" prop="minPrice" v-if="form.couponType==1||form.couponType==5||form.couponType==6">
  216. <el-input-number v-model="form.minPrice" :min="0" label="请输入最低消费金额可用"></el-input-number>
  217. </el-form-item>
  218. <el-form-item label="打折百分比" prop="rate" v-if="form.couponType==4">
  219. <el-input-number v-model="form.rate" :min="1" :max="100" label="请输入折扣百分比"></el-input-number>
  220. </el-form-item>
  221. <el-form-item label="有效期类型" prop="limitType">
  222. <el-select v-model="form.limitType" placeholder="请选择有效期类型">
  223. <el-option
  224. v-for="dict in limitTypeOptions"
  225. :key="dict.dictValue"
  226. :label="dict.dictLabel"
  227. :value="parseInt(dict.dictValue)"
  228. ></el-option>
  229. </el-select>
  230. </el-form-item>
  231. <el-form-item label="领取后有效期(天)" prop="limitDay" >
  232. <el-input-number v-model="form.limitDay" :min="1" label="请输入领取后有效期"></el-input-number>
  233. </el-form-item>
  234. <el-form-item label="数量" prop="number">
  235. <el-input-number v-model="form.number" :min="0" label="请输入数量"></el-input-number>
  236. </el-form-item>
  237. <el-form-item label="状态" prop="status">
  238. <el-radio-group v-model="form.status">
  239. <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
  240. </el-radio-group>
  241. </el-form-item>
  242. </el-form>
  243. <div slot="footer" class="dialog-footer">
  244. <el-button type="primary" @click="submitForm">确 定</el-button>
  245. <el-button @click="cancel">取 消</el-button>
  246. </div>
  247. </el-dialog>
  248. <el-drawer
  249. :with-header="false"
  250. size="75%"
  251. :title="show.title" :visible.sync="show.open">
  252. <couponDetails ref="Details" />
  253. </el-drawer>
  254. </div>
  255. </template>
  256. <script>
  257. import { listCoupon, getCoupon, delCoupon, addCoupon, updateCoupon, exportCoupon } from "@/api/his/coupon";
  258. import { sendCoupon } from "@/api/his/userCoupon";
  259. import couponDetails from '../../components/his/couponDetails.vue';
  260. import {getUserList} from "@/api/his/doctor";
  261. import {selectUser} from "@/api/his/user";
  262. import {getAllCateList} from "@/api/his/packageCate";
  263. export default {
  264. name: "Coupon",
  265. components: { couponDetails },
  266. data() {
  267. return {
  268. show:{
  269. open:false,
  270. },
  271. limitTime:[],
  272. userList:[],
  273. userName: null,
  274. // 遮罩层
  275. loading: true,
  276. phone:null,
  277. // 导出遮罩层
  278. exportLoading: false,
  279. // 选中数组
  280. ids: [],
  281. // 非单个禁用
  282. single: true,
  283. // 非多个禁用
  284. multiple: true,
  285. // 显示搜索条件
  286. showSearch: true,
  287. // 总条数
  288. total: 0,
  289. // 优惠券表格数据
  290. couponList: [],
  291. statusOptions: [],
  292. limitTypeOptions: [],
  293. privateTypeOptions: [],
  294. diseaseTypeOptions: [],
  295. orOptions: [],
  296. cateIdsOptions: [],
  297. // 弹出层标题
  298. title: "",
  299. // 是否显示弹出层
  300. open: false,
  301. openSend:false,
  302. // 卷类型 1代金券 字典
  303. couponTypeOptions: [],
  304. // 查询参数
  305. queryParams: {
  306. pageNum: 1,
  307. pageSize: 10,
  308. title: null,
  309. limitTime: null,
  310. price: null,
  311. number: null,
  312. couponType: null,
  313. minPrice: null,
  314. remainNumber: null,
  315. sTime:null,
  316. eTime:null
  317. },
  318. sendForm:{
  319. title: null,
  320. price: null,
  321. couponId:null,
  322. couponType:null,
  323. userId:null,
  324. },
  325. // 表单参数
  326. form: {},
  327. // 表单校验
  328. rules: {
  329. title: [
  330. { required: true, message: "标题不能为空", trigger: "blur" }
  331. ],
  332. limitTime: [
  333. { required: true, message: "有效期不能为空", trigger: "blur" }
  334. ],
  335. couponType: [
  336. { required: true, message: "券类型不能为空", trigger: "blur" }
  337. ],
  338. }
  339. };
  340. },
  341. created() {
  342. this.getList();
  343. getAllCateList().then(response => {
  344. this.diseaseTypeOptions = response.data.diseaseType;
  345. this.privateTypeOptions = response.data.privateType;
  346. });
  347. this.getDicts("sys_coupon_type").then(response => {
  348. this.couponTypeOptions = response.data;
  349. });
  350. this.getDicts("sys_company_status").then(response => {
  351. this.statusOptions = response.data;
  352. });
  353. this.getDicts("sys_coupon_limit_type").then(response => {
  354. this.limitTypeOptions = response.data;
  355. });
  356. this.getDicts("sys_company_or").then(response => {
  357. this.orOptions = response.data;
  358. });
  359. },
  360. methods: {
  361. send(row){
  362. this.openSend=true;
  363. this.sendForm.userId=null;
  364. this.sendForm.couponId=row.couponId;
  365. this.sendForm.title=row.title;
  366. this.sendForm.price=row.price;
  367. this.sendForm.couponType=row.couponType;
  368. },
  369. selectPhone(){
  370. selectUser(this.phone).then(response => {
  371. this.userList=response.rows;
  372. if(this.userList!=null){
  373. this.sendForm.userId=this.userList[0].id;
  374. }
  375. });
  376. },
  377. cancelSend(){
  378. this.openSend=false;
  379. },
  380. submitSendForm(row){
  381. if(this.sendForm.userId==null){
  382. return this.$message('未选择用户');
  383. }
  384. sendCoupon(this.sendForm).then(response => {
  385. this.msgSuccess("发送成功");
  386. this.openSend=false;
  387. this.getList();
  388. });
  389. },
  390. /** 查询优惠券列表 */
  391. getList() {
  392. this.loading = true;
  393. listCoupon(this.queryParams).then(response => {
  394. this.couponList = response.rows;
  395. this.total = response.total;
  396. this.loading = false;
  397. });
  398. },
  399. // 取消按钮
  400. cancel() {
  401. this.open = false;
  402. this.reset();
  403. },
  404. // 表单重置
  405. reset() {
  406. this.form = {
  407. couponId: null,
  408. title: null,
  409. createTime: null,
  410. limitTime: null,
  411. price: null,
  412. number: null,
  413. couponType: null,
  414. minPrice: null,
  415. remainNumber: null,
  416. status:"1",
  417. rate:0,
  418. limitDay:1,
  419. limitCount:1,
  420. limitType:null,
  421. cateIds:null,
  422. };
  423. this.resetForm("form");
  424. },
  425. /** 搜索按钮操作 */
  426. handleQuery() {
  427. this.queryParams.pageNum = 1;
  428. this.getList();
  429. },
  430. /** 重置按钮操作 */
  431. resetQuery() {
  432. this.resetForm("queryForm");
  433. this.limitTime=null;
  434. this.queryParams.sTime=null;
  435. this.queryParams.eTime=null;
  436. this.handleQuery();
  437. },
  438. // 多选框选中数据
  439. handleSelectionChange(selection) {
  440. this.ids = selection.map(item => item.couponId)
  441. this.single = selection.length!==1
  442. this.multiple = !selection.length
  443. },
  444. handledetails(row){
  445. this.show.open=true;
  446. setTimeout(() => {
  447. this.$refs.Details.getDetails(row.couponId);
  448. }, 1);
  449. },
  450. /** 新增按钮操作 */
  451. handleAdd() {
  452. this.reset();
  453. this.open = true;
  454. this.title = "添加优惠券";
  455. },
  456. isShowChange(){
  457. this.form.cateIds=null
  458. if(this.form.couponType==5){
  459. this.cateIdsOptions=this.privateTypeOptions;
  460. }else{
  461. this.cateIdsOptions=this.diseaseTypeOptions;
  462. }
  463. },
  464. /** 修改按钮操作 */
  465. handleUpdate(row) {
  466. this.reset();
  467. const couponId = row.couponId || this.ids
  468. getCoupon(couponId).then(response => {
  469. this.form = response.data;
  470. this.open = true;
  471. this.title = "修改优惠券";
  472. this.form.status=String(this.form.status)
  473. this.form.isShow=String(this.form.isShow)
  474. if(this.form.couponType==5){
  475. this.cateIdsOptions=this.privateTypeOptions;
  476. }else{
  477. this.cateIdsOptions=this.diseaseTypeOptions;
  478. }
  479. if(this.form.cateIds!=null){
  480. this.form.cateIds= JSON.parse(this.form.cateIds)
  481. }
  482. });
  483. },
  484. /** 提交按钮 */
  485. submitForm() {
  486. this.$refs["form"].validate(valid => {
  487. if (valid) {
  488. if(this.form.cateIds!=null){
  489. this.form.cateIds= JSON.stringify(this.form.cateIds)
  490. }
  491. if (this.form.couponId != null) {
  492. updateCoupon(this.form).then(response => {
  493. this.msgSuccess("修改成功");
  494. this.open = false;
  495. this.getList();
  496. });
  497. } else {
  498. addCoupon(this.form).then(response => {
  499. this.msgSuccess("新增成功");
  500. this.open = false;
  501. this.getList();
  502. });
  503. }
  504. }
  505. });
  506. },
  507. change(){
  508. if(this.limitTime!=null){
  509. this.queryParams.sTime=this.limitTime[0];
  510. this.queryParams.eTime=this.limitTime[1];
  511. }else{
  512. this.queryParams.sTime=null;
  513. this.queryParams.eTime=null;
  514. }
  515. },
  516. /** 删除按钮操作 */
  517. handleDelete(row) {
  518. const couponIds = row.couponId || this.ids;
  519. this.$confirm('是否确认删除优惠券编号为"' + couponIds + '"的数据项?', "警告", {
  520. confirmButtonText: "确定",
  521. cancelButtonText: "取消",
  522. type: "warning"
  523. }).then(function() {
  524. return delCoupon(couponIds);
  525. }).then(() => {
  526. this.getList();
  527. this.msgSuccess("删除成功");
  528. }).catch(() => {});
  529. },
  530. /** 导出按钮操作 */
  531. handleExport() {
  532. const queryParams = this.queryParams;
  533. this.$confirm('是否确认导出所有优惠券数据项?', "警告", {
  534. confirmButtonText: "确定",
  535. cancelButtonText: "取消",
  536. type: "warning"
  537. }).then(() => {
  538. this.exportLoading = true;
  539. return exportCoupon(queryParams);
  540. }).then(response => {
  541. this.download(response.msg);
  542. this.exportLoading = false;
  543. }).catch(() => {});
  544. }
  545. }
  546. };
  547. </script>