detail.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. siteid: wx.getStorageSync('userMsg').siteid
  21. })
  22. if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = options.sys_enterpriseid
  23. this.getDetail();
  24. getApp().globalData.Language.getLanguagePackage(this, '商城');
  25. },
  26. /* 获取详情 */
  27. getDetail() {
  28. let content = {
  29. "sa_itemgroupid": this.data.sa_itemgroupid,
  30. pageSize: 999
  31. }
  32. if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
  33. _Http.basic({
  34. "id": "20220926142403",
  35. content
  36. }).then(res => {
  37. console.log("商品详情", res)
  38. if (res.code != '1') return wx.showToast({
  39. title: res.msg,
  40. icon: "none"
  41. })
  42. if (res.data.length == 0) {
  43. wx.showToast({
  44. title: getApp().globalData.Language.getMapText('未查询到商品'),
  45. icon: "none",
  46. mask: true
  47. })
  48. setTimeout(() => {
  49. wx.navigateBack();
  50. }, 500)
  51. return;
  52. }
  53. let index = res.data.findIndex(v => v.itemno == this.data.itemno);
  54. if (index == -1) {
  55. index = 0;
  56. this.setData({
  57. itemno: res.data[0].itemno
  58. })
  59. }
  60. this.handleFiles(res.data[index].attinfos)
  61. const CNY = sum => currency(sum, {
  62. symbol: "¥",
  63. precision: 2
  64. }).format();
  65. this.setData({
  66. detail: res.data[index],
  67. rows: res.data.map(v => {
  68. v.gradeprice = CNY(v.gradeprice);
  69. v.marketprice = CNY(v.marketprice);
  70. return v
  71. }),
  72. loading: false
  73. })
  74. this.getRep()
  75. })
  76. },
  77. /* 更新库存 */
  78. getRep() {
  79. _Http.basic({
  80. "id": 20220923155302,
  81. "content": {
  82. "itemid": this.data.detail.itemid
  83. }
  84. }).then(res => {
  85. console.log("查询库存", res)
  86. if (res.code != '1') return wx.showToast({
  87. title: res.msg,
  88. icon: "none"
  89. })
  90. this.setData({
  91. "detail.stockstatus": res.data.stockstatus,
  92. "detail.cansaleqty": res.data.invbal_qty,
  93. })
  94. })
  95. },
  96. /* 预览媒体 */
  97. viewMedias(e) {
  98. const {
  99. index,
  100. type
  101. } = e.currentTarget.dataset;
  102. wx.previewMedia({
  103. current: index,
  104. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  105. })
  106. },
  107. /* 处理附件 */
  108. handleFiles(arr) {
  109. let files = {
  110. images: [],
  111. viewImages: [],
  112. videos: [],
  113. viewVideos: [],
  114. files: []
  115. },
  116. list = fileList(arr);
  117. list.forEach(v => {
  118. switch (v.fileType) {
  119. case "video":
  120. files.videos.push(v)
  121. files.viewVideos.push({
  122. url: v.url,
  123. type: "video",
  124. poster: v.subfiles[0].url
  125. })
  126. break;
  127. case "image":
  128. files.images.push(v)
  129. files.viewImages.push({
  130. url: v.url,
  131. type: "image"
  132. })
  133. break;
  134. default:
  135. files.files.push(v)
  136. break;
  137. }
  138. });
  139. this.setData({
  140. files
  141. })
  142. },
  143. /* 切换产品 */
  144. changeItemno(e) {
  145. const {
  146. item
  147. } = e.currentTarget.dataset;
  148. if (item.itemno == this.data.itemno) return;
  149. this.handleFiles(item.attinfos)
  150. this.setData({
  151. detail: item,
  152. itemno: item.itemno
  153. })
  154. this.getRep()
  155. },
  156. clickBut() {
  157. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  158. title: getApp().globalData.Language.getMapText('请选择加入产品领域'),
  159. icon: "none",
  160. duration: 3000
  161. }) : this.handleStorage(0);
  162. },
  163. /* 打开文档 */
  164. openDocument(e) {
  165. const {
  166. item
  167. } = e.currentTarget.dataset,
  168. that = this;
  169. console.log(item)
  170. wx.showLoading({
  171. title: getApp().globalData.Language.getMapText('加载中...'),
  172. mask: true,
  173. })
  174. wx.downloadFile({
  175. url: item.url,
  176. filePath: wx.env.USER_DATA_PATH + '/' + item.document, // 本地自定义的文件名
  177. success: function (res) {
  178. console.log(res)
  179. const filePath = res.tempFilePath || res.filePath
  180. wx.openDocument({
  181. filePath: filePath,
  182. showMenu: true,
  183. fileType: item.postfix,
  184. success: function (res) {
  185. wx.hideLoading();
  186. console.log('打开文档成功')
  187. _Http.basic({
  188. "id": 10020701,
  189. "content": {
  190. "linksid": item.linksid,
  191. "attachmentid": item.attachmentid
  192. }
  193. }).then(res => {
  194. console.log("创建记录", res)
  195. })
  196. },
  197. fail(e) {
  198. console.log(e)
  199. wx.showToast({
  200. title: getApp().globalData.Language.getMapText('打开失败'),
  201. icon: "error",
  202. mask: true
  203. })
  204. }
  205. })
  206. },
  207. fail(e) {
  208. console.log(e)
  209. wx.showToast({
  210. title: getApp().globalData.Language.getMapText('打开失败'),
  211. icon: "error",
  212. mask: true
  213. })
  214. }
  215. })
  216. },
  217. /* 选择领域 */
  218. storage(e) {
  219. this.handleStorage(e.detail.value)
  220. },
  221. handleStorage(index) {
  222. let detail = this.data.detail;
  223. _Http.basic({
  224. "id": 20220924095102,
  225. "content": {
  226. sa_brandid,
  227. "itemid": detail.itemid, //货品id
  228. "qty": detail.orderminqty, //数量
  229. "itemno": this.data.itemno, //货品编号
  230. tradefield: detail.tradefield[index].tradefield
  231. },
  232. }).then(res => {
  233. console.log("加入购物车", res)
  234. if (res.code != '1') return wx.showToast({
  235. title: res.msg,
  236. icon: "none"
  237. });
  238. _Http.basic({
  239. "id": 20220927093202,
  240. "content": {}
  241. }, false).then(res => {
  242. console.log("购物车数量", res)
  243. getApp().globalData.num = res.data.num;
  244. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(res.data.num)
  245. setTimeout(() => {
  246. getApp().globalData.Language.showToast('加入成功')
  247. }, 200);
  248. });
  249. })
  250. },
  251. onShow() {
  252. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
  253. },
  254. })