customer-popup-edit.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="app-container" style="width: 800px; margin: 0 auto">
  3. <el-form ref="bannerForm" :model="form" label-width="100px">
  4. <el-form-item label="弹窗图片:" prop="image" :rules="rules.image" style="margin-bottom: 40px">
  5. <div class="form-el-upload" style="width: 148px; height: 148px">
  6. <el-upload
  7. class="avatar-uploader"
  8. :action="actionUrl"
  9. :headers="getToken"
  10. :show-file-list="false"
  11. :on-success="handleSuccess"
  12. :before-upload="beforeUpload"
  13. >
  14. <div v-loading="loadImgLoading" class="avatar" style="width: 148px; height: 148px; display: block">
  15. <img
  16. v-if="form.image"
  17. :src="form.image"
  18. style="width: 148px; height: 148px; display: block"
  19. @error="reloadImage"
  20. @load="loadSucess"
  21. />
  22. <i
  23. v-else
  24. class="el-icon-plus avatar-uploader-icon"
  25. style="width: 148px; height: 148px; line-height: 148px"
  26. ></i>
  27. </div>
  28. </el-upload>
  29. <p class="uploader-tips">注:请尽量上传260*260(px)尺寸的图片。</p>
  30. </div>
  31. </el-form-item>
  32. <el-form-item label="引导语1:" prop="guidingOne" :rules="rules.guidingOne">
  33. <el-input
  34. v-model="form.guidingOne"
  35. placeholder="请输入第一句引导语,不多余15个汉字"
  36. maxlength="15"
  37. style="width: 350px"
  38. />
  39. </el-form-item>
  40. <el-form-item label="引导语2:" prop="guidingTwo" :rules="rules.guidingTwo">
  41. <el-input
  42. v-model="form.guidingTwo"
  43. placeholder="请输入第二句引导语,不多余15个汉字"
  44. maxlength="15"
  45. style="width: 350px"
  46. />
  47. </el-form-item>
  48. </el-form>
  49. <div class="el-dialog__footer" style="text-align: center">
  50. <el-button type="primary" @click="onSubmit('bannerForm')"> 保存 </el-button>
  51. <el-button plain @click="backToList"> 返回 </el-button>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { saveShopPopUp, getShopPopUp } from '@/api/user/customer/customer'
  57. export default {
  58. name: 'CustomerPopupEdit',
  59. data() {
  60. const defaultForm = () => {
  61. return {
  62. id: '',
  63. shopId: this.$route.query.shopId,
  64. image: '', // 弹窗图片
  65. guidingOne: '', // 引导语1
  66. guidingTwo: '', // 引导语2
  67. addTime: ''
  68. }
  69. }
  70. return {
  71. form: defaultForm(),
  72. loadImgLoading: false,
  73. rules: {
  74. image: [{ required: true, message: '请上传弹窗图片', trigger: 'blur' }],
  75. guidingOne: [{ required: true, message: '请填写引导语', trigger: 'blur' }],
  76. guidingTwo: [{ required: true, message: '请填写引导语', trigger: 'blur' }]
  77. }
  78. }
  79. },
  80. computed: {
  81. getToken() {
  82. return {
  83. token: this.$store.getters.token
  84. }
  85. },
  86. actionUrl() {
  87. return process.env.VUE_APP_BASE_API + '/formData/MultiPictareaddData'
  88. }
  89. },
  90. created() {
  91. this.getShopPopUp({ shopId: this.$route.query.shopId })
  92. },
  93. methods: {
  94. // 获取供应商弹窗详情
  95. async getShopPopUp(params) {
  96. try {
  97. const res = await getShopPopUp(params)
  98. this.form = { ...this.form, ...res.data }
  99. } catch (error) {
  100. console.log('error', error)
  101. }
  102. },
  103. onSubmit(formName) {
  104. this.$refs[formName].validate((valid) => {
  105. if (valid) {
  106. this.$confirm('是否提交保存信息', '提示', {
  107. confirmButtonText: '确定',
  108. cancelButtonText: '取消',
  109. type: 'warning'
  110. }).then(() => {
  111. console.log('form', this.form)
  112. this.saveShopPopUp(this.form)
  113. })
  114. } else {
  115. return false
  116. }
  117. })
  118. },
  119. async saveShopPopUp(params) {
  120. // 保存
  121. await saveShopPopUp(params)
  122. this.$message.success('保存成功')
  123. setTimeout(() => {
  124. this.$router.push({ path: '/user/customer/list' })
  125. }, 1000)
  126. },
  127. // 上传图标事件
  128. handleSuccess(res, file) {
  129. this.loadImgLoading = true
  130. this.$nextTick(() => {
  131. setTimeout(() => {
  132. this.form.image = res.data
  133. }, 1000 * 2)
  134. })
  135. },
  136. // 对上传图片的大小、格式进行限制
  137. beforeUpload(file) {
  138. const isJPG = file.type === 'image/jpeg'
  139. const isJPG2 = file.type === 'image/jpg'
  140. const isPNG = file.type === 'image/png'
  141. const isLt5M = file.size / 1024 / 1024 < 5
  142. if (!isJPG && !isJPG2 && !isPNG) {
  143. this.$message.error('只支持jpg或png格式图片')
  144. }
  145. if (!isLt5M) {
  146. this.$message.error('请上传5MB以内的图片!')
  147. }
  148. return (isJPG || isJPG2 || isPNG) && isLt5M
  149. },
  150. reloadImage() {
  151. this.loadImgLoading = true
  152. setTimeout(() => {
  153. this.temp.classifyImage = this.temp.classifyImage.split('?')[0] + '?r=' + Math.floor(Math.random() * 1000)
  154. }, 1000 * 2)
  155. },
  156. loadSucess() {
  157. this.loadImgLoading = false
  158. },
  159. backToList() {
  160. this.$store.dispatch('tagsView/delView', this.$route).then(() => {
  161. this.$nextTick(() => {
  162. this.$router.replace({ path: '/user/customer/list' })
  163. })
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style>
  170. .avatar-uploader .el-upload {
  171. border: 1px dashed #d9d9d9;
  172. border-radius: 6px;
  173. cursor: pointer;
  174. position: relative;
  175. overflow: hidden;
  176. float: left;
  177. }
  178. .avatar-uploader .el-upload:hover {
  179. border-color: #409eff;
  180. }
  181. .avatar-uploader-icon {
  182. font-size: 30px;
  183. color: #999999;
  184. }
  185. .el-form-item__label {
  186. text-align: right !important;
  187. }
  188. .el-upload__tip {
  189. line-height: 20px;
  190. color: red;
  191. text-align: left;
  192. }
  193. .span_tip {
  194. font-size: 12px;
  195. color: red;
  196. margin-left: 5px;
  197. }
  198. .filter-item-temp {
  199. width: 100px;
  200. }
  201. </style>