detail.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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(true);
  28. },
  29. /* 获取详情 */
  30. getDetail(init = false) {
  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. wx.hideLoading();
  38. console.log("商品详情", res)
  39. if (res.msg != '成功') return wx.showToast({
  40. title: res.msg,
  41. icon: "none"
  42. })
  43. if (res.data.item.length == 0) return wx.showToast({
  44. title: '未查询到商品',
  45. icon: "none",
  46. mask: true
  47. })
  48. this.handleFiles(res.data.item[0].attinfos)
  49. const CNY = sum => currency(sum, {
  50. symbol: "¥",
  51. precision: 2
  52. }).format();
  53. res.data.item[0].gradeprice = CNY(res.data.item[0].gradeprice);
  54. res.data.item[0].marketprice = CNY(res.data.item[0].marketprice);
  55. this.setData({
  56. content,
  57. detail: res.data.item[0],
  58. specRows: res.data.specRows,
  59. cheekRows: res.data.cheekRows,
  60. materialRows: res.data.materialRows,
  61. colorRows: res.data.colorRows,
  62. loading: false
  63. });
  64. })
  65. },
  66. /* 预览媒体 */
  67. viewMedias(e) {
  68. const {
  69. index,
  70. type
  71. } = e.currentTarget.dataset;
  72. wx.previewMedia({
  73. current: index,
  74. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  75. })
  76. },
  77. /* 处理附件 */
  78. handleFiles(arr) {
  79. let files = {
  80. images: [],
  81. viewImages: [],
  82. videos: [],
  83. viewVideos: [],
  84. files: []
  85. },
  86. list = fileList(arr);
  87. list.forEach(v => {
  88. switch (v.fileType) {
  89. case "video":
  90. files.videos.push(v)
  91. files.viewVideos.push({
  92. url: v.url,
  93. type: "video",
  94. poster: v.subfiles[0].url
  95. })
  96. break;
  97. case "image":
  98. files.images.push(v)
  99. files.viewImages.push({
  100. url: v.url,
  101. type: "image"
  102. })
  103. break;
  104. default:
  105. files.files.push(v)
  106. break;
  107. }
  108. });
  109. this.setData({
  110. files
  111. })
  112. },
  113. /* 切换产品 */
  114. changeItemno(e) {
  115. console.log("切换产品", e.currentTarget.dataset)
  116. const {
  117. value,
  118. valuename
  119. } = e.currentTarget.dataset,
  120. content = this.data.content;
  121. if (!value.flag) return;
  122. wx.showLoading({
  123. title: '加载中...',
  124. mask: true
  125. })
  126. content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
  127. this.getDetail()
  128. },
  129. clickBut() {
  130. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  131. title: '请选择加入产品领域',
  132. icon: "none",
  133. duration: 3000
  134. }) : this.handleStorage(0);
  135. },
  136. /* 打开文档 */
  137. openDocument(e) {
  138. const {
  139. item
  140. } = e.currentTarget.dataset;
  141. console.log(item)
  142. wx.showLoading({
  143. title: '加载中...',
  144. mask: true,
  145. })
  146. wx.downloadFile({
  147. url: item.url,
  148. success: function (res) {
  149. const filePath = res.tempFilePath
  150. wx.openDocument({
  151. filePath: filePath,
  152. showMenu: true,
  153. fileType: item.postfix,
  154. success: function (res) {
  155. wx.hideLoading();
  156. console.log('打开文档成功')
  157. },
  158. fail(e) {
  159. console.log(e)
  160. wx.showToast({
  161. title: '打开失败',
  162. icon: "error",
  163. mask: true
  164. })
  165. }
  166. })
  167. },
  168. fail(e) {
  169. console.log(e)
  170. wx.showToast({
  171. title: '打开失败',
  172. icon: "error",
  173. mask: true
  174. })
  175. }
  176. })
  177. },
  178. /* 选择领域 */
  179. storage(e) {
  180. this.handleStorage(e.detail.value)
  181. },
  182. handleStorage(index) {
  183. let detail = this.data.detail;
  184. _Http.basic({
  185. "id": 20220924095102,
  186. "content": {
  187. sa_brandid,
  188. "itemid": detail.itemid, //货品id
  189. "qty": detail.orderminqty, //数量
  190. itemno: detail.itemno, //货品编号
  191. tradefield: detail.tradefield[index].tradefield
  192. },
  193. }).then(res => {
  194. console.log("加入购物车", res)
  195. wx.showToast({
  196. title: res.msg == '成功' ? '加入成功' : res.msg,
  197. icon: "none"
  198. });
  199. if (res.msg == '成功') getApp().globalData.getCollectCount()
  200. })
  201. }
  202. })