<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="所属护理站" prop="nurseStationName">
        <el-button type="" class="stationbtn" @click="ParamsStation(true)">{{
          queryParams.nurseStationName
        }}</el-button>
      </el-form-item>
      <el-form-item label="商品名称" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="商品分类名称" prop="goodsCategoryName">
        <el-input
          v-model="queryParams.goodsCategoryName"
          placeholder="请输入商品分类名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="商品用途" prop="goodsPurpose">
        <el-select
          v-model="queryParams.goodsPurpose"
          placeholder="请选择商品用途"
        >
          <el-option
            v-for="item in goods"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否上架" prop="whetherShelf">
        <el-select v-model="queryParams.whetherShelf" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:operateGoodInfo:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:operateGoodInfo:edit']"
          >修改</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="goodsInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="所属护理站"
        align="center"
        prop="nurseStationName"
      />
      <el-table-column label="商品编码" align="center" prop="goodsCode" />
      <el-table-column
        label="商品名称"
        align="center"
        prop="goodsName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="商品分类名称"
        align="center"
        prop="goodsCategoryName"
      />
      <el-table-column label="商品用途" align="center" prop="goodsPurpose">
        <template slot-scope="scope">
          {{ scope.row.goodsPurpose == "BUSINESS" ? "买卖" : "" }}
          {{ scope.row.goodsPurpose == "LEASE" ? "租赁" : "" }}
        </template>
      </el-table-column>
      <el-table-column label="上架状态" align="center" prop="whetherShelf">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.whetherShelf"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="upwhetherShelf(scope.row)"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column
        label="上架时间"
        align="center"
        prop="shelfTime"
        width="180"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.whetherShelf">{{ scope.row.shelfTime }}</div>
          <div v-else></div>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        >chaxun
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:operateGoodInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:operateGoodInfo:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改商品基本信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
      :before-close="cancel"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
        :inline="true"
      >
        <el-form-item label="商品名称" prop="goodsName">
          <el-input
            v-model="form.goodsName"
            placeholder="请输入商品名称"
            max="40"
            style="width: 210px"
          />
        </el-form-item>
        <el-form-item label="护理站名称" prop="nurseStationId">
          <el-button
            type=""
            @click="clickinnerVisible"
            v-if="StationName == '请选择所属护理站'"
            style="

              width: 210px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ StationName }}</el-button
          >
          <el-button
            type=""
            @click="clickinnerVisible"
            v-else
            style="
              width: 210px;
              text-align: left;
              height: 36px;
              overflow: hidden;
            "
            >{{ StationName }}</el-button
          >
        </el-form-item>
        <el-form-item label="商品分类名称" prop="goodsCategoryId">
          <!-- v-model="form.parentIdList" -->
          <el-cascader
            :props="treeOption"
            @change="change"
            style="width: 210px"
            :show-all-levels="false"
            :clearable="true"
            ref="cascader"
            :placeholder="form.goodsCategoryName ? form.goodsCategoryName : ''"
            :key="isResouceShow"
          >
          </el-cascader>
          <!-- <el-select
            style="width: 210px"
            v-model="form.goodsCategoryId"
            clearable
            placeholder="请选择商品分类名称"
          >
            <el-option
              v-for="item in goodsCategorylist"
              :key="item.id"
              :label="item.goodsCategoryName"
              :value="item.id"
            >
            </el-option>
          </el-select> -->
        </el-form-item>
        <el-form-item label="商品用途" prop="goodsPurpose">
          <el-select
            v-model="form.goodsPurpose"
            placeholder="请选择商品用途"
            style="width: 210px"
          >
            <el-option
              v-for="item in goods"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品度量单位" prop="goodsUnit">
          <el-input
            max="8"
            v-model="form.goodsUnit"
            placeholder="请输入商品度量单位"
            style="width: 210px"
          />
        </el-form-item>
        <el-form-item label="商品顺序" prop="sort">
          <el-input
            max="8"
            v-model.number="form.sort"
            placeholder="值越大排名越靠前"
            style="width: 210px"
          />
        </el-form-item>
        <el-form-item label="商品图片" prop="goodsPictureUrl">
          <stationAcatar
            @imgUrl="imgUrl"
            :img="form.goodsPictureUrl"
            :type="'goodsPictureUrl'"
          />
        </el-form-item>
        <el-table
          ref="goodDetailsLists"
          :data="goodDetailsLists"
          label-width="50px"
          style="margin-top: 20px"
        >
          <el-table-column label="商品属性名称" align="center">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.attributeName"
                maxlength="40"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="商品单价" align="center">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.goodsPrice"
                type="number"
                oninput="if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)} if(value.length>7){value=value.slice(0,7)}"
                min="0"
                placeholder="小数点后两位(元)"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="库存" align="center">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.goodsStock"
                oninput="value=value.replace(/[^\d]/g,'')"
                maxLength="9"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="商品属性顺序" align="center">
            <template slot-scope="scope">
              <el-input
                v-model.number="scope.row.attributeDetailsSort"
                oninput="value=value.replace(/[^\d]/g,'')"
                placeholder="值越大排名越靠前"
                maxLength="9"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="积分兑换标识" align="center"  >
            <template slot-scope="scope">
              <el-select
                v-model.number="scope.row.integralExchangeFlag"
                placeholder="请选择积分兑换标识"
                clearable
                @change="changeExchangeFlag(scope.row)"
              >
                <el-option
                  v-for="item in integraloption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="使用积分数量" align="center" >
            <template slot-scope="scope">
              <el-input
              :disabled="!scope.row.integralExchangeFlag?true:false"
                v-model.number="scope.row.integralExchangeSill"
                oninput="value=value.replace(/[^\d]/g,'')"
                placeholder="使用积分数量"
                maxLength="10"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="积分兑换商品数量" align="center" >
            <template slot-scope="scope">
              <el-input
              :disabled="!scope.row.integralExchangeFlag?true:false"
                v-model.number="scope.row.integralExchangeCount"
                oninput="value=value.replace(/[^\d]/g,'')"
                placeholder="积分兑换商品数量"
                maxLength="10"
              ></el-input>
            </template>
          </el-table-column>

          <el-table-column label="商品属性图片" align="center" width="150">
            <template slot-scope="scope">
              <stationAcatar
                @imgUrl="attributePitureUrl"
                @item="attributePitureitem"
                :img="scope.row.attributePitureUrl"
                :type="'attributePitureUrl'"
                :item="scope.row"
              />
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="addgoodAttributeDetail"
                >新增</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="delgoodAttributeDetail(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-form-item
          label="商品概述"
          prop="goodsRemark"
          style="margin-top: 20px"
        >
          <editor
            @imgs="imgs"
            :min-height="100"
            style="width: 90%; margin: 0 auto"
            v-model="form.goodsRemark"
          ></editor>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 新增护理站名称弹框 -->
    <el-dialog
      title="选择护理站"
      :visible.sync="innerVisible"
      width="1000px"
      append-to-body
      :before-close="addcancel"
    >
      <el-form
        ref="queryForm"
        :model="getListByUserquery"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item
          label="护理站编码"
          prop="nurseStationCode"
          label-width="120"
        >
          <el-input
            v-model="getListByUserquery.nurseStationCode"
            placeholder="请输入护理站编码"
            clearable
          />
        </el-form-item>
        <el-form-item
          label="护理站名称"
          prop="nurseStationName"
          label-width="120"
        >
          <el-input
            v-model="getListByUserquery.nurseStationName"
            placeholder="请输入护理站名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery2"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery2"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table :data="nurseStationlist" @cell-dblclick="nurseclick">
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              v-if="form.nurseStationId == scope.row.id"
              circle
              @click="nurseclick(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="nurseclick(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="nurseStationCode"
          label="护理站编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="nurseStationName"
          label="护理站名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>

        <el-table-column property="phone" label="联系电话" align="center">
        </el-table-column>
        <el-table-column
          property="address"
          label="护理站地址"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total2 > 0"
        :total="total2"
        :page.sync="getListByUserquery.pageNum"
        :limit.sync="getListByUserquery.pageSize"
        @pagination="handleQuery2"
      />
    </el-dialog>
  </div>
</template>

<script>
import indexjs from "./indexjs.js";
export default indexjs;
</script>
<style lang="scss" scoped>
.stationbtn {
  width: 208px;
  text-align: left;
  height: 32px;
  overflow: hidden;
  font-size: 14px;
}
::v-deep .el-cascader .el-input input::-webkit-input-placeholder {
  color: black;
}
</style>

