<!-- @desc:销售退货入库新建  @auth:付斌  @time:2023-10-23 14:10 -->
<template>
  <div class="main-div">
    <DkCollapse @on-change="changeCollapse" ref="collapse">
      <DkPanel prop="essentialInformation">
        <!--  单据信息  -->
        <DkForm slot="content" ref="formInline" v-model="formData" style="width:100%;margin-top: 30px">
          <!--订单单号-->
          <DkFormItem prop="orderNo">
            <InputPop ref="orderNo" v-model="formData.orderNo" :readonly="true"/>
          </DkFormItem>
          <!--合同号-->
          <DkFormItem prop="contractNo">
            <InputPop ref="contractNo" v-model="formData.contractNo"
                      :readonly="checkColumnIsEdit('contractNo')"/>
          </DkFormItem>
          <!--客户电话-->
          <DkFormItem prop="customerPhone" :required="true">
            <SelectMagnifier v-model="formData.customerPhone"
                             :input-read-only="customerPhoneReadOnly"
                             ref="customerPhone" :select-flag=false
                             :type="this.$config.MagnifierType.staff"
                             :disabled="true"
                             @ok="selectCustomer"
                             :multiple="false">
            </SelectMagnifier>
          </DkFormItem>
          <!--客户名称-->
          <DkFormItem prop="customerName" :required="true">
            <InputPop ref="customerName" :readonly="checkColumnIsEdit('customerName')"
                      v-model="formData.customerName"/>
          </DkFormItem>
          <!--客户区域-->
          <!--          <DkFormItem prop="customerDistrict"-->
          <!--                      :required="true">-->
          <!--            &lt;!&ndash; 高德 &ndash;&gt;-->
          <!--            <RegionsChooseAmap v-model="regionData" :options="cityData" :default-value="formData.addressName"-->
          <!--                               :readonly="checkColumnIsEdit('addressName')"-->
          <!--                               @on-choose="chooseAddress"></RegionsChooseAmap>-->
          <!--          </DkFormItem>-->
          <!--门牌号-->
          <DkFormItem prop="addressNo" :required="true">
            <InputPop ref="addressNo" :readonly="checkColumnIsEdit('addressNo')"
                      v-model="formData.addressNo"
                      @input="setAddressFull"/>
          </DkFormItem>
          <!--联系人-->
          <DkFormItem prop="contactName">
            <InputPop ref="contactName" :readonly="checkColumnIsEdit('contactName')"
                      v-model="formData.contactName"/>
          </DkFormItem>
          <!--客户地址-->
          <DkFormItem prop="addressFull" :required="true">
            <InputPop ref="addressCustomerFull" :readonly="true" v-model="formData.addressFull"/>
          </DkFormItem>
          <!--业务员-->
          <DkFormItem prop="staffId" :label="$t('staffId')" :required="true">
            <SelectMagnifier v-model="formData.staffId" :display-text="formData.staffName"
                             :type="this.$config.MagnifierType.staff"
                             @ok="staffOk"
                             :initSearchFlag="true"
                             :readonly="checkColumnIsEdit('staffId')"
                             :multiple="false"/>
          </DkFormItem>
          <!--业务部门-->
          <DkFormItem prop="orgId" :label="$t('orgId')" :required="true">
            <SelectMagnifier v-model="formData.orgId" :display-text="formData.orgName"
                             :type="this.$config.MagnifierType.staff"
                             @ok="orgOk"
                             :initSearchFlag="true"
                             :readonly="checkColumnIsEdit('orgId')"
                             :multiple="false"/>
          </DkFormItem>
          <!--销售渠道-->
          <DkFormItem prop="saleChannel" :required="true">
            <!-- <InputPop ref="saleChannel" :readonly=true v-model="formData.saleChannel"/> -->
            <SelectPop v-model="formData.saleChannel" ref="channel"
                       :options="channelList"
                       :multiple="false"
                       :disabled="checkColumnIsEdit('saleChannel')"
                       labelKey="channelName"
                       valueKey="channelId">
            </SelectPop>
          </DkFormItem>
          <!--客户来源-->
          <DkFormItem prop="customerFrom" :required="true">
            <SelectPop v-model="formData.customerFrom" ref="customerFrom" :multiple="false"
                       :options="customerFromList"
                       :disabled="checkColumnIsEdit('customerFrom')"
                       labelKey="fromName"
                       valueKey=fromId>
            </SelectPop>
          </DkFormItem>
          <!--装修户型数-->
          <DkFormItem prop="toiletCount" :required="true">
            <SelectPop v-model="formData.toiletCount" :multiple="false" :options="tolietsList"
                       :disabled="checkColumnIsEdit('toiletCount')" ref="toiletCount"
                       labelKey="toiletsName"
                       valueKey=toiletsId>
            </SelectPop>
          </DkFormItem>
          <!--装修类型-->
          <DkFormItem prop="fitupType" :required="true">
            <SelectPop v-model="formData.fitupType" ref="fitupType" :multiple="false"
                       :options="customerFitupType"
                       :disabled="checkColumnIsEdit('fitupType')"
                       labelKey="dataValue"
                       valueKey="dataId"/>
          </DkFormItem>
          <!--房屋类型-->
          <DkFormItem prop="houseType" :required="false">
            <SelectPop v-model="formData.houseType" ref="houseType" :multiple="false" :options="houseType"
                       :disabled="checkColumnIsEdit('houseType')"
                       labelKey="dataValue"
                       valueKey=dataId>
            </SelectPop>
          </DkFormItem>
          <!--装修风格-->
          <DkFormItem prop="fitupStyle" :required="false">
            <SelectPop v-model="formData.fitupStyle" ref="fitupStyle" :multiple="false"
                       :options="customerfitupStyle"
                       :disabled="checkColumnIsEdit('fitupStyle')"
                       labelKey="dataValue"
                       valueKey="dataId"/>
          </DkFormItem>
          <!--年龄构成-->
          <DkFormItem prop="ageComposition" :required="false">
            <SelectPop v-model="formData.ageComposition" ref="ageComposition" :multiple="false"
                       :options="customerAgeComposition"
                       :disabled="checkColumnIsEdit('ageComposition')"
                       labelKey="dataValue"
                       valueKey="dataId"/>
          </DkFormItem>
          <!--决策者-->
          <DkFormItem prop="decisionMaker" :required="false">
            <SelectPop v-model="formData.decisionMaker" ref="decisionMaker" :multiple="false"
                       :options="customerDecisionMaker"
                       :disabled="checkColumnIsEdit('decisionMaker')"
                       labelKey="dataValue"
                       valueKey="dataId"/>
          </DkFormItem>
          <!--单据备注-->
          <DkFormItem prop="remarks">
            <InputPop ref="remarks" v-model="formData.remarks" :readonly="checkColumnIsEdit('remarks')"
                      maxlength=500 textareaFlag/>
          </DkFormItem>
          <!--入库日期-->
          <DkFormItem prop="entryTime">
            <DatePickerPop v-model="formData.entryTime"
                           :placeholder="$t('inputWords',{'search-name':$t('entryTime')})"
                           type="date" :short-cut-flag="true" :readonly="true"/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <!--商品信息-->
      <DkPanel prop="goodsInformation">
        <div id="search-cond-div-goods-info" ref="search-cond-div-goods-info" slot="content">
          <EditTable ref="goodsTable" :data="formData.goodsList" showFooter
                     combined-field="promotionId"
                     name="table"
                     :operate-flag="false"
                     :columns="goodsColumns" controlId="skuId"
                     @on-choose="getTotals"
                     @changeValue="changeValue"
          ></EditTable>
          <div>
            <DkForm ref="goodsFootFormData" v-model="goodsFootFormData"
                    class="form-content-class">
              <!--货物金额-->
              <DkFormItem prop="sumGoodsAmount">
                <InputNumberPop ref="sumGoodsAmount" v-model="goodsFootFormData.sumGoodsAmount" :readonly="true"
                                :digits="2"/>
              </DkFormItem>
              <!--总重量-->
              <DkFormItem prop="sumWeight">
                <InputNumberPop ref="sumWeight" v-model="goodsFootFormData.sumWeight" :digits="2"
                                :readonly="true" unit="KG"/>
              </DkFormItem>
              <!--总体积-->
              <DkFormItem prop="sumVolume">
                <InputNumberPop ref="sumVolume" v-model="goodsFootFormData.sumVolume" :digits="5"
                                :readonly="true" unit="m³"/>
              </DkFormItem>
            </DkForm>
          </div>
        </div>
      </DkPanel>
      <!--附件-->
      <DkPanel prop="files">
        <div id="search-cond-div-files-info" ref="search-cond-div-files-info" slot="content">
          <DkPicWall v-model="formData.annexPaths" :disabled="this.allCanNoEdit?true:false"
                     folder="t_order/annex_paths" :accept="$config.uploadFileConfig.acceptPicType"
                     :format="['jpg','jpeg','png']"></DkPicWall>
        </div>
      </DkPanel>
    </DkCollapse>
    <!--下部分按钮区域-->
    <DkSaveButton ref="saveButton" :disabled="allCanNoEdit" :showQuotation=true :loading="loading" @save="submitForm"
                  @close="closeForm"></DkSaveButton>
  </div>
</template>

<script>
import {formMixin} from '@/mixins/form'

export default {
  name: 'sale-return',
  mixins: [formMixin],
  data() {
    let self = this
    return {
      loading: false,
      allCanNoEdit: false, //是否所有的都不允许编辑
      customerPhoneReadOnly: false,//电话是否可以只读
      // 画面表单数据
      formData: {
        //所属公司
        ascpId: this.$store.state.user.ascpId,
        sale1Id: this.$store.state.user.sale1Id,
        sale2Id: this.$store.state.user.sale2Id,
        orderId: 0, //订单Id
        orderNo: null,
        entryId: null,
        rejectId: null,
        editTime: null,
        orderStatus: null,//订单状态
        docCode: null,//单据类型
        contractNo: null,//合同号
        customerId: null,//客户Id
        customerName: null,
        customerPhone: null,
        contactName: null,
        contactPhones: null,
        addressArea: {},//行政区
        customerDistrict: {},//记录选择的客户区域
        addressName: null,//小区档案
        addressGcj02: null,//地址坐标
        addressNo: null,//门牌号
        addressFull: null,//详细地址
        staffId: null,
        staffName: null,
        staffCode: null,
        staffNames: null,
        staffList: [],//存放从业务员id和分配百分比
        orgId: null,
        orgName: null,
        orgCode: null,
        orgNames: null,
        orgList: [],//存放从业务部门id和分配百分比
        channelId: null, //销售渠道
        toiletCount: null,//装修户型数
        customerFrom: null,//客户来源
        customerType: null,//客户类型
        houseType: null,//房屋类型
        fitupType: null,//装修类型
        fitupStyle: null,//装修风格
        ageComposition: null, //年龄构成
        decisionMaker: null,//决策者
        deliveryTime: null,//送货时间
        estateId: null,//小区档案
        designStatusFlag: false,//设计状态标识
        remarks: null,
        goodsList: [],
        goodsSocial: [],//记录列表的原始数据
        feeFormData: {},
        files: [],
        feeList: [], //费用金额
        sumFeeAmount: 0,//累计费用金额
        receiptList: [], //定金金额
        // 附件
        annexPaths: [],
        // 送货员
        deliveryUser: null,
        // 安装员
        installUser: null,
      },
      regionData: [],
      cityData: [],
      channelList: [],
      customerFromList: [],//客户来源
      tolietsList: [],//装修户型数
      //装修风格
      customerfitupStyle: [],
      //装修类型
      customerFitupType: [],
      //年龄构成
      customerAgeComposition: [],
      //决策者
      customerDecisionMaker: [],
      //客户类型
      customerType: [],
      //房屋类型
      houseType: [],
      goodsColumns: [
        //商品型号
        {
          field: 'skuModel',
          type: 'disabled',
          width: '200',
        },
        //唯一编码
        {
          field: 'skuCode',
          type: 'disabled',
          width: '255',
        },
        //商品名称
        {
          field: 'skuName',
          type: 'disabled',
          width: '255',
        },

        //退货数量
        {
          field: 'rejectQuantity',
          title: self.$t('nowRejectQuantity'),
          width: '120px',
          type: 'disabled',
          digits: 0,
          sum: true
        },
        //入库数量
        {field: 'entryGoingQuantity', width: '120px', type: 'number', digits: 0, dataType: 'number', sum: true},
        {
          copyVisible: this.type === this.$config.formMode.handle,
          field: 'whId',
          type: 'select',
          options: () => self.warehouseList,
          labelKey: 'whName',
          valueKey: 'whId',
          //equal: true,
          dataType: self.$config.tableSelectType.warehouse,
          fieldUpdate: [
            {updateField: 'warehouseName', valueFiled: 'whName'},
            {updateField: 'whId', valueFiled: 'whId'},
          ],
          searchDataFlag: false,
        },
        {field: 'nonStandardCode', type: 'text',}, //非标号
        {field: 'brandName', type: 'disabled'},//商品品牌
        {field: 'skuTypeName', type: 'disabled'},//型号分类
        {field: 'remarks', type: 'text', width: 300},
      ],
      //商品合计信息
      goodsFootFormData: {
        sumRejectGoodsAmount: null,
        sumStandard: 0,
        sumPromotion: 0,
        discountPromotion: 0,
        discountStandard: 0,
        sumVolume: 0,
        sumWeight: 0,
      },
      feeList: [],//费用项目
      receiptList: [],//定金
      //是否显示出库日期
      warehouseList: [],
    }
  },
  methods: {

    /**
     *   @desc   : 获取客户资料并且监听每一次的客户修改
     *   @date   : 2022/5/24 15:04
     *   @author : 付斌
     */
    selectCustomer(value) {

    },
    /**
     *   @desc   : 选择地址
     *   @date   : 2022/6/9 19:15
     *   @author : 付斌
     */
    chooseAddress(value) {

    },
    /**
     *   @desc   : 拼写详细地址
     *   @date   : 2022/6/9 10:08
     *   @author : 付斌
     */
    setAddressFull(e) {

    },
    /**
     * @desc   : desc
     * @author : 付斌
     * @date   : 2022/6/23 8:48
     */
    changeValue(field, row, rowIndex) {

    },
    /**
     *   @desc   : 获取商品表格中数量、金额后计算总单信息
     *   @date   : 2022/5/30 15:31
     *   @author : 付斌
     */
    getTotals(field, row, rowIndex) {
    },
    /**
     * @desc   : 关闭窗体
     * @author : 付斌
     * @date   : 2022/6/21 19:18
     */
    closeForm() {

    },
    /**
     * @desc   : 提交事件
     * @author : 付斌
     * @date   : 2022/03/04 13:17
     */
    submitForm(value) {

    },
    /**
     *   @desc   : 获取业务员相关
     *   @date   : 2022/5/28 10:43
     *   @author : 付斌
     */
    staffOk(val) {

    },
    /**
     *   @desc   : 获取业务员相关
     *   @date   : 2022/5/28 10:43
     *   @author : 付斌
     */
    orgOk(val) {

    },
    /***************************列表及其他事件************************************/


    /***************************设定参数函数************************************/
    /***************************created调用数据接口函数************************************/

    /**
     * @desc   : 通过id查询
     * @author : 付斌
     * @date   : 2022/03/04 13:17
     */
    detail(id) {

    },
    /**
     * @desc   : 判断列是否可以编辑
     * @author : 付斌
     * @date   : 2022/6/21 16:42
     */
    checkColumnIsEdit(field) {

    },
  },

  /**
   * @desc   : 在实例创建完成后被立即同步调用
   * @author : 付斌
   * @date   : 2022/3/3 10:32
   */
  created() {
    this.focusItem = 'saleReturnId';    // 给第一个组件赋值，可以在混入中自动去聚焦
    this.primaryKey = 'saleReturnId'  // 设置主键Id
  },
}
</script>
