<!--packageF/storeManagement/components/base_set/base_set.wxml-->

<view class="shop-img">
  <view class="img-title">
    <i class="iconfont icon-fontclass-xinghao"></i>
    <view>商品图片：</view>
  </view>

  <yz-uploader bind:updateImages="updateGoodsImg" fileSrc="{{goodsImg}}" customStyle="width:130rpx;height:130rpx;border:1rpx dashed #ccc;"
    customBoxStyle="padding:0;margin-top:29rpx;" max_count="{{1}}">
  </yz-uploader>

  <view class="img-title" style="margin-top:39rpx;">
    <view>其他图片：</view>
  </view>

  <yz-uploader bind:updateImages="updateOtherImgs" fileSrc="{{otherImgs}}" customStyle="width:130rpx;height:130rpx;border:1rpx dashed #ccc;"
    customBoxStyle="padding:0;margin-top:29rpx;">
  </yz-uploader>

</view>

<view class="cell" wx:if="{{!goodsId}}">
  <van-cell value="{{goodsDetail ? '修改' : '添加'}}" is-link bindtap="showGoodsDetailPop">
    <template is="cellTitle" data="{{title:'商品详情：',slot:'title'}}"></template>
  </van-cell>
</view>

<view class="cell">
  <van-field model:value="{{goodsName}}" placeholder="请输入商品名称">
    <template is="cellTitle" data="{{required:true,title:'商品名称：',slot:'label'}}"></template>
  </van-field>
</view>

<view class="cell">
  <van-cell is-link>
    <template is="cellTitle" data="{{required:true,title:'商品分类：',slot:'title'}}"></template>
    <goods-category-pop class="goods-category-pop" categoryList="{{categoryMenus}}" bindconfirmType="editCategory">
    </goods-category-pop>
  </van-cell>
  <view style="white-space: pre-wrap;">
    <view wx:for="{{goodsCategory}}" wx:for-item="tag" wx:key="index" class="category-tag">
      <view style="background-color:#F3F3F3;padding: 0.2rem 0.5rem;">
        <text wx:if="{{tag.parent_name}}">{{tag.parent_name}}</text>
        <text wx:if="{{tag.child_name}}">/{{tag.child_name}}</text>
        <text wx:if="{{tag.third_name}}">/{{tag.third_name}}</text>
      </view>
      <i class="close-icon icon-guanbi iconfont" data-index="{{index}}" bindtap="removeCategory"></i>
    </view>
  </view>
</view>

<view class="cell">
  <van-cell value="{{goodsType==1?'实体商品':'虚拟商品'}}" is-link bindtap="showGoodsTypePop">
    <template is="cellTitle" data="{{title:'商品类型：',slot:'title'}}"></template>
  </van-cell>
  <van-cell wx:if="{{goodsType==2}}">
    <template is="cellTitle" data="{{title:'下单是否需要地址',slot:'title'}}"></template>
    <van-switch checked="{{needAddress}}" size="40rpx" active-value="{{1}}" inactive-value="{{0}}"
      data-name="needAddress" bindchange="switchChange" inactive-color="#bebebe" active-color="#f15353" ></van-switch>
  </van-cell>
</view>

<view class="cell">
  <van-field model:value="{{goodsUnit}}" placeholder="请输入商品单位">
    <template is="cellTitle" data="{{required:true,title:'商品单位：',slot:'label'}}"></template>
  </van-field>
</view>

<view class="cell">
  <van-field model:value="{{price}}" placeholder="请输入商品现价" type="digit">
    <template is="cellTitle" data="{{required:true,title:'商品现价：',slot:'label'}}"></template>
  </van-field>
  <van-field model:value="{{marketPrice}}" placeholder="请输入商品原价" type="digit">
    <template is="cellTitle" data="{{title:'商品原价：',slot:'label'}}"></template>
  </van-field>
  <van-field model:value="{{costPrice}}" placeholder="请输入商品成本" type="digit">
    <template is="cellTitle" data="{{title:'商品成本：',slot:'label'}}"></template>
  </van-field>
</view>

<view class="cell">
  <van-field model:value="{{stock}}" placeholder="请输入商品库存" type="number">
    <template is="cellTitle" data="{{required:true,title:'商品库存：',slot:'label'}}"></template>
  </van-field>
  <van-cell value="{{tool.stockType(stockType)}}" is-link bindtap="showStockTypePop">
    <template is="cellTitle" data="{{title:'减库存的方式：',slot:'title'}}"></template>
  </van-cell>
</view>

<view class="cell">
  <van-cell>
    <template is="cellTitle" data="{{title:'不可退货退款',slot:'title'}}"></template>
    <van-switch checked="{{refund}}" size="40rpx" active-value="{{1}}" inactive-value="{{0}}" inactive-color="#bebebe" active-color="#f15353" data-name="refund"
      bindchange="switchChange"></van-switch>
  </van-cell>
</view>

<view class="hide-logistics {{ viewMore ? 'show-logistics' : ''}}">
  <view style="padding: 5px 16px;">配送</view>
  <view class="cell">
    <van-cell value="{{dispatchData.dispatch_type ? '统一邮费' : '运费模板'}}" is-link bindtap="showDispatchTypePop">
      <template is="cellTitle" data="{{title:'运费设置：',slot:'title'}}"></template>
    </van-cell>
    <van-cell value="{{tool.distributeStr(dispatchTypes,distributes)}}" is-link bindtap="showDistributeTypePop">
      <template is="cellTitle" data="{{title:'配送方式：',slot:'title'}}"></template>
    </van-cell>
  </view>
</view>
<!-- 更多设置 -->
<view class="more" bindtap="viewMoreSet">
  <text>{{viewMore ? '收起' : '更多设置'}}</text>
  <van-icon wx:if="{{viewMore}}" name="arrow-up"></van-icon>
  <van-icon wx:else name="arrow-down"></van-icon>
</view>

<goods-details-pop class="goods-details-pop" bindsaveEdit="saveGoodsDetail"></goods-details-pop>
<goods-type-pop class="goods-type-pop" defaultType="{{goodsType}}" bindconfirmType="editGoodsType"></goods-type-pop>
<stock-type-pop class="stock-type-pop" defaultType="{{stockType}}" bindconfirmType="editStockType"></stock-type-pop>
<dispatch-type-pop class="dispatch-type-pop" templates="{{dispatchTemplates}}" defaultData="{{dispatchData}}"
  bindconfirmType="editDispatch"></dispatch-type-pop>
<distribute-type-pop class="distribute-type-pop" dispatchTypeList="{{dispatchTypes}}" defaultChecks="{{distributes}}"
  bindconfirmType="editDistribute"></distribute-type-pop>


<template name="cellTitle">
  <view class="cell-title" slot="{{slot}}">
    <i wx:if="{{required}}" class="iconfont icon-fontclass-xinghao"></i>
    <view>{{title}}</view>
  </view>
</template>




<wxs module="tool">
  function stockType(i) {
    var arr = ['拍下减库存', '付款减库存', '永不减库存'];
    return arr[i];
  }

  function distributeStr(dispatchTypes,distributes) {
    var typeTexts = [];
    var arr = dispatchTypes.filter(function(item){ return distributes.indexOf(item.id + '') > -1; });
    typeTexts = arr.map(function(pre, current) {
      return pre.name;
    });
    return typeTexts.join("/");
  }

  module.exports.stockType = stockType;
  module.exports.distributeStr = distributeStr;

</wxs>