detail.js 4.5 KB

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