index.ts 11 KB

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