detail.js 5.8 KB

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