CreditActionDialog.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <el-dialog
  3. :title="isApprove ? 'APPROVE CREDIT' : 'AMEND CREDIT'"
  4. :visible="visible"
  5. custom-class="toptop-dialog"
  6. :before-close="hideDialog"
  7. :close-on-click-modal="false">
  8. <el-form
  9. ref="creditForm"
  10. :model="form"
  11. :rules="rules"
  12. label-width="130px"
  13. label-position="right"
  14. v-loading="loading">
  15. <el-form-item
  16. label="User-Email:"
  17. v-if="isApprove">
  18. <el-input
  19. class="input-text"
  20. :value="form.userEmail"
  21. readonly/>
  22. </el-form-item>
  23. <el-form-item
  24. label="Select User:"
  25. prop="userPk"
  26. v-else>
  27. <el-select
  28. v-model="userInfo.index"
  29. class="input-text"
  30. filterable
  31. remote
  32. clearable
  33. :remote-method="getUserOptions"
  34. placeholder="Search user email"
  35. @change="changeUser">
  36. <el-option
  37. v-for="(item,index) in options.user"
  38. :key="index"
  39. :label="item.email"
  40. :value="index"/>
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item
  44. label="Current Balance:">
  45. <el-input
  46. class="input-text"
  47. :value="userInfo.currentBalance"
  48. readonly/>
  49. </el-form-item>
  50. <el-form-item
  51. label="Credit Action:"
  52. v-if="isApprove">
  53. <el-input
  54. class="input-text"
  55. v-model="form.creditActionType"
  56. readonly/>
  57. </el-form-item>
  58. <el-form-item
  59. label="Credit Action:"
  60. prop="creditActionType"
  61. v-else>
  62. <el-select
  63. v-model="form.creditActionType"
  64. class="input-text"
  65. clearable>
  66. <el-option
  67. v-for="(item,index) in options.action"
  68. :key="index"
  69. :label="item"
  70. :value="item"/>
  71. </el-select>
  72. </el-form-item>
  73. <el-form-item
  74. label="Amount:"
  75. v-if="isApprove">
  76. <el-input
  77. class="input-text"
  78. v-model="form.creditActionAmount"
  79. readonly/>
  80. </el-form-item>
  81. <el-form-item
  82. label="Amount:"
  83. prop="creditActionAmount"
  84. v-else>
  85. <el-input
  86. class="input-text"
  87. v-model="form.creditActionAmount"
  88. maxlength="6"/>
  89. </el-form-item>
  90. <el-form-item
  91. label="Remarks:"
  92. prop="creditActionRemarks">
  93. <el-input
  94. class="input-text"
  95. v-model="form.creditActionRemarks"
  96. type="textarea"
  97. maxlength="300"
  98. :readonly="isApprove"
  99. :autosize="autoSize"/>
  100. </el-form-item>
  101. <el-form-item
  102. label="Status:"
  103. v-if="isApprove">
  104. <el-input
  105. class="input-text"
  106. v-model="form.creditActionStatus"
  107. readonly/>
  108. </el-form-item>
  109. <el-form-item
  110. label="Requester:"
  111. v-if="isApprove">
  112. <el-input
  113. class="input-text"
  114. v-model="form.requester"
  115. readonly/>
  116. </el-form-item>
  117. <div
  118. class="flexcc"
  119. style="padding-top: 20px;"
  120. v-if="isApprove"
  121. v-show="form.creditActionStatus == 'Pending Approval'">
  122. <el-button
  123. class="cancel-button button-reject"
  124. @click="onApprove('Rejected')"
  125. :disabled="loadingBtn">
  126. REJECT
  127. </el-button>
  128. <el-button
  129. type="accent"
  130. @click="onApprove('Approved')"
  131. :disabled="loadingBtn">
  132. APPROVE
  133. </el-button>
  134. </div>
  135. <div
  136. class="flexcc"
  137. style="padding-top: 20px;"
  138. v-else>
  139. <el-button
  140. class="cancel-button"
  141. @click="hideDialog">
  142. CANCEL
  143. </el-button>
  144. <el-button
  145. type="primary"
  146. @click="onSubmit"
  147. :loading="loadingBtn">
  148. SUBMIT
  149. </el-button>
  150. </div>
  151. </el-form>
  152. </el-dialog>
  153. </template>
  154. <script>
  155. import financial from '@/http/api/financial';
  156. export default {
  157. name: "CreditActionDialog",
  158. props: {
  159. visible: {
  160. type: Boolean,
  161. default: false
  162. },
  163. request: {
  164. type: String,
  165. default: ""
  166. }
  167. },
  168. data() {
  169. return {
  170. loading: false,
  171. loadingBtn: false,
  172. isApprove: false,
  173. form: {
  174. userPk: "",
  175. creditActionId: "",
  176. creditActionType: "",
  177. creditActionAmount: "",
  178. creditActionRemarks: ""
  179. },
  180. rules: {
  181. userPk: {
  182. required: true,
  183. trigger: 'change',
  184. message: 'Please select user'
  185. },
  186. creditActionAmount: [{
  187. required: true,
  188. trigger: 'blur',
  189. message: 'Please type amount',
  190. }, {
  191. pattern: /^[1-9]+\d*\.?\d*$/,
  192. trigger: 'blur',
  193. message: 'Please type a correct number'
  194. }],
  195. creditActionType: {
  196. required: true,
  197. trigger: 'change',
  198. message: 'Please select credit action'
  199. },
  200. creditActionRemarks: {
  201. required: true,
  202. trigger: 'blur',
  203. message: 'Please type remarks'
  204. }
  205. },
  206. options: {
  207. user: [],
  208. action: []
  209. },
  210. approve: {
  211. creditActionId: "",
  212. creditActionStatus: ""
  213. },
  214. userInfo: {
  215. index: "",
  216. currentBalance: ""
  217. },
  218. autoSize: {
  219. minRows: 3,
  220. maxRows: 8
  221. }
  222. };
  223. },
  224. watch: {
  225. visible: {
  226. handler(n, o) {
  227. if (n) {
  228. this.userInfo = {};
  229. if (this.request) {
  230. this.isApprove = true;
  231. this.approve.creditActionId = this.request;
  232. this.getActionInfo();
  233. } else {
  234. this.isApprove = false;
  235. this.form = {
  236. userPk: "",
  237. creditActionId: "",
  238. creditActionType: "",
  239. creditActionAmount: "",
  240. creditActionRemarks: ""
  241. }
  242. }
  243. this.$nextTick(() => {
  244. this.$refs.creditForm.clearValidate();
  245. })
  246. }
  247. }
  248. }
  249. },
  250. mounted() {
  251. this.getUserOptions();
  252. this.getActionOptions();
  253. },
  254. methods: {
  255. hideDialog(e, h) {
  256. this.$emit("hide", h);
  257. },
  258. getUserOptions(word) {
  259. financial.getUserOptions({
  260. email: word
  261. }).then(res => {
  262. if (res.data) {
  263. this.options.user = res.data
  264. } else {
  265. this.options.user = []
  266. }
  267. }).catch(() => {
  268. this.$message({
  269. message: err,
  270. type: 'error',
  271. duration: 3000,
  272. })
  273. this.options.user = []
  274. })
  275. },
  276. getActionOptions() {
  277. financial.getCreditTypeOptions().then(res => {
  278. if (res.data) {
  279. this.options.action = res.data
  280. } else {
  281. this.options.action = []
  282. }
  283. }).catch(err => {
  284. this.$message({
  285. message: error,
  286. type: 'error'
  287. })
  288. this.options.action = []
  289. })
  290. },
  291. getActionInfo() {
  292. this.loading = true;
  293. financial.viewCreditApply(this.approve.creditActionId).then(res => {
  294. if (res.data) {
  295. this.form = res.data;
  296. this.userInfo.currentBalance = res.data.currentBalance;
  297. }
  298. this.loading = false;
  299. }).catch(err => {
  300. this.$message({
  301. message: error,
  302. type: 'error'
  303. })
  304. this.loading = false;
  305. })
  306. },
  307. changeUser(index) {
  308. const user = this.options.user[index];
  309. this.form.userPk = user.userPk;
  310. this.userInfo.currentBalance = user.currentBalance;
  311. },
  312. onSubmit() {
  313. this.$refs.creditForm.validate((valid) => {
  314. if (valid) {
  315. this.createAction();
  316. }
  317. })
  318. },
  319. onApprove(status) {
  320. this.$confirm("Confirm operation?", status, {
  321. confirmButtonText: 'Confirm',
  322. cancelButtonText: 'Cancel',
  323. type: 'warning'
  324. }).then(res => {
  325. this.approve.creditActionStatus = status;
  326. this.$nextTick(() => {
  327. this.approveAction();
  328. })
  329. })
  330. },
  331. createAction() {
  332. this.loadingBtn = true;
  333. financial.createCreditApply(this.form).then(res => {
  334. this.loadingBtn = false;
  335. this.$message({
  336. message: res.msg,
  337. type: 'success',
  338. })
  339. this.hideDialog(true, true);
  340. }).catch(err => {
  341. this.loadingBtn = false;
  342. this.$message({
  343. message: err,
  344. type: 'error',
  345. })
  346. })
  347. },
  348. approveAction() {
  349. this.loadingBtn = true;
  350. financial.approveCreditApply(this.approve).then(res => {
  351. this.loadingBtn = false;
  352. this.$message({
  353. message: res.msg,
  354. type: 'success',
  355. })
  356. this.hideDialog(true, true);
  357. }).catch(err => {
  358. this.loadingBtn = false;
  359. this.$message({
  360. message: err,
  361. type: 'error',
  362. })
  363. })
  364. }
  365. }
  366. }
  367. </script>
  368. <style scoped>
  369. >>> .toptop-dialog {
  370. width: 100%;
  371. padding: 0 10px;
  372. max-width: 520px;
  373. }
  374. .input-text {
  375. width: 100%;
  376. max-width: 350px;
  377. }
  378. .input-text >>> .el-textarea__inner {
  379. font-family: sans-serif;
  380. }
  381. .cancel-button.button-reject {
  382. border-color: #ED3F3F;
  383. }
  384. .cancel-button.button-reject >>> span {
  385. color: #ED3F3F;
  386. }
  387. </style>