list.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <a-card size="small" :bordered="false" class="promotionRulesList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="创建时间">
  10. <rangeDate ref="rangeDate" @change="dateChange" />
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="促销名称">
  15. <a-input id="promotionRulesList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入促销名称"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="状态">
  20. <v-select code="ENABLE_FLAG" id="promotionRulesList-enabledFlag" v-model="queryParam.enabledFlag" allowClear placeholder="请选择状态"></v-select>
  21. </a-form-item>
  22. </a-col>
  23. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  24. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="promotionRulesList-refresh">查询</a-button>
  25. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="promotionRulesList-reset">重置</a-button>
  26. </a-col>
  27. </a-row>
  28. </a-form>
  29. </div>
  30. <!-- 操作按钮 -->
  31. <div class="table-operator">
  32. <a-button id="promotionRulesList-add" type="primary" v-if="$hasPermissions('B_promotionRules_add')" class="button-error" @click="openModal=true">新增</a-button>
  33. </div>
  34. <!-- 列表 -->
  35. <s-table
  36. class="sTable fixPagination"
  37. ref="table"
  38. :style="{ height: tableHeight+84.5+'px' }"
  39. size="small"
  40. :rowKey="(record) => record.id"
  41. :columns="columns"
  42. :data="loadData"
  43. :scroll="{ x: 1210, y: tableHeight }"
  44. :defaultLoadData="false"
  45. bordered>
  46. <!-- 促销时间 -->
  47. <template slot="activeDate" slot-scope="text, record">
  48. <div v-if="record.activeDateEnable != '0'">
  49. <span v-if="record.activeDateStart || record.activeDateEnd">{{ record.activeDateStart }} 至 {{ record.activeDateEnd }}</span>
  50. <span v-else>--</span>
  51. </div>
  52. <span v-else>不限</span>
  53. </template>
  54. <!-- 状态 -->
  55. <template slot="enabledFlag" slot-scope="text, record">
  56. <a-switch
  57. v-if="$hasPermissions('B_promotionRules_enable')"
  58. id="promotionRulesList-enable"
  59. checkedChildren="启用"
  60. unCheckedChildren="禁用"
  61. @change="changeStatus(record)"
  62. :checked="record.enabledFlag == 1 ? true : false" />
  63. <span v-else :style="{color:(record.enabledFlag==1?'#00aa00':'#999')}"> {{ record.enabledFlag==1? '已启用': '已禁用' }} </span>
  64. </template>
  65. <!-- 操作 -->
  66. <template slot="action" slot-scope="text, record">
  67. <a-button
  68. size="small"
  69. type="link"
  70. v-if="record.enabledFlag != 1 && $hasPermissions('B_promotionRules_ruleSet')"
  71. class="button-primary"
  72. @click="handleRule(record)"
  73. id="promotionRulesList-rule-btn">规则设置</a-button>
  74. <a-button
  75. size="small"
  76. type="link"
  77. v-if="record.enabledFlag != 1 && $hasPermissions('B_promotionRules_edit')"
  78. class="button-info"
  79. @click="handleEdit(record)"
  80. id="promotionRulesList-edit-btn">编辑</a-button>
  81. <a-button
  82. size="small"
  83. type="link"
  84. v-if="$hasPermissions('B_promotionRules_detail')"
  85. class="button-success"
  86. @click="handleDetail(record)"
  87. id="promotionRulesList-detail-btn">详情</a-button>
  88. <span v-if="!(record.enabledFlag != 1 && $hasPermissions('B_promotionRules_ruleSet')) && !(record.enabledFlag != 1 && $hasPermissions('B_promotionRules_edit')) && !$hasPermissions('B_promotionRules_detail')">--</span>
  89. </template>
  90. </s-table>
  91. </a-spin>
  92. <!-- 新增 -->
  93. <basic-info-modal :openModal="openModal" :itemSn="itemSn" @ok="handleOk" @close="closeModal" />
  94. </a-card>
  95. </template>
  96. <script>
  97. import { STable, VSelect } from '@/components'
  98. import rangeDate from '@/views/common/rangeDate.vue'
  99. import basicInfoModal from './basicInfoModal.vue'
  100. import { promoActiveList, promoActiveEnable } from '@/api/promoActive'
  101. export default {
  102. components: { STable, VSelect, basicInfoModal, rangeDate },
  103. data () {
  104. return {
  105. spinning: false,
  106. tableHeight: 0,
  107. queryParam: { // 查询条件
  108. beginDate: '',
  109. endDate: '',
  110. name: '', // 名称
  111. enabledFlag: undefined // 状态
  112. },
  113. disabled: false, // 查询、重置按钮是否可操作
  114. columns: [
  115. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  116. { title: '创建时间', dataIndex: 'createDate', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  117. { title: '促销名称', dataIndex: 'name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  118. { title: '促销时间', scopedSlots: { customRender: 'activeDate' }, width: 170, align: 'center' },
  119. { title: '参与客户', dataIndex: 'promoBuyerName', width: 180, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  120. { title: '备注', dataIndex: 'remark', width: 200, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  121. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: 100, align: 'center', fixed: 'right' },
  122. { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
  123. ],
  124. // 加载数据方法 必须为 Promise 对象
  125. loadData: parameter => {
  126. this.disabled = true
  127. this.spinning = true
  128. return promoActiveList(Object.assign(parameter, this.queryParam)).then(res => {
  129. const data = res.data
  130. const no = (data.pageNo - 1) * data.pageSize
  131. for (var i = 0; i < data.list.length; i++) {
  132. data.list[i].no = no + i + 1
  133. let str = ''
  134. const promoBuyerList = data.list[i].promoBuyerList ? data.list[i].promoBuyerList : []
  135. promoBuyerList.map(item => {
  136. str += item.buyerName + ','
  137. })
  138. str = str.substr(0, str.length - 1)
  139. data.list[i].promoBuyerName = str || '全部客户'
  140. }
  141. this.total = data.count || 0
  142. this.disabled = false
  143. this.spinning = false
  144. return data
  145. })
  146. },
  147. total: 0, // 总条数
  148. openModal: false, // 弹框
  149. itemSn: '' // 当前sn
  150. }
  151. },
  152. methods: {
  153. // 时间 change
  154. dateChange (date) {
  155. this.queryParam.beginDate = date[0] ? date[0] + ' 00:00:00' : ''
  156. this.queryParam.endDate = date[1] ? date[1] + ' 23:59:59' : ''
  157. },
  158. // 重置
  159. resetSearchForm () {
  160. this.$refs.rangeDate.resetDate()
  161. this.queryParam.beginDate = ''
  162. this.queryParam.endDate = ''
  163. this.queryParam.name = ''
  164. this.queryParam.enabledFlag = undefined
  165. this.$refs.table.refresh(true)
  166. },
  167. // 编辑
  168. handleEdit (row) {
  169. this.itemSn = row.promoActiveSn
  170. this.openModal = true
  171. },
  172. // 基本信息 保存
  173. handleOk (data) {
  174. this.$refs.table.refresh(true)
  175. },
  176. // 关闭弹框
  177. closeModal () {
  178. this.itemSn = ''
  179. this.openModal = false
  180. },
  181. // 详情
  182. handleDetail (row) {
  183. this.$router.push({ path: `/promotionRulesManagement/promotionRules/detail/${row.id}/${row.promoActiveSn}` })
  184. },
  185. // 规则设置
  186. handleRule (row) {
  187. this.$router.push({ path: `/promotionRulesManagement/promotionRules/rule/${row.id}/${row.promoActiveSn}` })
  188. },
  189. // 启用 禁用
  190. changeStatus (record) {
  191. const params = {
  192. sn: record.promoActiveSn,
  193. flag: record.enabledFlag == 1 ? '0' : '1'
  194. }
  195. this.spinning = true
  196. promoActiveEnable(params).then(res => {
  197. if (res.status == 200) {
  198. this.$message.success(res.message)
  199. this.$refs.table.refresh()
  200. this.spinning = false
  201. } else {
  202. this.$refs.table.refresh()
  203. this.spinning = false
  204. }
  205. })
  206. },
  207. setTableH () {
  208. const tableSearchH = this.$refs.tableSearch.offsetHeight
  209. this.tableHeight = window.innerHeight - tableSearchH - 235
  210. }
  211. },
  212. mounted () {
  213. const _this = this
  214. this.$nextTick(() => { // 页面渲染完成后的回调
  215. _this.setTableH()
  216. })
  217. },
  218. activated () {
  219. // 如果是新页签打开,则重置当前页面
  220. if (this.$store.state.app.isNewTab) {
  221. this.resetSearchForm()
  222. }
  223. },
  224. beforeRouteEnter (to, from, next) {
  225. next(vm => {
  226. if (!vm.disabled) {
  227. vm.$refs.table.refresh()
  228. }
  229. })
  230. }
  231. }
  232. </script>