裂变星小程序-25.03.04
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

307 lines
8.1 KiB

  1. <template>
  2. <view class="page">
  3. <navbar title="群分享" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <uv-form
  6. ref="form"
  7. :model="form"
  8. :rules="rules"
  9. labelPosition="left"
  10. labelWidth="300rpx"
  11. :labelStyle="{
  12. color: '#1B1B1B',
  13. fontSize: '32rpx',
  14. fontWeight: 'bold',
  15. }"
  16. errorType="toast"
  17. >
  18. <view class="form-item">
  19. <uv-form-item label="用户ID" prop="userId">
  20. <view class="form-item-content">
  21. <text>{{ userId }}</text>
  22. <view style="margin-left: 20rpx;">
  23. <button class="btn-simple" plain @click="$utils.copyText(userId)">
  24. <uv-icon name="file-text" color="#05D9A2" size="28rpx"></uv-icon>
  25. </button>
  26. </view>
  27. </view>
  28. </uv-form-item>
  29. </view>
  30. <view class="form-item">
  31. <uv-form-item label="选择群头像" prop="headImage">
  32. <view class="form-item-content">
  33. <formUpload v-model="form.headImage">
  34. <template v-slot="{ value }">
  35. <view class="flex" style="min-width: 116rpx; height: 45rpx;">
  36. <image
  37. :src="value"
  38. mode="aspectFill"
  39. style="width: 68rpx; height: 68rpx;"
  40. radius="14rpx"
  41. />
  42. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  43. </view>
  44. </template>
  45. </formUpload>
  46. </view>
  47. </uv-form-item>
  48. </view>
  49. <view class="form-item">
  50. <uv-form-item label="群名称" labelWidth="105rpx" prop="headTitle">
  51. <view class="form-item-content">
  52. <formInput v-model="form.headTitle" placeholder="请输入你的群名称" width="540rpx"></formInput>
  53. </view>
  54. </uv-form-item>
  55. </view>
  56. <view class="form-item">
  57. <uv-form-item label="选择群封面图" prop="indexImage">
  58. <view class="form-item-content">
  59. <formUpload v-model="form.indexImage">
  60. <template v-slot="{ value }">
  61. <view class="flex" style="min-width: 116rpx; height: 45rpx;">
  62. <image
  63. :src="value"
  64. mode="aspectFill"
  65. style="width: 68rpx; height: 68rpx;"
  66. radius="14rpx"
  67. />
  68. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  69. </view>
  70. </template>
  71. </formUpload>
  72. </view>
  73. </uv-form-item>
  74. </view>
  75. <view class="form-item">
  76. <uv-form-item label="群人数(人)" prop="memberNum">
  77. <view class="form-item-content">
  78. <formNumberBox v-model="form.memberNum" :min="3"></formNumberBox>
  79. </view>
  80. </uv-form-item>
  81. </view>
  82. <view class="form-item">
  83. <uv-form-item label="设置转发次数(次)" prop="num">
  84. <view class="form-item-content">
  85. <formNumberBox v-model="form.num"></formNumberBox>
  86. </view>
  87. </uv-form-item>
  88. </view>
  89. <view class="form-item">
  90. <uv-form-item label="选择二维码" prop="wxCodeImage">
  91. <view class="form-item-content">
  92. <formUpload v-model="form.wxCodeImage">
  93. <template v-slot="{ value }">
  94. <view class="flex" style="min-width: 93rpx; height: 45rpx;">
  95. <image
  96. :src="value"
  97. mode="aspectFill"
  98. style="width: 45rpx; height: 45rpx;"
  99. radius="14rpx"
  100. />
  101. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  102. </view>
  103. </template>
  104. </formUpload>
  105. </view>
  106. </uv-form-item>
  107. </view>
  108. </uv-form>
  109. </view>
  110. <!-- 审核通过 -->
  111. <button v-if="status === 1" class="button-submit" open-type="share">
  112. 发布
  113. </button>
  114. <!-- 不是 审核中 已发布 -> 创建分享 审核不通过 -->
  115. <button v-else-if="![0,1].includes(status)" class="button-submit" @click="onSubmit">
  116. 提交审核
  117. </button>
  118. </view>
  119. </template>
  120. <script>
  121. import { mapState } from 'vuex'
  122. import formInput from '../components/formInput.vue'
  123. import formNumberBox from '../components/formNumberBox.vue'
  124. import formUpload from '../components/formUpload.vue'
  125. import formTextarea from '../components/formTextarea.vue'
  126. export default {
  127. components: {
  128. formInput,
  129. formNumberBox,
  130. formUpload,
  131. formTextarea,
  132. },
  133. data() {
  134. return {
  135. id: null,
  136. status: null,
  137. form: {
  138. userId: null,
  139. headImage: null,
  140. headTitle: null,
  141. indexImage: null,
  142. memberNum: 200,
  143. num: 10,
  144. wxCodeImage: null,
  145. },
  146. rules: {
  147. 'headImage': {
  148. type: 'string',
  149. required: true,
  150. message: '请选择群封面图',
  151. },
  152. 'headTitle': {
  153. type: 'string',
  154. required: true,
  155. message: '请输入你的群名称',
  156. },
  157. 'indexImage': {
  158. type: 'string',
  159. required: true,
  160. message: '请选择群封面图',
  161. },
  162. 'memberNum': {
  163. type: 'number',
  164. required: true,
  165. message: '请填写群人数',
  166. },
  167. 'num': {
  168. type: 'number',
  169. required: true,
  170. message: '请设置转发次数',
  171. },
  172. 'wxCodeImage': {
  173. type: 'string',
  174. required: true,
  175. message: '请选择二维码',
  176. },
  177. },
  178. }
  179. },
  180. computed: {
  181. ...mapState(['userInfo']),
  182. userId() {
  183. return this.form.userId || this.userInfo?.id
  184. },
  185. },
  186. onLoad(option) {
  187. const { id } = option
  188. if (!id) {
  189. return
  190. }
  191. this.id = id
  192. this.fetchDetails(id)
  193. },
  194. onShareAppMessage(res) {
  195. const {
  196. headTitle,
  197. indexImage,
  198. } = this.form
  199. let o = {
  200. title : headTitle,
  201. imageUrl: indexImage,
  202. path: `/pages_order/sharing/group?id=${this.id}`
  203. }
  204. // todo: get times and check is unlocked
  205. this.isLocked = false
  206. return o
  207. },
  208. methods: {
  209. async fetchDetails(id) {
  210. try {
  211. const result = await this.$fetch('getGroupShareInfo', { id })
  212. const {
  213. userId,
  214. headImage,
  215. headTitle,
  216. indexImage,
  217. memberNum,
  218. num,
  219. wxCodeImage,
  220. status,
  221. } = result || {}
  222. this.form = {
  223. userId,
  224. headImage,
  225. headTitle,
  226. indexImage,
  227. memberNum,
  228. num,
  229. wxCodeImage,
  230. }
  231. this.status = status
  232. } catch (err) {
  233. }
  234. },
  235. async onSubmit() {
  236. try {
  237. await this.$refs.form.validate()
  238. const {
  239. headImage,
  240. headTitle,
  241. indexImage,
  242. memberNum,
  243. num,
  244. wxCodeImage,
  245. } = this.form
  246. const params = {
  247. id: this.id,
  248. userId: this.userId,
  249. headImage,
  250. headTitle,
  251. indexImage,
  252. memberNum,
  253. num,
  254. wxCodeImage,
  255. }
  256. await this.$fetch('saveOrUpdateGroupShare', params)
  257. uni.showToast({
  258. title: '提交成功',
  259. icon: 'none'
  260. })
  261. setTimeout(uni.navigateBack, 1000, -1)
  262. } catch (err) {
  263. }
  264. },
  265. onPublish() {
  266. // todo
  267. },
  268. }
  269. }
  270. </script>
  271. <style scoped lang="scss">
  272. @import '../styles/pageForm.scss';
  273. .button-submit {
  274. margin: 0;
  275. position: fixed;
  276. bottom: 138rpx;
  277. left: 20rpx;
  278. width: calc(100% - 40rpx);
  279. height: 90rpx;
  280. }
  281. </style>