detail.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. const _Http = getApp().globalData.http;
  2. let sa_brandid = null,
  3. sys_enterpriseid = null;
  4. import {
  5. fileList
  6. } from "../../utils/FormatTheAttachment";
  7. import currency from "../../utils/currency";
  8. Page({
  9. data: {
  10. loading: true
  11. },
  12. onLoad(options) {
  13. if (options.id) this.setData({
  14. sa_itemgroupid: options.id,
  15. itemno: options.itemno
  16. })
  17. sa_brandid = options.sa_brandid;
  18. this.setData({
  19. userrole: wx.getStorageSync('userrole')
  20. })
  21. if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = options.sys_enterpriseid
  22. this.getDetail();
  23. },
  24. /* 获取详情 */
  25. getDetail() {
  26. let content = {
  27. "sa_itemgroupid": this.data.sa_itemgroupid,
  28. pageSize: 999
  29. }
  30. if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
  31. console.log(sys_enterpriseid)
  32. _Http.basic({
  33. "id": "20220926142403",
  34. content
  35. }).then(res => {
  36. console.log("商品详情", res)
  37. if (res.msg != '成功') return wx.showToast({
  38. title: res.msg,
  39. icon: "none"
  40. })
  41. if (res.data.length == 0) {
  42. wx.showToast({
  43. title: '未查询到商品',
  44. icon: "none",
  45. mask: true
  46. })
  47. setTimeout(() => {
  48. wx.navigateBack();
  49. }, 500)
  50. return;
  51. }
  52. this.handleFiles(res.data[0].attinfos)
  53. const CNY = sum => currency(sum, {
  54. symbol: "¥",
  55. precision: 2
  56. }).format();
  57. this.setData({
  58. detail: res.data[0],
  59. rows: res.data.map(v => {
  60. v.gradeprice = CNY(v.gradeprice);
  61. v.marketprice = CNY(v.marketprice);
  62. return v
  63. }),
  64. loading: false
  65. })
  66. })
  67. },
  68. /* 预览媒体 */
  69. viewMedias(e) {
  70. const {
  71. index,
  72. type
  73. } = e.currentTarget.dataset;
  74. wx.previewMedia({
  75. current: index,
  76. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  77. })
  78. },
  79. /* 处理附件 */
  80. handleFiles(arr) {
  81. let files = {
  82. images: [],
  83. viewImages: [],
  84. videos: [],
  85. viewVideos: [],
  86. files: []
  87. },
  88. list = fileList(arr);
  89. list.forEach(v => {
  90. switch (v.fileType) {
  91. case "video":
  92. files.videos.push(v)
  93. files.viewVideos.push({
  94. url: v.url,
  95. type: "video",
  96. poster: v.subfiles[0].url
  97. })
  98. break;
  99. case "image":
  100. files.images.push(v)
  101. files.viewImages.push({
  102. url: v.url,
  103. type: "image"
  104. })
  105. break;
  106. default:
  107. files.files.push(v)
  108. break;
  109. }
  110. });
  111. this.setData({
  112. files
  113. })
  114. },
  115. /* 切换产品 */
  116. changeItemno(e) {
  117. const {
  118. item
  119. } = e.currentTarget.dataset;
  120. if (item.itemno == this.data.itemno) return;
  121. this.handleFiles(item.attinfos)
  122. this.setData({
  123. detail: item,
  124. itemno: item.itemno
  125. })
  126. },
  127. clickBut() {
  128. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  129. title: '请选择加入产品领域',
  130. icon: "none",
  131. duration: 3000
  132. }) : this.handleStorage(0);
  133. },
  134. /* 打开文档 */
  135. openDocument(e) {
  136. const {
  137. item
  138. } = e.currentTarget.dataset;
  139. console.log(item)
  140. wx.showLoading({
  141. title: '加载中...',
  142. mask: true,
  143. })
  144. wx.downloadFile({
  145. url: item.url,
  146. success: function (res) {
  147. const filePath = res.tempFilePath
  148. wx.openDocument({
  149. filePath: filePath,
  150. showMenu: true,
  151. fileType: item.postfix,
  152. success: function (res) {
  153. wx.hideLoading();
  154. console.log('打开文档成功')
  155. },
  156. fail(e) {
  157. console.log(e)
  158. wx.showToast({
  159. title: '打开失败',
  160. icon: "error",
  161. mask: true
  162. })
  163. }
  164. })
  165. },
  166. fail(e) {
  167. console.log(e)
  168. wx.showToast({
  169. title: '打开失败',
  170. icon: "error",
  171. mask: true
  172. })
  173. }
  174. })
  175. },
  176. /* 选择领域 */
  177. storage(e) {
  178. this.handleStorage(e.detail.value)
  179. },
  180. handleStorage(index) {
  181. let detail = this.data.detail;
  182. _Http.basic({
  183. "id": 20220924095102,
  184. "content": {
  185. sa_brandid,
  186. "itemid": detail.itemid, //货品id
  187. "qty": detail.orderminqty, //数量
  188. "itemno": this.data.itemno, //货品编号
  189. tradefield: detail.tradefield[index].tradefield
  190. },
  191. }).then(res => {
  192. console.log("加入购物车", res)
  193. if (res.msg != '成功') return wx.showToast({
  194. title: res.msg,
  195. icon: "none"
  196. });
  197. _Http.basic({
  198. "id": 20220927093202,
  199. "content": {}
  200. }, false).then(res => {
  201. console.log("购物车数量", res)
  202. getApp().globalData.num = res.data.num;
  203. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(res.data.num)
  204. setTimeout(() => {
  205. wx.showToast({
  206. title: '加入成功',
  207. icon: "none",
  208. icon: "none"
  209. });
  210. }, 200);
  211. });
  212. })
  213. },
  214. onShow() {
  215. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
  216. },
  217. })