detail.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="container" v-loading="loading.page">
  3. <el-form
  4. :model="form"
  5. :rules="rule"
  6. ref="form"
  7. label-position="right"
  8. label-width="150px"
  9. style="width: 100%;">
  10. <div class="content">
  11. <div class="section-title">Service Provider</div>
  12. <el-form-item
  13. label="Provider Name:"
  14. prop="providerName">
  15. <el-input
  16. class="add-text"
  17. maxlength="30"
  18. v-model="form.providerName"/>
  19. </el-form-item>
  20. <el-form-item
  21. label="Country:"
  22. prop="countryCode">
  23. <el-select
  24. v-model="form.countryCode"
  25. class="add-text">
  26. <el-option
  27. v-for="item in options.country"
  28. :key="item.countryCode"
  29. :label="item.countryName"
  30. :value="item.countryCode"/>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item
  34. label="Contact Person:"
  35. prop="providerContactPerson">
  36. <el-input
  37. class="add-text"
  38. maxlength="50"
  39. v-model="form.providerContactPerson"/>
  40. </el-form-item>
  41. <el-form-item
  42. label="Contact Number:"
  43. prop="providerContactPhoneNumber">
  44. <div class="add-text flexc">
  45. <el-select
  46. style="min-width: 75px; max-width: 80px;"
  47. v-model="form.providerContactCallingCode">
  48. <el-option
  49. v-for="item in options.country"
  50. :key="item.callingCode"
  51. :label="'+' + item.callingCode"
  52. :value="item.callingCode"/>
  53. </el-select>
  54. <el-input
  55. v-model="form.providerContactPhoneNumber"
  56. style="margin-left: 10px;"
  57. maxlength="15"/>
  58. </div>
  59. </el-form-item>
  60. <el-form-item
  61. label="Payment Gateway:"
  62. prop="paymentGateway">
  63. <el-select
  64. v-model="form.paymentGateway"
  65. class="add-text">
  66. <el-option
  67. v-for="item in options.payment"
  68. :key="item.key"
  69. :label="item.value"
  70. :value="item.key"/>
  71. </el-select>
  72. </el-form-item>
  73. <el-form-item
  74. label="Provider Logo:">
  75. <el-upload
  76. class="logo-upload"
  77. action
  78. :limit="1"
  79. :show-file-list="false"
  80. :file-list="[]"
  81. :on-remove="file => removeLogo(file)"
  82. :http-request="file => uploadLogo(file)"
  83. accept=".jpg,.jpeg,.png,.gif,.JPG,.JPEG"
  84. v-loading="loading.upload">
  85. <el-image
  86. v-if="logos.length > 0"
  87. :src="logos[0].url"
  88. title="Click to update logo"/>
  89. <i v-else
  90. class="el-icon-plus avatar-uploader-icon"
  91. title="Click to select file"/>
  92. </el-upload>
  93. </el-form-item>
  94. </div>
  95. <div class="content flexcr">
  96. <div class="buttons">
  97. <el-button
  98. type="primary"
  99. class="cancel-button"
  100. @click="onBack">
  101. Cancel
  102. </el-button>
  103. <el-button
  104. style="margin-left: 20px;"
  105. type="primary"
  106. :loading="loading.saving"
  107. @click="onClickSave">
  108. &nbsp;Save&nbsp;
  109. </el-button>
  110. </div>
  111. <div
  112. class="update-by"
  113. v-if="isEdit">
  114. <span
  115. class="add-text"
  116. :title='"CREATED BY " + form.createByName + " ON " + form.createTime'>
  117. LAST UPDATED BY {{form.updateByName}} TIMESTAMP: {{form.updateTime}}
  118. </span>
  119. </div>
  120. </div>
  121. </el-form>
  122. </div>
  123. </template>
  124. <script>
  125. import setting from '../../settings.js';
  126. import apiBase from '../../api/apiBase.js';
  127. import provider from '../../api/provider.js';
  128. export default {
  129. data() {
  130. return {
  131. isEdit: false,
  132. loading: {
  133. page: true,
  134. upload: false,
  135. saving: false
  136. },
  137. options: {
  138. country: [],
  139. payment: []
  140. },
  141. form: {
  142. providerPk: "",
  143. providerName: "",
  144. countryCode: setting.defaultCountry,
  145. providerLogo: "",
  146. paymentGateway: "",
  147. providerContactPerson: "",
  148. providerContactCallingCode: Number(setting.defaultCalling),
  149. providerContactPhoneNumber: ""
  150. },
  151. rule: {
  152. providerName: {
  153. required: true,
  154. trigger: 'blur',
  155. message: 'Please type provider name'
  156. },
  157. paymentGateway: {
  158. required: true,
  159. trigger: 'change',
  160. message: 'Please select payment gateway'
  161. }
  162. },
  163. logos: []
  164. };
  165. },
  166. created() {
  167. if (this.$route.params.id) {
  168. this.isEdit = true;
  169. this.getProviderInfo();
  170. }
  171. this.getCountryOptions();
  172. },
  173. methods: {
  174. onBack() {
  175. this.$nextTick(() => {
  176. this.$router.replace({
  177. path: "/partnership-management/service-provider-mgmt"
  178. })
  179. })
  180. },
  181. getCountryOptions() {
  182. apiBase.getCountryList().then(res => {
  183. if (res.data) {
  184. this.options.country = res.data
  185. }
  186. }).finally(() => {
  187. this.getPaymentOptions();
  188. })
  189. },
  190. getPaymentOptions() {
  191. apiBase.getPaymentGatewayList().then(res => {
  192. if (res.data) {
  193. this.options.payment = res.data
  194. }
  195. }).finally(() => {
  196. this.loading.page = false
  197. })
  198. },
  199. getProviderInfo() {
  200. provider.viewServiceProvider(this.$route.params.id).then(res => {
  201. if (res.data) {
  202. this.form = Object.assign(this.form, res.data);
  203. if (this.form.providerLogo) {
  204. this.logos.push({
  205. path: this.form.providerLogo,
  206. url: this.$imageSrc(this.form.providerLogo)
  207. });
  208. }
  209. }
  210. }).catch(err => {
  211. this.$message({
  212. message: err,
  213. type: 'error'
  214. })
  215. })
  216. },
  217. uploadLogo(file) {
  218. this.loading.upload = true;
  219. const formData = new FormData()
  220. formData.append('file', file.file)
  221. apiBase.uploadImage(formData).then(res => {
  222. if (this.logos.length == 0) {
  223. this.logos.push({
  224. url: ""
  225. })
  226. }
  227. this.logos[0] = ({
  228. path: res.data.picturePath,
  229. url: this.$imageSrc(res.data.picturePath)
  230. })
  231. }).catch(err => {
  232. this.$message({
  233. message: err,
  234. type: 'error'
  235. })
  236. }).finally(() => {
  237. this.loading.upload = false;
  238. })
  239. },
  240. removeLogo(file) {
  241. this.logos = []
  242. this.form.providerLogo = ""
  243. },
  244. onClickSave() {
  245. this.$refs['form'].validate(result => {
  246. if (result) {
  247. if (this.logos.length > 0) {
  248. this.form.providerLogo = this.logos[0].path
  249. } else {
  250. this.form.providerLogo = "";
  251. }
  252. if (!this.form.providerLogo) {
  253. this.$message({
  254. message: "Please upload provider logo",
  255. type: 'error'
  256. });
  257. return
  258. }
  259. this.loading.saving = true;
  260. if (this.isEdit) {
  261. this.updateProvider()
  262. } else {
  263. this.addProvider();
  264. }
  265. }
  266. });
  267. },
  268. addProvider() {
  269. provider.addServiceProvider(this.form).then(res => {
  270. this.$message({
  271. message: 'Add service provider successfully',
  272. type: 'success'
  273. })
  274. this.onBack();
  275. }).catch(err => {
  276. this.loading.saving = false;
  277. this.$message({
  278. message: err,
  279. type: 'error'
  280. })
  281. });
  282. },
  283. updateProvider() {
  284. provider.updateServiceProvider(this.form).then(res => {
  285. this.$message({
  286. message: 'Update service provider successfully',
  287. type: 'success'
  288. })
  289. this.onBack();
  290. }).catch(err => {
  291. this.loading.saving = false;
  292. this.$message({
  293. message: err,
  294. type: 'error'
  295. })
  296. });
  297. }
  298. }
  299. }
  300. </script>
  301. <style scoped lang='scss'>
  302. @import '../../styles/variables.scss';
  303. .container {
  304. width: 100%;
  305. padding: 20px 60px;
  306. min-height: $mainAppMinHeight;
  307. background-color: #F0F5FC;
  308. }
  309. .content {
  310. margin: 0 8px 16px;
  311. padding: 15px 80px;
  312. border-radius: 6px;
  313. background-color: white;
  314. }
  315. .section-title {
  316. color: #333;
  317. margin-top: 20px;
  318. margin-bottom: 30px;
  319. font-size: 15px;
  320. user-select: none;
  321. line-height: 24px;
  322. font-weight: bold;
  323. font-family: sans-serif;
  324. text-transform: uppercase;
  325. }
  326. .add-text {
  327. width: 100%;
  328. max-width: 300px;
  329. }
  330. .add-text ::v-deep .el-textarea__inner {
  331. font-family: sans-serif;
  332. }
  333. .buttons {
  334. padding-top: 15px;
  335. padding-bottom: 15px;
  336. }
  337. @media screen and (max-width: 500px) {
  338. .container {
  339. padding: 0px;
  340. }
  341. .content {
  342. padding: 15px 30px;
  343. }
  344. }
  345. .logo-upload {
  346. width: 148px;
  347. height: 148px;
  348. position: relative;
  349. ::v-deep .el-image {
  350. width: 148px;
  351. height: 148px;
  352. border-radius: 6px;
  353. }
  354. }
  355. .avatar-uploader-icon {
  356. width: 148px;
  357. height: 148px;
  358. color: #8c939d;
  359. cursor: pointer;
  360. font-size: 28px;
  361. text-align: center;
  362. line-height: 148px;
  363. border-radius: 6px;
  364. border: 1px dashed #d9d9d9;
  365. }
  366. </style>