customer-popup-edit.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. shopProductId: this.$route.query.shopProductId,
  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({ shopProductId: this.$route.query.shopProductId })
  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({
  125. path: '/user/customer/customer-goods-list',
  126. query: { id: this.$route.query.id, shopId: this.$route.query.shopId, shopName: this.$route.query.shopName }
  127. })
  128. }, 1000)
  129. },
  130. // 上传图标事件
  131. handleSuccess(res, file) {
  132. this.loadImgLoading = true
  133. this.$nextTick(() => {
  134. setTimeout(() => {
  135. this.form.image = res.data
  136. }, 1000 * 2)
  137. })
  138. },
  139. // 对上传图片的大小、格式进行限制
  140. beforeUpload(file) {
  141. const isJPG = file.type === 'image/jpeg'
  142. const isJPG2 = file.type === 'image/jpg'
  143. const isPNG = file.type === 'image/png'
  144. const isLt5M = file.size / 1024 / 1024 < 5
  145. if (!isJPG && !isJPG2 && !isPNG) {
  146. this.$message.error('只支持jpg或png格式图片')
  147. }
  148. if (!isLt5M) {
  149. this.$message.error('请上传5MB以内的图片!')
  150. }
  151. return (isJPG || isJPG2 || isPNG) && isLt5M
  152. },
  153. reloadImage() {
  154. this.loadImgLoading = true
  155. setTimeout(() => {
  156. this.temp.classifyImage = this.temp.classifyImage.split('?')[0] + '?r=' + Math.floor(Math.random() * 1000)
  157. }, 1000 * 2)
  158. },
  159. loadSucess() {
  160. this.loadImgLoading = false
  161. },
  162. backToList() {
  163. this.$store.dispatch('tagsView/delView', this.$route).then(() => {
  164. this.$nextTick(() => {
  165. this.$router.replace({
  166. path: '/user/customer/customer-goods-list',
  167. query: { id: this.$route.query.id, shopId: this.$route.query.shopId, shopName: this.$route.query.shopName }
  168. })
  169. })
  170. })
  171. }
  172. }
  173. }
  174. </script>
  175. <style>
  176. .avatar-uploader .el-upload {
  177. border: 1px dashed #d9d9d9;
  178. border-radius: 6px;
  179. cursor: pointer;
  180. position: relative;
  181. overflow: hidden;
  182. float: left;
  183. }
  184. .avatar-uploader .el-upload:hover {
  185. border-color: #409eff;
  186. }
  187. .avatar-uploader-icon {
  188. font-size: 30px;
  189. color: #999999;
  190. }
  191. .el-form-item__label {
  192. text-align: right !important;
  193. }
  194. .el-upload__tip {
  195. line-height: 20px;
  196. color: red;
  197. text-align: left;
  198. }
  199. .span_tip {
  200. font-size: 12px;
  201. color: red;
  202. margin-left: 5px;
  203. }
  204. .filter-item-temp {
  205. width: 100px;
  206. }
  207. </style>