details.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div>
  3. <el-dialog :title="exData.id ? '编辑': '新增'"
  4. :visible.sync="dialog"
  5. width="600px"
  6. :close-on-click-modal="false"
  7. top="50px">
  8. <el-form ref="form"
  9. :model="form"
  10. :rules="formRules"
  11. label-width="120px">
  12. <el-form-item prop="user_song_name"
  13. :rules="formRules.required"
  14. label="艺人姓名:">
  15. <el-input v-model="form.user_song_name"
  16. placeholder="请输入艺人姓名"
  17. clearable></el-input>
  18. </el-form-item>
  19. <el-form-item prop="phone"
  20. :rules="formRules.mobile"
  21. label="手机号:">
  22. <el-input style="width: 70%;"
  23. v-model="form.phone"
  24. disabled
  25. placeholder="请输入手机号"
  26. @input="form.phone = form.phone.replace(/[^\d]/g, '').slice(0, 11)"
  27. clearable></el-input>
  28. <p style="display: inline-block;width: 30%;text-align: right;">
  29. <el-button
  30. type="primary"
  31. @click="validatePhone('form')"
  32. :disabled="[0, 60].findIndex(item => item === numCount) < 0">
  33. 获取验证码<span>{{ [0, 60].findIndex(item => item === numCount) > -1 ? '' : numCount + '秒' }}</span>
  34. </el-button>
  35. </p>
  36. </el-form-item>
  37. <el-form-item prop="code"
  38. :rules="formRules.code"
  39. label="短信验证码:">
  40. <el-input v-model="form.code"
  41. placeholder="请输入短信验证码"
  42. @input="form.code=form.code.replace(/[^\d]/g, '').slice(0, 6)"
  43. clearable></el-input>
  44. </el-form-item>
  45. <el-form-item prop="plan_cover_url"
  46. :rules="formRules.uploadImgs"
  47. label="演出海报:">
  48. <el-upload :on-remove="handleRemove"
  49. :on-success="handleAvatarSuccess"
  50. :before-upload="beforeAvatarUpload"
  51. :on-exceed="hadnleExceed"
  52. :accept="'image/*'"
  53. :limit="1"
  54. :file-list="fileList"
  55. list-type="picture-card"
  56. action="/api/admin/v1/upload/file"
  57. multiple>
  58. <i class="el-icon-plus"></i>
  59. <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5M</div>
  60. </el-upload>
  61. </el-form-item>
  62. <el-form-item prop="user_sign_status"
  63. :rules="formRules.required"
  64. label="状态:">
  65. <el-radio v-model="form.user_sign_status"
  66. label="1">已签约
  67. </el-radio>
  68. <el-radio v-model="form.user_sign_status"
  69. label="0">未签约
  70. </el-radio>
  71. </el-form-item>
  72. <el-form-item prop="user_desc"
  73. :rules="formRules.required"
  74. label="描述:">
  75. <el-input type="textarea"
  76. :rows="4"
  77. placeholder="请输入艺人描述"
  78. v-model="form.user_desc">
  79. </el-input>
  80. </el-form-item>
  81. </el-form>
  82. <div slot="footer" class="dialog-footer text-center">
  83. <el-button @click="dialog = false">取 消</el-button>
  84. <el-button type="primary" :disabled="booLock" @click="handleSubmit">确 定</el-button>
  85. </div>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. import getCode from '@/views/ums/mixin/getCode'
  91. export default {
  92. mixins: [getCode],
  93. components: {},
  94. props: {
  95. value: {
  96. type: Boolean,
  97. default: true
  98. },
  99. exData: {
  100. type: Object,
  101. default: function () {
  102. return {}
  103. }
  104. }
  105. },
  106. data () {
  107. return {
  108. dialog: !!this.value,
  109. form: {
  110. user_song_name: '', // 歌手名称
  111. phone: '', // 手机号码
  112. code: '', // 验证码
  113. plan_cover_url: [],
  114. user_sign_status: '1', // 艺人签约状态(0未签约1已签约)
  115. user_desc: '' // 艺人描述
  116. },
  117. fileList: [],
  118. booLock: false
  119. }
  120. },
  121. methods: {
  122. beforeAvatarUpload (file) {
  123. const isLt2M = file.size / 1024 / 1024 < 5
  124. if (!isLt2M) {
  125. this.$message.error('上传图片大小不能超过 5MB!')
  126. }
  127. return isLt2M
  128. },
  129. handleRemove (file) {
  130. let path = file.url
  131. if (file.response && file.response.data) {
  132. path = file.response.data.path
  133. }
  134. this.form.plan_cover_url = this.form.plan_cover_url.filter(item => item !== path)
  135. },
  136. handleAvatarSuccess (res) {
  137. if (res.code === 200) {
  138. const { path } = res.data
  139. this.form.plan_cover_url.push(path)
  140. } else {
  141. this.$message.error('图片上传失败')
  142. }
  143. },
  144. hadnleExceed (files, fileList) {
  145. this.$message({
  146. message: '商品图最多上传一张',
  147. type: 'warning'
  148. })
  149. },
  150. handleSubmit () {
  151. const url = this.exData.id ? '/v1/user/member/song/modify' : ''
  152. this.$refs.form.validate(async valid => {
  153. if (valid) {
  154. this.booLock = true
  155. const data = await this.$fetch(url, {
  156. ...this.form,
  157. plan_cover_url: this.form.plan_cover_url[0]
  158. })
  159. this.booLock = false
  160. if (data.code === 200) {
  161. this.$message.success('提交成功')
  162. this.$emit('success')
  163. this.dialog = false
  164. }
  165. }
  166. })
  167. }
  168. },
  169. mounted () {
  170. if (this.exData.id) {
  171. this.$set(this.form, 'id', this.exData.id)
  172. this.$set(this.form, 'phone', this.exData.user_phone)
  173. this.fileList = [
  174. {
  175. name: '',
  176. url: this.exData.plan_cover_url
  177. }
  178. ]
  179. for (const key in this.exData) {
  180. if (this.form.hasOwnProperty(key)) {
  181. let value = this.exData[key]
  182. if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
  183. if (key === 'plan_cover_url') {
  184. value = [value]
  185. }
  186. if (key === 'user_sign_status') {
  187. value = value.toString()
  188. }
  189. this.$set(this.form, key, value)
  190. }
  191. }
  192. }
  193. }
  194. },
  195. watch: {
  196. dialog (val) {
  197. if (!val) this.$emit('input', val)
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .top-tip {
  204. margin-top: -20px;
  205. margin-bottom: 20px;
  206. }
  207. </style>