index.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. import { queryPermancePlanTmp } from "../../../../services/api/orders/index"
  2. import { accountid, clientType, getErrorMsg, isEncrypted, marketid, protoHeader, timetample, userid } from "../../../../services/utils"
  3. import { hideLoading, showLoading, showModel, showToast } from "../../../../utils/message/index"
  4. import services from "../../../../services/index"
  5. import { formatDate, getDecimalNum } from "../../../../utils/util"
  6. import { sendMsgToMQ } from "../../../../services/api/common/index"
  7. import { encryptBody } from "../../../../utils/websocket/crypto"
  8. import { FunCode } from "../../../../constants/enum/funcode"
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. /// 底部安全区域
  15. safeBottom: getApp().globalData.safeBottom,
  16. /// 履约模板信息
  17. tmps: <GuangZuan.PermancePlanTmp[]>[],
  18. /// 选中履约模板
  19. tmp: <GuangZuan.PermancePlanTmp>({}),
  20. /// 是否显示
  21. show: false,
  22. /// 是否显示日历
  23. showCal: false,
  24. /// 颜色
  25. tcolors: ['rebeccapurple', 'green', 'hotpink', 'orange', 'darkgoldenrod', 'firebrick', 'firebrick'],
  26. /// 是否开始日期
  27. isstart: true,
  28. /// 开始日期
  29. startdate: formatDate(new Date()),
  30. /// 结束日期
  31. enddate: formatDate(new Date()),
  32. /// 文件上传列表
  33. fileList: [],
  34. /// 上传的文件路径
  35. filePath: '',
  36. /// 显示信息
  37. actions: [''],
  38. /// 生产方式条件
  39. options: [{ text: 'HPHT', value: 1 }, { text: 'CVD', value: 2 }],
  40. /// 生产方式
  41. way: 1,
  42. /// 商品名称
  43. wrstandname: '',
  44. /// 预售总量
  45. pretotalqty: '',
  46. /// 预售价格
  47. preprice: '',
  48. /// 最小采购单位
  49. minbuyqty: '',
  50. /// 最大采购单位
  51. maxbuyqty: '',
  52. /// 最低成团量
  53. minsuccessqty: '',
  54. /// 采购保证金比例
  55. buymarginvalue: '',
  56. /// 颜色
  57. zscolor: '',
  58. /// 净度
  59. zsclarity: '',
  60. /// 尺寸
  61. zssize: '',
  62. /// 成品率
  63. zsyield: '',
  64. /// 重量描述
  65. weightdesc: '',
  66. /// 数量描述
  67. qtydesc: '',
  68. /// 备注
  69. remark: ''
  70. },
  71. /**
  72. * 返回上层视图
  73. */
  74. backToParent() {
  75. /// 返回上层视图
  76. wx.navigateBack()
  77. },
  78. /**
  79. * 按钮点击响应事件
  80. */
  81. onButtonClick(e: any) {
  82. switch (e.target.id) {
  83. case 'startdate': /// 开始日期
  84. this.setData({ showCal: true, isstart: true })
  85. break;
  86. case 'enddate': /// 结束日期
  87. this.setData({ showCal: true, isstart: false })
  88. break
  89. case 'submit': /// 申请提交
  90. this.doSubmit()
  91. break
  92. default:
  93. break;
  94. }
  95. },
  96. /// 日期确定触发
  97. onConfirm(e: any) {
  98. this.setData({ showCal: false })
  99. /// 开始日期
  100. if (this.data.isstart) {
  101. this.setData({
  102. startdate: formatDate(e.detail)
  103. })
  104. } else {
  105. this.setData({
  106. enddate: formatDate(e.detail)
  107. })
  108. }
  109. },
  110. check(): boolean {
  111. /// 请输入商品名称
  112. if (this.data.wrstandname === '') {
  113. showToast('请输入商品名称')
  114. return false
  115. }
  116. /// 请输入预售总量
  117. if ((this.data.pretotalqty === '') || (Number(this.data.pretotalqty) === 0.0) ) {
  118. debugger
  119. showToast('请输入预售总量')
  120. return false
  121. }
  122. /// 请输入预售价格
  123. if ((this.data.preprice === '') || (Number(this.data.preprice) === 0.0) ) {
  124. showToast('请输入预售价格')
  125. return false
  126. }
  127. /// 请输入最小采购单位
  128. if ((this.data.minbuyqty === '') || (Number(this.data.minbuyqty) === 0.0) ) {
  129. showToast('请输入最小采购单位')
  130. return false
  131. }
  132. /// 请输入最大采购单位
  133. if ((this.data.maxbuyqty === '') || (Number(this.data.maxbuyqty) === 0.0) ) {
  134. showToast('请输入最大采购单位')
  135. return false
  136. }
  137. /// 请输入最低成团量
  138. if ((this.data.minsuccessqty === '') || (Number(this.data.minsuccessqty) === 0.0) ) {
  139. showToast('请输入最低成团量')
  140. return false
  141. }
  142. /// 请输入采购保证金比例
  143. if ((this.data.buymarginvalue === '') || (Number(this.data.buymarginvalue) === 0.0) ) {
  144. showToast('请输入采购保证金比例')
  145. return false
  146. }
  147. return true
  148. },
  149. /// 日期关闭触发
  150. onCloseCal() {
  151. this.setData({ showCal: false })
  152. },
  153. /// 显示履约模板
  154. showPlanTmps() {
  155. this.setData({ show: true })
  156. },
  157. /// 关闭
  158. onClose() {
  159. this.setData({ show: false })
  160. },
  161. onSelect(e: any) {
  162. /// 默认显示项
  163. const { index } = e.detail;
  164. this.setData({ tmp: this.data.tmps[index], show: false })
  165. },
  166. /// 删除图片
  167. deleteImage(e: any) {
  168. const {index} = e.detail.index
  169. // 上传完成需要更新 fileList
  170. const { fileList = [] } = this.data;
  171. fileList.splice(index, 1)
  172. this.setData({ fileList });
  173. },
  174. onChange(e: any) {
  175. this.setData({ way: e.detail });
  176. },
  177. // input输入中
  178. getInputNum (e: any) {
  179. /// 截取2位小数位
  180. let num = getDecimalNum(e.detail)
  181. switch (e.target.id) {
  182. case 'maxbuyqty': /// 最大采购单位
  183. this.setData({ maxbuyqty: num})
  184. break;
  185. case 'pretotalqty': /// 预售总量
  186. this.setData({ pretotalqty: num})
  187. break;
  188. case 'preprice': /// 预售价格
  189. this.setData({ preprice: num})
  190. break;
  191. case 'buymarginvalue': /// 采购保证金
  192. this.setData({ buymarginvalue: num})
  193. break;
  194. case 'minbuyqty': /// 最小采购单位
  195. this.setData({ minbuyqty: num})
  196. break;
  197. case 'minsuccessqty': /// 最低成团量
  198. this.setData({ minsuccessqty: num})
  199. break;
  200. default:
  201. break;
  202. }
  203. },
  204. /// 照片上传
  205. afterRead(e: any) {
  206. const { file } = e.detail;
  207. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  208. wx.uploadFile({
  209. url: services.config.uploadUrl,
  210. filePath: file.url,
  211. name: 'file',
  212. formData: { user: 'test' },
  213. success: (res) => {
  214. if (res.statusCode != 200) {
  215. showToast('图片上传失败,原因:'+res.errMsg)
  216. return
  217. }
  218. // 上传完成需要更新 fileList
  219. const { fileList = [] } = this.data;
  220. fileList.push({ ...file, url: res.data });
  221. this.setData({ fileList });
  222. /// 设置文件路径
  223. this.setData({ filePath: JSON.parse(res.data)[0].filePath })
  224. },
  225. });
  226. },
  227. /// 申请提交
  228. doSubmit() {
  229. /// 校验不合规
  230. if (!this.check()) { return }
  231. /// showModel
  232. showModel(() => {
  233. /// showLoading
  234. showLoading(() => {
  235. /// 请求参数
  236. const info = JSON.stringify({
  237. Header: protoHeader(FunCode.GZPresaleApplyReq),
  238. SellUserID: userid(),
  239. SellAccountID: accountid(),
  240. WRStandardName: this.data.wrstandname,
  241. PresaleQty: Number(this.data.pretotalqty),
  242. MinBuyQty: Number(this.data.minbuyqty),
  243. MaxBuyQty: Number(this.data.maxbuyqty),
  244. MinSuccessQty: Number(this.data.minsuccessqty),
  245. UnitPrice: Number(this.data.preprice),
  246. StartDate: this.data.startdate,
  247. EndDate: this.data.enddate,
  248. BuyMarginAlgorithm: 1,
  249. BuyMarginValue: Number(this.data.buymarginvalue)/100.0,
  250. ZSColorTypeStr: this.data.zscolor,
  251. ZSClarityTypeStr: this.data.zsclarity,
  252. SizeStr: this.data.zssize,
  253. YieldRate: this.data.zsyield,
  254. QtyDesc: this.data.qtydesc,
  255. WeightDesc: this.data.weightdesc,
  256. YSProductionMode: this.data.way,
  257. PictureUrls: this.data.filePath,
  258. Remark: this.data.remark,
  259. PerformanceTemplateID: this.data.tmp.autoid,
  260. MarketID: marketid(),
  261. ClientType: clientType(),
  262. ClientSerialNo: timetample().toString()
  263. })
  264. /// 发送请求
  265. sendMsgToMQ({
  266. data: {
  267. data: encryptBody(info),
  268. funCodeReq: FunCode.GZPresaleApplyReq,
  269. funCodeRsp: FunCode.GZPresaleApplyRsp,
  270. isEncrypted: isEncrypted()
  271. },
  272. success: (res) => {
  273. /// 解析对象
  274. const data = JSON.parse(res.data.data)
  275. if (data.RetCode != 0) {
  276. hideLoading(() => {}, getErrorMsg(data.RetCode))
  277. return
  278. }
  279. /// 求购发布请求成功
  280. hideLoading(() => {
  281. wx.navigateBack()
  282. }, '提交申请成功', 'success')
  283. },
  284. fail: (emsg) => {
  285. hideLoading(()=>{}, emsg)
  286. }
  287. })
  288. }, '提交申请请求中....')
  289. }, '提示', '确认要提交申请吗?')
  290. },
  291. /// 获取履约模板信息
  292. queryPermancePlanTmp() {
  293. /// showLoading
  294. showLoading(() => {
  295. queryPermancePlanTmp({
  296. success: (res) => {
  297. /// 获取数据
  298. this.setData({
  299. tmps: res.data,
  300. tmp: res.data[0],
  301. actions: res.data.map(obj => { return obj.templatename })
  302. })
  303. },
  304. complete: () => {
  305. /// hideLoading
  306. hideLoading()
  307. }
  308. })
  309. })
  310. },
  311. /**
  312. * 生命周期函数--监听页面加载
  313. */
  314. onLoad() {
  315. /// 获取履约模板信息
  316. this.queryPermancePlanTmp()
  317. },
  318. /**
  319. * 生命周期函数--监听页面初次渲染完成
  320. */
  321. onReady() {
  322. },
  323. /**
  324. * 生命周期函数--监听页面显示
  325. */
  326. onShow() {
  327. },
  328. /**
  329. * 生命周期函数--监听页面隐藏
  330. */
  331. onHide() {
  332. },
  333. /**
  334. * 生命周期函数--监听页面卸载
  335. */
  336. onUnload() {
  337. },
  338. /**
  339. * 页面相关事件处理函数--监听用户下拉动作
  340. */
  341. onPullDownRefresh() {
  342. },
  343. /**
  344. * 页面上拉触底事件的处理函数
  345. */
  346. onReachBottom() {
  347. },
  348. /**
  349. * 用户点击右上角分享
  350. */
  351. onShareAppMessage() {
  352. }
  353. })