LeaseInfo.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * 租赁
  3. */
  4. import gameToast from "../Network/gameToast"
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. inputInviteValue: {
  9. default: 1,
  10. visible: false
  11. },
  12. //1 对应3个月,2对应1年,3对应5年
  13. toggleInputValue: {
  14. default: '1',
  15. visible: false
  16. },
  17. totalPriceLabel: {
  18. default: null,
  19. type: cc.Label,
  20. serializable: true
  21. },
  22. totalPriceValue: {
  23. default: 0,
  24. visible: false
  25. },
  26. ToastParent: {
  27. default: null,
  28. type: cc.Node,
  29. serializable: true
  30. },
  31. //输入节点
  32. inputContainer: {
  33. default: null,
  34. type: cc.Node,
  35. serializable: true
  36. },
  37. toggle1: {
  38. default: null,
  39. type: cc.Toggle,
  40. serializable: true
  41. },
  42. toggle2: {
  43. default: null,
  44. type: cc.Toggle,
  45. serializable: true
  46. },
  47. toggle3: {
  48. default: null,
  49. type: cc.Toggle,
  50. serializable: true
  51. },
  52. //这个显示的时候,拦截输入
  53. blockInput: {
  54. default: null,
  55. type: cc.Node,
  56. serializable: true
  57. },
  58. leaseFarmlandInfoNode: {
  59. default: null,
  60. type: cc.Node,
  61. serializable: true,
  62. visible:false,
  63. toolTip:"操作的土地对象,初始化时候传入"
  64. }
  65. },
  66. // LIFE-CYCLE CALLBACKS:
  67. // onLoad () {},
  68. // start() {
  69. // },
  70. onOpenInfo() {
  71. this.node.active = true;
  72. },
  73. //初始化时候需要初始化一次默认值
  74. onToggleInput(value, evnentData) {
  75. // console.log(value.isChecked, evnentData);
  76. this.toggleInputValue = evnentData;
  77. this._updatePrice();
  78. },
  79. inputLeaseValue(value, e) {
  80. var numberTemp = new RegExp("^[A-Za-z0-9]+$");
  81. if (numberTemp.test(value)) {
  82. if(Number(value)>=1){
  83. this.inputInviteValue = Number(value);
  84. }else{
  85. this.inputInviteValue = 1;
  86. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  87. }
  88. } else {
  89. this.inputInviteValue = 1;
  90. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  91. console.log("请输入整数的倍数", this.inputInviteValue);
  92. // gameToast.getInstance().show(this.ToastParent, "请输入整数的倍数", 2, () => {
  93. // console.log("finish toast!");
  94. // }, this);
  95. }
  96. this._updatePrice();
  97. },
  98. _updatePrice() {
  99. //this.inputInviteValue 默认是1倍
  100. // console.log( this.inputInviteValue);
  101. switch (this.toggleInputValue) {
  102. case "1":
  103. this.totalPriceValue = 700 * this.inputInviteValue;
  104. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  105. break;
  106. case "2":
  107. this.totalPriceValue = 2500 * this.inputInviteValue;
  108. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  109. break;
  110. case "3":
  111. this.totalPriceValue = 5000 * this.inputInviteValue;
  112. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  113. break;
  114. default:
  115. console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue);
  116. break;
  117. }
  118. },
  119. /**
  120. * 显示面板时候,设置一下初始化数据
  121. */
  122. onInitLeaseInfo(multiple){
  123. //这里处理倍数
  124. this.inputInviteValue = multiple;
  125. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  126. this._updatePrice();
  127. },
  128. //租赁支付
  129. onLeaseInfo() {
  130. console.log('支付总额:' + this.totalPriceValue);
  131. if (!GlobalD.dapp) {
  132. console.error("onBindInviteInfo warn,dapp未初始化!");
  133. return;
  134. }
  135. let _self = this;
  136. //cntAmount,payType,itemType,callback
  137. Global.game.payCNT(this.totalPriceValue, 1, this.toggleInputValue, (data) => {
  138. console.log("土地支付", this.totalPriceValue, "==", 1, "==", this.toggleInputValue);
  139. console.log("支付data:", data);
  140. gameToast.getInstance().show(this.ToastParent, "支付成功!", 3, () => {
  141. console.log("finish toast!");
  142. }, this);
  143. if (err === null) {
  144. // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
  145. console.log(tx) // 交易hash,唯一标识符
  146. //解锁土地操作
  147. this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").onUnlockLand();
  148. } else {
  149. console.log(err)
  150. }
  151. });
  152. // GlobalD.dapp.bindParent(_self.inputInviteValue).then((data) => {
  153. // if (data.err === null) {
  154. // // 返回成功,见下面消息体
  155. // console.log(data.res)
  156. // //绑定成功时候,隐藏输入框,设置父节点
  157. // GlobalD.Dapp.UserInfo.parent = data.res;
  158. // _self.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent.invite_code;
  159. // //如果存在父节点,隐藏输入框
  160. // _self.inputContainer.active = false;
  161. // } else {
  162. // //TODO 服务错误
  163. // console.log(data.err)
  164. // gameToast.getInstance().show(_self.ToastParent, "绑定失败!", 3, () => {
  165. // console.log("finish toast!");
  166. // }, _self);
  167. // }
  168. // })
  169. },
  170. onClose() {
  171. this.node.destroy();
  172. },
  173. });