addSubsidyModal.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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">
  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="99999999"
  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="99999999"
  50. :precision="2"
  51. placeholder="请输入"/>元
  52. </div>
  53. <div>
  54. 大于等于<a-input-number
  55. v-model="form.ruleTarget2"
  56. :min="form.ruleTarget1*1+1"
  57. style="width:80px;margin:0 6px;"
  58. :max="99999999"
  59. id="addSubsidyModal-ruleTarget2"
  60. :precision="0"
  61. placeholder="请输入"/>条,每条补贴
  62. <a-input-number
  63. v-model="form.ruleValue2"
  64. :min="form.ruleValue1*1+0.01"
  65. id="addSubsidyModal-ruleValue2"
  66. style="width:80px;margin:0 6px;"
  67. :max="99999999"
  68. :precision="2"
  69. placeholder="请输入"/>元
  70. </div>
  71. <div>
  72. 大于等于<a-input-number
  73. v-model="form.ruleTarget3"
  74. :min="form.ruleTarget2*1+1"
  75. style="width:80px;margin:0 6px;"
  76. :max="99999999"
  77. id="addSubsidyModal-ruleTarget3"
  78. :precision="0"
  79. placeholder="请输入"/>条,每条补贴
  80. <a-input-number
  81. v-model="form.ruleValue3"
  82. :min="form.ruleValue2*1+0.01"
  83. id="addSubsidyModal-ruleValue3"
  84. style="width:80px;margin:0 6px;"
  85. :max="99999999"
  86. :precision="2"
  87. placeholder="请输入"/>元
  88. </div>
  89. </a-form-model-item>
  90. </a-form-model>
  91. <div class="btn-cont">
  92. <a-button id="addSubsidyModal-cancel" @click="isShow = false" style="margin-right: 15px;">取消</a-button>
  93. <a-button type="primary" id="addSubsidyModal-save" @click="handleSave">保存</a-button>
  94. </div>
  95. </a-spin>
  96. </div>
  97. </a-modal>
  98. </template>
  99. <script>
  100. // 组件
  101. import { VSelect } from '@/components'
  102. import dealerSubareaScopeList from '@/views/common/dealerSubareaScopeList.vue'
  103. // 接口
  104. import { subsidyRuleSave, createSubsidyRule } from '@/api/subsidyRule'
  105. export default {
  106. name: 'AddSubsidyModal',
  107. components: { VSelect, dealerSubareaScopeList },
  108. props: {
  109. openModal: { // 弹框显示状态
  110. type: Boolean,
  111. default: false
  112. },
  113. pageType: { // 页面类型
  114. type: String,
  115. default: ''
  116. }
  117. },
  118. data () {
  119. return {
  120. isShow: this.openModal, // 是否打开弹框
  121. spinning: false,
  122. formItemLayout: {
  123. labelCol: { span: 5 },
  124. wrapperCol: { span: 17 }
  125. },
  126. // 提交数据
  127. form: {
  128. defaultFlag: 0, // 0指定客户 1默认
  129. dealerSn: undefined, // 客户名称
  130. ruleTarget1: undefined, // 增量补贴
  131. ruleValue1: undefined,
  132. ruleTarget2: undefined,
  133. ruleValue2: undefined,
  134. ruleTarget3: undefined,
  135. ruleValue3: undefined
  136. },
  137. // 必填项判断
  138. rules: {
  139. dealerSn: [{ required: true, message: '请选择客户名称', trigger: 'change' }],
  140. ruleTarget1: [{ required: true, message: '增量补贴不能为空', trigger: 'blur' }]
  141. }
  142. }
  143. },
  144. methods: {
  145. // 客户名称 change
  146. custChange (val) {
  147. if (val && val.key) {
  148. this.form.dealerSn = val.key
  149. } else {
  150. this.form.dealerSn = undefined
  151. }
  152. },
  153. // 保存
  154. handleSave () {
  155. const _this = this
  156. this.$refs.ruleForm.validate(valid => {
  157. if (valid) {
  158. // 为空判断
  159. const newForm = JSON.parse(JSON.stringify(_this.form))
  160. delete newForm.defaultFlag
  161. delete newForm.dealerSn
  162. const flagArr = []
  163. for (const i in newForm) { flagArr.push(newForm[i]) }
  164. if (flagArr && flagArr.length < 6) {
  165. _this.$message.error('增量补贴不能为空!')
  166. return
  167. }
  168. _this.form.ruleType = _this.pageType
  169. _this.spinning = true
  170. subsidyRuleSave(this.form).then(res => {
  171. if (res.status == 200) {
  172. if (!res.data) {
  173. this.isShow = false
  174. this.$message.success(res.message)
  175. this.$emit('ok')
  176. } else {
  177. _this.openTip(res.data)
  178. }
  179. }
  180. _this.spinning = false
  181. })
  182. } else {
  183. console.log('error submit!!')
  184. return false
  185. }
  186. })
  187. },
  188. openTip (code) {
  189. const _this = this
  190. if (code === 'IN_USE') {
  191. this.$confirm({
  192. title: '提示',
  193. content: '将重新生成新的运费补贴,并结束当前运费补贴。',
  194. centered: true,
  195. onOk () {
  196. createSubsidyRule(_this.form).then(res => {
  197. if (res.status == 200) {
  198. _this.isShow = false
  199. _this.$message.success(res.message)
  200. _this.$emit('ok')
  201. }
  202. })
  203. }
  204. })
  205. } else {
  206. this.$confirm({
  207. title: '提示',
  208. content: '已存在【未开始】的运费补贴',
  209. centered: true,
  210. okText: '知道了',
  211. cancelButtonProps: {
  212. style: {
  213. display: 'none' // 通过设置样式隐藏取消按钮
  214. }
  215. },
  216. onOk () {
  217. console.log('知道了')
  218. }
  219. })
  220. }
  221. },
  222. // 重置
  223. resetFormData () {
  224. this.form.defaultFlag = 0
  225. this.form.dealerSn = undefined
  226. this.form.ruleTarget1 = undefined
  227. this.form.ruleValue1 = undefined
  228. this.form.ruleTarget2 = undefined
  229. this.form.ruleValue2 = undefined
  230. this.form.ruleTarget3 = undefined
  231. this.form.ruleValue3 = undefined
  232. this.$refs.dealerSubareaScopeList.resetForm()
  233. this.$refs.ruleForm.resetFields()
  234. }
  235. },
  236. watch: {
  237. // 父页面传过来的弹框状态
  238. openModal (newValue, oldValue) {
  239. this.isShow = newValue
  240. },
  241. // 重定义的弹框状态
  242. isShow (newValue, oldValue) {
  243. if (!newValue) {
  244. this.$emit('close')
  245. this.resetFormData()
  246. }
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="less">
  252. .addSubsidy-modal{
  253. .formList{
  254. margin-left:60px;
  255. }
  256. .ant-modal-body {
  257. padding: 40px 40px 24px;
  258. }
  259. .btn-cont {
  260. text-align: center;
  261. margin: 35px 0 30px;
  262. }
  263. }
  264. </style>