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

343 lines
8.7 KiB

1 week ago
  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. <button
  34. class="btn-avatar"
  35. :plain="true"
  36. :hairline="false"
  37. open-type="chooseAvatar"
  38. @chooseavatar="onChooseAvatar"
  39. >
  40. <image
  41. :src="form.headImage || '../static/auth/avatar.png'"
  42. style="width: 68rpx; height: 68rpx;"
  43. mode=""
  44. ></image>
  45. </button>
  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="num">
  77. <view class="form-item-content">
  78. <formNumberBox v-model="form.num" ></formNumberBox>
  79. </view>
  80. </uv-form-item>
  81. </view>
  82. <view class="form-item">
  83. <uv-form-item label="选择二维码" prop="wxCodeImage">
  84. <view class="form-item-content">
  85. <formUpload v-model="form.wxCodeImage">
  86. <template v-slot="{ value }">
  87. <view class="flex" style="min-width: 93rpx; height: 45rpx;">
  88. <image
  89. :src="value"
  90. mode="aspectFill"
  91. style="width: 45rpx; height: 45rpx;"
  92. radius="14rpx"
  93. />
  94. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  95. </view>
  96. </template>
  97. </formUpload>
  98. </view>
  99. </uv-form-item>
  100. </view>
  101. <view class="form-item">
  102. <uv-form-item label="文案描述" prop="textDetails" labelPosition="top">
  103. <view style="margin-top: 32rpx;">
  104. <formTextarea
  105. v-model="form.textDetails"
  106. placeholder="请输入你的文案"
  107. ></formTextarea>
  108. </view>
  109. </uv-form-item>
  110. </view>
  111. </uv-form>
  112. </view>
  113. <!-- 审核通过 -->
  114. <button v-if="status === 1" class="button-submit" open-type="share">
  115. 发布
  116. </button>
  117. <!-- 不是 审核中 已发布 -> 创建分享 审核不通过 -->
  118. <button v-else-if="![0,1].includes(status)" class="button-submit" @click="onSubmit">
  119. 提交审核
  120. </button>
  121. </view>
  122. </template>
  123. <script>
  124. import { mapState } from 'vuex'
  125. import formInput from '../components/formInput.vue'
  126. import formNumberBox from '../components/formNumberBox.vue'
  127. import formUpload from '../components/formUpload.vue'
  128. import formTextarea from '../components/formTextarea.vue'
  129. export default {
  130. components: {
  131. formInput,
  132. formNumberBox,
  133. formUpload,
  134. formTextarea,
  135. },
  136. data() {
  137. return {
  138. id: null,
  139. status: null,
  140. form: {
  141. userId: null,
  142. headImage: null,
  143. headTitle: null,
  144. indexImage: null,
  145. num: 0,
  146. wxCodeImage: null,
  147. textDetails: null,
  148. },
  149. rules: {
  150. 'headImage': {
  151. type: 'string',
  152. required: true,
  153. message: '请选择头像',
  154. },
  155. 'headTitle': {
  156. type: 'string',
  157. required: true,
  158. message: '请输入你的昵称',
  159. },
  160. 'indexImage': {
  161. type: 'string',
  162. required: true,
  163. message: '请选择封面图',
  164. },
  165. 'num': {
  166. type: 'number',
  167. required: true,
  168. message: '请设置转发次数(大于0)',
  169. validator: (rule, value, callback) => {
  170. if (value > 0) {
  171. return true
  172. }
  173. return false;
  174. },
  175. },
  176. 'wxCodeImage': {
  177. type: 'string',
  178. required: true,
  179. message: '请选择二维码',
  180. },
  181. 'textDetails': {
  182. type: 'string',
  183. required: true,
  184. message: '请输入你的文案',
  185. },
  186. },
  187. }
  188. },
  189. computed: {
  190. ...mapState(['userInfo']),
  191. userId() {
  192. return this.userInfo?.intentionCode
  193. },
  194. },
  195. onLoad(option) {
  196. const { id } = option
  197. if (!id) {
  198. return
  199. }
  200. this.id = id
  201. this.fetchDetails(id)
  202. },
  203. onReady() {
  204. this.$refs.form.setRules(this.rules);
  205. },
  206. onShareAppMessage(res) {
  207. const {
  208. textDetails,
  209. indexImage,
  210. } = this.form
  211. let o = {
  212. title : textDetails,
  213. imageUrl: indexImage,
  214. path: `/pages_order/sharing/personal?id=${this.id}&state=0&shareId=${this.userInfo.id}`
  215. }
  216. //调用增加分享次数的方法
  217. const params = {
  218. id:this.id,
  219. state:"0",
  220. }
  221. this.$fetch('addLogShareInfo', params)
  222. this.isLocked = false
  223. return o
  224. },
  225. methods: {
  226. onChooseAvatar(res) {
  227. this.$Oss.ossUpload(res.target.avatarUrl)
  228. .then(url => {
  229. this.form.headImage = url
  230. })
  231. },
  232. async fetchDetails(id) {
  233. try {
  234. const result = await this.$fetch('getShareInfo', { id })
  235. const {
  236. userId,
  237. headImage,
  238. headTitle,
  239. indexImage,
  240. num,
  241. wxCodeImage,
  242. textDetails,
  243. status,
  244. } = result || {}
  245. this.form = {
  246. userId,
  247. headImage,
  248. headTitle,
  249. indexImage,
  250. num,
  251. wxCodeImage,
  252. textDetails,
  253. }
  254. this.status = status
  255. } catch (err) {
  256. }
  257. },
  258. async onSubmit() {
  259. try {
  260. await this.$refs.form.validate()
  261. const {
  262. headImage,
  263. headTitle,
  264. indexImage,
  265. num,
  266. wxCodeImage,
  267. textDetails,
  268. } = this.form
  269. const params = {
  270. userId: this.userId,
  271. headImage,
  272. headTitle,
  273. indexImage,
  274. num,
  275. wxCodeImage,
  276. textDetails,
  277. }
  278. if (this.id) {
  279. params.id = this.id
  280. }
  281. await this.$fetch('saveOrUpdateShare', params)
  282. uni.showToast({
  283. title: '提交成功',
  284. icon: 'none'
  285. })
  286. setTimeout(uni.navigateBack, 1000, -1)
  287. } catch (err) {
  288. }
  289. },
  290. }
  291. }
  292. </script>
  293. <style scoped lang="scss">
  294. @import '../styles/pageForm.scss';
  295. .btn-avatar {
  296. background: transparent;
  297. border: none;
  298. border-radius: none;
  299. box-shadow: none;
  300. padding: 0;
  301. margin: 0;
  302. font-size: 0;
  303. text-align: right;
  304. }
  305. .button-submit {
  306. margin: 0;
  307. position: fixed;
  308. bottom: 138rpx;
  309. left: 20rpx;
  310. width: calc(100% - 40rpx);
  311. height: 90rpx;
  312. }
  313. </style>