index.vue 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <div class="subPage">
  3. <div class="system-table-search">
  4. <div class="flex-h">
  5. <div class="flex-item flex-h">
  6. <el-button size="mini" type="success" @click="addCoupon('')">新增优惠券</el-button>
  7. </div>
  8. <ul>
  9. <li>
  10. <el-select v-model="CaseId" placeholder="请选择案场">
  11. <el-option
  12. key="all"
  13. label="所有案场"
  14. value="all">
  15. </el-option>
  16. <el-option
  17. v-for="item in cases"
  18. :key="item.CaseId"
  19. :label="item.CaseName"
  20. :value="item.CaseId">
  21. </el-option>
  22. </el-select>
  23. </li>
  24. </ul>
  25. <el-button
  26. size="mini"
  27. type="primary" @click="search">搜索</el-button>
  28. </div>
  29. <div class="moreFilter"></div>
  30. </div>
  31. <div class="system-table-box">
  32. <el-table
  33. :data="couponList.list"
  34. stripe
  35. style="width: 100%">
  36. <el-table-column
  37. prop="CouponName"
  38. label="券名称">
  39. </el-table-column>
  40. <el-table-column
  41. prop="CouponType"
  42. label="券类型">
  43. <template slot-scope="scope">{{scope.row.CouponType === 'goods' ? '商品券' : '课程券'}}</template>
  44. </el-table-column>
  45. <el-table-column
  46. prop="Price"
  47. label="券价格">
  48. </el-table-column>
  49. <el-table-column
  50. prop="StartDate"
  51. label="有效期"
  52. width="150">
  53. <template slot-scope="scope">
  54. <span v-if="scope.row.StartDate.substr(0, 4) !== '0001'" style="width:100%;display:block;text-align:center;white-space: nowrap;">{{toolClass.dateFormat(scope.row.StartDate, 'yyyy-MM-dd')}}</span>
  55. <span v-if="scope.row.StartDate.substr(0, 4) !== '0001'" style="width:100%;display:block;text-align:center;white-space: nowrap;">至</span>
  56. <span v-if="scope.row.StartDate.substr(0, 4) !== '0001'" style="width:100%;display:block;text-align:center;white-space: nowrap;">{{toolClass.dateFormat(scope.row.EndDate, 'yyyy-MM-dd')}}</span>
  57. <span v-else>领取后{{scope.row.ValidDays}}天内有效</span>
  58. </template>
  59. </el-table-column>
  60. <el-table-column
  61. prop="SendType"
  62. label="发放类型">
  63. <template slot-scope="scope">{{scope.row.SendType === 'channel' ? '渠道' : scope.row.SendType === 'case' ? '案场' : '系统'}}</template>
  64. </el-table-column>
  65. <el-table-column
  66. prop="TotalCount"
  67. label="总数量">
  68. </el-table-column>
  69. <el-table-column
  70. prop="Status"
  71. label="状态">
  72. <template slot-scope="scope">
  73. <span>{{scope.row.Status === 1 ? '正常' : '已过期'}}</span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作" fixed='right' width="350">
  77. <template slot-scope="scope">
  78. <el-button
  79. size="mini"
  80. type="warning"
  81. @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  82. <el-button
  83. size="mini"
  84. type="danger"
  85. @click="sendCoupon(scope.$index, scope.row)">赠送客户</el-button>
  86. <el-button
  87. size="mini"
  88. type="success"
  89. v-if="scope.row.SendType === 'channel'"
  90. v-clipboard:copy="clientUrl + 'wechat/user.html#/receiveChannelShared/' + scope.row.CouponId + '/coupon/receive'"
  91. v-clipboard:success="onCopy"
  92. v-clipboard:error="onError"
  93. >点击复制链接</el-button>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. </div>
  98. <el-pagination
  99. @current-change="handleCurrentChange"
  100. :current-page.sync="postData.page"
  101. :page-size="postData.pagesize"
  102. layout="prev, pager, next, jumper"
  103. :total="total">
  104. </el-pagination>
  105. <el-dialog
  106. title="选择赠送客户"
  107. :visible.sync="centerDialogVisible"
  108. width="800px"
  109. @close="dialogPostData.page = 1"
  110. center>
  111. <div>
  112. <ul class="dialogSearchList flex-h" style="margin-bottom:10px;">
  113. <li class="flex-item">
  114. <el-input
  115. placeholder="请输入用户名"
  116. v-model="dialogPostData.username"
  117. clearable>
  118. </el-input>
  119. </li>
  120. <li class="flex-item">
  121. <el-input
  122. placeholder="请输入手机号"
  123. v-model="dialogPostData.phone"
  124. clearable>
  125. </el-input>
  126. </li>
  127. <li class="flex-item">
  128. <el-input
  129. placeholder="请输入推荐人"
  130. v-model="dialogPostData.recommendname"
  131. clearable>
  132. </el-input>
  133. </li>
  134. <li>
  135. <el-button type="primary" @click="dialogSearch">搜索</el-button>
  136. </li>
  137. </ul>
  138. <ul class="dialogSearchList flex-h">
  139. <li class="flex-item">
  140. <el-date-picker
  141. value-format="yyyy-MM-dd"
  142. v-model="dialogPostData.begindate"
  143. type="date"
  144. placeholder="选择起始日期">
  145. </el-date-picker>
  146. <el-date-picker
  147. value-format="yyyy-MM-dd"
  148. v-model="dialogPostData.enddate"
  149. type="date"
  150. placeholder="选择截止日期">
  151. </el-date-picker>
  152. </li>
  153. </ul>
  154. </div>
  155. <div>
  156. <el-table
  157. ref="multipleTable"
  158. :data="customers.list"
  159. tooltip-effect="dark"
  160. style="width: 100%"
  161. @selection-change="handleSelectionChange">
  162. <el-table-column
  163. type="selection">
  164. </el-table-column>
  165. <el-table-column
  166. prop="Name"
  167. label="姓名">
  168. </el-table-column>
  169. <el-table-column
  170. prop="CustomerName"
  171. label="微信昵称">
  172. </el-table-column>
  173. <el-table-column
  174. prop="Phone"
  175. label="手机号">
  176. </el-table-column>
  177. <el-table-column
  178. prop="CreateDate"
  179. label="创建时间">
  180. <template slot-scope="scope">
  181. <span v-if="scope.row.CreateDate !== '0001-01-01T00:00:00Z'">{{toolClass.dateFormat(scope.row.CreateDate, 'yyyy-MM-dd')}}</span>
  182. <span v-else>-</span>
  183. </template>
  184. </el-table-column>
  185. <el-table-column
  186. prop="RecommendName"
  187. label="推荐人">
  188. </el-table-column>
  189. </el-table>
  190. </div>
  191. <div>
  192. <el-pagination
  193. @current-change="handleCurrentChangeDialog"
  194. :current-page.sync="dialogPostData.page"
  195. :page-size="dialogPostData.pagesize"
  196. layout="prev, pager, next, jumper"
  197. :total="customers.pagenum">
  198. </el-pagination>
  199. </div>
  200. <span slot="footer" class="dialog-footer">
  201. <el-button @click="centerDialogVisible = false">取 消</el-button>
  202. <el-button type="primary" @click="ForCustomer">确 定</el-button>
  203. </span>
  204. </el-dialog>
  205. </div>
  206. </template>
  207. <script>
  208. import { mapState, createNamespacedHelpers } from 'vuex'
  209. const { mapState: mapCouponState, mapActions: mapCouponActions } = createNamespacedHelpers('coupon')
  210. const { mapState: mapCustomerState, mapActions: mapCustomerActions } = createNamespacedHelpers('customer')
  211. export default {
  212. name: '',
  213. data () {
  214. return {
  215. dialogTotal: 0,
  216. dialogPostData: {
  217. username: '',
  218. phone: '',
  219. recommendname: '',
  220. begindate: '',
  221. enddate: '',
  222. page: 1, // 当前页码
  223. pagesize: 6, // 请求数据量
  224. },
  225. centerDialogVisible: false,
  226. total: 0,
  227. postData: { // 表格搜索条件
  228. caseid: '', // 案场id
  229. page: 1, // 当前页码
  230. pagesize: 10, // 请求数据量
  231. },
  232. currentInfo: {},
  233. selUsers: '',
  234. }
  235. },
  236. mounted () {
  237. this.$nextTick(function () {
  238. this.getList()
  239. })
  240. },
  241. computed: {
  242. ...mapCouponState({
  243. couponList: x => x.couponList,
  244. }),
  245. ...mapCustomerState({
  246. customers: x => x.customers,
  247. }),
  248. ...mapState({
  249. clientUrl: x => x.app.clientUrl,
  250. cases: x => x.app.cases.list,
  251. defaultCaseId: x => x.app.cases.default
  252. }),
  253. CaseId: {
  254. get () {
  255. return this.postData.caseid || this.defaultCaseId
  256. },
  257. set (val) {
  258. this.postData.caseid = val
  259. }
  260. }
  261. },
  262. methods: {
  263. ...mapCouponActions([
  264. 'GetCouponList',
  265. 'GiveCoupon',
  266. ]),
  267. ...mapCustomerActions([
  268. 'GetCustomerList',
  269. 'SetCustomerListNull',
  270. ]),
  271. dialogSearch () { // 赠送客户搜索
  272. this.GetCustomerList(this.dialogPostData).then((res) => {
  273. this.dialogTotal = res.pagenum
  274. })
  275. },
  276. handleCurrentChangeDialog (val) {
  277. this.dialogPostData.page = val
  278. this.GetCustomerList(this.dialogPostData).then((res) => {
  279. this.dialogTotal = res.pagenum
  280. })
  281. },
  282. handleSelectionChange (val) {
  283. this.selUsers = val.map(x => x.CustomerId).join(',')
  284. // 1
  285. },
  286. sendCoupon (index, row) { // 赠送优惠券
  287. this.currentInfo = row
  288. this.selUsers = ''
  289. this.SetCustomerListNull()
  290. this.centerDialogVisible = true
  291. },
  292. search () { // 搜索
  293. this.postData.page = 1
  294. if (this.couponList.length) {
  295. this.couponList = []
  296. }
  297. this.getList()
  298. },
  299. getList () { // 获取列表
  300. this.GetCouponList({
  301. ...this.postData,
  302. caseid: this.postData.caseid === 'all' || this.postData.caseid === '' ? '' : this.postData.caseid
  303. }).then((res) => {
  304. this.total = res.pagenum
  305. // console.log(JSON.stringify(res))
  306. })
  307. },
  308. handleCurrentChange (val) { // 跳转到分页
  309. this.postData.page = val
  310. this.getList()
  311. },
  312. handleEdit (index, row) { // 编辑
  313. this.$router.push({ name: 'editCoupon', query: { type: row.CouponType, id: row.CouponId, caseid: row.CaseId } })
  314. },
  315. handleDelete (index, row) { // 删除
  316. let name = '确认删除渠道“' + row.ChannelName + '”?'
  317. this.$confirm(name, '提示', {
  318. confirmButtonText: '确定',
  319. cancelButtonText: '取消',
  320. type: 'warning'
  321. }).then(() => {
  322. this.$ajax(this.$api.channelManager.deleteChannel.url, {
  323. method: this.$api.channelManager.deleteChannel.method,
  324. urlData: { channelId: row.ChannelId }
  325. }).then(res => {
  326. this.$message({
  327. type: 'success',
  328. message: '删除成功!'
  329. })
  330. this.search()
  331. })
  332. }).catch(() => {
  333. this.$message({
  334. type: 'info',
  335. message: '已取消删除'
  336. })
  337. })
  338. },
  339. addCoupon (val) {
  340. this.$router.push({ name: 'addCoupon', query: { type: val } })
  341. },
  342. ForCustomer () {
  343. if (this.selUsers === '') {
  344. this.$message({
  345. type: 'error',
  346. message: '请先选择客户!'
  347. })
  348. return false
  349. }
  350. if (!this.currentInfo || this.currentInfo.CouponId === '') {
  351. this.$message({
  352. type: 'error',
  353. message: '请先选择需要赠送的优惠券!'
  354. })
  355. return false
  356. }
  357. this.GiveCoupon({
  358. id: this.currentInfo.CouponId,
  359. users: this.selUsers,
  360. }).then(res => {
  361. this.$message({
  362. type: 'success',
  363. message: '赠送成功!'
  364. })
  365. this.centerDialogVisible = false
  366. this.dialogPostData = {
  367. username: '',
  368. phone: '',
  369. recommendname: '',
  370. begindate: '',
  371. enddate: '',
  372. page: 1, // 当前页码
  373. pagesize: 6, // 请求数据量
  374. }
  375. this.getList()
  376. })
  377. },
  378. onCopy () {
  379. this.$message({
  380. type: 'success',
  381. message: '复制成功!'
  382. })
  383. },
  384. onError () {
  385. this.$message({
  386. type: 'error',
  387. message: '复制失败!'
  388. })
  389. },
  390. }
  391. }
  392. </script>
  393. <!-- Add "scoped" attrib0 0ute to limit CSS to this component only -->
  394. <style lang="scss" scoped>
  395. @import "page.scss";
  396. .dialogSearchList {
  397. align-items: center;
  398. > li {
  399. font-size: 0;
  400. margin-left: 10px;
  401. &:first-child {
  402. margin-left: 0;
  403. }
  404. > *:nth-child(2) {
  405. margin-left: 10px;
  406. }
  407. }
  408. }
  409. </style>