detail.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. const _Http = getApp().globalData.http;
  2. import {
  3. fileList
  4. } from "../../utils/FormatTheAttachment";
  5. Page({
  6. data: {
  7. hidePrice: wx.getStorageSync('hidePrice'),
  8. loading: true,
  9. active: "",
  10. list: [],
  11. groupList: [],
  12. pageNumber: 1,
  13. pageTotal: 1,
  14. },
  15. onLoad(options) {
  16. if (options.id) this.setData({
  17. sa_promotionid: options.id
  18. })
  19. this.getDetail();
  20. },
  21. /* 获取详情 */
  22. getDetail() {
  23. _Http.basic({
  24. "id": "20221230144703",
  25. "version": 1,
  26. "content": {
  27. "sa_promotionid": this.data.sa_promotionid
  28. }
  29. }).then(res => {
  30. if (res.msg != '成功') return wx.showToast({
  31. title: res.msg,
  32. icon: "none"
  33. })
  34. this.handleFiles(res.data.attinfos)
  35. this.setData({
  36. detail: res.data,
  37. loading: false
  38. });
  39. this.getProductList();
  40. })
  41. },
  42. /* 切换商品tab */
  43. tabChange(e) {
  44. this.setData({
  45. active: e.detail.name,
  46. pageNumber: 1,
  47. pageTotal: 1
  48. });
  49. this.getProductList();
  50. },
  51. /* 获取产品列表 */
  52. getProductList() {
  53. let pageNumber = this.data.pageNumber,
  54. pageTotal = this.data.pageTotal;
  55. if (pageNumber > pageTotal) return;
  56. _Http.basic({
  57. "id": 20230116094803,
  58. "version": 1,
  59. "content": {
  60. sa_promotionid: this.data.sa_promotionid,
  61. "sa_promotion_itemgroupid": this.data.active,
  62. pageNumber,
  63. pageTotal,
  64. "where": {
  65. "condition": ""
  66. }
  67. }
  68. }).then(res => {
  69. console.log('活动产品列表', res)
  70. if (res.msg != '成功') return wx.showToast({
  71. title: res.msg,
  72. icon: "none"
  73. })
  74. res.data = res.data.map(value => {
  75. if (value.attinfos.length != 0) {
  76. value.attinfos = fileList(value.attinfos)
  77. let image = value.attinfos.find(v => v.fileType == "image");
  78. value.cover = image ? image.cover : "";
  79. }
  80. return value;
  81. })
  82. this.setData({
  83. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  84. pageNumber: res.pageNumber + 1,
  85. pageTotal: res.pageTotal
  86. })
  87. })
  88. },
  89. /* 预览图片 */
  90. viewImage(e) {
  91. const {
  92. file
  93. } = e.currentTarget.dataset;
  94. if (file.length) wx.previewMedia({
  95. sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
  96. return {
  97. url: v.url,
  98. type: v.fileType
  99. }
  100. }),
  101. current: 0,
  102. showmenu: true
  103. })
  104. },
  105. /* 预览媒体 */
  106. viewMedias(e) {
  107. const {
  108. index,
  109. type
  110. } = e.currentTarget.dataset;
  111. wx.previewMedia({
  112. current: index,
  113. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  114. })
  115. },
  116. /* 处理附件 */
  117. handleFiles(arr) {
  118. let files = {
  119. images: [],
  120. viewImages: [],
  121. videos: [],
  122. viewVideos: [],
  123. files: []
  124. },
  125. list = fileList(arr);
  126. list.forEach(v => {
  127. switch (v.fileType) {
  128. case "video":
  129. files.videos.push(v)
  130. files.viewVideos.push({
  131. url: v.url,
  132. type: "video",
  133. poster: v.subfiles[0].url
  134. })
  135. break;
  136. case "image":
  137. files.images.push(v)
  138. files.viewImages.push({
  139. url: v.url,
  140. type: "image"
  141. })
  142. break;
  143. default:
  144. files.files.push(v)
  145. break;
  146. }
  147. });
  148. this.setData({
  149. files
  150. })
  151. },
  152. /* 去下单 */
  153. clickBut() {
  154. wx.navigateTo({
  155. url: '/packageA/activity/selectProduct/index?params=' + JSON.stringify({
  156. "id": 20230116094803,
  157. "version": 1,
  158. "content": {
  159. nocache: true,
  160. sa_promotionid: this.data.sa_promotionid,
  161. sa_promotion_itemgroupid: this.data.active,
  162. "where": {
  163. "condition": ""
  164. }
  165. }
  166. }),
  167. });
  168. getApp().globalData.handleSelect = this.creadedOrderForm.bind(this);
  169. },
  170. creadedOrderForm({
  171. list
  172. }) {
  173. let that = this;
  174. wx.showModal({
  175. title: '提示',
  176. content: '是否确定创建促销订单?',
  177. complete: (res) => {
  178. if (res.confirm) _Http.basic({
  179. "id": 20221108111402,
  180. content: {
  181. sa_orderid: 0,
  182. sa_accountclassid: that.data.detail.sa_accountclassid,
  183. rec_contactsid: 0,
  184. pay_enterpriseid: 0,
  185. sa_contractid: 0,
  186. sa_projectid: 0,
  187. sa_promotionid: that.data.detail.sa_promotionid,
  188. "sa_brandid": that.data.detail.sa_brandid, //品牌ID
  189. "type": "促销订单", //订单类型
  190. "tradefield": that.data.detail.tradefield.join(','), //必选
  191. }
  192. }).then(res => {
  193. console.log("创建促销订单", res);
  194. wx.showToast({
  195. title: res.msg != '成功' ? res.msg : '创建成功',
  196. icon: "none"
  197. });
  198. /* 绑定产品 */
  199. _Http.basic({
  200. "id": 20221109093602,
  201. "content": {
  202. "sa_orderid": res.data.sa_orderid,
  203. "sa_contractid": res.data.sa_contractid,
  204. "sys_enterpriseid": res.data.sys_enterpriseid,
  205. "type": "促销订单",
  206. "items": list.map(v => {
  207. return {
  208. "sa_orderitemsid": 0,
  209. "itemid": v.itemid,
  210. "qty": v.qty,
  211. price: v.price
  212. }
  213. })
  214. }
  215. }).then(s => {
  216. if (s.msg == '成功') setTimeout(() => {
  217. wx.redirectTo({
  218. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  219. });
  220. }, 500)
  221. })
  222. })
  223. }
  224. })
  225. },
  226. onReachBottom() {
  227. this.getProductList();
  228. }
  229. })