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

355 lines
9.0 KiB

2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months 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="preSubmit">
  119. 提交审核
  120. </button>
  121. <autoCrop ref="autoCropRef" @change="onSubmit"></autoCrop>
  122. </view>
  123. </template>
  124. <script>
  125. import { mapState } from 'vuex'
  126. import formInput from '../components/formInput.vue'
  127. import formNumberBox from '../components/formNumberBox.vue'
  128. import formUpload from '../components/formUpload.vue'
  129. import formTextarea from '../components/formTextarea.vue'
  130. import autoCrop from '../components/autoCrop.vue'
  131. export default {
  132. components: {
  133. formInput,
  134. formNumberBox,
  135. formUpload,
  136. formTextarea,
  137. autoCrop,
  138. },
  139. data() {
  140. return {
  141. id: null,
  142. status: null,
  143. form: {
  144. userId: null,
  145. headImage: null,
  146. headTitle: null,
  147. indexImage: null,
  148. num: 0,
  149. wxCodeImage: null,
  150. textDetails: null,
  151. },
  152. rules: {
  153. 'headImage': {
  154. type: 'string',
  155. required: true,
  156. message: '请选择头像',
  157. },
  158. 'headTitle': {
  159. type: 'string',
  160. required: true,
  161. message: '请输入你的昵称',
  162. },
  163. 'indexImage': {
  164. type: 'string',
  165. required: true,
  166. message: '请选择封面图',
  167. },
  168. 'num': {
  169. type: 'number',
  170. required: true,
  171. message: '请设置转发次数(大于0)',
  172. validator: (rule, value, callback) => {
  173. if (value > 0) {
  174. return true
  175. }
  176. return false;
  177. },
  178. },
  179. 'wxCodeImage': {
  180. type: 'string',
  181. required: true,
  182. message: '请选择二维码',
  183. },
  184. 'textDetails': {
  185. type: 'string',
  186. required: true,
  187. message: '请输入你的文案',
  188. },
  189. },
  190. }
  191. },
  192. computed: {
  193. ...mapState(['userInfo']),
  194. userId() {
  195. return this.userInfo?.intentionCode
  196. },
  197. },
  198. onLoad(option) {
  199. const { id } = option
  200. if (!id) {
  201. return
  202. }
  203. this.id = id
  204. this.fetchDetails(id)
  205. },
  206. onReady() {
  207. this.$refs.form.setRules(this.rules);
  208. },
  209. onShareAppMessage(res) {
  210. const {
  211. textDetails,
  212. indexImage,
  213. } = this.form
  214. let o = {
  215. title : textDetails,
  216. imageUrl: indexImage,
  217. path: `/pages_order/sharing/personal?id=${this.id}&state=0&shareId=${this.userInfo.id}`
  218. }
  219. //调用增加分享次数的方法
  220. const params = {
  221. id:this.id,
  222. state:"0",
  223. }
  224. this.$fetch('addLogShareInfo', params)
  225. this.isLocked = false
  226. return o
  227. },
  228. methods: {
  229. onChooseAvatar(res) {
  230. this.$Oss.ossUpload(res.target.avatarUrl)
  231. .then(url => {
  232. this.form.headImage = url
  233. })
  234. },
  235. async fetchDetails(id) {
  236. try {
  237. const result = await this.$fetch('getShareInfo', { id })
  238. const {
  239. userId,
  240. headImage,
  241. headTitle,
  242. indexImage,
  243. num,
  244. wxCodeImage,
  245. textDetails,
  246. status,
  247. } = result || {}
  248. this.form = {
  249. userId,
  250. headImage,
  251. headTitle,
  252. indexImage,
  253. num,
  254. wxCodeImage,
  255. textDetails,
  256. }
  257. this.status = status
  258. } catch (err) {
  259. }
  260. },
  261. async preSubmit() {
  262. try {
  263. await this.$refs.form.validate()
  264. this.$refs.autoCropRef.set(this.form.indexImage)
  265. } catch (err) {
  266. }
  267. },
  268. async onSubmit(indexImage) {
  269. try {
  270. await this.$refs.form.validate()
  271. const {
  272. headImage,
  273. headTitle,
  274. num,
  275. wxCodeImage,
  276. textDetails,
  277. } = this.form
  278. const params = {
  279. userId: this.userId,
  280. headImage,
  281. headTitle,
  282. indexImage,
  283. num,
  284. wxCodeImage,
  285. textDetails,
  286. }
  287. if (this.id) {
  288. params.id = this.id
  289. }
  290. await this.$fetch('saveOrUpdateShare', params)
  291. uni.showToast({
  292. title: '提交成功',
  293. icon: 'none'
  294. })
  295. setTimeout(uni.navigateBack, 1000, -1)
  296. } catch (err) {
  297. }
  298. },
  299. }
  300. }
  301. </script>
  302. <style scoped lang="scss">
  303. @import '../styles/pageForm.scss';
  304. .btn-avatar {
  305. background: transparent;
  306. border: none;
  307. border-radius: none;
  308. box-shadow: none;
  309. padding: 0;
  310. margin: 0;
  311. font-size: 0;
  312. text-align: right;
  313. }
  314. .button-submit {
  315. margin: 0;
  316. position: fixed;
  317. bottom: 138rpx;
  318. left: 20rpx;
  319. width: calc(100% - 40rpx);
  320. height: 90rpx;
  321. }
  322. </style>