index.ts 12 KB

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