detail.js 4.8 KB

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