addSubsidyModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. <dealerSubareaScopeList style="width:90%;" ref="dealerSubareaScopeList" id="addSubsidyModal-dealerName" @change="custChange" />
  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.ruleTarget1 }}条,每条补贴{{ item.ruleValue2 }}元;</p>
  96. <p v-if="item.ruleTarget3">大于等于{{ item.ruleTarget1 }}条,每条补贴{{ 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 dealerSubareaScopeList from '@/views/common/dealerSubareaScopeList.vue'
  113. // 接口
  114. import { subsidyRuleSave, createSubsidyRule, getSubsidyRuleList } from '@/api/subsidyRule'
  115. export default {
  116. name: 'AddSubsidyModal',
  117. components: { VSelect, dealerSubareaScopeList },
  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. const flag = _this.isValid(newForm)
  197. if (!flag) {
  198. _this.$message.error('季度增量补贴【条数】与【补贴】不符合填写规则!')
  199. return
  200. }
  201. _this.form.ruleType = _this.pageType
  202. _this.spinning = true
  203. subsidyRuleSave(_this.form).then(res => {
  204. if (res.status == 200) {
  205. if (!res.data) {
  206. _this.isShow = false
  207. _this.$message.success(res.message)
  208. _this.$emit('ok')
  209. } else {
  210. _this.openTip(res.data)
  211. }
  212. }
  213. _this.spinning = false
  214. })
  215. } else {
  216. console.log('error submit!!')
  217. return false
  218. }
  219. })
  220. },
  221. // 为空判断
  222. isValid (obj) {
  223. const { ruleTarget1, ruleValue1, ruleTarget2, ruleValue2, ruleTarget3, ruleValue3 } = obj
  224. // 检查第一阶梯是否填写
  225. if (ruleTarget1 === undefined || ruleValue1 === undefined || typeof ruleValue1 !== 'number') {
  226. return false
  227. }
  228. // 如果第三阶梯存在,检查第二阶梯是否存在以及值是否正确
  229. if (ruleTarget3 !== undefined || ruleValue3 !== undefined) {
  230. if (ruleTarget2 === undefined || ruleValue2 === undefined || typeof ruleValue2 !== 'number') {
  231. return false
  232. }
  233. if (ruleValue1 >= ruleValue2 || (ruleValue3 !== undefined && ruleValue2 >= ruleValue3) || ruleTarget1 >= ruleTarget2 || (ruleTarget3 !== undefined && ruleTarget2 >= ruleTarget3)) {
  234. return false
  235. }
  236. }
  237. // 如果只有第二阶梯存在(没有第三阶梯),检查值是否正确
  238. if (ruleTarget2 !== undefined && ruleValue2 !== undefined && (ruleTarget3 === undefined && ruleValue3 === undefined)) {
  239. if (ruleValue1 >= ruleValue2 || ruleTarget1 >= ruleTarget2) {
  240. return false
  241. }
  242. }
  243. // 所有条件都满足,返回true
  244. return true
  245. },
  246. openTip (code) {
  247. const _this = this
  248. if (code === 'WAIT') {
  249. this.$confirm({
  250. title: '提示',
  251. content: '将重新生成新的' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季' : '年') + '度补贴,并结束当前' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季' : '年') + '度增量补贴。',
  252. centered: true,
  253. onOk () {
  254. createSubsidyRule(_this.form).then(res => {
  255. if (res.status == 200) {
  256. _this.isShow = false
  257. _this.$message.success(res.message)
  258. _this.$emit('ok')
  259. }
  260. })
  261. }
  262. })
  263. } else {
  264. this.$info({
  265. title: '提示',
  266. content: '已存在【启用中】的' + (_this.pageType === 'SUBSIDY_QUARTER_FEE' ? '季' : '年') + '度增量补贴',
  267. centered: true,
  268. onOk () {
  269. console.log('知道了')
  270. }
  271. })
  272. }
  273. },
  274. // 重置
  275. resetFormData () {
  276. this.form.defaultFlag = 0
  277. this.form.dealerSn = undefined
  278. this.form.ruleTarget1 = undefined
  279. this.form.ruleValue1 = undefined
  280. this.form.ruleTarget2 = undefined
  281. this.form.ruleValue2 = undefined
  282. this.form.ruleTarget3 = undefined
  283. this.form.ruleValue3 = undefined
  284. if (this.form.defaultFlag == 0) {
  285. this.$refs.dealerSubareaScopeList.resetForm()
  286. }
  287. this.feeDataList = null
  288. this.$refs.ruleForm.resetFields()
  289. }
  290. },
  291. watch: {
  292. // 父页面传过来的弹框状态
  293. openModal (newValue, oldValue) {
  294. this.isShow = newValue
  295. },
  296. // 重定义的弹框状态
  297. isShow (newValue, oldValue) {
  298. if (!newValue) {
  299. this.$emit('close')
  300. this.resetFormData()
  301. }
  302. }
  303. }
  304. }
  305. </script>
  306. <style lang="less">
  307. .addSubsidy-modal{
  308. .formList{
  309. margin-left:60px;
  310. }
  311. .formBoxList{
  312. div{
  313. margin-bottom:5px;
  314. }
  315. }
  316. .ant-modal-body {
  317. padding: 40px 40px 24px;
  318. }
  319. .btn-cont {
  320. text-align: center;
  321. margin: 35px 0 30px;
  322. }
  323. }
  324. </style>