detail.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. wx.navigateTo({
  175. url: '/packageA/activity/selectProduct/index?params=' + JSON.stringify({
  176. "id": 20230116094803,
  177. "version": 1,
  178. "content": {
  179. nocache: true,
  180. sa_promotionid: this.data.sa_promotionid,
  181. sa_promotion_itemgroupid: this.data.active,
  182. "where": {
  183. "condition": ""
  184. }
  185. }
  186. }),
  187. });
  188. getApp().globalData.handleSelect = this.creadedOrderForm.bind(this);
  189. },
  190. creadedOrderForm({
  191. list
  192. }) {
  193. console.log(list)
  194. let that = this;
  195. wx.showModal({
  196. title: '提示',
  197. content: '是否确定创建促销订单?',
  198. complete: (res) => {
  199. if (res.confirm) _Http.basic({
  200. "id": 20221108111402,
  201. content: {
  202. sa_orderid: 0,
  203. sa_accountclassid: that.data.detail.sa_accountclassid,
  204. rec_contactsid: 0,
  205. pay_enterpriseid: 0,
  206. sa_contractid: 0,
  207. sa_projectid: 0,
  208. sa_promotionid: that.data.detail.sa_promotionid,
  209. "sa_brandid": that.data.detail.sa_brandid, //品牌ID
  210. "type": "促销订单", //订单类型
  211. "tradefield": that.data.detail.tradefield, //必选
  212. }
  213. }).then(res => {
  214. console.log("创建促销订单", res);
  215. wx.showToast({
  216. title: res.msg != '成功' ? res.msg : '创建成功',
  217. icon: "none"
  218. });
  219. /* 绑定产品 */
  220. _Http.basic({
  221. "id": 20221109093602,
  222. "content": {
  223. "sa_orderid": res.data.sa_orderid,
  224. "sa_contractid": res.data.sa_contractid,
  225. "sys_enterpriseid": res.data.sys_enterpriseid,
  226. "type": "促销订单",
  227. "items": list.map(v => {
  228. return {
  229. "sa_orderitemsid": 0,
  230. "itemid": v.itemid,
  231. "qty": v.qty
  232. }
  233. })
  234. }
  235. }).then(s => {
  236. if (s.msg == '成功') setTimeout(() => {
  237. wx.redirectTo({
  238. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  239. });
  240. }, 500)
  241. })
  242. })
  243. }
  244. })
  245. },
  246. onReachBottom() {
  247. this.getProductList();
  248. }
  249. })