addSubsidyList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false" class="addSubsidyList-wrap searchBoxNormal">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper" ref="tableSearch">
  6. <a-form-model
  7. id="addSubsidyList-form"
  8. ref="ruleForm"
  9. class="form-model-con"
  10. layout="inline"
  11. :model="queryParam">
  12. <a-row :gutter="15">
  13. <a-col :md="5" :sm="24">
  14. <a-form-model-item label="客户名称">
  15. <dealerSubareaScopeList ref="dealerSubareaScopeList" id="addSubsidyList-dealerName" @change="custChange" />
  16. </a-form-model-item>
  17. </a-col>
  18. <a-col :md="5" :sm="24">
  19. <a-form-item label="区域">
  20. <subarea id="addSubsidyList-subarea" ref="subarea" @change="subareaChange"></subarea>
  21. </a-form-item>
  22. </a-col>
  23. <a-col :md="5" :sm="24">
  24. <a-form-model-item label="地区">
  25. <AreaList id="addSubsidyList-areaList" changeOnSelect ref="areaList" @change="areaChange" defValKey="id"></AreaList>
  26. </a-form-model-item>
  27. </a-col>
  28. <a-col :md="5" :sm="24">
  29. <a-form-model-item label="状态">
  30. <v-select
  31. v-model="queryParam.subsidyQueryStatus"
  32. id="addSubsidyList-subsidyQueryStatus"
  33. code="INCREMENT_SUBSIDY_QUERY_STATUS"
  34. placeholder="请选择状态"
  35. allowClear></v-select>
  36. </a-form-model-item>
  37. </a-col>
  38. <a-col :md="4" :sm="24">
  39. <a-button
  40. type="primary"
  41. @click="$refs.table.refresh(true)"
  42. :disabled="disabled"
  43. id="addSubsidyList-refresh">查询</a-button>
  44. <a-button
  45. style="margin-left: 8px"
  46. @click="resetSearchForm"
  47. :disabled="disabled"
  48. id="addSubsidyList-reset">重置</a-button>
  49. </a-col>
  50. </a-row>
  51. </a-form-model>
  52. </div>
  53. </a-card>
  54. <a-card size="small" :bordered="false">
  55. <a-spin :spinning="spinning" tip="Loading...">
  56. <!-- 操作按钮 -->
  57. <div class="table-operator">
  58. <a-button id="addSubsidyList-add" type="primary" @click="handleAdd">新增</a-button>
  59. </div>
  60. <!-- 列表 -->
  61. <s-table
  62. class="sTable fixPagination"
  63. ref="table"
  64. size="small"
  65. :rowKey="(record) => record.id"
  66. :style="{ height: tableHeight+70+'px' }"
  67. :columns="columns"
  68. :data="loadData"
  69. :scroll="{ y: tableHeight}"
  70. :defaultLoadData="false"
  71. bordered>
  72. <!-- 客户名称 -->
  73. <template slot="customName" slot-scope="text, record">
  74. {{ record.dealerEntity&&record.dealerEntity.dealerName?record.dealerEntity.dealerName:record.defaultFlag==1?'默认':'--' }}
  75. </template>
  76. <!-- 结束时间 -->
  77. <template slot="endDate" slot-scope="text, record">
  78. {{ record.status==='END'? record.ruleEndDate:'--' }}
  79. </template>
  80. <!-- 操作 -->
  81. <template slot="action" slot-scope="text, record">
  82. <a-button
  83. size="small"
  84. type="link"
  85. class="button-info"
  86. @click="handleEdit(record)"
  87. v-if="record.status=='IN_USE' && record.isSomeTimeFlag"
  88. :id="'addSubsidyList-edit-btn'+record.id"
  89. >
  90. 编辑
  91. </a-button>
  92. <a-button
  93. size="small"
  94. type="link"
  95. class="button-error"
  96. :id="'costCollectionList-end-btn'+record.id"
  97. v-if="record.status=='IN_USE'&&record.defaultFlag==0&&!record.isSomeTimeFlag"
  98. @click="handleEndOrDel(record,'end')"
  99. >
  100. 结束
  101. </a-button>
  102. <a-button
  103. size="small"
  104. type="link"
  105. class="button-error"
  106. @click="handleEndOrDel(record)"
  107. v-if="record.status=='IN_USE'&&record.defaultFlag==0&&record.isSomeTimeFlag"
  108. :id="'addSubsidyList-del-btn'+record.id"
  109. >
  110. 删除
  111. </a-button>
  112. <span v-if="record.status=='END'">--</span>
  113. </template>
  114. </s-table>
  115. </a-spin>
  116. </a-card>
  117. <!-- 新增 -->
  118. <add-subsidy-modal v-drag :openModal="openAddSubsidyModal" :pageType="pageType" @ok="$refs.table.refresh(true)" @close="openAddSubsidyModal = false" />
  119. <!-- 编辑 -->
  120. <edit-modal
  121. v-drag
  122. :openModal="openEditSubsidyModal"
  123. ref="editSubsidyModal"
  124. :pageType="pageType"
  125. @ok="$refs.table.refresh(true)"
  126. @close="openEditSubsidyModal = false" ></edit-modal>
  127. </div>
  128. </template>
  129. <script>
  130. import { commonMixin } from '@/utils/mixin'
  131. // 组件
  132. import { STable, VSelect } from '@/components'
  133. import subarea from '@/views/common/subarea.js'
  134. import AreaList from '@/views/common/areaList.js'
  135. import addSubsidyModal from './addSubsidyModal.vue'
  136. import editModal from './editModal.vue'
  137. import dealerSubareaScopeList from '@/views/common/dealerSubareaScopeList.vue'
  138. // 接口
  139. import { tireSubsidyRuleList, endSubsidyRule, delSubsidyRule } from '@/api/subsidyRule'
  140. export default {
  141. name: 'AddSubsidyList',
  142. mixins: [commonMixin],
  143. components: { STable, VSelect, subarea, AreaList, dealerSubareaScopeList, addSubsidyModal, editModal },
  144. props: {
  145. pageType: { // 弹框显示状态
  146. type: String,
  147. default: ''
  148. }
  149. },
  150. data () {
  151. return {
  152. spinning: false,
  153. disabled: false, // 查询、重置按钮是否可操作
  154. tableHeight: 0, // 表格高度
  155. // 查询条件
  156. queryParam: {
  157. subareaArea: {
  158. subareaSn: '', // 区域
  159. subareaAreaSn: '' // 分区
  160. },
  161. dealerSn: undefined, // 客户sn
  162. dealerName: undefined, // 客户名称
  163. provinceSn: undefined, // 省
  164. citySn: undefined, // 市
  165. districtSn: undefined, // 区
  166. ruleType: undefined, // 页面类型
  167. subsidyQueryStatus: 'NOT_FINISH'// 状态
  168. },
  169. openAddSubsidyModal: false, // 新增弹窗
  170. openEditSubsidyModal: false, // 编辑弹窗
  171. // 加载数据方法 必须为 Promise 对象
  172. loadData: parameter => {
  173. this.disabled = true
  174. this.spinning = true
  175. this.queryParam.ruleType = this.pageType
  176. const params = Object.assign(parameter, this.queryParam)
  177. // 获取列表数据 有分页
  178. return tireSubsidyRuleList(params).then(res => {
  179. let data
  180. if (res.status == 200) {
  181. data = res.data
  182. // 计算表格序号
  183. const no = (data.pageNo - 1) * data.pageSize
  184. for (var i = 0; i < data.list.length; i++) {
  185. data.list[i].no = no + i + 1
  186. if (data.list[i].ruleStartDate) {
  187. data.list[i].ruleStartDate = this.pageType === 'SUBSIDY_QUARTER_FEE' ? this.getYearAndQuarter(data.list[i].ruleStartDate).showWords : this.getYear(data.list[i].ruleStartDate)
  188. }
  189. if (data.list[i].ruleEndDate) {
  190. data.list[i].ruleEndDate = this.pageType === 'SUBSIDY_QUARTER_FEE' ? this.getYearAndQuarter(data.list[i].ruleEndDate).showWords : this.getYear(data.list[i].ruleEndDate)
  191. }
  192. if (data.list[i].ruleStartDate) {
  193. data.list[i].isSomeTimeFlag = this.pageType === 'SUBSIDY_QUARTER_FEE' ? this.isSameQuarter(data.list[i].ruleStartDate) : this.isSameYear(data.list[i].ruleStartDate)
  194. }
  195. }
  196. }
  197. this.disabled = false
  198. this.spinning = false
  199. return data
  200. })
  201. }
  202. }
  203. },
  204. watch: {
  205. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  206. this.setTableH()
  207. }
  208. },
  209. computed: {
  210. columns () {
  211. const _this = this
  212. const arr = [
  213. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  214. { title: '创建时间', dataIndex: 'createDate', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  215. { title: '区域', dataIndex: 'subareaArea.subareaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  216. { title: '分区', dataIndex: 'subareaArea.subareaAreaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  217. { title: '客户名称', dataIndex: 'dealerEntity.dealerName', width: '14%', align: 'center', scopedSlots: { customRender: 'customName' }, ellipsis: true },
  218. { title: '开始' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季度' : '年份'), dataIndex: 'ruleStartDate', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  219. { title: '结束' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季度' : '年份'), dataIndex: 'ruleEndDate', width: '14%', align: 'center', scopedSlots: { customRender: 'endDate' } },
  220. { title: '增量补贴(' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季度)' : '年度)'),
  221. children: [
  222. { title: '1阶目标(条)', dataIndex: 'ruleTarget1', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  223. { title: '1阶补贴(元)', dataIndex: 'ruleValue1', width: '13%', align: 'right', customRender: text => { return (text || text == 0) ? _this.toThousands(text) : '--' } },
  224. { title: '2阶目标(条)', dataIndex: 'ruleTarget2', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  225. { title: '2阶补贴(元)', dataIndex: 'ruleValue2', width: '13%', align: 'right', customRender: text => { return (text || text == 0) ? _this.toThousands(text) : '--' } },
  226. { title: '3阶目标(条)', dataIndex: 'ruleTarget3', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  227. { title: '3阶补贴(元)', dataIndex: 'ruleValue3', width: '13%', align: 'right', customRender: text => { return (text || text == 0) ? _this.toThousands(text) : '--' } }
  228. ] },
  229. { title: '状态', dataIndex: 'statusDictValue', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  230. { title: '操作', scopedSlots: { customRender: 'action' }, width: '11%', align: 'center' }
  231. ]
  232. return arr
  233. }
  234. },
  235. methods: {
  236. // 计算是第几季度
  237. getYearAndQuarter (dateString) {
  238. // 解析日期字符串
  239. const date = new Date(dateString)
  240. // 获取年份
  241. const year = date.getFullYear()
  242. // 获取月份
  243. const month = date.getMonth() + 1 // getMonth() 返回的是0-11,所以要加1
  244. // 确定季度
  245. let quarter
  246. if (month >= 1 && month <= 3) {
  247. quarter = 1
  248. } else if (month >= 4 && month <= 6) {
  249. quarter = 2
  250. } else if (month >= 7 && month <= 9) {
  251. quarter = 3
  252. } else {
  253. quarter = 4
  254. }
  255. return { showWords: year + '年' + quarter + '季度', quarter }
  256. },
  257. // 获取年份
  258. getYear (dateString) {
  259. const year = new Date(dateString).getFullYear()
  260. return year
  261. },
  262. // 当前时间与创建时间是否属于同一年
  263. isSameYear (fixedDate) {
  264. // 获取当前时间
  265. const currentDate = new Date()
  266. const currentYear = currentDate.getFullYear()
  267. // 比较年份
  268. return currentYear === fixedDate
  269. },
  270. // 当前时间与创建时间是否属于同一季度
  271. isSameQuarter (inputVal) {
  272. const currentDate = new Date()
  273. const quarterNum = this.getYearAndQuarter(currentDate).quarter
  274. const yearNum = currentDate.getFullYear()
  275. const fullWord = yearNum + '年' + quarterNum + '季度'
  276. return fullWord === inputVal
  277. },
  278. // 新增
  279. handleAdd () {
  280. this.openAddSubsidyModal = true
  281. },
  282. // 客户名称 change
  283. custChange (val) {
  284. this.queryParam.dealerName = val.name
  285. this.queryParam.dealerSn = val.key
  286. },
  287. // 地区
  288. areaChange (val) {
  289. this.queryParam.provinceSn = val[0] ? val[0] : undefined
  290. this.queryParam.citySn = val[1] ? val[1] : undefined
  291. this.queryParam.districtSn = val[2] ? val[2] : undefined
  292. },
  293. // 区域分区 change
  294. subareaChange (val) {
  295. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : ''
  296. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : ''
  297. },
  298. // 重置
  299. resetSearchForm () {
  300. this.queryParam.provinceSn = undefined
  301. this.queryParam.citySn = undefined
  302. this.queryParam.districtSn = undefined
  303. this.queryParam.dealerName = undefined
  304. this.queryParam.dealerSn = undefined
  305. this.queryParam.ruleType = undefined
  306. this.queryParam.subareaArea.subareaSn = ''
  307. this.queryParam.subareaArea.subareaAreaSn = ''
  308. this.queryParam.subsidyQueryStatus = 'NOT_FINISH'
  309. this.$refs.subarea.clearData()
  310. this.$refs.dealerSubareaScopeList.resetForm()
  311. this.$refs.areaList.clearData()
  312. this.$refs.table.refresh(true)
  313. },
  314. // 编辑
  315. handleEdit (row) {
  316. const sendData = {
  317. dealerName: row.dealerEntity && row.dealerEntity.dealerName ? row.dealerEntity.dealerName : undefined,
  318. defaultFlag: row.defaultFlag,
  319. ruleSn: row.ruleSn,
  320. ruleTarget1: row.ruleTarget1 || undefined,
  321. ruleValue1: row.ruleValue1 || undefined,
  322. ruleTarget2: row.ruleTarget2 || undefined,
  323. ruleValue2: row.ruleValue2 || undefined,
  324. ruleTarget3: row.ruleTarget3 || undefined,
  325. ruleValue3: row.ruleValue3 || undefined
  326. }
  327. this.$refs.editSubsidyModal.getFormData(sendData)
  328. this.openEditSubsidyModal = true
  329. },
  330. // 结束 删除
  331. handleEndOrDel (row, type) {
  332. const ajaxName = type === 'end' ? endSubsidyRule : delSubsidyRule
  333. let tipWord = null
  334. if (this.pageType === 'SUBSIDY_QUARTER_FEE') {
  335. tipWord = '确定' + (type === 'end' ? '结束' : '删除') + '季度补贴吗?' + (type === 'end' ? '结束' : '删除') + '后以默认季度补贴计算'
  336. } else {
  337. tipWord = '确定' + (type === 'end' ? '结束' : '删除') + '年度增量补贴吗?' + (type === 'end' ? '结束' : '删除') + '后以默认年度增量补贴计算'
  338. }
  339. const _this = this
  340. _this.$confirm({
  341. title: '提示',
  342. content: tipWord,
  343. centered: true,
  344. onOk () {
  345. ajaxName({ ruleSn: row.ruleSn, ruleType: _this.pageType }).then(res => {
  346. if (res.status == 200) {
  347. if (res.data && res.data === 'FALSE') {
  348. _this.$info({
  349. title: '提示',
  350. content: '当前规则不可操作,请刷新后重试',
  351. centered: true,
  352. onOk () {
  353. console.log('知道了')
  354. }
  355. })
  356. } else {
  357. _this.$message.success(res.message)
  358. _this.$refs.table.refresh(true)
  359. }
  360. }
  361. })
  362. }
  363. })
  364. },
  365. // 初始化
  366. pageInit () {
  367. this.$nextTick(() => { // 页面渲染完成后的回调
  368. this.setTableH()
  369. })
  370. this.resetSearchForm()
  371. },
  372. // 计算表格高度
  373. setTableH () {
  374. const tableSearchH = this.$refs.tableSearch.offsetHeight
  375. this.tableHeight = window.innerHeight - tableSearchH - 300
  376. }
  377. }
  378. }
  379. </script>