LeaseInfo.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. }
  93. this._updatePrice();
  94. },
  95. _updatePrice() {
  96. //this.inputInviteValue 默认是1倍
  97. // console.log( this.inputInviteValue);
  98. switch (this.toggleInputValue) {
  99. case "1":
  100. this.totalPriceValue = 700 * this.inputInviteValue;
  101. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  102. break;
  103. case "2":
  104. this.totalPriceValue = 2500 * this.inputInviteValue;
  105. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  106. break;
  107. case "3":
  108. this.totalPriceValue = 5000 * this.inputInviteValue;
  109. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  110. break;
  111. default:
  112. console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue);
  113. break;
  114. }
  115. },
  116. /**
  117. * 显示面板时候,设置一下初始化数据
  118. */
  119. onInitLeaseInfo(multiple) {
  120. //这里处理倍数
  121. this.inputInviteValue = multiple;
  122. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  123. this._updatePrice();
  124. },
  125. //租赁支付
  126. onLeaseInfo() {
  127. console.log('支付总额:' + this.totalPriceValue);
  128. if (!GlobalD.dapp) {
  129. console.error("onBindInviteInfo warn,dapp未初始化!");
  130. return;
  131. }
  132. let _self = this;
  133. //cntAmount,payType,itemType,callback
  134. let _configLandInfo = this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").configLandInfo
  135. let payType = 0;
  136. switch (this.toggleInputValue) {
  137. case "1":
  138. payType = 1;
  139. break;
  140. case "2":
  141. payType = 5;
  142. break;
  143. case "3":
  144. payType = 6;
  145. break;
  146. default:
  147. console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue);
  148. break;
  149. }
  150. if(0 === payType){
  151. console.log('选择租赁日错误:' + this.totalPriceValue + " == " + payType);
  152. }
  153. GlobalD.GameData.payCNT(this.totalPriceValue, payType, _configLandInfo.id, (data) => {
  154. console.log("土地支付:", this.totalPriceValue, "== playType=", 1, ",item_type==", _configLandInfo.id);
  155. console.log("支付data:", data);
  156. const [err, tx] = data;
  157. if (err === null) {
  158. // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
  159. console.log(tx) // 交易hash,唯一标识符
  160. //解锁土地操作
  161. this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").onUnlockLand();
  162. this.onClose();
  163. } else {
  164. console.log(err)
  165. }
  166. });
  167. // GlobalD.dapp.bindParent(_self.inputInviteValue).then((data) => {
  168. // if (data.err === null) {
  169. // // 返回成功,见下面消息体
  170. // console.log(data.res)
  171. // //绑定成功时候,隐藏输入框,设置父节点
  172. // GlobalD.Dapp.UserInfo.parent = data.res;
  173. // _self.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent.invite_code;
  174. // //如果存在父节点,隐藏输入框
  175. // _self.inputContainer.active = false;
  176. // } else {
  177. // //TODO 服务错误
  178. // console.log(data.err)
  179. // }
  180. // })
  181. },
  182. onClose() {
  183. this.node.destroy();
  184. },
  185. });