addSubsidyModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <a-modal
  3. centered
  4. class="addSubsidy-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="新增"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="700">
  11. <div>
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <a-form-model
  14. id="addSubsidyModal-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol"
  20. >
  21. <div class="formList" style="margin-bottom:15px;">
  22. <a-radio-group id="addSubsidyModal-defaultFlag" v-model="form.defaultFlag" @change="defaultChange">
  23. <a-radio :value="0" id="addSubsidyModal-defaultFlag0">
  24. 指定客户
  25. </a-radio>
  26. <a-radio :value="1" id="addSubsidyModal-defaultFlag1">
  27. 默认
  28. </a-radio>
  29. </a-radio-group>
  30. </div>
  31. <a-form-model-item label="客户名称" prop="dealerSn" v-if="form.defaultFlag==0">
  32. <custList style="width:90%;" dataAuthFlag="0" ref="dealerSubareaScopeList" id="addSubsidyModal-dealerName" @change="custChange"></custList>
  33. </a-form-model-item>
  34. <a-form-model-item label="增量补贴(季度)" prop="ruleTarget1">
  35. <div>
  36. 大于等于<a-input-number
  37. v-model="form.ruleTarget1"
  38. :min="1"
  39. style="width:80px;margin:0 6px;"
  40. :max="999999"
  41. id="addSubsidyModal-ruleTarget1"
  42. :precision="0"
  43. placeholder="请输入"/>条,每条补贴
  44. <a-input-number
  45. v-model="form.ruleValue1"
  46. :min="0.01"
  47. id="addSubsidyModal-ruleValue1"
  48. style="width:80px;margin:0 6px;"
  49. :max="999999"
  50. :precision="2"
  51. placeholder="请输入"/>元
  52. </div>
  53. <div>
  54. 大于等于<a-input-number
  55. v-model="form.ruleTarget2"
  56. :min="form.ruleTarget1"
  57. style="width:80px;margin:0 6px;"
  58. :max="999999"
  59. id="addSubsidyModal-ruleTarget2"
  60. :precision="0"
  61. placeholder="请输入"/>条,每条补贴
  62. <a-input-number
  63. v-model="form.ruleValue2"
  64. :min="form.ruleValue1"
  65. id="addSubsidyModal-ruleValue2"
  66. style="width:80px;margin:0 6px;"
  67. :max="999999"
  68. :precision="2"
  69. placeholder="请输入"/>元
  70. </div>
  71. <div>
  72. 大于等于<a-input-number
  73. v-model="form.ruleTarget3"
  74. :min="form.ruleTarget2"
  75. style="width:80px;margin:0 6px;"
  76. :max="999999"
  77. id="addSubsidyModal-ruleTarget3"
  78. :precision="0"
  79. placeholder="请输入"/>条,每条补贴
  80. <a-input-number
  81. v-model="form.ruleValue3"
  82. :min="form.ruleValue2"
  83. id="addSubsidyModal-ruleValue3"
  84. style="width:80px;margin:0 6px;"
  85. :max="999999"
  86. :precision="2"
  87. placeholder="请输入"/>元
  88. </div>
  89. </a-form-model-item>
  90. <div class="formList formBoxList" v-if="feeDataList&&feeDataList.length>0">
  91. <div v-for="item in feeDataList" :key="item.id" style="display:flex;align-items:baseline;">
  92. <span>{{ item.effectType==1?'当前':'次月' }}增量补贴({{ pageType==='SUBSIDY_QUARTER_FEE'?'季':'年' }}度):</span>
  93. <div>
  94. <p v-if="item.ruleTarget1">大于等于{{ item.ruleTarget1 }}条,每条补贴{{ item.ruleValue1 }}元;</p>
  95. <p v-if="item.ruleTarget2">大于等于{{ item.ruleTarget2 }}条,每条补贴{{ item.ruleValue2 }}元;</p>
  96. <p v-if="item.ruleTarget3">大于等于{{ item.ruleTarget3 }}条,每条补贴{{ item.ruleValue3 }}元;</p>
  97. </div>
  98. </div>
  99. </div>
  100. </a-form-model>
  101. <div class="btn-cont">
  102. <a-button id="addSubsidyModal-cancel" @click="isShow = false" style="margin-right: 15px;">取消</a-button>
  103. <a-button type="primary" id="addSubsidyModal-save" @click="handleSave">保存</a-button>
  104. </div>
  105. </a-spin>
  106. </div>
  107. </a-modal>
  108. </template>
  109. <script>
  110. // 组件
  111. import { VSelect } from '@/components'
  112. import custList from '@/views/common/custList.vue'
  113. // 接口
  114. import { subsidyRuleSave, createSubsidyRule, getSubsidyRuleList } from '@/api/subsidyRule'
  115. export default {
  116. name: 'AddSubsidyModal',
  117. components: { VSelect, custList },
  118. props: {
  119. openModal: { // 弹框显示状态
  120. type: Boolean,
  121. default: false
  122. },
  123. pageType: { // 页面类型
  124. type: String,
  125. default: ''
  126. }
  127. },
  128. data () {
  129. return {
  130. isShow: this.openModal, // 是否打开弹框
  131. spinning: false,
  132. formItemLayout: {
  133. labelCol: { span: 5 },
  134. wrapperCol: { span: 17 }
  135. },
  136. // 提交数据
  137. form: {
  138. defaultFlag: 0, // 0指定客户 1默认
  139. dealerSn: undefined, // 客户名称
  140. ruleTarget1: undefined, // 增量补贴
  141. ruleValue1: undefined,
  142. ruleTarget2: undefined,
  143. ruleValue2: undefined,
  144. ruleTarget3: undefined,
  145. ruleValue3: undefined
  146. },
  147. // 必填项判断
  148. rules: {
  149. dealerSn: [{ required: true, message: '请选择客户名称', trigger: 'change' }],
  150. ruleTarget1: [{ required: true, message: '增量补贴不能为空', trigger: 'blur' }]
  151. },
  152. feeDataList: null
  153. }
  154. },
  155. methods: {
  156. // 客户名称 change
  157. custChange (val) {
  158. if (val && val.key) {
  159. this.form.dealerSn = val.key
  160. this.getHistoryData({ dealerSn: val.key, subsidyQueryStatus: 'NOT_FINISH', ruleType: this.pageType })
  161. } else {
  162. this.feeDataList = null
  163. }
  164. },
  165. // 0指定客户 1默认客户 change
  166. defaultChange (e) {
  167. this.form.defaultFlag = e.target.value
  168. this.form.dealerSn = undefined
  169. if (e.target.value == '1') {
  170. this.getHistoryData({ defaultFlag: 1, subsidyQueryStatus: 'NOT_FINISH', ruleType: this.pageType })
  171. } else {
  172. this.feeDataList = null
  173. }
  174. },
  175. // 获取当月/次月 历史数据值
  176. getHistoryData (ajaxData) {
  177. this.spinning = true
  178. getSubsidyRuleList(ajaxData).then(res => {
  179. if (res.status == 200) {
  180. this.feeDataList = res.data
  181. } else {
  182. this.feeDataList = null
  183. }
  184. this.spinning = false
  185. })
  186. },
  187. // 保存
  188. handleSave () {
  189. const _this = this
  190. this.$refs.ruleForm.validate(valid => {
  191. if (valid) {
  192. // 为空判断
  193. const newForm = JSON.parse(JSON.stringify(_this.form))
  194. delete newForm.defaultFlag
  195. delete newForm.dealerSn
  196. delete newForm.ruleType
  197. const flag = _this.isValid(newForm)
  198. if (!flag) {
  199. _this.$message.error('季度增量补贴【条数】与【补贴】不符合填写规则!')
  200. return
  201. }
  202. _this.form.ruleType = _this.pageType
  203. _this.spinning = true
  204. subsidyRuleSave(_this.form).then(res => {
  205. if (res.status == 200) {
  206. if (!res.data) {
  207. _this.isShow = false
  208. _this.$message.success(res.message)
  209. _this.$emit('ok')
  210. } else {
  211. _this.openTip(res.data)
  212. }
  213. }
  214. _this.spinning = false
  215. })
  216. } else {
  217. console.log('error submit!!')
  218. return false
  219. }
  220. })
  221. },
  222. // 为空判断
  223. isValid (obj) {
  224. const { ruleTarget1, ruleValue1, ruleTarget2, ruleValue2, ruleTarget3, ruleValue3 } = obj
  225. // 检查第一阶梯是否填写
  226. if (!ruleTarget1 || !ruleValue1) {
  227. return false
  228. }
  229. // 如果第三阶梯存在,检查第二阶梯是否存在以及值是否正确
  230. if (ruleTarget3 || ruleValue3) {
  231. if ((!ruleTarget2 || !ruleValue2) || (!ruleTarget3 || !ruleValue3)) {
  232. return false
  233. } else {
  234. if (ruleValue1 >= ruleValue2 || ruleValue2 >= ruleValue3 || ruleTarget1 >= ruleTarget2 || ruleTarget2 >= ruleTarget3) {
  235. return false
  236. }
  237. }
  238. }
  239. // 如果只有第二阶梯存在(没有第三阶梯),检查值是否正确
  240. if ((ruleTarget2 || ruleValue2) && (!ruleTarget3 && !ruleValue3)) {
  241. if (!ruleTarget2 || !ruleValue2) {
  242. return false
  243. } else {
  244. if (ruleValue1 >= ruleValue2 || ruleTarget1 >= ruleTarget2) {
  245. return false
  246. }
  247. }
  248. }
  249. // 所有条件都满足,返回true
  250. return true
  251. },
  252. openTip (code) {
  253. const _this = this
  254. if (code === 'WAIT') {
  255. this.$confirm({
  256. title: '提示',
  257. content: '将重新生成新的' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季' : '年') + '度补贴,并结束当前' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季' : '年') + '度增量补贴。',
  258. centered: true,
  259. onOk () {
  260. createSubsidyRule(_this.form).then(res => {
  261. if (res.status == 200) {
  262. if (res.data && res.data === 'IN_USE') {
  263. const tipWord = '已存在【启用中】的' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季' : '年') + '度增量补贴'
  264. _this.setInfoModal(tipWord)
  265. } else {
  266. _this.isShow = false
  267. _this.$message.success(res.message)
  268. _this.$emit('ok')
  269. }
  270. }
  271. })
  272. }
  273. })
  274. } else {
  275. const tipWord = '已存在【启用中】的' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季' : '年') + '度增量补贴'
  276. this.setInfoModal(tipWord)
  277. }
  278. },
  279. // 提示弹窗
  280. setInfoModal (tip) {
  281. this.$info({
  282. title: '提示',
  283. content: tip,
  284. centered: true,
  285. onOk () {
  286. console.log('知道了')
  287. }
  288. })
  289. },
  290. // 重置
  291. resetFormData () {
  292. if (this.form.defaultFlag == 0) {
  293. this.$refs.dealerSubareaScopeList.resetForm()
  294. }
  295. this.form.defaultFlag = 0
  296. this.form.dealerSn = undefined
  297. this.form.ruleTarget1 = undefined
  298. this.form.ruleValue1 = undefined
  299. this.form.ruleTarget2 = undefined
  300. this.form.ruleValue2 = undefined
  301. this.form.ruleTarget3 = undefined
  302. this.form.ruleValue3 = undefined
  303. this.feeDataList = null
  304. this.$refs.ruleForm.resetFields()
  305. }
  306. },
  307. watch: {
  308. // 父页面传过来的弹框状态
  309. openModal (newValue, oldValue) {
  310. this.isShow = newValue
  311. },
  312. // 重定义的弹框状态
  313. isShow (newValue, oldValue) {
  314. if (!newValue) {
  315. this.$emit('close')
  316. this.resetFormData()
  317. }
  318. }
  319. }
  320. }
  321. </script>
  322. <style lang="less">
  323. .addSubsidy-modal{
  324. .formList{
  325. margin-left:60px;
  326. }
  327. .formBoxList{
  328. div{
  329. margin-bottom:5px;
  330. }
  331. }
  332. .ant-modal-body {
  333. padding: 40px 40px 24px;
  334. }
  335. .btn-cont {
  336. text-align: center;
  337. margin: 35px 0 30px;
  338. }
  339. }
  340. </style>