detail.vue 12 KB

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