detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <div class="container" v-loading="loading.page">
  3. <el-form
  4. ref="limitForm"
  5. :model="form"
  6. :rules="rules"
  7. label-width="165px"
  8. label-position="right">
  9. <div class="content">
  10. <div class="section-title">CREDIT LIMIT CONTRACT</div>
  11. <div class="flexr">
  12. <div class="form-left">
  13. <el-form-item
  14. label="Group:"
  15. prop="groupPk">
  16. <el-select
  17. class="add-text"
  18. v-model="form.groupPk"
  19. placeholder="Select with search">
  20. <el-option
  21. v-for="(item, index) in options.group"
  22. :key="index"
  23. :label="item.groupName"
  24. :value="item.groupPk"/>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item
  28. label="Service Provider:"
  29. prop="providerPk">
  30. <el-select
  31. class="add-text"
  32. v-model="form.providerPk"
  33. placeholder="Select">
  34. <el-option
  35. v-for="(item, index) in options.provider"
  36. :key="index"
  37. :label="item.key"
  38. :value="item.value"/>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item
  42. label="Effective Period:"
  43. prop="effectivePeriod">
  44. <el-date-picker
  45. class="add-text"
  46. v-model="form.effectivePeriod"
  47. type="daterange"
  48. format="dd/MM/yyyy"
  49. value-format="dd/MM/yyyy"
  50. placeholder="Select date"/>
  51. </el-form-item>
  52. <el-form-item
  53. label="Monthly Credit Limit:"
  54. prop="creditLimitAmount">
  55. <span class="item-unit">(S$)</span>
  56. <el-input
  57. class="add-text"
  58. v-model="form.creditLimitAmount"
  59. placeholder=""
  60. maxlength="10"/>
  61. </el-form-item>
  62. </div>
  63. <div class="form-right" v-if="isEdit">
  64. <el-form-item
  65. label="Status:"
  66. prop="dataStatus">
  67. <el-select
  68. class="add-text"
  69. v-model="form.dataStatus"
  70. placeholder="Select"
  71. disabled>
  72. <el-option
  73. v-for="(item, index) in options.status"
  74. :key="index"
  75. :label="item.key"
  76. :value="item.value"/>
  77. </el-select>
  78. </el-form-item>
  79. <el-form-item
  80. label="Approved Users:">
  81. <el-input
  82. class="add-text"
  83. v-model="form.approvedUsers"
  84. readonly/>
  85. </el-form-item>
  86. <el-form-item
  87. label="Overall Balance:">
  88. <el-input
  89. class="add-text"
  90. :value="form.individualCredit + '/' + form.groupCredit"
  91. readonly/>
  92. </el-form-item>
  93. </div>
  94. </div>
  95. </div>
  96. <div class="content" v-if="isEdit">
  97. <div class="section-title">Group Credit</div>
  98. <el-table
  99. :data="[form]">
  100. <el-table-column
  101. align="center"
  102. label="Amount"
  103. prop="groupCredit"
  104. min-width="100"/>
  105. <el-table-column
  106. align="center"
  107. label="Assigned Users"
  108. min-width="120">
  109. <template slot-scope="{row}">
  110. <span>{{row.approvedUsers-row.individualApprovedUsers}}</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column
  114. align="center"
  115. label="Current Consumption"
  116. prop="currentConsumptionCredit"
  117. min-width="140">
  118. <template slot-scope="{row}">
  119. <span>{{row.creditLimitRemainingAmount}}/{{row.groupCredit}}</span>
  120. </template>
  121. </el-table-column>
  122. </el-table>
  123. <p></p>
  124. </div>
  125. <div class="content" v-if="isEdit">
  126. <div class="section-title">Individual Plans</div>
  127. <plans
  128. :id="form.groupCreditPk"
  129. :groupPk="form.groupPk"
  130. v-if="form.groupCreditPk"
  131. @refresh="getLimitInfo"/>
  132. <p></p>
  133. </div>
  134. <div class="content flexcr">
  135. <div class="buttons">
  136. <el-button
  137. type="primary"
  138. class="cancel-button"
  139. @click="onBack">
  140. Cancel
  141. </el-button>
  142. <el-button
  143. style="margin-left: 20px;"
  144. type="primary"
  145. :loading="loading.save"
  146. @click="onSaveClick">
  147. Save
  148. </el-button>
  149. </div>
  150. <div
  151. class="flex1"
  152. style="margin-left: 20px;"
  153. v-if="isEdit">
  154. <span
  155. class="add-text"
  156. :title='"CREATED BY " + form.createdBy + " ON " + form.createdOn'>
  157. LAST UPDATED BY {{form.updatedBy}} TIMESTAMP: {{form.updatedOn}}
  158. </span>
  159. </div>
  160. </div>
  161. </el-form>
  162. </div>
  163. </template>
  164. <script>
  165. import apiBase from '@/api/apiBase';
  166. import limit from '@/api/limit.js'
  167. import provider from '@/http/api/provider'
  168. import group from '@/http/api/group'
  169. import plans from './plans.vue'
  170. export default {
  171. data() {
  172. return {
  173. isEdit: false,
  174. loading: {
  175. page: true,
  176. save: false
  177. },
  178. form: {
  179. groupCreditPk: "",
  180. groupPk: "",
  181. providerPk: "",
  182. effectivePeriod: ["", ""],
  183. creditLimitAmount: ""
  184. },
  185. rules: {
  186. groupPk: {
  187. required: true,
  188. trigger: 'change',
  189. message: 'Please select a group'
  190. },
  191. providerPk: {
  192. required: true,
  193. trigger: 'change',
  194. message: 'Please select a provider'
  195. },
  196. creditLimitAmount: [{
  197. required: true,
  198. trigger: 'blur',
  199. message: 'Please type Monthly Credit Limit'
  200. }, {
  201. pattern: /^\d+(.{0,1}\d{1,})?$/,
  202. trigger: 'blur',
  203. message: 'Please type a number of amount'
  204. }],
  205. effectivePeriod: {
  206. required: true,
  207. trigger: 'change',
  208. validator: (rule, value, callback) => {
  209. if (value && value.length > 0) {
  210. if (value[0] && value[1]) {
  211. callback()
  212. } else {
  213. callback("Please select effective period")
  214. }
  215. } else {
  216. callback("Please select effective period")
  217. }
  218. }
  219. },
  220. },
  221. options: {
  222. group: [],
  223. status: [],
  224. provider: []
  225. },
  226. companyParams: {
  227. "pageSize": 50,
  228. "pageNo": 1,
  229. "pageVo": {
  230. "criteria": ""
  231. }
  232. },
  233. };
  234. },
  235. components: {plans},
  236. created() {
  237. this.getGroupOptions();
  238. if (this.$route.params.id) {
  239. this.isEdit = true;
  240. this.getStatusOptions();
  241. this.getLimitInfo();
  242. }
  243. },
  244. methods: {
  245. onBack() {
  246. this.$nextTick(() => {
  247. this.$router.push({
  248. path: "/partnership-management/monthly-credit-limit"
  249. })
  250. })
  251. },
  252. getStatusOptions() {
  253. apiBase.getDataStatusOptions().then(res => {
  254. if (res.data && res.data.length > 0) {
  255. this.options.status = res.data
  256. }
  257. }).catch(err => {
  258. this.$message.error(err);
  259. })
  260. },
  261. getGroupOptions() {
  262. group.getGroupPages(this.companyParams).then(res => {
  263. if (res.data) {
  264. this.options.group = res.data
  265. }
  266. }).catch(err => {
  267. this.$message({
  268. message: err,
  269. type: 'error'
  270. })
  271. }).finally(() => {
  272. this.getAllProvider();
  273. });
  274. },
  275. getAllProvider() {
  276. apiBase.getProviderList().then(res => {
  277. if (res.data && res.data.length > 0) {
  278. this.options.provider = res.data
  279. if (!this.form.providerPk)
  280. this.form.providerPk = res.data[0].value
  281. }
  282. }).finally(() => {
  283. this.loading.page = false;
  284. });
  285. },
  286. getLimitInfo() {
  287. limit.viewCreditLimit(this.$route.params.id).then(res => {
  288. if (res.data) {
  289. this.form = res.data
  290. }
  291. }).catch(err => {
  292. this.loading.page = false;
  293. this.$message({
  294. message: err,
  295. type: 'error'
  296. })
  297. });
  298. },
  299. onSaveClick() {
  300. this.$refs['limitForm'].validate(result => {
  301. if (result) {
  302. this.loading.save = true;
  303. this.isEdit ? this.updateLimites() : this.addLimites();
  304. }
  305. })
  306. },
  307. addLimites() {
  308. limit.addCreditLimit(this.form).then(res => {
  309. this.$message({
  310. message: 'Add credit limit successfully',
  311. type: 'success'
  312. })
  313. this.onBack();
  314. }).catch(err => {
  315. this.$message({
  316. message: err,
  317. type: 'error'
  318. })
  319. }).finally(() => {
  320. this.loading.save = false;
  321. });
  322. },
  323. updateLimites() {
  324. limit.updateCreditLimit(this.form).then(res => {
  325. this.$message({
  326. message: 'Update credit limit successfully',
  327. type: 'success'
  328. })
  329. this.onBack();
  330. }).catch(err => {
  331. this.$message({
  332. message: err,
  333. type: 'error'
  334. })
  335. }).finally(() => {
  336. this.loading.save = false;
  337. });
  338. }
  339. }
  340. }
  341. </script>
  342. <style lang="scss" scoped>
  343. @import '../../styles/variables.scss';
  344. .container {
  345. width: 100%;
  346. padding: 20px 60px;
  347. min-height: $mainAppMinHeight;
  348. background-color: #F0F5FC;
  349. }
  350. .content {
  351. margin: 0 8px 16px;
  352. padding: 15px 50px;
  353. border-radius: 6px;
  354. background-color: white;
  355. }
  356. .section-title {
  357. color: #333;
  358. margin-top: 20px;
  359. margin-bottom: 30px;
  360. font-size: 15px;
  361. user-select: none;
  362. line-height: 24px;
  363. font-weight: bold;
  364. font-family: sans-serif;
  365. text-transform: uppercase;
  366. }
  367. .add-text {
  368. width: 100% !important;
  369. min-width: 150px;
  370. max-width: 300px;
  371. }
  372. .add-text ::v-deep .el-textarea__inner {
  373. font-family: sans-serif;
  374. }
  375. .hr {
  376. height: 2px;
  377. margin: 10px -40px;
  378. background-color: #F0F5FC;
  379. }
  380. .buttons {
  381. padding-top: 15px;
  382. padding-bottom: 15px;
  383. }
  384. .form-left,.form-right {
  385. flex: 1;
  386. min-width: 300px;
  387. }
  388. .item-unit {
  389. top: 12px;
  390. left: -40px;
  391. font-size: 12px;
  392. user-select: none;
  393. position: absolute;
  394. }
  395. @media screen and (max-width: 500px) {
  396. .container {
  397. padding: 0px;
  398. }
  399. .content {
  400. padding: 15px 30px;
  401. }
  402. .form-left,.form-right {
  403. width: 100%;
  404. min-width: auto;
  405. }
  406. }
  407. </style>