index.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 { FunCode } from "../../../../constants/enum/funcode"
  7. import { sendMsgToMQ } from "../../../../services/api/common/index"
  8. import { encryptBody } from "../../../../utils/websocket/crypto"
  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', 'forestgreen', 'darksalmon', 'goldenrod', 'khaki', 'rosybrown', 'sandybrown'],
  26. /// 是否开始日期
  27. isstart: true,
  28. /// 开始日期
  29. startdate: formatDate(new Date()),
  30. /// 结束日期
  31. enddate: formatDate(new Date()),
  32. /// 文件上传列表
  33. fileList: [],
  34. /// 上传的文件路径
  35. filePath: '',
  36. /// 商品名称
  37. wrstandname: '',
  38. /// 预售总量
  39. pretotalqty: '',
  40. /// 最小采购单位
  41. minbuyqty: '',
  42. /// 最大采购单位
  43. maxbuyqty: '',
  44. /// 最低成团量
  45. minsuccessqty: '',
  46. /// 采购保证金比例
  47. buymarginvalue: '',
  48. /// 形状
  49. zsshape: '',
  50. /// 颜色
  51. zscolor: '',
  52. /// 净度
  53. zsclarity: '',
  54. /// 尺寸
  55. zssize: '',
  56. /// 抛光
  57. zspolish: '',
  58. /// 对称
  59. zssymmetry: '',
  60. /// 切工
  61. zscut: '',
  62. /// 荧光
  63. zsfluorescence: '',
  64. /// 备注
  65. remark: '',
  66. /// 成品率
  67. zsyield: '',
  68. /// 重量描述
  69. weightdesc: '',
  70. /// 数量描述
  71. qtydesc: '',
  72. /// 生产方式条件
  73. options: [{ text: 'HPHT', value: 1 }, { text: 'CVD', value: 2 }],
  74. /// 生产方式
  75. way: 1,
  76. /// 钻石分类
  77. categorys: [{ text: '成品裸钻', value: 1 }, { text: '毛坯钻石', value: 2 }],
  78. category: 1,
  79. /// 列头
  80. columns: ['序号', '数量 >=', '价格(元/克拉)', '操作'],
  81. /// 显示信息
  82. actions: [''],
  83. /// 数据信息
  84. datas: [{ price: '', qty: '0.0', step: 1 }]
  85. },
  86. /**
  87. * 返回上层视图
  88. */
  89. backToParent() {
  90. /// 返回上层视图
  91. wx.navigateBack()
  92. },
  93. /**
  94. * 按钮点击响应事件
  95. */
  96. onButtonClick(e: any) {
  97. switch (e.target.id) {
  98. case 'startdate': /// 开始日期
  99. this.setData({ showCal: true, isstart: true })
  100. break;
  101. case 'enddate': /// 结束日期
  102. this.setData({ showCal: true, isstart: false })
  103. break
  104. case 'submit': /// 申请提交
  105. this.doSubmit()
  106. break
  107. default:
  108. break;
  109. }
  110. },
  111. check(): boolean {
  112. /// 请输入商品名称
  113. if (this.data.wrstandname === '') {
  114. showToast('请输入商品名称')
  115. return false
  116. }
  117. /// 请输入预售总量
  118. if ((this.data.pretotalqty === '') || (Number(this.data.pretotalqty) === 0.0) ) {
  119. showToast('请输入预售总量')
  120. return false
  121. }
  122. /// 请输入最小采购单位
  123. if ((this.data.minbuyqty === '') || (Number(this.data.minbuyqty) === 0.0) ) {
  124. showToast('请输入最小采购单位')
  125. return false
  126. }
  127. /// 请输入最大采购单位
  128. if ((this.data.maxbuyqty === '') || (Number(this.data.maxbuyqty) === 0.0) ) {
  129. showToast('请输入最大采购单位')
  130. return false
  131. }
  132. /// 请输入最低成团量
  133. if ((this.data.minsuccessqty === '') || (Number(this.data.minsuccessqty) === 0.0) ) {
  134. showToast('请输入最低成团量')
  135. return false
  136. }
  137. /// 请输入采购保证金比例
  138. if ((this.data.buymarginvalue === '') || (Number(this.data.buymarginvalue) === 0.0) ) {
  139. showToast('请输入采购保证金比例')
  140. return false
  141. }
  142. return true
  143. },
  144. /// 日期确定触发
  145. onConfirm(e: any) {
  146. this.setData({ showCal: false })
  147. /// 开始日期
  148. if (this.data.isstart) {
  149. this.setData({
  150. startdate: formatDate(e.detail)
  151. })
  152. } else {
  153. this.setData({
  154. enddate: formatDate(e.detail)
  155. })
  156. }
  157. },
  158. /// 日期关闭触发
  159. onCloseCal() {
  160. this.setData({ showCal: false })
  161. },
  162. /// 显示履约模板
  163. showPlanTmps() {
  164. this.setData({ show: true })
  165. },
  166. /// 关闭
  167. onClose() {
  168. this.setData({ show: false })
  169. },
  170. onSelect(e: any) {
  171. /// 默认显示项
  172. const { index } = e.detail;
  173. this.setData({ tmp: this.data.tmps[index], show: false })
  174. },
  175. /// 删除图片
  176. deleteImage(e: any) {
  177. const {index} = e.detail.index
  178. // 上传完成需要更新 fileList
  179. const { fileList = [] } = this.data;
  180. fileList.splice(index, 1)
  181. this.setData({ fileList });
  182. },
  183. onChange(e: any) {
  184. this.setData({ category: e.detail });
  185. },
  186. /// 照片上传
  187. afterRead(e: any) {
  188. const { file } = e.detail;
  189. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  190. wx.uploadFile({
  191. url: services.config.uploadUrl,
  192. filePath: file.url,
  193. name: 'file',
  194. formData: { user: 'test' },
  195. success: (res) => {
  196. if (res.statusCode != 200) {
  197. showToast('图片上传失败,原因:'+res.errMsg)
  198. return
  199. }
  200. // 上传完成需要更新 fileList
  201. const { fileList = [] } = this.data;
  202. fileList.push({ ...file, url: res.data});
  203. this.setData({ fileList });
  204. /// 设置文件路径
  205. this.setData({ filePath: JSON.parse(res.data)[0].filePath })
  206. },
  207. });
  208. },
  209. // input输入中
  210. getInputNum (e: any) {
  211. /// 截取两位小数位
  212. let num = getDecimalNum(e.detail)
  213. switch (e.target.id) {
  214. case 'maxbuyqty': /// 最大采购单位
  215. this.setData({ maxbuyqty: num})
  216. break;
  217. case 'pretotalqty': /// 预售总量
  218. this.setData({ pretotalqty: num})
  219. break;
  220. case 'buymarginvalue': /// 采购保证金
  221. this.setData({ buymarginvalue: num})
  222. break;
  223. case 'minbuyqty': /// 最小采购单位
  224. this.setData({ minbuyqty: num})
  225. break;
  226. case 'minsuccessqty': /// 最低成团量
  227. this.setData({ minsuccessqty: num})
  228. break;
  229. default:
  230. break;
  231. }
  232. },
  233. /// 申请提交
  234. doSubmit() {
  235. /// 校验不合规
  236. if (!this.check()) { return }
  237. /// showModel
  238. showModel(() => {
  239. /// showLoading
  240. showLoading(() => {
  241. /// 钻石属性
  242. var list = this.data.datas.map(obj => {
  243. return {
  244. StepIndex: obj.step,
  245. Qty: Number(obj.qty),
  246. Price: Number(obj.price)
  247. }
  248. })
  249. /// 请求参数
  250. const info = JSON.stringify({
  251. Header: protoHeader(FunCode.GZCenterPurchaseApplyReq),
  252. SellUserID: userid(),
  253. SellAccountID: accountid(),
  254. WRStandardName: this.data.wrstandname,
  255. PresaleQty: Number(this.data.pretotalqty),
  256. MinBuyQty: Number(this.data.minbuyqty),
  257. MaxBuyQty: Number(this.data.maxbuyqty),
  258. MinSuccessQty: Number(this.data.minsuccessqty),
  259. StartDate: this.data.startdate,
  260. EndDate: this.data.enddate,
  261. BuyMarginAlgorithm: 1,
  262. BuyMarginValue: this.data.buymarginvalue,
  263. PerformanceTemplateID: this.data.tmp.autoid,
  264. YSZSCategory: this.data.category,
  265. ZSShapeTypeStr: this.data.zsshape,
  266. ZSColorTypeStr: this.data.zscolor,
  267. ZSClarityTypeStr: this.data.zsclarity,
  268. ZSCutTypeStr: this.data.zscut,
  269. ZSSymmetryTypeStr: this.data.zssymmetry,
  270. ZSPolishTypeStr: this.data.zspolish,
  271. ZSFluorescenceTypeStr: this.data.zsfluorescence,
  272. SizeStr: this.data.zssize,
  273. PictureUrls: this.data.filePath,
  274. Remark: this.data.remark,
  275. GZCenterPurchasePriceLists: list,
  276. YieldRate: this.data.zsyield,
  277. QtyDesc: this.data.qtydesc,
  278. WeightDesc: this.data.weightdesc,
  279. YSProductionMode: this.data.way,
  280. MarketID: marketid(),
  281. ClientType: clientType(),
  282. ClientSerialNo: timetample().toString()
  283. })
  284. /// 发送请求
  285. sendMsgToMQ({
  286. data: {
  287. data: encryptBody(info),
  288. funCodeReq: FunCode.GZCenterPurchaseApplyReq,
  289. funCodeRsp: FunCode.GZCenterPurchaseApplyRsp,
  290. isEncrypted: isEncrypted()
  291. },
  292. success: (res) => {
  293. /// 解析对象
  294. const data = JSON.parse(res.data.data)
  295. if (data.RetCode != 0) {
  296. hideLoading(() => {}, getErrorMsg(data.RetCode))
  297. return
  298. }
  299. /// 求购发布请求成功
  300. hideLoading(() => {
  301. wx.navigateBack()
  302. }, '提交申请成功', 'success')
  303. },
  304. fail: (emsg) => {
  305. hideLoading(()=>{}, emsg)
  306. }
  307. })
  308. }, '提交申请请求中....')
  309. }, '提示', '确认要提交申请吗?')
  310. },
  311. /// 获取履约模板信息
  312. queryPermancePlanTmp() {
  313. /// showLoading
  314. showLoading(() => {
  315. queryPermancePlanTmp({
  316. // data: {
  317. // marketid: marketid()
  318. // },
  319. success: (res) => {
  320. /// 获取数据
  321. this.setData({
  322. tmps: res.data,
  323. tmp: res.data[0],
  324. actions: res.data.map(obj => { return obj.templatename })
  325. })
  326. },
  327. complete: () => {
  328. /// hideLoading
  329. hideLoading()
  330. }
  331. })
  332. })
  333. },
  334. /**
  335. * 新增价格
  336. */
  337. addPrice() {
  338. this.setData({
  339. datas: this.data.datas.concat([{ price: '', qty: '', step: this.data.datas.length+1 }])
  340. })
  341. },
  342. /**
  343. * 删除某一行
  344. */
  345. deleteRow(e: any) {
  346. const row = e.target.id
  347. var obj = this.data.datas[row-1]
  348. if ( Number(obj.qty) === 0 && row === '1') {
  349. showToast('第一条数据信息不能删除')
  350. return
  351. }
  352. /// 删除数据
  353. this.data.datas.splice(row-1, 1)
  354. this.setData({ datas: this.data.datas })
  355. },
  356. /**
  357. * 数据变化
  358. */
  359. onRowChanged(e: any) {
  360. /// 获取对应的id
  361. const ids = (<string> e.target.id).split(' ')
  362. const row = <number><unknown>ids[0]
  363. const id = ids[1]
  364. var obj = this.data.datas[row-1]
  365. /// 截取两位小数
  366. let num = getDecimalNum(e.detail)
  367. /// 数据赋值
  368. if (id === "qty") { obj.qty = num } else { obj.price = num }
  369. /// 删除数据
  370. this.data.datas.splice(row-1, 1)
  371. this.data.datas.splice(row-1, 0, obj)
  372. this.setData({ datas: this.data.datas })
  373. },
  374. /**
  375. * 数据变化重新排序
  376. */
  377. onRowSort() {
  378. /// 数据排序
  379. this.setData({
  380. datas: this.data.datas.sort(function(a, b) {
  381. if (a.qty > b.qty) { return 1; }
  382. if (a.qty < b.qty) { return -1; }
  383. return 0;
  384. })
  385. })
  386. },
  387. /**
  388. * 生命周期函数--监听页面加载
  389. */
  390. onLoad() {
  391. /// 获取履约模板信息
  392. this.queryPermancePlanTmp()
  393. },
  394. /**
  395. * 生命周期函数--监听页面初次渲染完成
  396. */
  397. onReady() {
  398. },
  399. /**
  400. * 生命周期函数--监听页面显示
  401. */
  402. onShow() {
  403. },
  404. /**
  405. * 生命周期函数--监听页面隐藏
  406. */
  407. onHide() {
  408. },
  409. /**
  410. * 生命周期函数--监听页面卸载
  411. */
  412. onUnload() {
  413. },
  414. /**
  415. * 页面相关事件处理函数--监听用户下拉动作
  416. */
  417. onPullDownRefresh() {
  418. },
  419. /**
  420. * 页面上拉触底事件的处理函数
  421. */
  422. onReachBottom() {
  423. },
  424. /**
  425. * 用户点击右上角分享
  426. */
  427. onShareAppMessage() {
  428. }
  429. })