<template>
<view class="audit">
	<view class="ddlist">
		<view class="cont">
			<view class="list border"><text class="glay">处方编号</text><text>{{drugNo}}</text></view>
			<view class="list"><text class="glay">订单编号</text><text>{{orderId}}</text></view>
			<!-- <view class="list"><text class="glay">订单金额</text><text class="red">￥<text>金额</text></text></view> -->
		</view>
	</view>
	<view class="content">
		<image :src="picUrlss+'audit.png'" class="img" v-if="flag"></image>
		<image :src="picUrlss+'audit2.png'" v-else></image>
		<text v-if="flag">处方审核中，请稍等！</text>
		<text v-else>
			{{drugNo?'处方审核失败':'开方失败'}}，请重新下单~
			</text>
		
	</view>
	<view class="btn">
		<view class="mini-btn" v-if="flag" @tap="goOrder">查看订单</view>
		<view class="mini-btn" v-else @tap="black">返回</view>
	</view>
</view>
</template>

<script>
// prescription/audit/audit.js
const app = getApp();
const req = require("../../utils/request.js");

export default {
  data() {
    return {
		picUrlss: req.public.picUrls,
      orderId: '',
      drugNo: '',
      flag: true,
	  config: ''
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderId: options.orderId,
      drugNo: options.drugNo
    });
    // console.log(options.orderId, options);
    uni.setNavigationBarTitle({
      title: "处方审核中"
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getsavedesdrug();
	this.config = JSON.parse(req.getStorage('configRes'));
  },
  methods: {
    // async init() {
    //   await this.getsavedesdrug();
    // },
    getsavedesdrug(sc) {
      let data = {
        orderId: this.orderId,
        drugNo: this.drugNo
      };
      let than = this;
      // console.log(this.flag);

      if (this.drugNo == '') {
        than.setData({
          flag: false
        });
        uni.setNavigationBarTitle({
          title: "开方失败"
        });
        uni.showToast({
          title: '开方失败',
          icon: 'none',
          success: function () {
            setTimeout(function () {
				app.globalData.reLaunchTo('pages/index/index')
            }, 2000);
          }
        });
      } else {
        req.postRequest('/api/orderdurg/drugStatus', data, function (res) {
          //审核中 
          if (res.checkType == 0) {
            // console.log("审核中");
          } //审核成功 1 跳转到订单详情


          if (res.checkType == 1) {
            uni.redirectTo({
              url: '/mine/orderDet/orderDet?id=' + res.orderId
            });
            // console.log("审核成功");
          } //审核失败 3   样式改变


          if (res.checkType == 3) {
            than.setData({
              flag: false
            });
            uni.setNavigationBarTitle({
              title: "处方审核失败"
            });
          }
        });
      }
    },

    goOrder() {
      uni.redirectTo({
        url: '/mine/orderDet/orderDet?id=' + this.orderId
      });
    },

    black() {
      app.globalData.reLaunchTo('pages/index/index')
    }

  }
};
</script>
<style>
@import "./audit.css";
</style>