writeoffitem.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <view class="pages writeoffitem">
  3. <view class="writeoffitem-number">
  4. <view class="number">订单编号:{{resdata.ordersn}}</view>
  5. <view class="time">预订时间:{{resdata.addDate}}</view>
  6. </view>
  7. <view class="wrap">
  8. <!-- 验证蝴蝶券 实体券才有 -->
  9. <view v-if="hd_type == 2" class="write-radius scan-hd">
  10. <view class="scan-hd-header">
  11. <view class="scan-hd-header-til">
  12. 验证蝴蝶券 {{ticket.length}}/{{resdata.hd_count}}
  13. </view>
  14. <!-- <button class="scan-hd-header-btn" @click="scanCode" type="default"><i class="iconfont iconsaomiao"></i>扫码</button> -->
  15. </view>
  16. <view class="addhd">
  17. <input class="addhd-input" v-model="enterHDnumber" placeholder="请输入蝴蝶券号码" type="text" value="" />
  18. <button class="addhd-button" @click="enterHD" type="primary">添加</button>
  19. </view>
  20. <view class="scan-hd-list" v-for="(item,index) in ticket" :key="index">
  21. <view class="scan-hd-list-item">
  22. <view class="item-til">蝴蝶券{{index +1}}</view>
  23. <view class="item-con"><input type="text" :value="item" disabled /></view>
  24. </view>
  25. </view>
  26. <view class="scan-hd-tip">还差{{ resdata.hd_count - ticket.length }}张蝴蝶券</view>
  27. </view>
  28. <!-- 验证蝴蝶券 实体券才有end -->
  29. <!-- 消费码蝴蝶券才有 -->
  30. <view v-if="hd_type == 1" class="write-radius consumer-code">
  31. <text class="consumer-code-text">消费码:</text>
  32. <input class="consumer-code-input" v-model="eticketno" type="text" value="" placeholder="请填写订单消费码" />
  33. </view>
  34. <!-- 消费码蝴蝶券才有 end -->
  35. <view class="write-radius hotel-info">
  36. <view class="hotel-info-room">
  37. <image class="room-image" :src="resdata.litpic" mode="scaleToFill"></image>
  38. <view class="hotel-info-text">
  39. <view class="hotel-info-text-item hotel-info-text-hotel">{{hotelname}}</view>
  40. <view class="hotel-info-text-item hotel-info-text-room">{{roomname}}</view>
  41. <view class="hotel-info-text-item hotel-info-text-service">
  42. <text class="hotel-info-text-service-item" v-if="breakfirst">{{breakfirst}}</text>
  43. <text class="hotel-info-text-service-item" v-if="roomwindow">{{roomwindow}}</text>
  44. <text class="hotel-info-text-service-item" v-if="roomstyle">{{roomstyle}}</text>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="room-detail">
  49. <view class="room-detail-item room-detail-time">
  50. <view class="room-detail-time-data">
  51. 入住:{{resdata.usedate}} 离店:{{resdata.departdate}}
  52. </view>
  53. <view class="room-detail-time-total">
  54. 共{{havenight}}晚
  55. </view>
  56. </view>
  57. <!-- <view class="room-detail-item">
  58. <view class="room-list">
  59. <view class="room-list-item">
  60. <view class="room-list-item-date">2020-08-19</view>
  61. <view class="room-list-item-number">1间</view>
  62. </view>
  63. <view class="room-list-item">
  64. <view class="room-list-item-date">2020-08-19</view>
  65. <view class="room-list-item-number">1间</view>
  66. </view>
  67. </view>
  68. <view class="room-list-total">
  69. </view>
  70. </view> -->
  71. <!-- <view class="pay-total">
  72. <view class="pay-total-item pay-total-number">
  73. <view class="pay-total-til">总计</view>
  74. <view class="pay-total-con">¥500</view>
  75. </view>
  76. <view class="pay-total-item pay-total-way">
  77. <view class="pay-total-til">预订方式</view>
  78. <view class="pay-total-con">全款支付</view>
  79. </view>
  80. </view> -->
  81. </view>
  82. <!-- room-detail end -->
  83. </view>
  84. <!-- hotel-info end -->
  85. <view class="write-radius contact-info">
  86. <view class="contact-info-item contact-info-name">
  87. <view class="contact-info-item-til">联系人:</view>
  88. <view class="contact-info-item-con">蝴蝶旅居</view>
  89. </view>
  90. <view class="contact-info-item contact-info-phone">
  91. <view class="contact-info-item-til">联系电话:</view>
  92. <view class="contact-info-item-con">13984111111</view>
  93. </view>
  94. </view>
  95. <!-- contact-info end -->
  96. </view>
  97. <view class="bottom-btn-wrap">
  98. <button class="bottom-btn" @click="writeoff" type="primary">核销</button>
  99. </view>
  100. </view>
  101. </template>
  102. <script>
  103. // import $wxApi from "../../../wxapi.js";
  104. export default{
  105. components:{
  106. },
  107. props:{
  108. },
  109. data(){
  110. return{
  111. id:'',
  112. hd_type:'',//订单类别 1电子券,2实体券
  113. hotelname:'',
  114. roomname:'',
  115. breakfirst:'',
  116. roomstyle:'',
  117. roomwindow:'',
  118. orderId:'',//orderId 订单ID,与订单消费码必填其一 如果是电子券则等于 this.id
  119. eticketno:'',//订单消费码,与订单ID必填其一
  120. ticket:[],//蝴蝶券编号数组,实体券支付时必填
  121. enterHDnumber:'',
  122. writeoff_remark:'',//核销备注
  123. resdata:{},
  124. params:{
  125. token:'',
  126. },
  127. writeoffparams:{
  128. token:'',
  129. },
  130. havenight:'',//共几晚
  131. }
  132. },
  133. onLoad(option){
  134. //检查登录,获取token
  135. let loginRes = this.checkLogin('pages/index/index', '2');
  136. // console.log('loginRes',loginRes);
  137. if(!loginRes){return false;}
  138. this.params.token=loginRes[0];
  139. this.id = option.id;
  140. this.params = Object.assign(this.params,{id:option.id});
  141. this.getdetail();
  142. },
  143. methods:{
  144. //获取订单详情
  145. getdetail:function(){
  146. this.$api.http.post(this.config.apiBaseurl+'hotel/writeoff/detail', this.params,{
  147. header: {
  148. Accept:'application/json',
  149. Authorization: 'Bearer '+ this.params.token, //注意Bearer后面有一空格
  150. }
  151. } ).then(res => {
  152. if(res.data.code=='1001'){
  153. uni.redirectTo({
  154. url:`/pages/login/login?backpage=/pages/writeoff/writeoffitem/writeoffitem?id=${this.id}&backtype=2`,
  155. });
  156. };
  157. this.hd_type = res.data.hd_type;
  158. this.resdata = res.data;
  159. this.hotelname = res.data.hotel.title;
  160. this.roomname = res.data.room.roomname;
  161. this.breakfirst = res.data.room.breakfirst;
  162. this.roomstyle = res.data.room.roomstyle;
  163. this.roomwindow = res.data.room.roomwindow;
  164. //计算几晚
  165. let day1 = Date.parse(new Date(res.data.usedate.replace(/-/g, '/'))) / 1000;
  166. let day2 = Date.parse(new Date(res.data.departdate.replace(/-/g, '/'))) / 1000;
  167. this.havenight = Math.abs((day1 - day2) / (3600 * 24));
  168. // console.log(JSON.parse(JSON.stringify(res.data)));
  169. }).catch(err => {
  170. });
  171. },
  172. //添加蝴蝶券
  173. pushHD(hd){
  174. let self = this;
  175. Array.prototype.pushNoRepeat = function(){
  176. for(var i=0; i<arguments.length; i++){
  177. var ele = arguments[i];
  178. if(this.indexOf(ele) == -1){
  179. let codeparames ={
  180. token :self.params.token,
  181. code:ele
  182. };
  183. //验证蝴蝶券
  184. self.$api.http.post(self.config.apiBaseurl+'hotel/writeoff/verify',codeparames,{
  185. header: {
  186. Accept:'application/json',
  187. Authorization: 'Bearer '+ self.params.token, //注意Bearer后面有一空格
  188. }
  189. }).then(res =>{
  190. if(res.data.state == 'ok'){
  191. this.push(ele);
  192. }else{
  193. uni.showToast({
  194. icon:'none',
  195. title:res.data.message,
  196. duration: 2000
  197. });
  198. }
  199. console.log(res)
  200. }).catch(err =>{
  201. console.log(err)
  202. });
  203. }else{
  204. uni.showToast({
  205. icon:'none',
  206. title:'该券已经添加',
  207. duration: 2000
  208. });
  209. }
  210. }
  211. };
  212. this.ticket.pushNoRepeat(hd);
  213. },
  214. //手动输入蝴蝶券
  215. enterHD(){
  216. this.pushHD(this.enterHDnumber)
  217. },
  218. //扫码蝴蝶券
  219. scanCode:function(){
  220. $wxApi.JSAPI().then(res =>{
  221. alert('555'+res)
  222. });
  223. // alert('1111'+hdcode);
  224. // document.write('1111'+hdcode);
  225. console.log('$wxApi',$wxApi);
  226. this.pushHD(res.resultStr);
  227. uni.showToast({
  228. icon:'none',
  229. title:'暂时无法使用3',
  230. duration: 2000
  231. });
  232. return;
  233. // wx.scanQRCode({
  234. // needResult: 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  235. // scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  236. // success: function (res) {
  237. // var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
  238. // console.log('scanQRCode',result);
  239. // }
  240. // });
  241. // uni.scanCode({
  242. // onlyFromCamera: true,// 只允许通过相机扫码
  243. // success: function (res) {
  244. // console.log('条码类型:' + res.scanType);
  245. // console.log('条码内容:' + res.result);
  246. // }
  247. // });
  248. },
  249. //提交
  250. writeoff:function(){
  251. console.log(this.hd_type);
  252. if(this.hd_type == 2){
  253. this.orderId = this.id;
  254. if(this.writeoffparams.ticket.length<this.resdata.hd_count){
  255. uni.showToast({
  256. icon:'none',
  257. title:'蝴蝶券不足',
  258. duration: 2000
  259. });
  260. return false;
  261. };
  262. };
  263. this.writeoffparams.token = this.params.token;
  264. this.writeoffparams = Object.assign(this.writeoffparams,{orderId:this.orderId,eticketno:this.eticketno,ticket:this.ticket});
  265. // console.log('this.writeoffparams',this.writeoffparams);
  266. this.$api.http.post(this.config.apiBaseurl+'hotel/writeoff/inspection', this.writeoffparams,{
  267. header: {
  268. Accept:'application/json',
  269. Authorization: 'Bearer '+ this.params.token, //注意Bearer后面有一空格
  270. }
  271. } ).then(res => {
  272. uni.showToast({
  273. icon:'none',
  274. title:res.data.message,
  275. duration: 2000
  276. });
  277. console.log(res);
  278. }).catch(err => {
  279. console.log(err);
  280. });
  281. },
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. page{background-color: $uni-bg-color-grey;}
  287. @import url("/common/css/order.scss");
  288. .addhd{margin: 40rpx 0;display: flex;justify-content: space-between;}
  289. .addhd-input,
  290. .addhd-button{height: 50rpx;line-height: 50rpx;font-size: 28rpx;}
  291. .addhd-button{margin: 0;}
  292. .addhd-input{border: 1px solid #4235B6;border-radius: 12rpx;flex: 1;margin-right: 15rpx;padding: 0 12rpx;}
  293. </style>