detail.vue 8.8 KB

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