index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <view class="red-envelope-distribution-container">
  3. <JHeader tabbar="/pages/tabbar/user/index" width="50" height="50" title="红包发放"></JHeader>
  4. <view style="font-size: 30upx;">
  5. <!-- <view class="line-item" @click="$jump('/user/marketing-tools/red-envelope-distribution/publication-type')">
  6. <view>发布类型</view>
  7. <input v-model="redForm.wrapName" disabled placeholder="请选择发布类型" class="input-el" placeholder-style="color:#9F9F9F" />
  8. </view> -->
  9. <!-- <view class="line-item">
  10. <view>发布者名称</view>
  11. <input v-model="redForm.publisherName" type="text" placeholder="请输入发布者名称" class="input-el" placeholder-style="color:#9F9F9F" />
  12. </view> -->
  13. <view class="line-item">
  14. <text>红包类型</text>
  15. <tui-radio-group
  16. v-model="redForm.wrapType"
  17. style="flex: 1;display: flex;justify-content: flex-end;flex-wrap: wrap;"
  18. @change="(e) => {}"
  19. >
  20. <block v-if="userInfo.roleIds === 6 && brandId">
  21. <tui-label
  22. v-for="(part, index) in [{ name: '普通红包', value: '0' }, { name: '携带优惠券红包', value: '1' }]"
  23. :key="index"
  24. >
  25. <tui-list-cell padding="16upx">
  26. <view>
  27. <tui-radio :checked="false" :value="part.value" color="#07c160" border-color="#999">
  28. </tui-radio>
  29. <text>{{ part.name }}</text>
  30. </view>
  31. </tui-list-cell>
  32. </tui-label>
  33. </block>
  34. <block v-else>
  35. <tui-label
  36. v-for="(part, index) in [ { name: '普通红包', value: '0' } ]"
  37. :key="index"
  38. >
  39. <tui-list-cell padding="16upx">
  40. <view>
  41. <tui-radio :checked="false" :value="part.value" color="#07c160" border-color="#999">
  42. </tui-radio>
  43. <text>{{ part.name }}</text>
  44. </view>
  45. </tui-list-cell>
  46. </tui-label>
  47. </block>
  48. </tui-radio-group>
  49. </view>
  50. <view
  51. v-if="userInfo.roleIds === 6 && brandId && redForm.wrapType === '1'" class="line-item"
  52. @click="isShowCouponPopup = true"
  53. >
  54. <view>红包关联优惠券</view>
  55. <input
  56. v-model="redForm.couponName" disabled placeholder="请选择发布类型" class="input-el"
  57. placeholder-style="color:#9F9F9F"
  58. />
  59. </view>
  60. <view v-if="userInfo.roleIds === 6 && brandId" class="line-item" @click="isShowStoreGoodsPopup = true">
  61. <view>红包关联商品</view>
  62. <input
  63. v-model="redForm.goodsName" disabled placeholder="请选择发布类型" class="input-el"
  64. placeholder-style="color:#9F9F9F"
  65. />
  66. </view>
  67. <view class="line-item">
  68. <view>红包金额</view>
  69. <input
  70. v-model.number="redForm.redpackAllmonkey" type="digit" placeholder="请输入红包金额" class="input-el"
  71. placeholder-style="color:#9F9F9F"
  72. />
  73. <view class="company">元</view>
  74. </view>
  75. <view class="line-item">
  76. <view>红包个数</view>
  77. <input
  78. v-model.number="redForm.redpackNumber" type="number" placeholder="请输入红包个数" class="input-el"
  79. placeholder-style="color:#9F9F9F"
  80. />
  81. <view class="company">个</view>
  82. </view>
  83. <view class="line-item">
  84. <text>红包金额</text>
  85. <tui-radio-group
  86. v-model="redForm.wrapType"
  87. style="flex: 1;display: flex;justify-content: flex-end;flex-wrap: wrap;"
  88. @change="(e) => {}"
  89. >
  90. <tui-label
  91. v-for="(part, index) in [{ name: '随机', value: '1' }, { name: '等额', value: '0' }]"
  92. :key="index"
  93. >
  94. <tui-list-cell padding="16upx">
  95. <view>
  96. <tui-radio :checked="false" :value="part.value" color="#07c160" border-color="#999">
  97. </tui-radio>
  98. <text>{{ part.name }}</text>
  99. </view>
  100. </tui-list-cell>
  101. </tui-label>
  102. </tui-radio-group>
  103. </view>
  104. <view class="line-item" @click="handleChooseRange">
  105. <view>红包范围</view>
  106. <view class="input-el">
  107. {{ redForm.effectiveDistance | filterEffectiveDistance }}
  108. </view>
  109. </view>
  110. <view class="line-item" @click="handleChooseRedPackLocation">
  111. <view>红包位置</view>
  112. <input
  113. v-model="redPackAddress" readonly disabled placeholder="请选择红包位置"
  114. class="input-el"
  115. placeholder-style="color:#9F9F9F"
  116. />
  117. </view>
  118. <view style="margin-top: 40upx;">
  119. <view class="title-form">红包内容</view>
  120. <textarea
  121. v-model.trim="redForm.publisherText" placeholder="(留言15字符以内)" class="rich-text" cols="30"
  122. rows="10"
  123. maxlength="15"
  124. ></textarea>
  125. </view>
  126. <view style="margin-top: 40upx;">
  127. <view class="title-form">
  128. 红包图片
  129. <button v-show="redForm.picUrl" class="preview" @click="handlePreview">
  130. 红包预览
  131. </button>
  132. </view>
  133. <view class="upload-pane">
  134. <view class="left">
  135. <view v-if="!redForm.picUrl" class="upload" @click="chooseImg">+</view>
  136. <image v-else class="iamge-background" :src="redForm.picUrl" mode="" />
  137. </view>
  138. <image
  139. v-show="redForm.picUrl" class="delete-icon" src="../../../static/images/icon/delete-box.png"
  140. mode="" @click="removeBackground"
  141. />
  142. </view>
  143. </view>
  144. </view>
  145. <button class="sendRedPackage" @click="handleConfirm">确定</button>
  146. <view ref="previewWrapperRef" class="preview-wrapper">
  147. <JRedEnvelope
  148. :is-show="showRedPackage" :show-type="redEnvelopeType" :desc="redForm.publisherText"
  149. :src="redForm.picUrl" :name="userInfo.nickName" :avatar="userInfo.avatarUrl"
  150. @click-red="redEnvelopeType = 1" @close="(showRedPackage = false) || (redEnvelopeType = 0) || closePreview()"
  151. >
  152. </JRedEnvelope>
  153. </view>
  154. <!-- 优惠券选择 -->
  155. <view v-if="userInfo.roleIds === 6 && brandId">
  156. <tui-bottom-popup :show="isShowCouponPopup" @close="isShowCouponPopup = false">
  157. <BrandCouponList :brand-id="brandId" btn-text="选择" @click-btn="handleSelectCoupon">
  158. </BrandCouponList>
  159. </tui-bottom-popup>
  160. </view>
  161. <!-- 商品选择 -->
  162. <view v-if="userInfo.roleIds === 6 && brandId">
  163. <tui-bottom-popup :show="isShowStoreGoodsPopup" @close="isShowStoreGoodsPopup = false">
  164. <BrandGoodsList v-if="isShowStoreGoodsPopup" :brand-id="brandId" @send="handleSend"></BrandGoodsList>
  165. </tui-bottom-popup>
  166. </view>
  167. </view>
  168. </template>
  169. <script>
  170. import { J_STORAGE_KEY } from '../../../config/constant'
  171. import { handleDoPay } from '../../../utils/payUtil'
  172. import { addWrapRedReleaseApi } from '../../../api/user'
  173. export default {
  174. name: 'RedEnvelopeDistribution',
  175. onLoad(option) {
  176. // uni.$on('sendWrapMsg', (data) => {
  177. // console.log(data)
  178. // this.redForm.wrapType = data.data.wrapType
  179. // this.redForm.wrapName = data.data.wrapName
  180. // this.redForm.magicId = data.data.magicId
  181. // })
  182. },
  183. onShow() {
  184. },
  185. onUnload(option) {
  186. // uni.$off('sendWrapMsg', function (data) {
  187. // console.log(data)
  188. // })
  189. },
  190. filters: {
  191. filterEffectiveDistance(value) {
  192. const items = [
  193. {
  194. label: '1km',
  195. value: 1
  196. },
  197. {
  198. label: '2km',
  199. value: 2
  200. },
  201. {
  202. label: '3km',
  203. value: 3
  204. },
  205. {
  206. label: '4km',
  207. value: 4
  208. },
  209. {
  210. label: '5km',
  211. value: 5
  212. }
  213. ]
  214. const item = items.find((item) => item.value === value)
  215. if (item) {
  216. return item.label
  217. }
  218. return '--'
  219. }
  220. },
  221. data() {
  222. return {
  223. redForm: {
  224. wrapType: '',
  225. // wrapName: '',
  226. // magicId: '',
  227. // publisherName: '',
  228. redpackAllmonkey: '',
  229. redpackNumber: '',
  230. type: '0',
  231. effectiveDistance: 1,
  232. latitude: null,
  233. longitude: null,
  234. publisherText: '',
  235. picUrl: '',
  236. bindLink: '',
  237. goodsName: '',
  238. business: '',
  239. couponName: ''
  240. },
  241. redPackAddress: '',
  242. userInfo: uni.getStorageSync(J_STORAGE_KEY) || {},
  243. brandId: uni.getStorageSync(J_STORAGE_KEY) ? uni.getStorageSync(J_STORAGE_KEY).brandId : '',
  244. showRedPackage: false,
  245. redEnvelopeType: 0,
  246. isShowCouponPopup: false,
  247. isShowStoreGoodsPopup: false
  248. }
  249. },
  250. methods: {
  251. handleSend(obj) {
  252. this.isShowStoreGoodsPopup = false
  253. this.redForm.bindLink = obj.id
  254. this.redForm.goodsName = obj.name
  255. },
  256. handleSelectCoupon(obj) {
  257. this.isShowCouponPopup = false
  258. this.redForm.business = obj.id
  259. this.redForm.couponName = obj.name
  260. },
  261. // 删除红包图片
  262. removeBackground() {
  263. const _this = this
  264. uni.showModal({
  265. title: '提示',
  266. content: '确定删除当前红包图片吗?',
  267. success(res) {
  268. if (res.confirm) {
  269. _this.redForm.picUrl = ''
  270. }
  271. }
  272. })
  273. },
  274. // 选择图片
  275. chooseImg() {
  276. uni.chooseImage({
  277. count: 1,
  278. success: (chooseImageRes) => {
  279. uni.uploadFile({
  280. url: 'https://nsappapi.tuanfengkeji.cn/wx/storage/upload',
  281. filePath: chooseImageRes.tempFiles[0].path,
  282. name: 'file',
  283. success: (uploadFileRes) => {
  284. this.redForm.picUrl = JSON.parse(uploadFileRes.data).data.url
  285. // this.$refs.previewWrapperRef.$el.style.transform = 'scale(1)'
  286. }
  287. })
  288. }
  289. })
  290. },
  291. handleChooseRedPackLocation() {
  292. uni.chooseLocation({
  293. success: (res) => {
  294. this.redPackAddress = res.name
  295. this.redForm.latitude = res.latitude
  296. this.redForm.longitude = res.longitude
  297. }
  298. })
  299. },
  300. // 发送红包
  301. handleConfirm() {
  302. // if ((this.redForm.wrapType === undefined || this.redForm.wrapType === '' || this.redForm.wrapType === null) || !this.redForm.magicId) {
  303. // this.$showToast('请选择发布类型')
  304. // return
  305. // }
  306. if (this.redForm.wrapType === undefined || this.redForm.wrapType === '' || this.redForm.wrapType === null) {
  307. this.$showToast('请选择红包类型')
  308. return
  309. }
  310. if (
  311. !this.redForm.redpackNumber ||
  312. typeof this.redForm.redpackNumber !== 'number' ||
  313. this.redForm.redpackNumber <= 0
  314. ) {
  315. this.$showToast('请输入正确的红包个数')
  316. return
  317. }
  318. if (this.redForm.redpackNumber < 2) {
  319. this.$showToast('红包数量至少两个哟~')
  320. return
  321. }
  322. if (
  323. !this.redForm.redpackAllmonkey ||
  324. typeof this.redForm.redpackAllmonkey !== 'number'
  325. ) {
  326. this.$showToast('请输入正确的红包金额')
  327. return
  328. }
  329. if (this.redForm.redpackAllmonkey < 0.2) {
  330. this.$showToast('红包金额不能小于0.2')
  331. }
  332. if (!this.redForm.latitude || !this.redForm.longitude) {
  333. this.$showToast('请选择红包位置')
  334. return
  335. }
  336. if (!this.redForm.type) {
  337. this.$showToast('请选择红包金额选项')
  338. return
  339. }
  340. const data = {
  341. // publisherName: this.redForm.publisherName,
  342. wrapType: this.redForm.wrapType,
  343. latitude: this.redForm.latitude,
  344. longitude: this.redForm.longitude,
  345. // magicId: this.redForm.magicId, // 去除
  346. redpackNumber: this.redForm.redpackNumber,
  347. redpackAllmonkey: this.redForm.redpackAllmonkey,
  348. // imageUrl: this.redForm.imageUrl, // 去除
  349. // remark: this.redForm.remark, // 去除
  350. effectiveDistance: this.redForm.effectiveDistance || 1,
  351. type: this.redForm.type,
  352. brandId: this.brandId || '',
  353. wrapRedText: {
  354. publisherText: this.redForm.publisherText,
  355. bindLink: this.redForm.bindLink,
  356. business: this.redForm.wrapType === '1' ? this.redForm.business : '',
  357. picUrl: this.redForm.picUrl
  358. }
  359. }
  360. addWrapRedReleaseApi(data)
  361. .then((res) => {
  362. if (res.errno !== 0) {
  363. uni.showToast({
  364. title: '红包发送失败',
  365. duration: 2000,
  366. icon: 'none'
  367. })
  368. return
  369. }
  370. handleDoPay({ orderSn: res.data }, 5)
  371. })
  372. .catch(() => {
  373. this.$showToast('红包发送失败')
  374. })
  375. },
  376. // 预览红包
  377. handlePreview() {
  378. this.showRedPackage = true
  379. this.$refs.previewWrapperRef.$el.style.transform = 'scale(1)'
  380. },
  381. // 关闭预览弹窗
  382. closePreview() {
  383. this.$refs.previewWrapperRef.$el.style.transform = 'translateX(-100%)'
  384. },
  385. // 点击选择范围
  386. handleChooseRange() {
  387. uni.showActionSheet({
  388. itemList: ['1km', '2km', '3km', '4km', '5km'],
  389. success: (res) => {
  390. console.log(res)
  391. this.redForm.effectiveDistance = res.tapIndex + 1
  392. }
  393. })
  394. }
  395. }
  396. }
  397. </script>
  398. <style lang="less" scoped>
  399. .red-envelope-distribution-container {
  400. padding: 40upx;
  401. box-sizing: border-box;
  402. .line-item {
  403. margin-top: 40upx;
  404. display: flex;
  405. align-items: center;
  406. padding: 20upx 0;
  407. padding-right: 20upx;
  408. border-bottom: 1px solid #D8D8D8;
  409. .input-el {
  410. text-align: right;
  411. flex: 1;
  412. font-size: 24upx;
  413. margin-right: 10upx;
  414. }
  415. }
  416. .title-form {
  417. margin: 28upx 0;
  418. .preview {
  419. margin: 0;
  420. padding: 0;
  421. width: auto;
  422. font-size: 24upx;
  423. line-height: 1;
  424. display: inline;
  425. background-color: transparent;
  426. border: none !important;
  427. float: right;
  428. padding: 0 4upx;
  429. color: #07b9b9;
  430. transition: all 350ms;
  431. }
  432. }
  433. .rich-text {
  434. width: 100%;
  435. height: 264upx;
  436. border: 1upx solid #d8d8d8;
  437. border-radius: 20upx;
  438. padding: 28upx 16upx;
  439. box-sizing: border-box;
  440. font-size: 24upx;
  441. /deep/ .uni-textarea-placeholder {
  442. font-size: 24upx;
  443. color: #999;
  444. }
  445. }
  446. .upload-pane {
  447. border: 1upx solid #d8d8d8;
  448. padding: 32upx 24upx;
  449. box-sizing: border-box;
  450. border-radius: 20upx;
  451. display: flex;
  452. justify-content: space-between;
  453. align-items: flex-end;
  454. .delete-icon {
  455. width: 32upx;
  456. height: 36upx;
  457. }
  458. .left {
  459. display: flex;
  460. align-items: center;
  461. }
  462. .upload {
  463. margin: 0;
  464. width: 160upx;
  465. height: 160upx;
  466. background-color: #d8d8d8;
  467. border-radius: 20upx;
  468. color: #767676;
  469. text-align: center;
  470. line-height: 160upx;
  471. font-size: 60upx;
  472. }
  473. .iamge-background {
  474. width: 160upx;
  475. height: 160upx;
  476. object-fit: cover;
  477. }
  478. }
  479. .sendRedPackage {
  480. width: 100%;
  481. height: 72upx;
  482. line-height: 72upx;
  483. background-color: #fa5151;
  484. color: #fff;
  485. font-size: 32upx;
  486. padding: 0;
  487. border-radius: 100px;
  488. margin-top: 100upx;
  489. }
  490. .preview-wrapper {
  491. position: fixed;
  492. top: 0;
  493. left: 0;
  494. width: 100vw;
  495. height: 100vh;
  496. // background-color: rgb(255, 255, 255);
  497. transition: all 350ms;
  498. // .flex(center, center);
  499. // flex-direction: column;
  500. // padding: 0 40upx;
  501. box-sizing: border-box;
  502. transform: scale(0);
  503. transition: all 350ms;
  504. }
  505. /deep/ .tui-popup-class.tui-bottom-popup {
  506. height: 85vh !important;
  507. }
  508. }
  509. </style>