details.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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="phone"
  22. :rules="formRules.mobile"
  23. label="手机号:">
  24. <el-col :span="10">
  25. <el-input v-model="form.phone"
  26. placeholder="请输入手机号"
  27. @input="form.phone = form.phone.replace(/[^\d]/g, '').slice(0, 11)"
  28. clearable></el-input>
  29. </el-col>
  30. <el-col :span="5" :offset="1">
  31. <el-button
  32. type="primary"
  33. @click="validatePhone"
  34. :disabled="[0, 60].findIndex(item => item === numCount) < 0">
  35. 获取验证码<span>{{ [0, 60].findIndex(item => item === numCount) > -1 ? '' : numCount + '秒' }}</span>
  36. </el-button>
  37. </el-col>
  38. </el-form-item>
  39. <el-form-item prop="code"
  40. :rules="formRules.code"
  41. label="短信验证码:">
  42. <el-col :span="16">
  43. <el-input v-model="form.code"
  44. placeholder="请输入短信验证码"
  45. @input="form.code=form.code.replace(/[^\d]/g, '').slice(0, 6)"
  46. clearable></el-input>
  47. </el-col>
  48. </el-form-item>
  49. <el-form-item prop="plan_cover_url"
  50. :rules="formRules.uploadImgs"
  51. label="演出海报:">
  52. <el-upload :on-remove="handleRemove"
  53. :on-success="handleAvatarSuccess"
  54. :before-upload="beforeAvatarUpload"
  55. :on-exceed="hadnleExceed"
  56. :accept="'image/*'"
  57. :limit="1"
  58. :file-list="fileList"
  59. list-type="picture-card"
  60. action="/api/admin/v1/upload/file"
  61. multiple>
  62. <i class="el-icon-plus"></i>
  63. <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5M</div>
  64. </el-upload>
  65. </el-form-item>
  66. <el-form-item prop="user_sign_status"
  67. :rules="formRules.required"
  68. label="状态:">
  69. <el-radio v-model="form.user_sign_status"
  70. label="1">已签约
  71. </el-radio>
  72. <el-radio v-model="form.user_sign_status"
  73. label="0">未签约
  74. </el-radio>
  75. </el-form-item>
  76. </el-form>
  77. <div slot="footer" class="dialog-footer text-center">
  78. <el-button @click="dialog = false">取 消</el-button>
  79. <el-button type="primary" @click="handleSubmit">确 定</el-button>
  80. </div>
  81. </el-dialog>
  82. </div>
  83. </template>
  84. <script>
  85. import { fen2Yuan, yuan2Fen } from '@/utils'
  86. export default {
  87. components: {},
  88. props: {
  89. value: {
  90. type: Boolean,
  91. default: true
  92. },
  93. exData: {
  94. type: Object,
  95. default: function () {
  96. return {}
  97. }
  98. }
  99. },
  100. data () {
  101. return {
  102. dialog: !!this.value,
  103. form: {
  104. user_song_name: '', // 歌手名称
  105. phone: '', // 手机号码
  106. code: '', // 验证码
  107. plan_cover_url: [],
  108. user_sign_status: '1', // 艺人签约状态(0未签约1已签约)
  109. },
  110. fileList: [],
  111. numCount: 60,
  112. timer: null
  113. }
  114. },
  115. methods: {
  116. beforeAvatarUpload (file) {
  117. const isLt2M = file.size / 1024 / 1024 < 5
  118. if (!isLt2M) {
  119. this.$message.error('上传图片大小不能超过 5MB!')
  120. }
  121. return isLt2M
  122. },
  123. handleRemove (file) {
  124. let path = file.url
  125. if (file.response && file.response.data) {
  126. path = file.response.data.path
  127. }
  128. this.form.plan_cover_url = this.form.plan_cover_url.filter(item => item !== path)
  129. },
  130. handleAvatarSuccess (res) {
  131. if (res.code === 200) {
  132. const { path } = res.data
  133. this.form.plan_cover_url.push(path)
  134. } else {
  135. this.$message.error('图片上传失败')
  136. }
  137. },
  138. hadnleExceed (files, fileList) {
  139. this.$message({
  140. message: '商品图最多上传一张',
  141. type: 'warning'
  142. })
  143. },
  144. removeDeskNum (item) {
  145. var index = this.form.place_number.indexOf(item)
  146. if (this.form.place_number.length <= 1) {
  147. this.$message.warning('桌数不能小于1')
  148. return
  149. }
  150. if (index !== -1) {
  151. this.form.place_number.splice(index, 1)
  152. }
  153. },
  154. addDomain () {
  155. this.form.place_number.push({
  156. value: ''
  157. })
  158. },
  159. validatePhone () {
  160. this.$refs['form'].validateField('phone', emailError => {
  161. if (!emailError) {
  162. this.funGetCode()
  163. } else {
  164. return false
  165. }
  166. })
  167. },
  168. funCutDown () {
  169. clearInterval(this.timer)
  170. this.timer = setInterval(() => {
  171. if (this.numCount === 0) {
  172. clearInterval(this.timer)
  173. this.numCount = 0
  174. return
  175. }
  176. this.numCount--
  177. }, 1000)
  178. },
  179. // 获取验证码
  180. async funGetCode () {
  181. const numCount = this.numCount
  182. const { phone } = this.form
  183. if (numCount < 60 && numCount > 0) {
  184. return
  185. }
  186. this.numCount = 60
  187. this.funCutDown()
  188. const data = await this.$fetch('/v1/send/code', {
  189. phone
  190. })
  191. if (data.code === 200) {
  192. this.$message.success('发送成功')
  193. } else {
  194. clearInterval(this.timer)
  195. this.numCount = 60
  196. }
  197. },
  198. handleSubmit () {
  199. // todo 艺人添加、艺人海报数组转字符串
  200. const url = this.exData.id ? '/v1/user/member/song/modify' : ''
  201. this.$refs.form.validate(async valid => {
  202. if (valid) {
  203. const data = await this.$fetch(url, {
  204. ...this.form,
  205. place_price: yuan2Fen(this.form.place_price)
  206. })
  207. if (data.code === 200) {
  208. this.$message.success('提交成功')
  209. this.$emit('success')
  210. this.dialog = false
  211. }
  212. }
  213. })
  214. }
  215. },
  216. mounted () {
  217. if (this.exData.id) {
  218. this.$set(this.form, 'id', this.exData.id)
  219. for (const key in this.exData) {
  220. if (this.form.hasOwnProperty(key)) {
  221. let value = this.exData[key]
  222. if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
  223. if (key === 'place_price') {
  224. value = fen2Yuan(value)
  225. }
  226. this.$set(this.form, key, value)
  227. }
  228. }
  229. }
  230. }
  231. },
  232. watch: {
  233. dialog (val) {
  234. if (!val) this.$emit('input', val)
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss" scoped>
  240. .top-tip {
  241. margin-top: -20px;
  242. margin-bottom: 20px;
  243. }
  244. </style>