detail.js 5.5 KB

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