share_set.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div class="container add_edit">
  3. <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px">
  4. <el-form-item label="分享标题" prop="share_title" ref="share_title"><el-input v-model="form.share_title"></el-input></el-form-item>
  5. <el-form-item label="分享图标">
  6. <uni-file-picker v-model="imageValue" fileMediatype="image" returnType="object" :image-styles="imageStyle" @success="imgUpload" @delete="imgDelete" />
  7. </el-form-item>
  8. <el-form-item label="分享描述"><el-input type="textarea" :autosize="{ minRows: 3 }" v-model="form.share_desc"></el-input></el-form-item>
  9. <el-form-item label="分享状态">
  10. <el-tooltip :content="form.state == '禁用' ? '点击启用' : '点击禁用'" placement="top" :hide-after="1000" :enterable="false" effect="light">
  11. <el-switch v-model="form.state" active-color="#ff6a6c" inactive-color="#bbb" active-value="启用" inactive-value="禁用"></el-switch>
  12. </el-tooltip>
  13. </el-form-item>
  14. <el-form-item><el-button class="confirm_btn" @click="submitForm('ruleForm')">提 交</el-button></el-form-item>
  15. </el-form>
  16. </div>
  17. </template>
  18. <script>
  19. const __name = 'usemall-app-share';
  20. export default {
  21. data() {
  22. return {
  23. dataId: '',
  24. form: {
  25. share_title: '',
  26. share_img: '',
  27. share_desc: '',
  28. state: '启用'
  29. },
  30. imageValue: null,
  31. imageStyle: {
  32. height: '150px',
  33. width: '150px'
  34. },
  35. rules: {
  36. share_title: [
  37. {
  38. required: true,
  39. message: '请输入分享标题',
  40. trigger: 'change'
  41. }
  42. ]
  43. }
  44. };
  45. },
  46. methods: {
  47. async loadData() {
  48. await this.$db[__name].tofirst().then(res => {
  49. if (res.code == 200) {
  50. for (let item in this.form) {
  51. this.form[item] = res.datas[item];
  52. }
  53. this.dataId = res.datas._id;
  54. if (this.form.share_img != '') {
  55. this.imageValue = {};
  56. this.imageValue.url = this.form.share_img;
  57. }
  58. }
  59. });
  60. },
  61. submitForm(formName) {
  62. this.$refs[formName].validate((valid, obj) => {
  63. // 默认获取第一个未验证 form 属性名
  64. this.$api.set_unvalidated_form_focus(this, obj);
  65. if (valid) {
  66. if (!this.dataId) {
  67. this.$db[__name].add(this.form).then(res => {
  68. if (res.code == 200) {
  69. this.$message({
  70. message: '操作成功',
  71. type: 'success'
  72. });
  73. this.loadData();
  74. }
  75. });
  76. } else {
  77. this.$db[__name].update(this.dataId, this.form).then(res => {
  78. if (res.code == 200) {
  79. this.$message({
  80. message: '操作成功',
  81. type: 'success'
  82. });
  83. this.loadData();
  84. }
  85. });
  86. }
  87. }
  88. });
  89. },
  90. imgUpload(e) {
  91. this.form.share_img = e.tempFilePaths[0];
  92. },
  93. imgDelete() {
  94. this.imageValue = null;
  95. this.form.share_img = '';
  96. }
  97. },
  98. created() {
  99. this.loadData();
  100. }
  101. };
  102. </script>
  103. <style></style>