/*
 * @Descripttion: HJ
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2021-02-07 09:37:55
 * @LastEditors: HJ
 * @LastEditTime: 2021-03-19 16:09:31
 */
import { loadEnd } from "../../utils/index";
import { __FAIL_FN } from "../../utils/network";
const masses = require("../../api/masses.js");
const baseUrl = require("../../api/index.js").config;
const { Tips } = getApp();
Page({
  data: {
    foodSafetyInfo: [
      {
        label: "单位名称",
        field: "companyName",
      },
      {
        label: "许可证号",
        field: "licenseNumber",
      },
      {
        label: "法定代表人（负责人）",
        field: "legalRepresentative",
      },
      {
        label: "经营地址",
        field: "businessAddress",
      },
      {
        label: "主体业态",
        field: "mainBusiness",
      },
      {
        label: "经营范围",
        field: "businessScope",
      },
      {
        label: "有效期至",
        field: "quantitativeClassificationEnd",
      },
      {
        label: "量化分级信息",
        field: "quantitativeClassificationImage",
      },
    ],
    infoResult: {},
    quantification: "",
    licenses: [],
  },
  onLoad(option) {
    const { storeId } = option;
    if (storeId) {
      this.getInfo(storeId);
    } else {
      Tips("参数错误，请重新进入");
    }
  },
  getInfo(storeid) {
    const merchantid = wx.getStorageSync("merchantid");
    const lat = wx.getStorageSync("latitude");
    const lon = wx.getStorageSync("longitude");
    masses.getFeedbackstore(
      baseUrl.waimaiUrl +
        "/client/merchants/" +
        merchantid +
        "/stores/" +
        storeid,
      {
        latitude: lat,
        longitude: lon,
      },
      {},
      "加载中",
      (res) => {
        this.handlerInfo(res);
      },
      (err) => {
        loadEnd(this);
        __FAIL_FN({
          res: err,
        });
      }
    );
  },
  handlerInfo(res) {
    const { results } = res;

    const {
      businessLicenseImgs,
      manageLicenseImags,
      quantitativeClassificationImage: quantification,
    } = results;

    this.setData({
      infoResult: results,
      quantification,
      licenses: [businessLicenseImgs, manageLicenseImags],
    });
  },
  previewImgs({ currentTarget: { dataset } }) {
    const { imgPath } = dataset;
    const { licenses } = this.data;
    wx.previewImage({
      current: imgPath,
      urls: licenses,
    });
  },
  previewQImgs(e) {
    const {
      currentTarget: {
        dataset: { imgPath },
      },
    } = e;
    const { quantification } = this.data;
    wx.previewImage({
      current: imgPath || quantification,
      urls: [quantification],
    });
  },
});
