details.vue 5.9 KB

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