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

358 lines
9.1 KiB

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