<template>
    <div class="app-container">
        <el-row :gutter="20">
            <!--部门数据-->
            <el-col :span="2" :xs="24" style="margin-top: 80px">
                <div class="head-container">
                    <el-tabs v-model="checkClothType" @tab-click="handleQuery" tab-position="left">
                        <el-tab-pane v-for="item in clothTypeList" :label="item.name" :name="item.id + ''"></el-tab-pane>
                    </el-tabs>
                </div>
            </el-col>
            <el-col :span="22" :xs="24">
                <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
                    <el-form-item prop="checkStoreAreaId">
                        <el-tabs v-model="checkStoreAreaId" @tab-click="handleQuery">
                            <el-tab-pane v-for="item in areaList" :label="item.name" :name="item.id + ''"></el-tab-pane>
                        </el-tabs>
                        <!--                <el-select v-model="queryParams.storeAreaId" placeholder="请选择区域" clearable @change="handleQuery" filterable>-->
                        <!--                    <el-option v-for="(item, index) in areaList" :key="index" :label="item.name" :value="item.id" />-->
                        <!--                </el-select>-->
                    </el-form-item>
                    <div></div>
                    <el-form-item prop="name">
                        <el-input v-model="queryParams.name" placeholder="请输入衣服名称" clearable @keyup.enter.native="handleQuery" />
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <!--        <el-row :gutter="10" class="mb8">-->
                <!--          <el-button type="primary" plain icon="el-icon-document-copy" @click="handleCopy">复制区域</el-button>-->

                <!--            -->
                <!--        </el-row>-->
                <!--                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
                <Page uri="/mapi/cloth/price/getClothPriceListByClothType" :request-params="queryParams" ref="pagination">
                    <el-table-column label="衣服ID" align="center" prop="clothId" />
                    <el-table-column label="区域" align="center" prop="areaName" />

                    <el-table-column label="衣服名称" align="center" prop="name" />
                    <el-table-column label="洗衣类型名称" align="center" prop="typeName" />
                    <el-table-column label="价格" align="center" prop="price">
                        <template slot-scope="scope">
                            {{ scope.row.price ? scope.row.price : '未设置价格' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
                        <template slot-scope="scope">
                            <el-button type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">设置</el-button>
                        </template>
                    </el-table-column>
                </Page>
            </el-col>
        </el-row>
        <!--  设置价格  -->
        <el-dialog title="设置价格" :visible.sync="unitPriceType" width="30%" :before-close="handleClose">
            <form ref="unitpriceForm">
                <el-input-number v-model="unitpriceForm.price" :min="1" :max="99999" :step="1" style="width: 100%" />
            </form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="unitPriceType = false">取 消</el-button>
                <el-button type="primary" @click="setunitPrice('unitpriceForm')">提 交</el-button>
            </span>
        </el-dialog>

        <!-- 复制区域 -->
        <el-dialog title="区域复制" :visible.sync="open" size="30%" append-to-body>
            <el-row :gutter="15">
                <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                    <el-col :span="24">
                        <el-form-item label="选择区域" prop="storeAreaIdFrom">
                            <el-select v-model="form.storeAreaIdFrom" placeholder="请选择区域" clearable filterable>
                                <el-option v-for="(item, index) in areaList" :key="index" :label="item.name" :value="item.id" :disabled="item.id == form.storeAreaIdTo" />
                            </el-select>
                        </el-form-item>
                        <el-form-item label="复制区域" prop="storeAreaIdTo">
                            <el-select v-model="form.storeAreaIdTo" placeholder="请选择复制区域" clearable filterable>
                                <el-option v-for="(item, index) in areaList" :key="index" :label="item.name" :value="item.id" :disabled="item.id == form.storeAreaIdFrom" />
                            </el-select>
                        </el-form-item>
                        <el-form-item label="价格倍数" prop="multiple">
                            <el-input-number v-model="form.multiple" :min="0.01" :max="100" :step="0.01" style="width: 100%" />
                            <div class="remark">价格倍数是以选择区域为底数乘以当前选择的价格倍数,最终得到复制区域的价格体系</div>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-row>

            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm" style="margin-left: 5%">提交</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { listStoreArea } from '@/api/system/storeArea'
import { getClothPriceListByClothType, setPriceByClothType, setPriceByClothTypeCopyArea } from '@/api/cloth/unitPrice'

export default {
    name: 'unitPrice',
    dicts: ['sys_normal_disable'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            clothType: null,
            // 单价表格数据
            unitPriceList: [],
            checkStoreAreaId: '1',
            checkClothType: '1',
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                clothType: null,
                storeAreaId: null,
                name: null
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                storeAreaIdFrom: [{ required: true, message: '请选择区域', trigger: 'change' }],
                storeAreaIdTo: [{ required: true, message: '请选择复制区域', trigger: 'change' }],
                multiple: [{ required: true, message: '清填写价格倍数', trigger: 'blur' }]
            },
            areaList: [],
            clothTypeList: [
                {
                    id: '1',
                    name: '加厚类型'
                },
                {
                    id: '2',
                    name: '羊绒类型'
                },
                {
                    id: '3',
                    name: '真丝类型'
                },
                {
                    id: '4',
                    name: '儿童类型'
                }
            ],
            unitPriceType: false,
            unitpriceForm: {}
        }
    },
    created() {
        this.getAreaList()
        this.getList()
    },
    methods: {
        /** 查询衣服品牌列表 */
        getList() {
            this.queryParams.storeAreaId = parseInt(this.checkStoreAreaId)
            this.queryParams.clothType = parseInt(this.checkClothType)
            this.$nextTick(() => {
                this.$refs.pagination.handleSearch(true)
            })
        },
        getAreaList() {
            listStoreArea({ pageSize: 10000, pageNum: 1, status: '0' }).then((res) => {
                this.areaList = res.rows
            })
        },
        // 表单重置
        reset() {
            this.form = {
                storeAreaIdFrom: null,
                storeAreaIdTo: null,
                multiple: null
            }
            this.resetForm('form')
        },
        // 取消按钮
        cancel() {
            this.reset()
            this.open = false
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 区域复制按钮操作 */
        handleCopy() {
            this.open = true
        },
        /** 设置按钮操作 */
        handleUpdate(row) {
            this.unitpriceForm = Object.assign({}, row)
            this.unitPriceType = true
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    setPriceByClothTypeCopyArea({ ...this.form, ...{ clothType: this.checkClothType } }).then((response) => {
                        this.$modal.msgSuccess('复制成功')
                        this.open = false
                        this.getList()
                    })
                }
            })
        },
        checkClose(done) {
            this.$confirm('是否关闭表单，关闭后数据将丢失？')
                .then(function () {
                    done()
                })
                .then(() => {})
                .catch(() => {})
        },

        setunitPrice() {
            if (!this.unitpriceForm.price) {
                this.$modal.msgError('请输入价格')
                return
            }
            setPriceByClothType({ ...this.unitpriceForm, ...{ clothType: this.checkClothType } }).then((response) => {
                this.$modal.msgSuccess('设置成功')
                this.unitPriceType = false
                this.getList()
            })
        },

        handleClose(done) {
            this.$confirm('是否关闭设置表单？')
                .then((_) => {
                    done()
                })
                .catch((_) => {})
        }
    }
}
</script>
<style lang="scss" scoped>
.remark {
    margin-top: 10px;
    background-color: rgba(255, 228, 74, 0.1);
    border: 1px dashed #ffe44a;
    font-size: 14px;
    color: #e6a23c;
    width: 100%;
    padding: 20px;
    border-radius: 5px;
    line-height: 25px;
}
</style>
