pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="tel flex">
  5. <label>缴费名称:</label>
  6. <input type="text" class="card input" v-model="payInfo.name" disabled/>
  7. </view>
  8. <view class="tel flex">
  9. <label>订单编号:</label>
  10. <input type="text" class="card input" v-model="payInfo.code" disabled/>
  11. </view>
  12. <view class="tel flex">
  13. <label>住宅地址:</label>
  14. <input type="text" class="card input" v-model="payInfo.address" disabled/>
  15. </view>
  16. <view class="tel flex">
  17. <label>户主姓名:</label>
  18. <input type="text" class="card input" v-model="payInfo.owner_name" disabled/>
  19. </view>
  20. <view class="tel flex">
  21. <label>住宅面积:</label>
  22. <input type="text" class="card input" v-model="payInfo.area" disabled/>
  23. </view>
  24. <view class="tel flex">
  25. <label>缴费类型:</label>
  26. <radio-group @change="payChange">
  27. <radio value="1" :checked="payInfo.type!=2" style="margin-right: 30rpx;transform: scale(0.85);" >全额</radio>
  28. <radio value="2" :checked="payInfo.type==2" style="transform: scale(0.85);" :disabled="payInfo.status==1 || payInfo.status==3">空置</radio>
  29. </radio-group>
  30. </view>
  31. <view class="tel flex">
  32. <label>缴费金额:</label>
  33. <input type="text" class="card input" id="real_fee" v-model="payInfo.real_fee" disabled/>
  34. </view>
  35. <view class="tel flex">
  36. <label>订单状态:</label>
  37. <input type="text" class="card input" id="status" :style="{color:statusColor[payInfo.status]}" v-model="statusObj[payInfo.status]" disabled/>
  38. </view>
  39. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  40. <label>发票抬头:</label>
  41. <input type="text" class="card input" id="real_fee" v-model="payInfo.invoice" disabled/>
  42. </view>
  43. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  44. <label>发票备注:</label>
  45. <input type="text" class="card input" id="real_fee" v-model="payInfo.invoice_remark" disabled/>
  46. </view>
  47. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  48. <label>发票状态:</label>
  49. <input type="text" class="card input" id="real_fee" v-model="invoiceStatusStr" disabled/>
  50. </view>
  51. </view>
  52. <button class="submit" style="margin-bottom:20rpx" @tap="paySubmit" v-if="needPay">{{payStatusStr}}</button>
  53. <button class="submit" style="margin-top:20rpx" @tap="openPopup" v-if="needInvoice">申请开票</button>
  54. <uni-popup ref="popup" :mask-click="false" popHeight="55%">
  55. <view class="popup-box">
  56. <view>
  57. <view class="popup-title">申请开票</view>
  58. <view class="popup-content-box">
  59. <view class="popup-content">
  60. <view class="popup-type">
  61. <view>开票抬头:</view><input class="card input" style="width: 75%;" type="text" v-model="invoiceName" />
  62. </view>
  63. <view class="popup-type">
  64. <view>手机号:</view><input class="card input" style="width: 75%;" type="tel" v-model="invoicePhone" />
  65. </view>
  66. <view class="popup-type">
  67. <view>邮箱:</view><input class="card input" style="width: 75%;" type="text" v-model="invoiceEmail" />
  68. </view>
  69. <view class="popup-type">
  70. <view>备注:</view><input class="card input" style="width: 75%;" type="text" v-model="invoiceRemark" />
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="popup-footer">
  76. <button class="popup-cancel" @click="cancelInvocie">取消</button>
  77. <button class="popup-submit" @click="submitInvocie">提交</button>
  78. </view>
  79. </view>
  80. </uni-popup>
  81. </view>
  82. </template>
  83. <script>
  84. import md5 from "@/common/md5.js";
  85. export default {
  86. data() {
  87. return {
  88. payInfo: {
  89. },
  90. payStatus:0,
  91. payStatusStr : '缴费',
  92. needPay : 1,
  93. needInvoice : 0,
  94. invoiceStatusStr : "待开票",
  95. pay_code : '',
  96. statusObj:getApp().globalData.statusObj,
  97. statusColor:getApp().globalData.statusColor,
  98. invoiceName : '',
  99. invoiceRemark : '',
  100. invoicePhone:getApp().globalData.user_phone,
  101. invoiceEmail:''
  102. };
  103. },
  104. onLoad(option) {
  105. this.getPayDetail(option.id);
  106. this.pay_code = option.id;
  107. },
  108. methods: {
  109. reload(){
  110. this.getPayDetail(this.pay_code);
  111. },
  112. getPayDetail(payId) {
  113. let url = getApp().makeApiUrl("user",'user','get_order_info');
  114. let postData = {
  115. code:payId,
  116. openId: getApp().globalData.open_id,
  117. };
  118. uni.request({
  119. url: url,
  120. method: "POST",
  121. header: {
  122. "content-type": "application/x-www-form-urlencoded",
  123. },
  124. data: postData,
  125. success: (res) => {
  126. if (res.data.code === 200) {
  127. this.payInfo = res.data.data;
  128. this.payInfo.address = this.payInfo.estate_name + this.payInfo.building_name + this.payInfo.unit + this.payInfo.room;
  129. if (this.payInfo.status > 0 && this.payInfo.invoice_status == 0){
  130. this.needInvoice = 1;
  131. }
  132. else{
  133. this.needInvoice = 0;
  134. }
  135. if (this.payInfo.status == 2){
  136. this.payStatusStr = '补充缴费';
  137. }
  138. if (this.payInfo.status == 1 || this.payInfo.status == 3){
  139. this.needPay = 0;
  140. }
  141. if (this.payInfo.invoice_status == 2){
  142. this.invoiceStatusStr = "已开票";
  143. }
  144. } else {
  145. uni.showToast({
  146. title: res.data.msg,
  147. icon: "none",
  148. duration: 2500,
  149. });
  150. }
  151. },
  152. fail: () => {
  153. console.log("连接失败");
  154. },
  155. });
  156. },
  157. payChange(e){
  158. let v = e.detail.value;
  159. if (v == 2)
  160. {
  161. let value = this.payInfo.part_fee - this.payInfo.reduction;
  162. value = Math.round(value * 100) / 100;
  163. this.payInfo.real_fee = value.toFixed(2);
  164. }
  165. else
  166. {
  167. let value = this.payInfo.total_fee - this.payInfo.reduction;
  168. value = Math.round(value * 100) / 100;
  169. this.payInfo.real_fee = value.toFixed(2);
  170. }
  171. this.payInfo.type = e.detail.value;
  172. },
  173. paySubmit(){
  174. if (this.payInfo.before > 0){
  175. uni.showToast({
  176. title: "您有历史供暖订单未完成缴费,请先完成后再次尝试",
  177. icon: "none",
  178. duration: 2500,
  179. });
  180. return;
  181. }
  182. let that = this;
  183. let type = this.payInfo.type;
  184. if (this.payInfo.status == 2)
  185. {
  186. type = 3;
  187. }
  188. let url = getApp().makeApiUrl("user",'user','prepay');
  189. let postData = {
  190. code:this.pay_code,
  191. type : type,
  192. openId: getApp().globalData.open_id,
  193. };
  194. uni.request({
  195. url: url,
  196. method: "POST",
  197. header: {
  198. "content-type": "application/x-www-form-urlencoded",
  199. },
  200. data: postData,
  201. success: (res) => {
  202. if (res.data.code === 200) {
  203. let r = res.data.data;
  204. let timeStamp = Date.now().toString();
  205. let nonceStr = getApp().randomStr(32);
  206. let p = 'prepay_id=' + r.prepay_id;
  207. let appId = "wx3cf5d0fd376116e2";
  208. let key = 'd2452k56khlk987HJ456uy7856HKJsd3'; //支付的key
  209. let origin = "appId="+appId+"&nonceStr="+nonceStr+"&package="+p+"&signType=MD5&timeStamp="+timeStamp+"&key="+key;
  210. let md5Sign = getApp().MD5(origin);
  211. // console.log('md5Sign_origin:' + origin);
  212. // console.log('md5Sign:' + md5Sign);
  213. uni.requestPayment({
  214. appId: appId,
  215. timeStamp: timeStamp,
  216. nonceStr: nonceStr,
  217. package: p,
  218. signType: 'MD5',
  219. paySign: md5Sign,
  220. success: function (res) {
  221. console.log('success:' + JSON.stringify(res));
  222. setTimeout(function() {
  223. that.reload();
  224. }, 500);
  225. },
  226. fail: function (err) {
  227. console.log('fail:' + JSON.stringify(err));
  228. }
  229. });
  230. } else {
  231. uni.showToast({
  232. title: res.data.msg,
  233. icon: "none",
  234. duration: 2500,
  235. });
  236. }
  237. },
  238. fail: () => {
  239. console.log("连接失败");
  240. },
  241. });
  242. //支付这里缺少签名参数 还需要后台配合调用微信那边的接口
  243. //参考https://github.com/dcloudio/H5P.Server/tree/master/payment
  244. },
  245. submitInvocie(){
  246. this.closePopup();
  247. },
  248. cancelInvocie(){
  249. this.$refs.popup.close();
  250. },
  251. openPopup() {
  252. this.$refs.popup.open('center');
  253. },
  254. closePopup() {
  255. if (this.invoiceName === ''){
  256. uni.showToast({
  257. title: '请填写发票抬头!',
  258. icon: "none",
  259. duration: 2500,
  260. });
  261. return;
  262. }
  263. if (this.invoicePhone === '' && this.invoiceEmail === ''){
  264. uni.showToast({
  265. title: '手机号和邮箱至少填写一项!',
  266. icon: "none",
  267. duration: 2500,
  268. });
  269. return;
  270. }
  271. this.$refs.popup.close();
  272. let that = this;
  273. let url = getApp().makeApiUrl("user",'user','invoice');
  274. let postData = {
  275. code:this.pay_code,
  276. invoice : this.invoiceName,
  277. remark : this.invoiceRemark,
  278. phone:this.invoicePhone,
  279. email:this.invoiceEmail,
  280. openId: getApp().globalData.open_id,
  281. };
  282. uni.request({
  283. url: url,
  284. method: "POST",
  285. header: {
  286. "content-type": "application/x-www-form-urlencoded",
  287. },
  288. data: postData,
  289. success: (res) => {
  290. if (res.data.code === 200) {
  291. uni.showToast({
  292. title: res.data.msg,
  293. icon: "none",
  294. duration: 2500,
  295. });
  296. setTimeout(function() {
  297. that.reload();
  298. }, 500);
  299. } else {
  300. uni.showToast({
  301. title: res.data.msg,
  302. icon: "none",
  303. duration: 2500,
  304. });
  305. }
  306. },
  307. fail: () => {
  308. console.log("连接失败");
  309. },
  310. });
  311. },
  312. },
  313. };
  314. </script>
  315. <style lang="scss" scoped>
  316. .content {
  317. font-size: 28rpx;
  318. font-weight: 200;
  319. padding: 1% 2%;
  320. .title {
  321. font-size: 30rpx;
  322. margin: 4% 0;
  323. }
  324. label {
  325. display: inline-block;
  326. width: 25%;
  327. vertical-align: middle;
  328. }
  329. .card {
  330. background-color: rgb(248, 247, 247);
  331. border-radius: 10rpx;
  332. }
  333. .flex {
  334. display: flex;
  335. align-items: center;
  336. margin-bottom: 2%;
  337. }
  338. .input {
  339. padding: 0 2%;
  340. margin: 2% 0;
  341. display: inline-block;
  342. width: 80%;
  343. height: 70rpx;
  344. }
  345. .supplyInfo {
  346. border-radius: 40rpx;
  347. padding: 4%;
  348. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  349. margin: 30rpx 0 30rpx 0;
  350. }
  351. .info {
  352. margin-top: 2%;
  353. border-radius: 40rpx;
  354. padding: 2% 4%;
  355. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  356. }
  357. .submit {
  358. color: white;
  359. font-weight: normal;
  360. width: 55%;
  361. border-radius: 20rpx;
  362. background-color: #02a7f0;
  363. margin: 120rpx auto;
  364. }
  365. }
  366. .popup-box {
  367. height: 95%;
  368. display: flex;
  369. flex-direction: column;
  370. justify-content: space-between;
  371. }
  372. .popup-title {
  373. text-align: center;
  374. font-weight: bold;
  375. height: 30px;
  376. border-bottom: 1px solid #d8d8d8;
  377. }
  378. .popup-content {
  379. font-size: 28rpx;
  380. padding: 10rpx 0 10rpx 0;
  381. }
  382. .uni-popup__wrapper-box {
  383. height: 65%!important;
  384. }
  385. .popup-type {
  386. display: flex;
  387. height: 80rpx;
  388. align-items: center;
  389. margin-top: 40rpx;
  390. view {
  391. width: 30%;
  392. }
  393. }
  394. .popup-footer {
  395. display: flex;
  396. button{
  397. font-size: 26rpx;
  398. height: 60rpx;
  399. width: 150rpx;
  400. line-height: 60rpx;
  401. color: #FFFFFF;
  402. }
  403. }
  404. .popup-cancel {
  405. background-color: #AAAAAA;
  406. }
  407. .popup-submit {
  408. background-color: #249CD3;
  409. }
  410. </style>