裂变星小程序-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.

321 lines
8.5 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" inputWidth="80rpx"></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" inputWidth="80rpx"></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: 50,
  143. num: 0,
  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: '请设置转发次数(大于1)',
  171. validator: (rule, value, callback) => {
  172. if (value > 1) {
  173. return true
  174. }
  175. return false;
  176. },
  177. },
  178. 'wxCodeImage': {
  179. type: 'string',
  180. required: true,
  181. message: '请选择二维码',
  182. },
  183. },
  184. }
  185. },
  186. computed: {
  187. ...mapState(['configList', 'userInfo']),
  188. userId() {
  189. return this.form.userId || this.userInfo?.id
  190. },
  191. },
  192. onLoad(option) {
  193. const { id } = option
  194. if (!id) {
  195. this.form.headImage = this.configList.index_sign
  196. return
  197. }
  198. this.id = id
  199. this.fetchDetails(id)
  200. },
  201. onReady() {
  202. this.$refs.form.setRules(this.rules);
  203. },
  204. onShareAppMessage(res) {
  205. const {
  206. headTitle,
  207. indexImage,
  208. } = this.form
  209. let o = {
  210. title : headTitle,
  211. imageUrl: indexImage,
  212. path: `/pages_order/sharing/group?id=${this.id}&state=2&shareId=${this.userInfo.id}`
  213. }
  214. // todo: get times and check is unlocked
  215. this.isLocked = false
  216. return o
  217. },
  218. methods: {
  219. async fetchDetails(id) {
  220. try {
  221. const result = await this.$fetch('getGroupShareInfo', { id })
  222. const {
  223. userId,
  224. headImage,
  225. headTitle,
  226. indexImage,
  227. memberNum,
  228. num,
  229. wxCodeImage,
  230. status,
  231. } = result || {}
  232. this.form = {
  233. userId,
  234. headImage,
  235. headTitle,
  236. indexImage,
  237. memberNum,
  238. num,
  239. wxCodeImage,
  240. }
  241. this.status = status
  242. } catch (err) {
  243. }
  244. },
  245. async onSubmit() {
  246. try {
  247. await this.$refs.form.validate()
  248. const {
  249. headImage,
  250. headTitle,
  251. indexImage,
  252. memberNum,
  253. num,
  254. wxCodeImage,
  255. } = this.form
  256. const params = {
  257. userId: this.userId,
  258. headImage,
  259. headTitle,
  260. indexImage,
  261. memberNum,
  262. num,
  263. wxCodeImage,
  264. }
  265. if (this.id) {
  266. params.id = this.id
  267. }
  268. await this.$fetch('saveOrUpdateGroupShare', params)
  269. uni.showToast({
  270. title: '提交成功',
  271. icon: 'none'
  272. })
  273. setTimeout(uni.navigateBack, 1000, -1)
  274. } catch (err) {
  275. }
  276. },
  277. onPublish() {
  278. // todo
  279. },
  280. }
  281. }
  282. </script>
  283. <style scoped lang="scss">
  284. @import '../styles/pageForm.scss';
  285. .button-submit {
  286. margin: 0;
  287. position: fixed;
  288. bottom: 138rpx;
  289. left: 20rpx;
  290. width: calc(100% - 40rpx);
  291. height: 90rpx;
  292. }
  293. </style>